akhauriyash/Code-Regression huggingface dataset:
from math import sqrt
n = int(input())
x,y,s = [],[],0
for _ in range(n):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
for i in range(n):
    for j in range(n):
        a = x[i]-x[j]
        b = y[i]-y[j]
        s += sqrt(a*a+b*b)
print(s/n)

Measured memory_bytes: 3064
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

struct Mod {
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod()
	: value(0) {}
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	Mod operator-() const { return Mod(-value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;

int main() {
	ll N, K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	Mod::BASE = K;
	vector<ll> Ais(N);
	rep(i,0,N) {
		cin >> Ais[i];
		Ais[i]--;
	}
	unordered_map<ll, ll> sum_mod_cnt;
	sum_mod_cnt.reserve(N);
	Mod sum = 0;
	rep(i,0,min(N,K-1)) {
		sum += Ais[i];
		sum_mod_cnt[sum.value]++;
	}
	vector<Mod> sums(N+1);
	sum = 0;
	rep(n,1,N+1) {
		sum += Ais[n-1];
		sums[n] = sum;
	}
	ll ans = 0;
	rep(i,0,N) {
		ans += sum_mod_cnt[sums[i].value];
		if (sum_mod_cnt[sums[i+1].value] > 0) {
			sum_mod_cnt[sums[i+1].value]--;
		}
		if (K+i <= N) {
			sum_mod_cnt[sums[K+i].value]++;
		}
	}
	cout << ans << endl;
}

/*

5 1
1 4 2 3 5

*/

Measured memory_bytes: 14336
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,dy[]={0,1},dx[]={1,0};
string s[10];
// 0
//1 3
// 2

string rot90(string s){
    return s[3]+s.substr(0,3);
}

int enc(char c){
    if(c=='R')return 0;
    if(c=='r')return 1;
    if(c=='G')return 2;
    if(c=='g')return 3;
    if(c=='B')return 4;
    if(c=='b')return 5;
    if(c=='W')return 6;
    if(c=='w')return 7;
    cout<<"ERROR: "<<(int)c<<endl;
    assert(0);
}

#define id(y,x) ((y)*3+(x))

int f(int y,int x,int mask,string* state_){
    if(y==3)return 1;
    if(x==3)return f(y+1,0,mask,state_);
    int res=0;
    string state[10];
    rep(i,9)state[i]=state_[i];
    rep(i,9)if(!(mask>>i&1)){
        string t=s[i];
        rep(j,4){
            t=rot90(t);
            if(y>0){
                int a=enc(t[0]),b=enc(state[id(y-1,x)][2]);
                if((a+b)%2==0 || a/2!=b/2)continue;
            }
            if(x>0){
                int a=enc(t[1]),b=enc(state[id(y,x-1)][3]);
                if((a+b)%2==0 || a/2!=b/2)continue;
            }
            state[id(y,x)]=t;
            res+=f(y,x+1,mask|1<<i,state);
        }
    }
    return res;
}

int main(){
	cin>>n;
    rep(tc,n){
        rep(i,9)cin>>s[i];
        int used[10]={};
        string state[10];
        cout<<f(0,0,0,state)<<endl;
    }
}

Measured memory_bytes: 928
local n = io.read("*n")
io.read("*l")
local arr
do
  local _accum_0 = { }
  local _len_0 = 1
  for e in io.read("*l"):gmatch("%d+") do
    _accum_0[_len_0] = tonumber(e)
    _len_0 = _len_0 + 1
  end
  arr = _accum_0
end
table.sort(arr, function(a, b)
  return a > b
end)
local r = 0
local t = 1
for _index_0 = 1, #arr do
  local e = arr[_index_0]
  r = r + (t * e)
  t = -t
end
return print(r)

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static HashMap<String, Integer> map;
	static ArrayList<String> favs;
	static final int WEEKTIME = 7 * 24 * 60;

	static int solve() {
		boolean[] used = new boolean[WEEKTIME];
		for (String f : favs) {
			int t = map.get(f);
			for (int i = 0; i < 30; ++i) {
				if (used[t]) return -1;
				used[t] = true;
				++t;
				if (t >= WEEKTIME) t -= WEEKTIME;
			}
			map.remove(f);
		}
		ArrayList<Integer> programs = new ArrayList<Integer>(map.values());
		Collections.sort(programs);
		int ret = favs.size();
		for (int p : programs) {
			boolean ok = true;
			int t = p;
			for (int i = 0; i < 30; ++i) {
				if (used[t]) {
					ok = false;
					break;
				}
				++t;
				if (t >= WEEKTIME) t -= WEEKTIME;
			}
			if (ok) {
				++ret;
				t = p;
				for (int i = 0; i < 30; ++i) {
					used[t] = true;
					++t;
					if (t >= WEEKTIME) t -= WEEKTIME;
				}
			}
		}
		return ret;
	}

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			map = new HashMap<String, Integer>();
			for (int i = 0; i < N; ++i) {
				String name = sc.next();
				int weekday = sc.nextInt();
				int time = sc.nextInt();
				int weektime = weekday * 24 * 60 + (time / 100) * 60 + time % 100;
				weektime += WEEKTIME - 6 * 60;
				weektime %= WEEKTIME;
				map.put(name, weektime);
			}
			int P = sc.nextInt();
			favs = new ArrayList<String>(P);
			for (int i = 0; i < P; ++i) {
				favs.add(sc.next());
			}
			System.out.println(solve());
		}
	}

}

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

