akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
can_cost = sorted([cost[a] for a in A])
D = {}
for a in A:
    c = cost[a]
    D[c] = max(a, D.setdefault(c, -1))

min_cost = can_cost[0]
min_cost_num = D[min_cost]


def f2(v, l, num):
    L = list(str(v))
    min_cost = cost[int(num)]
    num = D.setdefault(min_cost + l, -1)
    if num == -1:
        return -1

    min_cost_num = D[min_cost]
    L[L.index(str(min_cost_num))] = str(num)
    L.sort(reverse=True)
    return int("".join(L))


def f(v, l):
    L = list(str(v))
    set_L = set(L)
    L2 = [f2(v, l, num) for num in set_L]
    return max(L2)

def g(K, r):
    temp = int("".join([str(min_cost_num)] * K))
    dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]
    dp[0][0] = temp

    for k in range(min(r, K)):
        for n in range(r):
            v = dp[n][k]
            if v == -1:
                continue
            for l in range(1, r - n + 1):
                dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))
    return max(dp[r])

K = N // min_cost
r = N - K * min_cost
res = g(K, r)
if g(K, r) == -1:
    res = g(K - 1, r + min_cost)
print(res)

Measured memory_bytes: 3192
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		if(a.length()==1) {
			if(a.charAt(0)=='3') {
				System.out.println("bon");
			}else if(a.charAt(0)=='0'||a.charAt(0)=='1'||a.charAt(0)=='6'||a.charAt(0)=='8') {
				System.out.println("pon");
			}else {
				System.out.println("hon");
			}
		}else if(a.length()==2) {
			if(a.charAt(1)=='3') {
				System.out.println("bon");
			}else if(a.charAt(1)=='0'||a.charAt(1)=='1'||a.charAt(1)=='6'||a.charAt(1)=='8') {
				System.out.println("pon");
			}else {
				System.out.println("hon");
			}
		}else{
			if(a.charAt(2)=='3') {
				System.out.println("bon");
			}else if((a.charAt(2)=='0')||(a.charAt(2)=='1')||(a.charAt(2)=='6')||(a.charAt(2)=='8')) {
				System.out.println("pon");
			}else {
				System.out.println("hon");
			}
		}

	}
}

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

int main()
{
	string str;
	int n;

	cin >> n;
	cin >> str;

	int m = 0;
	for (int i = 0; i < n; i++) {
		if ((str[i] == 'O') && (str[i + 1] == 'X')) {
			m++;
			i++;
		}
		else if ((str[i]=='X')&&(str[i+1]=='O'))
		{
			m++;
			i++;
		}
	}
	cout << m << endl;

	return 0;
}


