akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

int vis[110][110];
const int maxn = 11000;
int a[maxn], n, m, c;
int dir[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};

void dfs(int x, int y, int color) {
    vis[x][y] = color;
    a[color]--;
    if (a[color] == 0) color++;
    for (int i = 0; i < 4; i++) {
        int dx = x + dir[i][0], dy = y + dir[i][1];
        if (dx <= 0 || dy <= 0 || dx > n || dy > m || vis[dx][dy]) continue;
        dfs(dx, dy, color);
    }
}

int main() {
    scanf("%d%d", &n, &m);
    scanf("%d", &c);
    for (int i = 1; i <= c; i++) scanf("%d", &a[i]);
    dfs(1, 1, 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            printf("%d", vis[i][j]);
            if (j != m) putchar(' ');
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
//debug() << imie(x) imie(y);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
int n;cin>>n;
cout<<(n<1200?"ABC":"ARC");

return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())

W,H = abs(x1-x2),abs(y1-y2)



flip_x = x1 > x2
flip_y = y1 > y2

xo = min(x1,x2)
yo = min(y1,y2)

N = int(input())

F = []

for i in range(N):
  x,y = map(int,input().split())
  x -= xo
  y -= yo
  if 0 <= x <= W and 0 <= y <= H:
    if flip_x:
      x = W-x
    if flip_y:
      y = H-y
    F.append((x,y))

N = len(F)

from math import pi
from bisect import bisect


#直線の場合
L = (W+H)*100

if (W == 0 or H == 0) and F:
  L += pi*10-20
elif N > 0:
  # find LIS
  F.sort()
  F = [y for x,y in F]

  dp = [H+1]*len(F)

  for i,f in enumerate(F):
    dp[bisect(dp,f)] = f

  n = bisect(dp,H)

  L -= (20-pi*5)*n
  if n == min(W,H) + 1:
    L += pi*5

print(L)

Measured memory_bytes: 32380
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = h[k-1] - h[0];
    rep(i,n-k+1){
        chmin(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

int main() {
    boost();

    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) if (s[i] != t[i]) ans++;
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 3840
main :: IO ()
main = do
  line <- getLine
  let [s, t] = words line
  [numS, numT] <- getInts
  name <- getLine
  putStrLn $ (show $ getBallNum s numS name) ++ " " ++ (show $ getBallNum t numT name)

getBallNum :: String -> Int -> String -> Int
getBallNum name count removeName
  | name == removeName = count - 1
  | otherwise = count

getInts = do
  x <- getLine
  let y = (map $ read) $ words x :: [Int]
  return y


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
	vector <int> inputs( N );
	int maxi = 0;
	rep( i, 0, N ){
		scanf("%d", &inputs[i]);
		maxi = max( maxi, inputs[ i ] );
	}
	vector <bool> dp( maxi + 5, false ), is_appeared( maxi + 5, false );
	rep( i, 0, N ){
		int cnt = 2;
		if (is_appeared[ inputs[ i ] ]){
			dp[ inputs[ i ] ] = true;
			continue;
		}
		while(inputs[ i ] * cnt <= maxi + 1){
			dp[ inputs[ i ] * cnt ] = true;
			cnt++;
		}
		is_appeared[ inputs[ i ] ] = true;
	}
	int ans = 0;
	rep( i, 0, N ){
		if (!dp[ inputs[ i ] ]){
			ans++;
			dp[ inputs[ i ] ] = true;
		}
	}
	cout << ans << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


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

int main()
{
long long h,n; cin>>h>>n;
  int sum=0;
 for(int i=0;i<n;i++) 
 {
   long long int temp; cin>>temp;
   sum+=temp;
 }
  if(sum>=h)
 cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
N, K = map(int, input().split())
gems = [int(x) for x in input().split()]

max_price = 0
for pick in range(1, min(K, N) + 1):
    for left_pick_num in range(pick + 1):
        right_pick_num = max(pick - left_pick_num, 0)
        if not left_pick_num and not right_pick_num: continue
#        print("Pick {} from left, {} from right".format(left_pick_num, right_pick_num))
        picked = gems[:left_pick_num]
        if right_pick_num: picked += gems[-right_pick_num:]
#        print("Pick {} gems".format(pick))
#        print("The gems picked: {}".format(picked))
        picked.sort()
        num_throw = min(pick, K - pick)
        j = 0
        while j < num_throw and picked[j] < 0:
            j += 1
#        print("The gems picked after throwing: {}".format(picked[j:]))
        max_price = max(max_price, sum(picked[j:]))
print(max_price)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    ll N,x;
    cin >> N >> x;
    ll a[N+2];
    ll cumsum[N+1];
    a[0]=a[N+1]=0;
    cumsum[N] = 0;
    for(int i=1; i<N+1; ++i)
    {
        cin >> a[i];
        cumsum[i-1] = a[i] + a[i-1];
    }

    ll ans = 0;
    for (int i=0; i<N; ++i)
    {
        if(cumsum[i]>x)
        {
            ll diff = cumsum[i]-x;
            cumsum[i] -= diff;
            cumsum[i+1] -= diff;

            ans += diff;
        }
    }

    if(cumsum[N]>x) ans+= (cumsum[N]-x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int N;
    cin>>N;
    int one=0,two=0,thr=0,fou=0;
    rep(i,N){
        char s[2];
        cin>>s;
        if(s[0]=='P'){
            one=1;
        }else if(s[0]=='W'){
            two=1;
        }else if(s[0]=='G'){
            thr=1;
        }else{
            fou=1;
        }
    }
    if(one+two+thr+fou==3){
        cout<<"Three"<<endl;
    }else{
        cout<<"Four"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, x; cin >> n >> x;
    int a[100010];
    rep(i,0,n) cin >> a[i];
    int cnt = 0;
    rep(i,0,n-1) {
        if(a[i] + a[i+1] > x) {
            if(a[i] <= x) {
                int t = a[i+1] - (x - a[i]);
                a[i+1] -= t;
                cnt += t;
            }
            else {
                cnt += a[i+1];
                a[i+1] = 0;
                int t = a[i] - x;
                a[i] -= t;
                cnt += t;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
//abc149A
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  long long n, k, i, cou=0, tmp, a, b;

  scanf("%lld %lld %lld", &a, &b, &k);
  if(k > a){
    printf("%d", 0);
    if(k > a + b) printf(" %d", 0);
    else printf(" %lld", a + b - k);
  }else printf("%lld %lld", a - k, b);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s; cin >> s;
    string ret = "";
    rep(i,0,s.length()) {
        if(s[i] != 'B') ret += s[i];
        else {
            if(ret == "") continue;
            ret = ret.substr(0, ret.length() - 1);
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
//ABC146B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main(){
	int x;
	cin >> x;
	int a = x/100, b = x%100;
	if(5*a < b){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
}

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

int main()
{
	int r, D, x[11];
	cin >> r >> D >> x[0];
	for (int i = 0; i < 10; i++) {
		x[i + 1] = r*x[i] - D;
		cout << x[i + 1]<<endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007,INF=1e18;

int N;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N;
    double ans=0;
    rep(i,0,N){
        double a;
        string s;
        cin>>a>>s;
        if(s=="JPY"){
            ans+=a;
        }else{
            ans+=a*380000.0;
        }
    }
    printf("%.10lf",ans);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool b[100001];
vector <ll> adj[100001];
void dfs(ll x)
{
    b[x] = true;
    vector <ll> ::iterator it;
    for(it=adj[x].begin();it!=adj[x].end();it++)
    {
        if(!b[(*it)])
        {
            dfs(*it);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll n,m;
    cin>>n>>m;
    for(ll i=1;i<=m;i++)
    {
        ll x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    ll ctr = 0;
    for(ll i=1;i<=n;i++)
    {
        if(!b[i])
        {
            dfs(i);
            ctr++;
        }
    }
    cout<<ctr-1<<"\n";
}


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

template <class T, class U>
inline bool chmin(T& t, const U& f) { return t > f ? t = f, true : false; }

double solve(int D, int E) {
    double err = max(D, E);
    for (int x = 0; x <= D; ++x) chmin(err, fabs(hypot(x, D - x) - E));
    return err;
}

int main() {
    cout << fixed << setprecision(10);
    for (int D, E; cin >> D >> E, D | E;) cout << solve(D, E) << endl;
}

Measured memory_bytes: 3300
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
#define ll long long
int main()
{
    ll x=0,n,max=0;
    char s[100];
    cin>>n;
    cin>>s;
    for(int i=0;s[i];i++)
    {
        if(s[i]=='I')
            x++;
        else
            x--;
        if(max<x)
            max=x;
    }
    cout<<max;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int table[20];
int main(){
	int a;
	while(scanf("%d",&a),a){
		int sum=0;
		for(int i=0;i<a;i++){
			scanf("%d",table+i);
			sum+=table[i];
		}
		int ret=99999999;
		for(int i=0;i<(1<<a);i++){
			int val=0;
			for(int j=0;j<a;j++){
				if(i&(1<<j))val+=table[j];
			}
			ret=min(ret,abs(sum-val-val));
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 760
K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N):
    if a[i+1] - a[i] >= 0 and a[i+1] - a[i] >= max_d:
      max_d = a[i+1] - a[i]
    elif a[i+1] - a[i] < 0 and a[i+1] - a[i] +K >= max_d:
      max_d = a[i+1] - a[i] + K
      
print(K-max_d)
  

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

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll ans = b/x - (a-1)/x;
  if (a == 0) ans = b/x + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}


int main() {
    ll a,b;
    cin>>a>>b;
    if(b>=a) pr(a);
    else pr(a-1);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;
int a,b,c,d;
map<int,int> dp;
int rec(int n){
	if(n == 0){
		return 0;
	}
	if(n == 1)
		return d;

	if(dp.find(n)!=dp.end())
		return dp[n];

	int l2 = (n/2)*2;
	int r2 = ((n+1)/2)*2;

	int l3 = (n/3)*3;
	int r3 = ((n+2)/3)*3;

	int l5 = (n/5)*5;
	int r5 = ((n+4)/5)*5;

	int ans = 1e18;
	if(n < ans/d) ans = n*d;

	ans = min(ans, llabs(l2-n)*d + a + rec(l2/2));
	ans = min(ans, llabs(r2-n)*d + a + rec(r2/2));

	ans = min(ans, llabs(l3-n)*d + b + rec(l3/3));
	ans = min(ans, llabs(r3-n)*d + b + rec(r3/3));

	ans = min(ans, llabs(l5-n)*d + c + rec(l5/5));
	ans = min(ans, llabs(r5-n)*d + c + rec(r5/5));

	dp[n] = ans;
	return ans;

}
int32_t main(){

	int t;
	cin>>t;
	while(t--){
		dp.clear();
		int n;
		cin>>n>>a>>b>>c>>d;

		cout<<rec(n)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  stringstream ss;
  ss<<s[0]<<s[1];
  string saki;
  saki=ss.str();
  //cout<<saki<<endl;
  ss.str("");
  ss<<s[2]<<s[3];
  string ato;
  ato=ss.str();
  //cout<<ato<<endl;
  bool hantei_saki_nen=true;
  bool hantei_saki_tuki=false;
  bool hantei_ato_nen=true;
  bool hantei_ato_tuki=false;
  bool YYMM=false;
  bool MMYY=false;
  //if(saki!="0")hantei_saki_nen=true;
  if(saki=="01"||saki=="02"||saki=="03"||saki=="04"||saki=="05"||saki=="06"||saki=="07"||saki=="08"||saki=="09"||saki=="10"||saki=="11"||saki=="12")hantei_saki_tuki=true;
  //if(ato!="0")hantei_ato_nen=true;
  if(ato=="01"||ato=="02"||ato=="03"||ato=="04"||ato=="05"||ato=="06"||ato=="07"||ato=="08"||ato=="09"||ato=="10"||ato=="11"||ato=="12")hantei_ato_tuki=true;
  if(hantei_saki_nen==true){
    if(hantei_ato_tuki==true){
      YYMM=true;
    }else{
      YYMM=false;
    }
  }
  //cout<<hantei_saki_nen<<" "<<hantei_ato_tuki<<" "<<YYMM<<endl;
  if(hantei_ato_nen==true){
    if(hantei_saki_tuki==true){
      MMYY=true;
    }else{
      MMYY=false;
    }
  }
  //cout<<hantei_ato_nen<<" "<<hantei_saki_tuki<<" "<<MMYY<<endl;
  if(YYMM==true&&MMYY==true){
    cout<<"AMBIGUOUS"<<endl;
  }else if(YYMM==true&&MMYY==false){
    cout<<"YYMM"<<endl;
  }else if(YYMM==false&&MMYY==true){
    cout<<"MMYY"<<endl;
  }else{
    cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int N, answer = 1000000000, total;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin>> A[i];
    
    for(int i = -100; i <= 100; i++){
        total = 0;
        for(int j = 0; j < N; j++) total += (A[j] - i) * (A[j] - i);
        answer = min(answer, total);
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define test      cout<<"THIS_AND_THIS"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll x,y;
	cin>>x>>y;
	bool check=false;
	for(int i=0;i<=x;i++){
		ll k=i*2+(x-i)*4;
		if(k==y){check=true;}
	}
	if(check){cout<<"Yes";}
	else{cout<<"No";}
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}




Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s,ans=0,mod=998244353;cin>>n>>s;
  lvector A(n,0);rep(i,n) cin>>A[i];
  lvector f(s+1,0);
  for(ll a:A) {
    f[0]+=1;
    lvector f_;
    for(ll i=0;i<=s-a;++i) f_.emplace_back(f[i]);
    for(ll i=a;i<=s;++i) f[i]+=f_[i-a];
    rep(i,s+1) f[i]%=mod;
    ans+=f[s];
  }
  ans%=mod;
  print(ans);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main()
{
  int x, y;
  bool res = false;
  std::cin >> x >> y;

  for (int a = 0; a <= x; a++)
  {
    int b = x - a;
    if (2 * a + 4 * b == y)
    {
      std::cout << "Yes" << std::endl;
      res = true;
      break;
    }
  }
  if (res == false)
  {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3620
function Main(input){
  input = input.split('\n').map(x=>x.split(' ').map(y=>parseInt(y)));
  var ans = 'NG';
  for (i=input[1][0];i<=input[1][1];i++){
    if (i%input[0][0] == 0){
      ans = 'OK';
      break;
    }
  }
  console.log(ans);
}

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

Measured memory_bytes: 29588
public class Main {

	/**
	 * ????????????????????????
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				System.out.println(i + "x" + j + "=" + i * j);
			}
		}
	}
}

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

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        #[cfg(debug_assertions)]
        { match &$var { v => eprintln!("{}={:?}", stringify!($var), v) } }
    };
    ($var:expr, $($vars:expr),*) => {
        #[cfg(debug_assertions)]
        { match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let k: usize = input();
    let _a: Vec<i32> = (0..n).map(|_| input()).collect();

    println!("{}", (n - 1 + k - 1 - 1) / (k - 1));
}


Measured memory_bytes: 4352
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();

        if(a > b){
            int temp = a;
            a = b;
            b = temp;
        }
        if(b > c){
            int temp = b;
            b = c;
            c = temp;
        }
        if(a > b){
            int temp = a;
            a = b;
            b = temp;
        }

        System.out.println(a +" "+ b +" "+ c);
    }
}


Measured memory_bytes: 26268
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=1000000007;
int M=510000;
long long inv[510000];
long long fact[510000];
long long factinv[510000];
int b[510000];
int at[510000];
int v[510000];
pair<int,int> p[510000];
int bit[510000];
int sum(int a,int b){
	if(a)return sum(0,b)-sum(0,a-1);
	int ret=0;
	for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
	return ret;
}
void add(int a,int b){
	for(;a<510000;a|=a+1)bit[a]+=b;
}
int main(){
	inv[1]=fact[0]=factinv[0]=1;
	for(int i=2;i<M;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	for(int i=1;i<M;i++)fact[i]=fact[i-1]*i%mod;
	for(int i=1;i<M;i++)factinv[i]=factinv[i-1]*inv[i]%mod;
	int a;scanf("%d",&a);
	int ind=0;
	for(int i=0;i<a;i++){
		scanf("%d",b+i);
		b[i]--;
		v[b[i]]++;
		if(b[i]>=0){
			p[ind++]=make_pair(b[i],i);
		}
	}
	int sz=0;
	for(int i=0;i<a;i++)if(!v[i])at[sz++]=i;
	long long ret=0;
	int cnt=0;
	long long ad=0;
	long long hu=0;
	long long ks=1;
	int ps=0;
	for(int i=0;i<a;i++)if(b[i]==-1)ps++;
	for(int i=a-1;i>=0;i--){
		
		if(b[i]==-1){
			cnt++;
			ret=(ret+(long long)(cnt)*(cnt-1)/2%mod*inv[cnt]%mod*fact[ps]%mod*ks)%mod;
			ret=(ret+ad%mod*inv[sz]%mod*ks%mod*fact[ps])%mod;
		}else{
			int ts=sum(0,b[i]);
			hu=(hu+(long long)ts*ks%mod)%mod;
			int tmp=lower_bound(at,at+sz,b[i])-at;
			hu=(hu+(long long)tmp*cnt%mod*inv[sz]%mod*ks)%mod;
			add(b[i],1);
			ad+=sz-tmp;
		}
	//	printf("%lld\n",ret);
		ks=ks*(a-i)%mod;
	}
	//printf("%lld\n",ret);
	ret=(ret+fact[cnt])%mod;
	ret=(ret+hu%mod*fact[cnt])%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 21888
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

using ll = long long;
const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    for(int i = 0; i < n-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }

    int q, k;
    cin >> q >> k;
    k--;

    dfs(k, -1, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	string s;
	cin>>n; cin>>s;
	ll mc[1000001], dc[1000001];
	mc[0]=0, dc[0]=0;
	for(int i=0; i<n; i++){
		mc[i+1]=mc[i];
		dc[i+1]=dc[i];
		if(s[i]=='D'){
			dc[i+1]++;
		}else if(s[i]=='M'){
			mc[i+1]++;
		}
	}
	int q;
	cin>>q;
	for(int t=0; t<q; t++){
		int k; cin>>k;
		ll dm=0, ans=0;
		for(int i=0; i<n; i++){
			if(s[i]=='C') ans+=dm;
			if(s[i]=='M'){
				dm+=(dc[i]-dc[max(0, i-k+2)]);
			}
			if(i-k+1>=0 && s[i-k+1]=='D'){
				dm-=(mc[i]-mc[i-k+2]);
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 17028
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		double s[]=new double[1000],t1,t2;
		int n,i;
		while(true) {
			n=scan.nextInt();
			if(n==0) break;
			t1=0;
			for(i=0;i<n;i++) {
				s[i]=scan.nextDouble();
				t1+=s[i];
			}
			t1/=n;
			t2=0;
			for(i=0;i<n;i++) t2+=Math.pow(s[i]-t1, 2);
			System.out.println(Math.sqrt(t2/n));
		}
		scan.close();
	}
}


Measured memory_bytes: 38628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n, d;
    cin >> n >> d;
    ll ans = 0;
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
//include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
typedef long long int ll;
 
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 100005;
const ll mod = 10e8+7;
const long long int inf = 10000000000;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	decimal(8);
	
	ld l;
	cin>>l;
	l = l/3;
	l = l*l*l;
	cout<<l<<endl;



}


	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

alias T = Tuple!(int, int);

void main() {
  int n;
  readf (" %d", &n);
  auto e = new T[][n];
  foreach (k; 0 .. n - 1) {
    int i, j;
    readf (" %d %d", &i, &j);
    --i; --j;
    e[i] ~= tuple (j, k);
    e[j] ~= tuple (i, k);
  }
  auto p = new int[n];
  p[] = -2;
  auto c = new int[n-1];
  void go (int i, int fc) {
    int curc = 0;
    foreach (ref q; e[i]) {
      int j = q[0];
      if (p[j] == -2) {
        p[j] = i;
        ++curc;
        if (curc == fc) ++curc;
        c[q[1]] = curc;
        go (j, curc);
      }
    }
  }
  p[0] = -1;
  go (0, 0);
  int m = 0;
  foreach (i; 0 .. c.length) {
    m = max (m, c[i]);
  }
  writeln (m);
  writefln ("%(%s\n%)", c);

}



Measured memory_bytes: 9852
#include <iostream>
 using namespace std;
 int main(){
 int R;
 cin >> R;
 string ans;
 if(R < 1200){
 ans = "ABC";
 }else if(R < 2800){
 ans = "ARC";
 }else{
 ans = "AGC";
 }
 cout << ans << endl;
 }

 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

vector<pair<int,int>> v[20];
int h[20];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);

	for(int i=0;i<n;i++){
		cin >> a[i];
		for(int j=0;j<a[i];j++){
			int x,y; cin >> x >> y;
			x--;
			v[i].push_back({x,y});
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		bool ok=1;
		for(int j=0;j<n;j++){
			h[j]=-1;
		}
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				if(h[j]==0){
					ok=0;
					break;
				}
				h[j]=1;
				for(int k=0;k<a[j];k++){
					int x=v[j][k].first,y=v[j][k].second;
					if(y==0){
						if(h[x]==-1){
							h[x]=0;
						}
						else if(h[x]==1){
							ok=0;
						}
					}
					else{
						if(h[x]==0){
							ok=0;
						}
						else{
							h[x]=1;
						}
					}
				}
			}
			else{
				if(h[j]==1)ok=0;
				h[j]=0;
			}
		}
		if(ok){
			ans=max(ans,__builtin_popcount(i));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector <int> ar(100005, 0);
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		ar[x]++;
	}	

	for(int i=2; i<100003; i++){
		ar[i] += ar[i-1];
	}

	int res = 0;
	for(int i=1; i<100003; i++){
		if(ar[i] == ar[100000] - ar[i])
			res++;
	}
	cout << res;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
int a,b,c=0,w[1000000];
scanf("%d%d",&a,&b);
for(int i=0;i<b;i++){
    scanf("%d",&w[i]);
}
for(int j=0;j<b-1;j++){
    if(c<w[j+1]-w[j]){
        c=w[j+1]-w[j];
    }
}
if(c<a-w[b-1]+w[0]){
    c=a-w[b-1]+w[0];
}
printf("%d",a-c);
}

Measured memory_bytes: 2816
using System;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var s = Console.ReadLine();

		var dp = new int[n + 1, n + 1];
		var M = 0;
		for (var j = n - 1; j >= 0; j--)
			for (var i = j - 1; i >= 0; i--)
				if (s[i] == s[j]) M = Math.Max(M, dp[i, j] = Math.Min(dp[i + 1, j + 1] + 1, j - i));
		Console.WriteLine(M);
	}
}


Measured memory_bytes: 108640
start = input()
goal = input()

first_idx = start.find(goal[0])
id = first_idx
new_str = []
for _ in range(len(start)):
  new_str.append(start[id])
  if id == len(start) - 1:
    id = 0
  else:
    id += 1
new_str = "".join(new_str)
result = 'Yes' if new_str == goal else 'No'
print(result)


Measured memory_bytes: 3060
import Data.List
import Data.Bool

solve :: String -> String -> String
solve s t =
    case go rs of
        Just p ->
          let i = length s - length t  - p
              j = length s - p
              (s1,s2) = splitAt i s
              (_, s3) = splitAt j s
              s1' = replace '?' 'a' s1
              s3' = replace '?' 'a' s3
           in (s1' ++ t ++ s3')
        Nothing -> "UNRESTORABLE"
  where
    rs = reverse s
    rt = reverse t
    go as@(x:xs)
      | length t > length as = Nothing
      | match as = Just 0
      | otherwise = (+) <$> Just 1 <*> go xs
    match = all (uncurry f) . zip rt
    f a b
      | b == '?' = True
      | otherwise = a == b
    replace a b = map (\x -> bool x b (x==a))

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    putStrLn $ solve s t

Measured memory_bytes: 508
#include <iostream>
using namespace std;
int P[26] = {};
int L[26] = {};
int R[26] = {};

void preorder(int root)
{
	if (root < 0) return;
	cout << " " << root;
	preorder(L[root]);
	preorder(R[root]);
}

void inorder(int root)
{
	if (root < 0) return;
	inorder(L[root]);
	cout << " " << root;
	inorder(R[root]);
}

void postorder(int root)
{
	if (root < 0) return;
	postorder(L[root]);
	postorder(R[root]);
	cout << " " << root;
}

int main()
{
	int n, p, l, r;
	cin >> n;
	
	for (int i = 0; i < 26; ++i){
		P[i] = i;
		L[i] = R[i] = -1;
	}
	
	while (n--){
		cin >> p >> l >> r;
		L[p] = l;
		R[p] = r;
		if (l != -1) P[l] = p;
		if (r != -1) P[r] = p;
	}
	int root = 0;
	while (P[root] != root) 
		root = P[root];
	
	cout << "Preorder\n";
	preorder(root);
	cout << "\nInorder\n";
	inorder(root);
	cout << "\nPostorder\n";
	postorder(root);
	cout << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=1e5+7;
vi G[maxn];
int dis[2][maxn];
int vis[maxn];
void dfs(int tp,int u,int fa=-1)
{
	for(auto v:G[u])if(v!=fa)
	{
		dis[tp][v]=dis[tp][u]+1;
		dfs(tp,v,u);
	}
}
int main()
{
	int n,u,v;
	cin>>n>>u>>v;
	for(int i=1,x,y;i<n;i++)
	{
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dis[0][u]=dis[1][v]=0;
	dfs(0,u);
	dfs(1,v);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x=dis[0][i],y=dis[1][i];
		if(x<y)
			ans=max(ans,y-1);
	}
	cout<<ans<<endl;

}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string S[220000];
set<string> st;
signed main() {
    cin >> N;
    rep(i, N) { cin >> S[i], st.insert(S[i]); }
    cout << st.size() << endl;
}

Measured memory_bytes: 26128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    a[i]--;
  }
  vec idx(n);
  for(ll i=0;i<n;i++) idx[a[i]]=i;
  ll ans=0;
  set<ll> s;
  for(ll x=n-1;x>=0;x--) {
    ll i=idx[x];
    ll c=0;
    {
      s.insert(i);
      vec l(2,-1);
      vec r(2,n);
      auto it=s.find(i);
      for(ll j=0;j<2;j++) {
        if(it==s.begin()) break;
        l[j]=*--it;
      }
      it=s.find(i);
      for(ll j=0;j<2;j++) {
        ++it;
        if(it==s.end()) break;
        r[j]=*it;
      }
      vec ls(2);
      ls[0]=i-l[0];
      ls[1]=l[0]-l[1];
      vec rs(2);
      rs[0]=r[0]-i;
      rs[1]=r[1]-r[0];
      for(ll j=0;j<2;j++) {
        c+=ls[j]*rs[1-j];
      }
    }
    ans+=(x+1)*c;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 100, INF = 1e18; 
string s, ans; 
int n, dp[maxn], nxt[maxn][30], t[maxn]; 

void out() {
	cout << ans; 
	exit(0); 
}

signed main()
{
	cin >> s; 
	n = s.length(); s = ' ' + s; 
	for(int i = n + 1; i >= 0; i--) {
		for(int j = 0; j < 26; j++) {
			if(i == n + 1) nxt[i][j] = i; 
			else if(s[i+1] - 'a' == j) nxt[i][j] = i + 1; 
			else nxt[i][j] = nxt[i+1][j]; 
		}
		dp[i] = INF; 
	}
	dp[n+1] = 1; 
	for(int i = n; i >= 0; i--) {
		for(int j = 0; j < 26; j++) {
			if(dp[i] > dp[nxt[i][j]] + 1) {
				dp[i] = dp[nxt[i][j]] + 1; 
				t[i] = j; 
			}
		}
	}
 	int cur = 0; 
	while(cur < n + 1) {
		cout << char(t[cur] + 'a'); 
		cur = nxt[cur][t[cur]];
	}
}


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

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

  int A[N];
  rep(i, 0, N) {
    cin >> A[i];
  }

  bool hantei = true;
  int count = 0;

  while (true) {
    rep(i, 0, N) {
      if (A[i]%2) {
        hantei = false;
      }
    }
    if (hantei) {
      count++;
      rep(i, 0, N) {
        A[i] /= 2;
      }
    }
    else break;
  }

  cout << count << endl;
}


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

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

  int ans;
  if (A > B)
    ans = A + (A - 1);
  else if (A < B)
    ans = B + (B - 1);
  else
    ans = A + B;

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


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

int main(){
int a,b,c,k,sum=0;
cin>>a>>b>>c>>k;
if(a>=k)cout<<k;
else{
	sum+=a;
	k-=a;
	if(k<b)cout<<a;
	else cout <<sum-(k-b);

}
}



Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	ll x, y;
	cin >> x >> y;
	if (x%y == 0) {
		cout << "-1";
		return 0;
	}
	else {
		cout << x;
		return 0;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int x = sc.nextInt();
        final int y = sc.nextInt();
        sc.close();
        int kame = x;
        int tsuru = 0;
        String result = "No";
        for (int i = 0; i <= x; i++) {
            if (y == kame * 2 + tsuru * 4) {
                result = "Yes";
                break;
            }
            kame--;
            tsuru++;
        }
        System.out.println(result);
    }
}


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

int main(){

  int x1, x2, x3, x4, x5;
  cin >>x1 >> x2>> x3 >> x4>>x5;
  int ans = 0;

  if(x1 == 0) ans = 1;
  if(x2 == 0) ans = 2;
  if(x3 == 0) ans = 3;
  if(x4 == 0) ans = 4;
  if(x5 == 0) ans = 5;
  cout << ans << endl;
  return 0;
  

}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, v[100000], cou[100001][2];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	memset(cou, 0, sizeof(cou));
	for(int i = 0; i < n; i++) {
		cou[v[i]][i % 2]++;
	}
	set<pair<int, int>> best;
	for(int i = 1; i <= 100000; i++) {
		best.insert({cou[i][1], i});
	}
	int ans = INT_MAX;
	for(int i = 1; i <= 100000; i++) {
		set<pair<int, int>>::reverse_iterator it = best.rbegin();
		for(int j = 0; j < 2; j++) {
			if((*it).second != i) {
				break;
			}
			it++;
		}
		ans = min(ans, n - cou[i][0] - (*it).first);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6144