string temp[150];

int main()
{
	int n, l;
	cin >> n >> l;
	for(int i = 1; i <= n; ++i)
		cin >> temp[i];
	sort(temp + 1, temp + 1 + n);
	for(int i = 1; i <= n; ++i)
		cout << temp[i];
	cout << endl;
}

Measured memory_bytes: 256
N = int(input())
As = []
Bs = []
for _ in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)

As.sort()
Bs.sort()

if N % 2 == 0:
    leftA, leftB = As[N // 2 - 1], Bs[N // 2 - 1]
    rightA, rightB = As[N // 2], Bs[N // 2]
    minM = leftA + rightA
    maxM = leftB + rightB
    print(maxM-minM+1)
else:
    midA, midB = As[N // 2], Bs[N // 2]
    print(midB-midA+1)


Measured memory_bytes: 25400
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> A(n);
	for (int &a: A) cin >> a;;
	vector<int> dp(n, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i - 1; j >= 0; j--) {
			if (A[i] >= A[j] && A[i] - k <= A[j]) {
				dp[i] = max(dp[i], dp[j] + 1);
				break;
			}
		}
		for (int j = i - 1; j >= 0; j--) {
			if (A[i] <= A[j] && A[i] + k >= A[j]) {
				dp[i] = max(dp[i], dp[j] + 1);
				break;
			}
		}
	}
	int ans = 0;
	for (int a: dp) ans = max(a, ans);
	cout << ans << endl;
}


Measured memory_bytes: 5576
while True:
    n,m=[int(i) for i in input().split()]
    if n==0:
        break 
    a = [int(i) for i in input().split()]

    ans  = -1
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j] <= m:
                ans =max(a[i]+a[j] ,ans)
    if ans ==-1:
        print("NONE")
    else:
        print(ans)



Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    string s;
    cin>>s;
    if(s[1]=='R')
        cout<<"ABC";
    else
        cout<<"ARC";
}
int32_t main()
{
    //_READ  
      _FAST
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 3628
#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_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() 
{
    int x,y;
    cin>>x>>y;
    if(x==1 && (y%2 == 0 || y%4 == 0))
    {   cout<<"Yes";
        return;
    }
    for(int i = 1; i<=x; i++)
    {
        int c,t;
        c=i;
        t=x-i;
        if(c*2 + t*4 == y || c*4 + t*2 == y)
        {
            cout<<"Yes";
            return;
        }
    }
    cout<<"No";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc = 1; 
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <atomic>
#include <thread>
#include <mutex>
#include <string>
#include <string.h>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, a[200010];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int l = 0, r = 1, c = a[0], ans = 0;
	while (l < n) {
		while (!(c & a[r]) && r != n) {
			c ^= a[r];
			r++;
		}
		ans += (r - l);
		c ^= a[l];
		l++;
	}
	cout << ans << endl;
	return 0;
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"

int main(){
    int a,b;
    cin >> a >> b;
    if(a<b)printf("a < b\n");
    else if(a>b)printf("a > b\n");
    else printf("a == b\n");
    return 0;
}



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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    double money = 0.0;
    for (int i = 0; i < n; ++i) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") money += x;
        else money += 380000 * x;
    }
    cout << money << endl;

    return 0;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    ll n;
    cin >> n;
    set<string> a;
    rep(i, n) {
        string s;
        cin >> s;
        a.insert(s);
    }

    cout << a.size() << endl;

    return 0;
}