Measured memory_bytes: 3336
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, m, now = 0,ans = 0;
vector<pair<ll, ll>> p;
int main() {
	cin >> n >> m;
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(ALL(p));
	REP(i,n){
		ans += min(m - now, p[i].second) * p[i].first;
		now += min(m - now, p[i].second);
		
		if (now == m) {
			cout << ans << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <set>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

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

int main(void){
    int n;
    cin >> n;
    
    /*
    REP(i, 200){
        REP(j, 200){
            REP(k, 200){
                int tmp = (x + y) * (x + y) + (y + z) * (y + z) + (z + x) * (z + x);
                if(tmp == 2 * n) ctr++;
            }
        }
    }
    */
    
    for(int i = 1; i <= n; i++){
        int ctr = 0;
        
        for(int x = 2; x * x<= n; x++){
            for(int y = x; y * y <= n; y++){
                int z = sqrt(2 * i - x * x - y * y);
                
                
                if(z * z == 2 * i - x * x - y * y && z >= y){
                    //cout << i << ":" << x << " " << y << " " << z << endl;
                    
                    set<int> st;
                    st.insert(x);
                    st.insert(y);
                    st.insert(z);
                    /*
                    if(st.size() == 1) ctr++;
                    else if(st.size() == 2) ctr += 3;
                    else ctr += 6;
                    */
                    
                    int a = (x - y + z) /2, b = (x + y - z) / 2, c = (-x + y + z) / 2;
                    if(a >= 1 && b >= 1 && c >= 1){
                        if(st.size() == 1) ctr++;
                        else if(st.size() == 2) ctr += 3;
                        else ctr += 6;
                    }
                    
                }
            }
        }
        cout <<ctr << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3744
N = int(input())
h_ls = [int(i) for i in input().split()]
flg = True
for i in range(N-2, -1, -1):
    if h_ls[i] - h_ls[i + 1] > 1:
        flg = False
        break
    elif h_ls[i] - h_ls[i + 1] == 1:
        h_ls[i] -= 1
if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  int n;
  cin >> n;
  
  int num[220];
  
  int ans = 0;
  REP(i,n) cin >> num[i];

  for(;;){
    REP(i,n){
      if(num[i] % 2 == 1){
      cout << ans << endl; return 0;
      }
      num[i] /= 2;
    }
    ans++;
  }

 return 0;
}

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

using namespace std;

# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


#define M_DEBUG if (1)

/******************************************************************************
	Main
******************************************************************************/
int main()
{
	int n = 0, m = 0;
	cin >> n >> m;
	assert(m >= 0 && m <= n);
	assert(n >= m && n <= 100);

	int a_list[101] = {0};
	int sum_a = 0;
	rep(i, n){
		cin >> a_list[i];
		assert(a_list[i] >= 1 && a_list[i] <= 1000);
		sum_a += a_list[i];
	}
	double border = double(sum_a) / double(4*m);
	int over_count = 0;
	rep(i, n){
		if (a_list[i] >= border) {
			over_count++;
		}
	}
	string ret = "No";
	if (over_count >= m) ret = "Yes";
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())
sum_1 = 0
sum_2 = 0
ct_1 = 0
if (A-1) % 2:
    if A//2 % 2:
        ct_1 += 1
    else:
        pass
else:
    if (A-1)//2 % 2:
        sum_1 += A-1
        ct_1 += 1
    else:
        sum_1 += A-1
if B % 2:
    if (B+1)//2 % 2:
        ct_1 += 1
    else:
        pass
else:
    if B//2 % 2:
        sum_2 += B
        ct_1 += 1
    else:
        sum_2 += B

if ct_1 % 2:
    ct_1 = 1
else:
    ct_1 = 0

print(ct_1 ^ sum_1 ^ sum_2)


Measured memory_bytes: 3064
array = list(map(int, input().split()))
A = array[0]
B = array[1]
C = array[2]
D = array[3]

if A >= C:
    start = A
else:
    start = C

if B >= D:
    end = D
else:
    end = B

ans = end - start

if ans < 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var A = parseInt(input[0].split(" ")[1]);
  var B = parseInt(input[0].split(" ")[2]);
  var ans ="";
  var x = Math.max(0,A+B-N);
  var y = Math.min(A,B);
  var ans = y + " " + x;

  
  
  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n: u32 = n.trim().parse().unwrap();

    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let vec: Vec<_> = s.trim().chars().collect();

    let mut wv: Vec<u32> = Vec::new();
    let mut total = 0;
    for i in 0..n {
        if vec[i as usize] == 'W' {
            total += 1;
        }
        wv.push(total);
    }

    let mut min = n;
    for i in 0..n {
        let num = if i == 0 {
            (n - 1) - (wv[(n-1) as usize] - wv[0])
        } else {
            wv[(i-1) as usize] + (n - i - 1) - (wv[(n-1) as usize] - wv[i as usize])
        };
        if num < min {
            min = num;
        }
    }
    println!("{}", min);
}


Measured memory_bytes: 8444
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
int n,m;
int main(){
    read(n),read(m);
	cout<<n*(n-1)/2+m*(m-1)/2; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=3e5+5;
const int mod=998244353;

int n,a,b,f[N],in[N];
long long k;

void add(int &x, int y){
	x+=y;
	if (x>=mod){
		x-=mod;
	}
}

int poww(int x, int e){
	int ret=1;
	while (e){
		if (e&1){
			ret=1ll*ret*x%mod;
		}
		x=1ll*x*x%mod;
		e>>=1;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b >> k;
	f[0]=in[0]=1;
	for (int i=1;i<=n;i++){
		f[i]=1ll*f[i-1]*i%mod;
		in[i]=poww(f[i],mod-2);
	}
	int ans=0;
	for (int i=0;i<=n;i++){
		if (1ll*i*a>k){
			break;
		}
		if (!((k-1ll*i*a)%b)&&
		(k-1ll*i*a)/b<=n){
			int j=(k-1ll*i*a)/b;
			add(ans,1ll*f[n]*in[i]%mod*in[n-i]%mod*
			f[n]%mod*in[j]%mod*in[n-j]%mod);
		}
	}
	cout << ans << "\n";
}

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

using namespace std;
int d[100010];

int h(int n,int g[])
{

    if(n==1)
    {
        return 0;
    }
    if((n==2)||(n==3))
    {
        return abs(g[n-1]-g[0]);
    }
    if(d[n]!=-1){
        return d[n];
    }
    d[n]=min(abs(g[n-1]-g[n-2])+h(n-1,g),abs(g[n-1]-g[n-3])+h(n-2,g));
    return d[n];
}
int main()
{
    int n;
    cin>>n;
    int g[n];
    for(int i=0;i<100010;i++){
        d[i]=-1;
    }
    for(int a=0;a<n;a++)
    {
        cin>>g[a];
    }
    cout << h(n,g) << endl;
    return 0;
}


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


int main(){
    int N;
    scanf("%d",&N);
    
    int A[N][N];
    for(int i=0;i!=N;++i){
        for(int j=0;j!=N;++j){
            A[i][j]=-1;
        }
    }
    for(int i=0;i!=N;++i){
        int a;
        scanf("%d",&a);
        for(int j=0;j!=a;++j){
            int x,y;
            scanf("%d",&x);
            scanf("%d",&y);
            A[i][x-1]=y;
        }
    }
    
   
    int ans=0;
    for(int bit=0;bit!=(1<<N);++bit){
        int d[N];
        for(int i=0;i!=N;++i){
            if(bit>>i&1){
                d[i]=1;
            }else{
                d[i]=0;
            }
        }
        
         bool ok=true;
       
        for(int i=0;i!=N;++i){
            if(d[i]){
                for(int k=0;k!=N;++k){
                    if(A[i][k]==-1)continue;
                    if(A[i][k]!=d[k])ok=false;
                }
            }
        }
        if(ok){
            ans=max(ans,__builtin_popcount(bit));
        }
    }
    printf("%d\n",ans);
    
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  char s[4];
  scanf("%s",s);
  
  int a=0,b=0,c=0;
  int i;
  for(i=0;i<3;i++){
    switch(s[i]){
      case 'a':
        a=1;
        break;
      case 'b':
        b=1;
        break;
      case 'c':
        c=1;
        break;
    }
  }
  
  if(a==1&&b==1&&c==1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, m;
ll dp[1005][1005];
char grid[1005][1005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n>>m;
    f(i, n){
        f(j, m){
            cin>>grid[i][j];
        }
    }
    f(i, n){
        f(j, m){
            if(i == 0 && j == 0) {
                dp[i][j] = 1;
                continue;
            }
            if(grid[i][j] == '.'){
                if(i - 1 >= 0) dp[i][j] = add(dp[i][j], dp[i - 1][j]);
                if(j - 1 >= 0) dp[i][j] = add(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    cout<<dp[n - 1][m - 1];
    return 0;
}

Measured memory_bytes: 9088
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N-1; i++ {
		var j int
		fmt.Scan(&j)
		A[j-1] += 1
	}
	for _, a := range A {
		fmt.Println(a)
	}
}


Measured memory_bytes: 6456
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <numeric>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  int n, m, c, ans=0;

  cin >> n >> m >> c;
  vector<int> b(m), a(m);

  for (int j = 0; j < m; j++)
  {
    cin >> b[j];
  }

  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      cin >> a[j];
    }

    if(inner_product(a.begin(), a.end(), b.begin(), 0)+c>0){
      ans++;
    }

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,b,a) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<#x" = "<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nex)
typedef pair<int,int> pii;
typedef long long ll;
const int inf=~0u>>1,MOD=1e9+7;/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=((TT=but)+fread(but,1,1<<15,stdin)),TT==mo))?-1:*TT++)//*/
inline int rd() {
	int x=0,c=0,f=1;
	for(; c<'0'||c>'9'; c=getchar())f=c!='-';
	for(; c>='0'&&c<='9'; c=getchar())x=x*10+c-'0';
	return f?x:-x;
}
const int N=2e6;
ll fac[N+11],facinv[N+11];
ll inv(ll x){return x<=1?x:(MOD-MOD/x)*inv(MOD%x)%MOD;}
void init(){
	fac[0]=1;
	rep(i,1,N)fac[i]=fac[i-1]*i%MOD;
	facinv[N]=inv(fac[N]);
	//debug(facinv[N]);
	per(i,N-1,0)facinv[i]=facinv[i+1]*(i+1)%MOD;
}
inline ll C(int x,int y){
	return fac[x]*facinv[y]%MOD*facinv[x-y]%MOD;
}
int main(){
	init();
	int H=rd(),W=rd(),A=rd(),B=rd();
	ll ans=0;
	for(int i=H-A,j=W-B;i&&j;i--,j--){
		//cout << i << " " << j << endl;
		//debug(C(i+1-2+W-j,i-1));
		//debug(C(H-i+j-1,j-1));
		ans+=(C(i-1+W-j,i-1)*(C(H-i+j-1,j-1)))%MOD;
	}
	cout<<ans%MOD<<endl;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll k;cin>>k;
   ll ans=0;
   for(int i=1;i<=k;i++)
    for(int j=1;j<=k;j++)
    for(int l=1;l<=k;l++)
    ans+=__gcd(i,__gcd(j,l));
   cout<<ans<<endl;
}


Measured memory_bytes: 3620
/// awoooooo

# include <bits/stdc++.h>

# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int l[N];

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= 2 * n; ++i){
    scanf("%d", l + i);
  }
  sort(l + 1, l + 1 + 2 * n);
  int ans = 0;
  for(int i = 2 * n - 1; i > 0; i -= 2){
    ans += l[i];
  }
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a;
	cin>>a;
	if(a>=30)
		cout<<"Yes";
	else
		cout<<"No";
		
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int l = s.length();
        boolean flag = false;
        for (int i = 1; i < s.length(); i++) {
            String ss = s.substring(0, l - i);
                if (ss.substring(0, (l - i) / 2).equals(ss.substring((l - i) / 2 , l - i)))
                    if ((l - i) % 2 == 0) {
                        System.out.println(l-i); break;
                    }
                    else {
                        System.out.println(l-i-1); break;
                    }
        }
    }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n, u, v;
vector<vector<int>> p, parentk;
vector<int> d2, d, parent;

void dfs(int i, int dep, int from) {
  d[i] = dep;
  parent[i] = from;
  if (i == v) return;
  for (auto &j : p[i]) {
    if (j == from) continue;
    dfs(j, dep + 1, i);
  }
}

int lca(int i, int j) {
  if (d[i] < d[j]) swap(i, j);
  int k = 22;
  while (k >= 0 && d[i] > d[j]) {
    if (d[parentk[k][i]] >= d[j]) {
      i = parentk[k][i];
    }
    k--;
  }
  k = 22;
  if (i == j) return i;
  while (k >= 0 && i != j) {
    if (parentk[k][i] != parentk[k][j]) {
      i = parentk[k][i];
      j = parentk[k][j];
    }
    k--;
  }
  return parent[i];
}

void dfs2(int i, int dep, int from) {
  if (i == v) return;
  d2[i] = dep;
  for (auto &j : p[i]) {
    if (from == j) continue;
    dfs2(j, dep + 1, i);
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  u--;
  v--;
  p.resize(n);
  d.resize(n);
  d2.resize(n);
  parent.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  dfs(u, 0, u);
  ll ans = 0;
  vector<int> q;
  int w = v;
  while (w != u) {
    q.push_back(w);
    w = parent[w];
  }
  q.push_back(u);
  if (q.size() == 1) {
    cout << 0 << endl;
  }
  if (q.size() % 2 == 0) {
    v = q[q.size() / 2 - 1];
    dfs2(q[q.size() / 2], 0, -1);
    cout << q.size() / 2 - 1 + *max_element(d2.begin(), d2.end()) << endl;
  } else {
    v = q[q.size() / 2];
    dfs2(q[q.size() / 2 + 1], 0, -1);
    cout << (q.size() - 2) / 2 + *max_element(d2.begin(), d2.end()) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 10496
fun main(args:Array<String>) {
    val a = readLine()!!
    val b = readLine()!!
    val ls:List<String> = listOf(a,b)
    val l:MutableList<String> = mutableListOf("1","2","3")
    for (x in ls) {
        l.remove(x)
    }
    println(l[0])
}

Measured memory_bytes: 32232
import numpy as np
mod=10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%mod)

Measured memory_bytes: 48820
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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

vector<P> g[210000];

pair<int, int> dfs(int idx, int par) {
    pair<int, int> ret(0, idx);
    for(auto e : g[idx]) {
        if(e.sc == par) continue;
        auto cost = dfs(e.sc, idx);
        cost.first += e.fs;
        ret = max(ret, cost);
    }
    return ret;
}

int tree_diameter(){
    auto p = dfs(0, -1);
    auto q = dfs(p.second, -1);
    return (q.first);
}


int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(P(1, b));
        g[b].emplace_back(P(1, a));
    }

    int d = tree_diameter();
    if(d % 3 == 1){
        cout << "Second" << endl;
    }
    else{
        cout << "First" << endl;
    }

    return 0;
}


Measured memory_bytes: 27008
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define each(i, c) for (auto& (i) : (c))

using namespace std;
typedef long long int ll;
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }

int main() {
    string s;
    cin >> s;
    set<char> cs;
    bool ng = false;
    for (int i = 0; i < s.size(); i++) {
        if (cs.find(s[i])!= cs.end()) {
            ng = true;
        }
        cs.insert(s[i]);
    }
    cout << (ng ? "no" : "yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a[3]; REP(i,3) cin >> a[i];
  int ans=INF,tot=0;
  REP(i,3) {
    tot = 0;
    REP(j,3) tot += abs(a[i]-a[j]);
    ans=min(ans,tot);
  }
  COUT(ans);
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <unordered_map>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;




int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n;
	cin >> n;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	bool used = false;
	for (int i = 0; i < n; i++) {
		if (a[i] != i) {
			if (used) {
				cout << "NO" << endl;
				return 0;
			}
			if (a[a[i]] == i) {
				swap(a[i], a[a[i]]);
				used = true;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long n;
	long brk = 0;
	long a=0,b;
	long i;
	
	scanf("%ld",&n);
	
	for(i=0;i<n;i++){
		scanf("%ld",&b);
		if(b!=a+1)
			brk++;
		else
			a=b;
		
	}
			
	if(brk==n)
		printf("-1");
	else
		printf("%ld",brk);
	return 0;
}

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

int main(){
  int M, D;
  cin >> M >> D;
  int ans = 0;
  for(int i = 1; i < M + 1; i++){
    for(int j = 1; j < D + 1; j++){
      int d1 = j / 10;
  	  int d2 = j % 10;
      if(d1 >= 2 && d2 >=2 && i == d1 * d2){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


struct sushi{
  ll p, t;
  bool friend operator<(sushi a, sushi b){
    return a.p<b.p;
  }
  bool friend operator>(sushi a, sushi b){
    return a.p>b.p;
  }
};

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  vector<sushi> v;
  rep(i, N){
    sushi tmp;
    cin >> tmp.t >> tmp.p;
    v.push_back(tmp);
  }
  sort(ALL(v), [](sushi a, sushi b){return a>b;});
  map<ll, ll> types;
  stack<sushi> q;
  ll ans = 0;
  rep(i, K){
    q.push(v[i]);
    types[v[i].t]++;
    ans += v[i].p;
  }
  ans += types.size()*types.size();
  ll focus=K;
  //cout << ans << " " << types.size() << endl;
  ll prevans = ans;
  while(focus<N){
    if(types[v[focus].t]>0){
      //種類ポイントは増えない
    }else{
      while(!q.empty()){
        sushi tmp = q.top();
        q.pop();
        if(types[tmp.t]==1){
          continue;
          //種類ポイントが減るのでこれは捨てない
        }else{
          types[tmp.t]--;
          ll cand=prevans;
          cand -= tmp.p;
          cand += v[focus].p;
          types[v[focus].t]+=1;
          cand+=(2 * types.size() -1 );
          ans = max(cand, ans);
          prevans = cand;
          //cout << ans << " "<< v[focus].t<< " "<< v[focus].p<< " " << types.size() << endl;
          break;
        }
      }
    }
    if(q.empty()){
      break;
    }
    focus++;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 7280
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()


def Z_algorithm(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i,j = 1,0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        # S[0:j] == S[i:i+j] となっている
        A[i] = j
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A


ans = 0
for i in range(N):
    A = Z_algorithm(S)
    for j in range(N-i):
        if A[j] <= j:
            ans = max(ans,A[j])
    del S[0]

print(ans)


Measured memory_bytes: 77032
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* s[100];
  int p[100];

int cmp(const int *a, const int *b){
  int c=strcmp(s[*a],s[*b]);
  if(c!=0)return c;
  else return p[*b]-p[*a];
}

int main(){
  int n;
  scanf("%d", &n);
  int m[n],i;
  for(i=0;i<n;i++){
    s[i]=(char*)malloc(sizeof(char*));
    scanf("%s%d", s[i], &p[i]);
    m[i]=i;
  }
  qsort(m,n,sizeof(int),cmp);
  for(i=0;i<n;i++){
    printf("%d\n", m[i]+1);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    String line = scanner.nextLine();
    String[] a = line.split(" ");
    for (int ii = 0; ii < a.length; ii++) {
      boolean flag = false;
      for (int jj = 0; jj < a[ii].length(); jj++) {
        if (a[ii].startsWith("apple", jj)) {
          a[ii] = a[ii].replace("apple", "peach");
          flag = true;
        }
      }
      if (!flag) {
        a[ii] = a[ii].replace("peach", "apple");
      }
      out += a[ii] + " ";
    }
    System.out.println(out.trim());
  }
}

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

int main() {
    string s;
    cin >> s;
    rep(i,3) {
        if(s[i] ==  '1') s[i] = '9';
        else s[i] = '1';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
N, A, B = [int(x) for x in input().split(" ")]
s = input()
num_passed = 0
num_passed_f = 0
for index, s in enumerate(s):
    if s == "a":
        if num_passed < A + B:
            print("Yes")
            num_passed += 1
            continue
    if s == "b":
        if num_passed < A + B and num_passed_f < B:
            print("Yes")
            num_passed += 1
            num_passed_f += 1
            continue
    print("No")


Measured memory_bytes: 4016
n,m = map(int, input().split())
nums = [-1]*n
for _ in range(m):
  s,c = map(int, input().split())
  s = int(s)-1
  if nums[s] != -1 and nums[s] != c:
    print(-1)
    exit()
  elif n > 1 and s == 0 and c == 0:
    print(-1)
    exit()
  nums[s] = c
  
for i in range(n):
  if nums[i] == -1:
    if i == 0:
      if n == 1:
        nums[0] = 0
      else:
        nums[0] = 1
    else:
      nums[i] = 0
ans = ""
for i in nums:
  ans += str(i)
print(ans)

Measured memory_bytes: 3064
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = 2

x,y = list(map(int,input().split()))

def ck(x,y):
  if x in a and y in a:
    yes()
  elif x in b and y in b:
    yes()
  elif x == c and y == c:
    yes()
  else:
    no()
    
def yes():
  print("Yes")

def no():
  print("No")
  
ck(x,y)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  int cnt=1,m; cin >>m;
  rep(i,n-1){
    int x; cin >>x;
    if(x<m){
      cnt++;
      m=x;
    }
  }
  printf("%d",cnt);
}

/// confirm df==0 ///


Measured memory_bytes: 256
// Nが小さいので適当に頭から探索してTを埋め込めたところで余った?はaにでもしておけ
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	SS, TT := make([]string, len(S)), make([]string, len(T))
	for i, c := range []rune(S) {
		SS[i] = string(c)
	}
	for i, c := range []rune(T) {
		TT[i] = string(c)
	}
	reverse(SS)
	reverse(TT)
	idx := -1
	for i := 0; i <= len(SS)-len(TT); i++ {
		if SS[i] == TT[0] || SS[i] == "?" {
			flag := true
			for j := 1; j < len(TT); j++ {
				if SS[i+j] == TT[j] || SS[i+j] == "?" {
					continue
				} else {
					flag = false
				}
			}
			if flag {
				idx = i
				break
			}
		}
	}
	if idx == -1 {
		fmt.Println("UNRESTORABLE")
	} else {
		for i := 0; i < len(SS); i++ {
			if idx <= i && i < idx+len(TT) {
				SS[i] = TT[i-idx]
			} else {
				if SS[i] == "?" {
					SS[i] = "a"
				}
			}
		}
		reverse(SS)
		fmt.Println(strings.Join(SS, ""))
	}
}

func reverse(arr []string) {
	for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
		arr[i], arr[j] = arr[j], arr[i]
	}
}


Measured memory_bytes: 640
<?php

fscanf(STDIN, '%d', $N);
$nums = array();
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    $nums[] = $n;
}

//与えられた整数の最も大きな値と10000を比較し小さい方
$max = min(max($nums), 10000);
//上記の値以下の素数を取得
$primes = eratosthenes($max);
$cnt = 0;

foreach ($nums as $n) {
    //最大値以下は素数配列に値があるか確認
    if ($n <= $max) {
        in_array($n, $primes) && $cnt++;
        continue;
    }

    //2の倍数は素数ではない
    if ($n % 2 === 0) {
        continue;
    }

    //10000以下の素数で割り切れるか確認
    $bool = true;
    foreach ($primes as $prime) {
        if ($n % $prime === 0) {
            $bool = false;
            break;
        }
    }

    //割り切れたので素数ではない
    if (!$bool) {
        continue;
    }

    //10001からループ(偶数は無視)
    for ($i = $max + 1, $len = sqrt($n); $i <= $len; $i += 2) {
        if ($n % $i === 0) {
            $bool = false;
            break;
        }
    }

    //割り切れない場合はカウント
    $bool && $cnt++;
}

echo $cnt, PHP_EOL;

//エラトステネスのふるい
function eratosthenes($n)
{
    $arr = array(0, 0) + array_fill(2, $n - 1, 1);
    for ($i = 2, $len = sqrt($n); $i <= $len; $i++) {
        if (!$arr[$i]) {
            continue;
        }

        for ($j = $i, $len2 = $n / $i; $j <= $len2; $j++) {
            $arr[$i * $j] = 0;
        }
    }

    return array_keys(array_filter($arr, function ($val) {
        return $val;
    }));
}

Measured memory_bytes: 10136
#include<iostream>
#include<stack>
using namespace std;
bool b[1234];
stack<int>s;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int p; cin >> p;
		if (p > 0) {
			if (b[p]) {
				cout << i + 1 << endl;
				return 0;
			}
			s.push(p); b[p] = 1;
		}
		else if (s.size() == 0 || s.top() != -p || !b[-p]) {
			cout << i + 1 << endl;
			return 0;
		}
		else {
			b[-p] = 0; s.pop();
		}
	}
	cout << "OK\n";
}


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

int main(){
    int n, r;
    cin >> n >> r;
    int ans = 0;
    if (n >= 10) {
        ans = r;
    } else {
        ans =r + 100*(10-n);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
vector<int> G[100000];
int fennec[100000], snuke[100000];
void dfs(int v, int p, int d,int *dist) {
	dist[v] = d;
	rep(i, G[v].size()) {
		if (G[v][i] == p) continue;
		dfs(G[v][i], v, d + 1, dist);
	}
}
int main() {
	int N;
	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, -1, 0, fennec);
	dfs(N - 1, -1, 0, snuke);
	int sum = 0;
	rep(i, N) {
		if (fennec[i] <= snuke[i]) sum++;
	}
	if (sum > N - sum) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
}

Measured memory_bytes: 14336
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double X = sc.nextDouble();

		int cnt = 0;
		double tmp = 100.0;
		while (tmp<X) {
			cnt++;
			tmp *= 1.01;
			tmp = Math.floor(tmp);
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 37360
#include<stdio.h>
int main()
{
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if(w>=(x+r)&&h>=(y+r)&&(x-r)>=0&&(y-r)>=0){
printf("Yes\n");
}else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()

int n;
int A[100010],co[100010];
set <int> S;
//int ans[100010];

int32_t main() {
	cin >> n;
	for (int i =1;i<=n;i++) {
		cin >> A[i];
		co[A[i]]++;
		S.insert(i);
	}
	
	if (n == 1) {
		cout << "1";
		return 0;
	} else if (n == 2) {
		 if (A[1] != 2) cout << "12";
		 else if (A[2] != 1) cout << "21";
		 else cout << "-1";
		 return 0;
	}
	
	int prev = n+1;
	//int co = 0;
	while (S.size() > 3) {
		auto it = S.begin();
		//Conditions to fail:
		//1: Cannot put it after previous
		//2: Guys from i to n all have the same ban on x AND x has not been used yet. 
		while (A[prev] == *it or (S.find(A[*it]) != S.end() and  co[A[*it]] == (int)S.size()-1)) it++;
		
		cout << *it << " ";
		prev = *it;
		co[A[*it]]--;
		S.erase(it);
	}
	
	vector <int> v;
	for (auto it: S) {
		v.push_back(it);
	}
	
	//cout << v[0] << " " << v[1] << " " << v[2] << "\n";
	while (true) {
		if (A[prev] != v[0] and A[v[0]] != v[1] and A[v[1]] != v[2]) {
			cout << v[0] << " " << v[1] << " " << v[2];
			return 0;
		}
		next_permutation(v.begin(),v.end());
	}
}









Measured memory_bytes: 6400
from collections import deque

import sys
sys.setrecursionlimit(10**6)

N = int(input())
AB = [list(map(int,input().split())) for i in range(N-1)]
nodes = [[-1, [], -1] for i in range(N+1)]

#入力を木構造に入力する
root = 1
nodes[root][0] = root
for i in range(N-1):
    a,b = AB[i]
    nodes[a][1].append(b)
    nodes[b][0] = a
#print(nodes)

K = len(nodes[1][1])

for i in range(2,N+1):
    K = max(K,len(nodes[i][1])+1)

Q = deque([root])

while len(Q) != 0:
    q = Q.popleft()
    children = nodes[q][1]
    root_color = nodes[q][2]
    i = 1
    for child in children:
        Q.append(child)
        if i == root_color:
            i += 1
        nodes[child][2] = i
        i += 1

#print(nodes)
print(K)
for a,b in AB:
    print(nodes[b][2])


Measured memory_bytes: 42428
//include
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
//マクロとか
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

//自前の関数たち
//最大公約数
ll GCD(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

//最小公倍数
ll LCM(ll a, ll b)
{
    return (a * b) / GCD(a, b);
}

//namespace my
namespace my
{
//配列の最大値or最小値を数値で返す関数
int max_element(std::vector<int> vec)
{
    std::sort(vec.begin(), vec.end());
    return vec.at(vec.size() - 1);
}
int min_element(std::vector<int> vec)
{
    std::sort(vec.begin(), vec.end());
    return vec.at(0);
}
} // namespace my

//yes,noを出力するやつ
void ans(bool qus)
{
    if (qus == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool qust)
{
    if (qust == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

//std名前空間を使用
using namespace std;

////////////////////////////////////////////////////////////////////////////////
//スタート

int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }

    bool flag = true;
    int count = 0;
    int j = 0;
    while (flag)
    {
        flag = false;
        for (int i = n - 1; i > j; i--){
            if (vec[i] < vec[i - 1]){
                swap(vec[i], vec[i - 1]);
                count++;
                flag = true;
            }
        }
        j++;
    }
    rep(i,n){
        if(i<n-1){
            cout << vec[i] << ' ';
        }
        else
        {
            cout << vec[i] << endl;
        }
        
    }
    cout << count << endl;
}


Measured memory_bytes: 3116
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vint a(n), b(n), c(n);
	rep(i, n)	cin >> a[i];	
	sort(all(a));
	rep(i, n)	cin >> b[i];
	sort(all(b));
	rep(i, n)	cin >> c[i];
	sort(all(c));
	ll ret = 0;
	vector<ll> bnum(n + 1, 0);
	rep(i, n) {
		bnum[i] = c.size() - (upper_bound(all(c), b[i]) - c.begin());
	}
	vector<ll> add = bnum;
	rrep(i, n)	add[i] += add[i + 1];
	rep(i, n) {
		ret += add[upper_bound(all(b), a[i]) - b.begin()];
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2944
n = int(input())
n %= 10

hon = [2,4,5,7,9]
pon = [0,1,6,8]
for i in hon:
	if n == i:
		print("hon")
		exit()
for i in pon:
	if n == i:
		print("pon")
		exit()
print("bon")

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main() {
	int N;
	cin >> N;
	int a, b, c, d;
	a = N / 1000;
	b = N / 100 - a * 10;
	c = N / 10 - a * 100 - b * 10;
	d = N % 10;
	if (a == b && a == c) cout << "Yes";
	else if (b == c && c == d) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            int[] tmp = new int[d];
            for (int j = 0; j < d; j++) {
                tmp[j] = sc.nextInt();
            }
            x[i] = tmp;
        }
        int ans = 0;
        for (int i = 0; i < n-1; i++) {
            for (int k = i+1; k < n; k++) {
                int sum = 0;
                for (int j = 0; j < d; j++) {
                    int a = x[i][j];
                    int b = x[k][j];
                    sum += Math.abs(a-b)*Math.abs(a-b);
                }
                if (Math.sqrt(sum) == (int)Math.sqrt(sum)) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21716
n = int(input())
li = [0]*(10001)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            tmp = x*x+y*y+z*z+x*y+y*z+z*x
            if tmp>10000:
                continue
            li[tmp] += 1
for i in range(1, n+1):
    print(li[i])

Measured memory_bytes: 69332
import Control.Monad
main = do
  n <- read <$> getLine
  (d:x:xs) <- map read . words <$> getLine
  ys <- forM [1..n] $ \t -> do
    read <$> getLine
  putStrLn . show $ solve d x ys

solve :: Int -> Int -> [Int] -> Int
solve d x ys = x + sum (map (\y -> 1 + (d-1) `div` y) ys)

Measured memory_bytes: 1020
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	// 入力
	string S, T;
	cin >> S >> T;
	string sJoin = S + S;

	string ans = "No";
	REP(i, T.length()) {
		int pos = sJoin.find(T);
		if (pos != string::npos) {
			ans = "Yes";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}



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

int main(){
    int n,A[100];
    cin >> n;
    for(int i =0; i<n;i++)cin>>A[i];
    for(int i=n-1; i>=0; i--){
        if(i!= n-1) cout<<" ";
    cout << A[i];
    
}
cout<<endl;
return 0;
}


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

int n,s[200],sum=0;

int main()
{
    scanf("%i",&n);
    for(int i=0;i<2*n;++i) scanf("%i",&s[i]);
    sort(s+0,s+2*n);
    for(int i=0;i<2*n;i+=2) sum+=s[i];
    printf("%i",sum);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll n, a[200005], ans;
vector<pll> v;

int main()
{
	scanf("%lld",&n);
	v.push_back({0ll, 0ll});
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		if(a[i]) v.push_back({a[i], i});
	}
	v.push_back({n+1, n+1});
	for(ll i=0;i+1<v.size();i++) {
		ll p = 0, x = 0;
		ll L = v[i+1].Y - v[i].Y - 1;
		ans += L * (L+1) / 2;
		if(!i) continue;
		for(ll j=i;j<v.size();j++) {
			p += v[j].X;
			x ^= v[j].X;
			if(j+1 == v.size() || p != x) {
				ans += (v[j].Y - v[i].Y) * (v[i].Y - v[i-1].Y);
				break;
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 7408
from heapq import heappush, heappop

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

for i in range(M):
  l, r, c = map(int, input().split())
  graph[l-1].append((r-1, c))

dist = [-1] * N
d = [(0, 0)]
while d:
  cost, node = heappop(d)
  if dist[node] >= 0:
    continue
  dist[node] = cost
  for child, c in graph[node]:
    if dist[child] >= 0:
      continue
    heappush(d, (cost+c, child))

print(dist[-1])

Measured memory_bytes: 45464