Measured memory_bytes: 19252
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(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 VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int a;
	cin>>a;
	vector<int> vec{a/100,(a/10)%10,a%10};
	FDS(i,3){
		if(vec[i]==1){
			cout<<9;
		}
		else if(vec[i]==9){
			cout<<1;
		}
		else{
			cout<<vec[i];
		}
	}
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};


using namespace std;

int main() {
    int n,a;
    cin>>n>>a;
    n%=500;
    if(n<=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 764
nums = input()

N = 3
for i in range(2**N):
    equation = ''
    for j in range(N):
        equation += nums[j]
        if ((i >> j) & 1):
            equation += '+'
        else:
            equation += '-'
    equation += nums[-1]
    if eval(equation) == 7:
        print(equation + '=7')
        exit()

Measured memory_bytes: 9060
from collections import Counter
n = int(input())
nums = list(map(int,input().split(" ")))
 
c = Counter(nums)
a = 0
for k,v in c.items():
    if v >=2:
        a+=(v-1)*v//2
 
for num in nums:
    curr = -1
    if c[num] >= 2:
        curr = a - (c[num]-1)
    else:
        curr = a
    print(curr)

Measured memory_bytes: 26780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AChristmasEveEveEve solver = new AChristmasEveEveEve();
        solver.solve(1, in, out);
        out.close();
    }

    static class AChristmasEveEveEve {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            final String C = "Christmas", E = " Eve";
            int d = in.nextInt();
            String answer = C;
            for (int i = 0; i < 25 - d; i++)
                answer += E;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    using namespace std;
    int pairs[22][22];
    ll dp[1<<22];
    ll solve(int mask,int men, int n)
    {
       // cout<<men<<" "<<mask<<"\n";
        if(men > n)
            return 0;
        if(mask== (1<<n)-1)
            return 1;
        if(dp[mask]!=-1)
            return dp[mask];

        ll ans =0;
        for(int i=0; i<n; i++)
        {
            if(pairs[men][i]==1 && !(mask & (1<<i)))
            {
                ans= ((ans%M)+(solve((mask | (1<<i)),men+1, n)%M))%M;

            }
        }
        //cout<<men<<" "<<ans<<"\n";
        return dp[mask]=ans;
    }
    int main()
    {

        ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

      int  n;
      cin>>n;
      for(int i=0; i<n; i++)
      {

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

              cin>>pairs[i][j];
          }
      }
      int mask=0;
      memset(dp,-1,sizeof(dp));
      cout<<(solve(mask,0,n)%M);
        return 0;

    }


Measured memory_bytes: 36356
N,M,Q=map(int, input().split())

ans=[[0 for _ in range(N+2)] for _ in range(N+2)]

for _ in range(M):
	L,R=map(int, input().split())
	ans[1][R] += 1
	ans[1][N+1] -= 1
	ans[L+1][R] -= 1
	ans[L+1][N+1] += 1

for h in range(N+2):
	for w in range(1, N+2):
		ans[h][w] += ans[h][w-1]

for w in range(N+2):
	for h in range(1, N+2):
		ans[h][w] += ans[h-1][w]

for _ in range(Q):
	p,q=map(int, input().split())
	print(ans[p][q])


Measured memory_bytes: 60012
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
  int a, b;
  cin >> a >> b;
  if((a*b)%2==0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
}


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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] a_asArgs)
		{
			long[] l_aiNM = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
			long l_iN;
			long l_iM;

			if (l_aiNM[0] < l_aiNM[1])
			{
				l_iN = l_aiNM[0];
				l_iM = l_aiNM[1];
			}
			else
			{
				l_iN = l_aiNM[1];
				l_iM = l_aiNM[0];
			}

			long l_iCount = 0;

			if (l_iN == 1 && l_iM > 3)
			{
				Console.WriteLine((l_iM - 2));
				return;
			}

			if (l_iN == 2 && l_iM > 3)
			{
				Console.WriteLine(0);
				return;
			}

			if (l_iN > 3 && l_iM > 3)
			{
				Console.WriteLine((l_iN - 2) * (l_iM - 2));
				return;
			}

			for (long l_iPos = 0; l_iPos < l_iN * l_iM; l_iPos++)
			{
				long l_iNeighbor = 0;
				bool l_bNotLeftEnd = l_iPos % l_iM != 0;//左端
				bool l_bNotRightEnd = l_iPos % l_iM != l_iM - 1;//右端
				bool l_bNotTopEnd = l_iPos / l_iM != 0;//上端
				bool l_bNotBottomEnd = l_iPos / l_iM != l_iN - 1;//上端
				if (l_bNotLeftEnd && l_bNotRightEnd && l_bNotTopEnd && l_bNotBottomEnd)
				{
					l_iCount++;
					continue;
				}
				if (l_bNotLeftEnd)
				{
					l_iNeighbor += 1;
					if (l_bNotTopEnd)
					{
						l_iNeighbor += 1;
					}
					if (l_bNotBottomEnd)
					{
						l_iNeighbor += 1;
					}
				}
				if (l_bNotRightEnd)
				{
					l_iNeighbor += 1;
					if (l_bNotTopEnd)
					{
						l_iNeighbor += 1;
					}
					if (l_bNotBottomEnd)
					{
						l_iNeighbor += 1;
					}
				}
				if (l_bNotTopEnd)
				{
					l_iNeighbor += 1;
				}
				if (l_bNotBottomEnd)
				{
					l_iNeighbor += 1;
				}
				if (l_iNeighbor % 2 == 0)
				{
					l_iCount++;
				}
			}

			Console.WriteLine(l_iCount);
		}
	}
}


Measured memory_bytes: 11348
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int x;

int main(){
    cin >> x;
    
    cout << x*x*x << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    
    ll n,m;
    cin>>n;
    ll a[n+1]={0};
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        a[x]++;
    }
    for(ll i=1;i<=n;i++)
    cout<<a[i]<<"\n";
  }  
  return 0;
}

Measured memory_bytes: 5204
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (LL I = 0; I < (N); ++I)
#define REPP(I, A, B) for (LL I = (A); I < (B); ++I)
#define RI(X) scanf("%lld", &(X))
#define RII(X, Y) scanf("%lld%lld", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%lld%lld%lld", &(X), &(Y), &(Z))
#define DRI(X) LL (X); scanf("%lld", &X)
#define DRII(X, Y) LL X, Y; scanf("%lld%lld", &X, &Y)
#define DRIII(X, Y, Z) LL X, Y, Z; scanf("%lld%lld%lld", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;

int main(){
  DRII(N,A);
  DRIII(B,C,D);
  REP(i,N){
    LL m=i,n=N-i-1,L=-n*D+m*C,R=m*D-n*C;
    if(L<=B-A && B-A<=R)return 0*puts("YES");
  }puts("NO");
}


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

#define N 110
int n, a[N];

void solve()
{
	vector <int> res;
	int m = n;
	while (1)
	{
		int pos = -1;
		for (int i = m; i >= 1; --i)
		{
			if (a[i] == i)
			{
				pos = i;
				break;
			}
		}
		if (pos == -1) 
		{
			puts("-1");
			return;
		}
		res.push_back(pos);
		for (int i = pos; i < m; ++i)
			a[i] = a[i + 1];
		--m;
		if (m == 0) break;
	}
	reverse(res.begin(), res.end());
	for (auto it : res)
		printf("%d\n", it);
}

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i)
			scanf("%d", a + i);
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int c[8],n[8]={1,2,1,2,1,4,1,4},m,p,r[8]={1,5,2,6,4,8,3,7};

int main(){
	while(cin>>c[0]>>c[1]>>c[2]>>c[3]>>c[4]>>c[5]>>c[6]>>c[7]){
		int m=99999999;
		for(int i=0;i<8;i++){
			int sum=0;
			for(int j=0;j<8;j++)sum+=max(0,c[j]-n[(i+j)%8]);
			//cout<<sum<<" ";
			if(sum<m||sum==m&&n[i]*1000+n[(i+1)%8]*100+n[(i+2)%8]*10+n[(i+3)%8]<n[p]*1000+n[(p+1)%8]*100+n[(p+2)%8]*10+n[(p+3)%8]){m=sum;p=i;}
		}
		//cout<<"p"<<p<<" ";
		for(int i=0;i<8;i++){
			cout<<n[(i+p)%8];
			if(i<7)cout<<" ";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 0
nums = input().split()
A=int(nums[0])
B=int(nums[1])

if A>B:
    t=A
    A=B
    B=t

A_div=[]
AB_div=[]
front=[]
back=[]
for i in range(1, int(A**0.5)+1):
    if A % i == 0:
        front.append(i)
        if i != A // i:
            back.insert(0,A//i)
A_div=front+back
# print(A_div)
for n in A_div:
    if(B%n==0):
        AB_div.append(n)
# print(AB_div)

for i in AB_div:
    if i==1:
        continue
    # exit内にあるかどうか
    for j in reversed(AB_div):
        if j%i==0 and j>i:
            # print(j)
            AB_div.remove(j)
# print(AB_div)
print(len(AB_div))


Measured memory_bytes: 3408
#include <bits/stdc++.h>
#define BPhuong "vsteps"
#define maxn 100009
#define maxm
#define bit(x, i) ((x>>i)&1)
#define fid(i,a,b) for(int i = a; i>=b; i--)
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<int, int>
#define ll long long
#define f first
#define se second
#define pb push_back
using namespace std;
int n, k, a[maxn][4], q[maxn],t, mod;
int f[maxn][4];
void nhap(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    srand(time(NULL));
    cin >> n;
}
void xuli(){
    fi(i, 1, n)
        fi(j, 1, 3) cin >>a[i][j];
    fi(i, 1, n){
        f[i][1] = max(f[i-1][2], f[i-1][3]) + a[i][1];
        f[i][2] = max(f[i-1][1], f[i-1][3]) + a[i][2];
        f[i][3] = max(f[i-1][1], f[i-1][2]) + a[i][3];
    }
    cout << max(f[n][1], max(f[n][2], f[n][3]));
}
int main(){
    nhap();
    xuli();
}


Measured memory_bytes: 6760
import sys
import numpy as np

x_list = []
y_list = []
z_list = []
hin_list = []

N, M = list(map(int, sys.stdin.readline().strip().split(" ")))

for i in range(N):
    x, y, z = list(map(int, sys.stdin.readline().strip().split(" ")))
    x_list.append(x)
    y_list.append(y)
    z_list.append(z)
    hin_list.append((x, y, z))

x_list = np.array(x_list)
y_list = np.array(y_list)
z_list = np.array(z_list)

comb_list = [(True, True, True), (True, True, False), (True, False, True), (True, False, False), (False, True, True), (False, True, False), (False, False, True), (False, False, False)]

tmp = 0
for cmb in comb_list:
    point_list = []
    for i in range(N):
        x, y, z = hin_list[i]
        if not cmb[0]:
            x = -x
        if not cmb[1]:
            y = -y
        if not cmb[2]:
            z = -z
        point_list.append(x + y + z)
    #print(point_list)
    tmp = max(tmp, sum(list(reversed(sorted(point_list)))[:M]))

print(tmp)


Measured memory_bytes: 12504
inp = int(input())


a = int(inp / 1000)
b = int((inp % 1000)/100)
c = int((inp % 100)/10)
d = int((inp % 10))
'''

d = inp % 10
inp //= 10

c = inp % 10
inp //= 10

b = inp % 10
inp //= 10

a = inp % 10
inp //= 10
'''

pm = 8
total = a


for i in range(8):
    total = a
    siki = str(a)
    if(i & 1):
        total += b
        siki += '+' +str(b)
    elif((i&1) != 1):
        total -= b
        siki += '-' +str(b)

    if((i>>1) &1 ):
        total += c
        siki += '+' +str(c)
    else:
        total -= c
        siki += '-' +str(c)

    if((i>>2) &1):
        total += d
        siki += '+' +str(d)
    else:
        total -= d
        siki += '-' +str(d)

    if (total == 7):
        siki += "=7"
        print(siki)
        quit()





Measured memory_bytes: 3064
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

r=gets.to_i
puts r**2

Measured memory_bytes: 1788
from sys import exit
S = input()
for i in range(len(S)):
  for j in range(i):
    if S[i] == S[j]:
      print('no')
      exit(0)
  for j in range(i+1,len(S)):
    if S[i] == S[j]:
      print('no')
      exit(0)
print('yes')

Measured memory_bytes: 9120
# -*- coding: utf-8 -*-

def main():
    S = input()
    a, b = int(S[:2]), int(S[2:])
    
    can_a_be_month = 1 <= a <= 12
    can_b_be_month = 1 <= b <= 12
    if can_a_be_month and can_b_be_month:
      print('AMBIGUOUS')
    elif can_a_be_month:
      print('MMYY')
    elif can_b_be_month:
      print('YYMM')
    else:
      print('NA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
ans=[]
for i in range(X):
    a=i+1
    ans.append(p[-a])
for i in range(Y):
    a=i+1
    ans.append(q[-a])
for i in r:
    ans.append(i)
ans.sort()
Ans=0
for i in range(X+Y):
    a=i+1
    Ans+=ans[-a]
print(Ans)

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const long MOD = 1000000007;

int main(){
  long N;
  cin >> N;
  long fact = 1;
  for(long i = 1;i <=N; i ++){
    fact *= i;
    fact %= MOD;
  }
  cout << fact%MOD << endl;
}


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

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<int> looking_east(n+1);
    vector<int> looking_west(n+1);
    vector<int> movers(n);
    int east_total = 0;
    int west_total = 0;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'E') { 
            east_total++;
            looking_east[i+1] = east_total;
            looking_west[i+1] = west_total;
        }
        else {
            west_total++;
            looking_east[i+1] = east_total;
            looking_west[i+1] = west_total;
        }
    }
    for (int i = 0; i < n; i++) {
        movers[i] = looking_east[n] - looking_east[i+1] + looking_west[i];
    }
    int ans = *min_element(movers.begin(), movers.end());
    cout << ans << endl;
}

Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
typedef long long ll;
 
int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	int r;
	cin>>r;
	double pi=3.141592653589;
	
	cout<<2*pi*r;
	
	return 0;
}

Measured memory_bytes: 3796
from _collections import deque
n = int(input())
edges = [[]for _ in range(n)]
for i in range(n-1):
    a, b, w = map(int, input().split())
    edges[a-1].append([b-1, w])
    edges[b-1].append([a-1, w])
color = [0]*n
color[0] = -1
q = deque()
q.append(0)
while q:
    a = q.popleft()
    for v, w in edges[a]:
        if color[v] != 0:
            continue
        else:
            q.append(v)
            if w % 2 == 0:
                color[v] = color[a]
            else:
                color[v] = (-1)*color[a]

for i in range(n):
    if color[i] == -1:
        print(0)
    elif color[i] == 1:
        print(1)

Measured memory_bytes: 85152
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += a[j]; 
      v.push_back(sum);
    }
  }
  sort(v.rbegin(), v.rend());
  int ans = 0;
  for (int b = 61; b >= 0; b--) {
    if ((v[0] & (int)pow(2, b)) == 0) {
      continue;
    }
    if ((v[k - 1] & (int)pow(2, b)) == 0) {
      int nt = (int) pow(2, 62) - 1 - (int) pow(2, b);
      for (int i = 0; i < sz(v); i++) {
        v[i] &= nt;
      }
      sort(v.rbegin(), v.rend());
    } else {
      ans += (int) pow(2, b);
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 6256
/**
 *    author:  tourist
 *    created: 29.09.2018 15:20:39       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  int p=((x[0]+y[0])%2+2)%2;
  for(int i=1;i<n;i++)
  {
      if(p!=((x[i]+y[i])%2+2)%2)
      {
          puts("-1");
          return 0;
      }
  }
  vector<long long> d;
  vector<string> s(n, "");
  if ((x[0] & 1) == (y[0] & 1)) {
    d.push_back(1);
    for (int i = 0; i < n; i++) {
      s[i].push_back('U');
      y[i]--;
    }
  }
  
  long long step = 1;
  while (step < (1LL << 33)) {
    d.push_back(step);
    for (int i = 0; i < n; i++) {
      /*if ((x[i] & 1) == (y[i] & 1)) {
        cout << -1 << '\n';
        return 0;
      }*/
      if (x[i] & 1) {
        if (((x[i] - 1) & 2) != (y[i] & 2)) {
          x[i]--;
          s[i].push_back('R');
        } else {
          x[i]++;
          s[i].push_back('L');
        }
      } else {
        if (((y[i] - 1) & 2) != (x[i] & 2)) {
          y[i]--;
          s[i].push_back('U');
        } else {
          y[i]++;
          s[i].push_back('D');
        }
      }
      x[i] /= 2;
      y[i] /= 2;
    }
    step <<= 1;
  }
  d.push_back(step);
  for (int i = 0; i < n; i++) {
    assert(x[i] * x[i] + y[i] * y[i] == 1);
    s[i].push_back(x[i] == 1 ? 'R' : (x[i] == -1 ? 'L' : (y[i] == 1 ? 'U' : 'D')));
  }
  int m = (int) d.size();
  cout << m << '\n';
  for (int i = 0; i < m; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << d[i];
  }              
  cout << '\n';
  for (int i = 0; i < n; i++) {
    cout << s[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  
  int m=0;
  for(int i=2;i<500;i++){
    if(i*(i-1)==2*n) m=i;
  }
  if(m==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  cout<<m<<endl;
  
  vector<vector<int>> A(m,vector<int>(m));
  int k=1;
  for(int i=0;i<m;i++){
    for(int j=i+1;j<m;j++){
      A[i][j]=k++;
    }
  }
  
  for(int i=0;i<m;i++){
    cout<<m-1;
    for(int j=i+1;j<m;j++) cout<<" "<<A[i][j];
    for(int j=0;j<i;j++) cout<<" "<<A[j][i];
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3892
#include <cstdio>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int countp = 0;
    for(int i = a; i <= b; i++){
        if(c % i == 0){
            countp++;
        }
    }
    printf("%d\n",countp);

    return 0;
}


Measured memory_bytes: 2744
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    a, b, c, d = (int(_) for _ in input().split())  
    print(max(a*b,c*d))
    
if __name__ == '__main__':
    main()


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,x,y,ans;

vector<int> G[maxn],G2[maxn];

int tim[maxn],fa[maxn];

void dfs2(int u,int ff){
	fa[u]=ff;
	tim[u]=tim[ff]+1;
	for(auto v:G2[u])if(v!=ff)dfs2(v,u);
}

bool check(int x,int y){
	if(fa[fa[x]]==y)return 0;
	if(fa[x]==y)return 0;
	if(fa[fa[y]]==x)return 0;
	if(fa[y]==x)return 0;
	if(fa[x]==fa[y])return 0;
	return 1;
}

void dfs1(int u,int fa,int now){
	ans=max(ans,(tim[u]-1)*2);
	for(auto v:G[u])if(v!=fa){
		if(check(u,v)){
			puts("-1");
			exit(0);
		}
		if(now+1<tim[v]&&v!=fa)dfs1(v,u,now+1);
	}
}

void Work(){
	if(x==y){
		puts("0");
		return;
	}
	dfs2(y,0);
	dfs1(x,0,1);
	iout(ans);
}

void Init(){
	read(n,x,y);
	REP(i,2,n){
		int u,v;
		read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
	REP(i,2,n){
		int u,v;
		read(u,v);
		G2[u].PB(v);G2[v].PB(u);
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 32252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
    while (b) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    ll a, b, c, d, g;
    cin >> a >> b >> c >> d; a--; g = c * d / gcd(c, d);
    cout << (b - b / c - b / d + b / g) - (a - a / c - a / d + a / g);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

#入力
#C1 = str(input())
#C2 = str(input())
A, B, C, D = map(int, input().split())

if (A+B) > (C+D) :
  print ("Left")
elif (A+B) < (C+D) :
  print ("Right")
else :
  print ("Balanced")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> b(n); for (auto&& e : b) cin >> e;
  V<bool> done(n);
  V<> res;
  for (int _ = 0; _ < n; ++_) {
    V<> c(n + 1);
    for (int i = 0; i < n; ++i) {
      c[i + 1] = c[i] + done[i];
    }
    for (int i = n - 1; i >= 0; --i) if (!done[i] and c[i] == b[i] - 1) {
      done[i] = true;
      res.push_back(b[i]);
      break;
    }
  }
  if (res.size() < n) return cout << -1 << '\n', 0;
  for (int e : res) {
    cout << e << '\n';
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int t;
	char c;
	char buf[3];
	int count[4];
	
	count[0] = count[1] = count[2] = count[3] = 0;
	
	while(scanf("%d%c%s\n", &t, &c, buf)==3) {
		if(buf[1] == 'B') {
			count[2]++;
		} else if(buf[0] == 'A') {
			count[0]++;
		} else if(buf[0] == 'B') {
			count[1]++;
		} else if(buf[0] == 'O') {
			count[3]++;
		}
	}
	
	printf("%d\n%d\n%d\n%d\n", count[0], count[1], count[2], count[3]);
	
	return 0;
}

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

int main(void) {
	int n, maxa = 0, mina = 1000;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 0; i < n; i++) {
		maxa = max(maxa, a[i]);
		mina = min(mina, a[i]);
	}
	cout << maxa - mina << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
const LL lim = 1e10;

int n, m, p, q, ans;
bool flag, is_prime[N];
LL a[N], prime[N], prime2[N], prime3[N];
set<LL> ST;
map<LL, LL> MP, G;

void init(){
	LL s;
    for(LL i=1; ;i++){
		s = i * i * i;
		if(s > lim)	break;
		ST.insert(s);
    }
    for(LL i=1; ;i++){
		s = i * i;
		if(s > lim)	break;
		MP[s] = i;
    }

    memset(is_prime, 1, sizeof(is_prime));
    p = q = 0;

    for(int i=2; i<N; i++){
		if(is_prime[i]){
			prime[p] = i;
			prime2[p] = prime[p] * prime[p];
			s = prime2[p] * prime[p];
			p++;
			if(s <= lim){
				prime3[q++] = s;
			}
			for(int j=i<<1; j<N; j+=i){
				is_prime[j] = 0;
			}
		}
    }
}

void trans(LL x){
	if(ST.count(x)){
		flag = 1;
		return;
	}

    for(int i=0; i<q && prime3[i]<=x; i++){
        while(x % prime3[i] == 0){
			x /= prime3[i];
        }
    }

    LL y = 1, z = x;

    for(int i=0; prime[i]<10000 && prime2[i]<=x; i++){
		if(x % prime[i] == 0){
			if(x % prime2[i] == 0){
				y *= prime[i];
				x /= prime2[i];
			} else {
				x /= prime[i];
				y *= prime2[i];
			}
		}
    }

    if(x > 1){
		if(MP.count(x)){
			y *= MP[x];
			a[m++] = z;
			G[z] = y;
		} else if(x <= 100000){
			y = y * x * x;
			a[m++] = z;
			G[z] = y;
		} else {
			ans++;
		}
    } else {
    	a[m++] = z;
    	G[z] = y;
    }
}

int Cnt(LL x){
	int j = lower_bound(a, a+m, x) - a;
	int k = upper_bound(a, a+m, x) - a;
	return k - j;
}

int main(){
	init();
	LL x, y;
	int c, d;
    while(~scanf("%d", &n)){
		ans = m = 0;
		flag = 0;
		G.clear();
		for(int i=0; i<n; i++){
			scanf("%lld", &x);
			trans(x);
		}

		ans += flag;

		if(m){
			sort(a, a+m);

			y = G[a[0]];
			c = Cnt(a[0]);
			d = Cnt(y);
			ans += max(c, d);
			for(int i=1; i<m; i++){
				if(a[i]==a[i-1])	continue;
				y = G[a[i]];
				d = Cnt(y);
				if(y<a[i] && d)	continue;
                c = Cnt(a[i]);
                ans += max(c, d);
			}
		}

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


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n;
    cin >> n;
    int d[n];
    int m[256] = {0};
    rep(i, n) {
        cin >> d[i];
        m[d[i]] += 1;
    }    

    int count = 0;
    rep(i, 256){
        if(m[i] != 0){
            count ++;
        }
    }

    p(count);
}


Measured memory_bytes: 384
#include <stdio.h>
int main() {
        int a,b,d,r;
        double f;
        
        scanf("%d %d",&a,&b);
        
            //a/b
            d = a / b;
            //余り
            r = a % b;
            //浮動小数点数
            f = (double)a / b;
            
            printf("%d %d %lf\n", d, r, f);
        return 0;
}


Measured memory_bytes: 2108
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    cin>>N;
    long long int ans=0;
    for(int i=1;i<N;i++){
        for(int j=1;i*j<N;j++){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define se second
#define endll "\n"
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    unordered_set<string> us;
    int n;cin>>n;
    string s;
    ll cont=0;
    while(n--){
        cin>>s;
        if(us.find(s)==us.end()){
            cont++;
            us.insert(s);
        }
    }
    cout<<cont<<endll;
}



Measured memory_bytes: 17752
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int n = s.nextInt();
		int x = s.nextInt();
		Integer array[] = new Integer[n];
		for (int i = 0; i < array.length; i++) {
			array[i] = s.nextInt();
		}
		s.close();
		System.out.println(Main.calc(n, x, array));
	}

	private static int calc(int n, int x, Integer[] array) {
		java.util.Arrays.sort(array);
		int okasi = x;
		int res = 0;
		for (int i = 0; i < array.length; i++) {
			if (okasi >= array[i]) {
				okasi -= array[i];
				res++;
			} else {

				break;
			}
		}
		if (res == array.length && okasi > 0) {
			res--;
		}
		return res;
	}
}

Measured memory_bytes: 21972