akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll a,b,x;
    cin>>a>>b>>x;
    ll A,B;
    if(a-1<0) A=-1;
    else A=(a-1)/x;
    B=b/x;
    cout<<B-A<<endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}



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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    int64_t n, x = 0, y = 0; cin >> n;
    vector<int64_t> a(n);
    rep(i, n) {
        cin >> a[i];
        x += a[i];
    }
    REP(i, 1, n) {
        a[i] = max(a[i-1], a[i]);
    }
    rep(i, n) {
        y += a[i];
    }
    cout << y - x << endl;
}


Measured memory_bytes: 4744
N = int(input())
H = [int(h) for h in input().split()]

ans = "Yes"
for i in range(1, N-1):
    if H[i] > H[i-1]:
        H[i] -= 1
    if H[i] > H[i+1]:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n;
	cin>>n;
	ll arr[n];
	ll val = 0;
	REP(i,0,n){
		cin>>arr[i];
		val = val ^ arr[i];
	} 
	REP(i,0,n){
		cout<<(val ^ arr[i])<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 5032
from collections import deque

def main():
    n, m, k = [int(e) for e in input().split()]

    Df, Db = {}, {}
    for i in range(1, n + 1):
        Df[i] = set()
        Db[i] = set()

    for i in range(m):
        a, b = [int(e) for e in input().split()]
        Df.get(a).add(b)
        Df.get(b).add(a)

    for i in range(k):
        c, d = [int(e) for e in input().split()]
        Db.get(c).add(d)
        Db.get(d).add(c)

    Q = deque()
    C = set()
    ANS = {}
    for i in range(1, n + 1):
        if i in C:
            continue

        C.add(i)
        Cin = set()
        Cin.add(i)
        Q.appendleft(i)
        while len(Q) != 0:
            for f in Df.get(Q.pop()) - Cin:
                Q.appendleft(f)
                C.add(f)
                Cin.add(f)

        for k in Cin:
            ANS[k] = len(Cin) - len(Df[k]) - len(Cin & Db[k] - Df[k]) - 1

    print(*[ANS[i] for i in range(1, n + 1)])

if __name__ == "__main__":
    main()


Measured memory_bytes: 136840
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, m;
typedef struct _cake {
    ll x, y, z;
} cake;

vector<cake> cs;

ll calc_ans(vector<cake> v, ll op1, ll op2, ll op3) {
    ll ret = 0;
    rep(i, m)ret += (v[i].x * op1 + v[i].y * op2 + v[i].z * op3);
    return ret;
}

void solve() {
    ll ans = 0;
    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return c1.x + c1.y + c1.z > c2.x + c2.y + c2.z; });
    ans = max(ans, calc_ans(cs, 1, 1, 1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return c1.x + c1.y - c1.z > c2.x + c2.y - c2.z; });
    ans = max(ans, calc_ans(cs, 1, 1, -1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return c1.x - c1.y + c1.z > c2.x - c2.y + c2.z; });
    ans = max(ans, calc_ans(cs, 1, -1, 1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return -c1.x + c1.y + c1.z > -c2.x + c2.y + c2.z; });
    ans = max(ans, calc_ans(cs, -1, 1, 1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return c1.x - c1.y - c1.z > c2.x - c2.y - c2.z; });
    ans = max(ans, calc_ans(cs, 1, -1, -1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return -c1.x - c1.y + c1.z > -c2.x - c2.y + c2.z; });
    ans = max(ans, calc_ans(cs, -1, -1, 1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return -c1.x + c1.y - c1.z > -c2.x + c2.y - c2.z; });
    ans = max(ans, calc_ans(cs, -1, 1, -1));

    sort(cs.begin(), cs.end(),
         [](cake c1, cake c2) { return -c1.x - c1.y - c1.z > -c2.x - c2.y - c2.z; });
    ans = max(ans, calc_ans(cs, -1, -1, -1));

    cout << ans << endl;
}


int main() {
    cin >> n >> m;
    cs.resize(n);
    rep(i, n) {
        ll x, y, z;
        cin >> x >> y >> z;
        cake c = {x, y, z};
        cs[i] = c;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int, input().split())
H = [int(i) for i in input().split()]

ans = [float("inf"), 0]
for i,h in enumerate(H):
    tmp = abs(A - (T - h * 0.006))
    if ans[0] > tmp:
        ans = [tmp, i + 1]

print(ans[-1])

Measured memory_bytes: 3060
from copy import deepcopy

n,k = map(int,input().split())

p = list(map(int,input().split()))


max_sum = 0
temp_sum = 0

#最初の一組目を計算
for j in range(k):
    temp_sum += ((p[j] + 1) * p[j] / 2) / p[j]

if n == k:
    max_sum = temp_sum
    print(max_sum)

else:
    #2組目以降を計算
    for i in range(1,n-k+1):
        temp_sum = temp_sum - ((p[i-1] + 1) * p[i-1] / 2) / p[i-1] + ((p[i+k-1] + 1) * p[i+k-1] / 2) / p[i+k-1]

        if temp_sum > max_sum:
            max_sum = temp_sum


    print(max_sum)




#n,k = map(int,input().split())
#
#p = list(map(int,input().split()))
#
#max_sum = 0#for j in range(k):
#    result += ((p[max_where + j] + 1) * p[max_where + j] / 2) / p[max_where + j]
#max_where = 0
#
##pi ~ pi+2の合計が最大のものが期待値も最大になる。
#for i in range(0,n-k+1):
#    temp_sum = sum(p[i:i+k])
#    if temp_sum > max_sum:
#        max_sum = temp_sum
#        max_where = i
#
#result = 0
#

#
#print(result)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    ll n, k;
    cin >> n >> k;

    // 2a = 2b = 2c = 0 (mod k)
    // (0) a = b = c = 0 mod k
    // (1) a = b = c = k/2 mod k

    ll x = n / k;
    ll ans = x * x * x; // (0)
    if (!(k & 1)) {
        ll y = (n + k / 2) / k;
        ans += y * y * y; // (0)+(1)
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int x;
  cin >> x;
  int ans = 1;
  rep2(i, 2, x){
    int j = i*i;
    while(j <= x){
      ans = max(j, ans);
      j *= i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n == m) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)


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

int main(){
  long long int n;
  cin>>n;
  int res=1e3;
  for(long long int a=1;a*a<=n;a++){
    if(n%a!=0) continue;
    long long int b=n/a;
    res=min(res,static_cast<int>(max(to_string(a).size(),to_string(b).size())));
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

string tos(ll n, ll l) {
	string res = "";
	if(n == 0) {
		REP(i, l) {
			res += "0";
		}
		return res;
	} else {
		ll m = n;
		ll cnt = 0;
		while(m > 0) {
			res = to_string(m % 10) + res;
			++cnt;
			m /= 10;
		}
		REP(i, l - cnt) {
			res = "0" + res;
		}
		return res;
	}
}

int main(void) {
	while(true) {
		ll a, l;
		cin>>a>>l;
		map<ll, ll> s;
		if(a == 0 && l == 0) break;
		s[a] = 0;
		ll cnt = 1;
		while(true) {
			string hoge = tos(a, l);
			sort(ALL(hoge), greater<char>());
			ll ma = stoi(hoge);
			sort(ALL(hoge));
			ll mi = stoi(hoge);
			a = ma - mi;
			if(s.count(a) != 0) {
				cout<<s[a]<<" "<<a<<" "<<cnt - s[a]<<endl;
				break;
			}
			s[a] = cnt;
			++cnt;
		}
	}
}

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

int mystoi(string s){
  int ret = 0,t = 1;
  for(int i = s.size()-1; i >= 0; i--){
    ret += (int)(s[i]-'0') * t;
    t *= 10;
  }
  return ret;
}

signed main(){

  stack<int> t;
  string s;

  while(cin >> s){
    if(s[0] == '+'){
      int a = t.top(); t.pop();
      int b = t.top(); t.pop();
      t.push( a+b );
    }
    else if(s[0] == '-'){
      int a = t.top(); t.pop();
      int b = t.top(); t.pop();
      t.push( b-a );
    }
    else if(s[0] == '*'){
      int a = t.top(); t.pop();
      int b = t.top(); t.pop();
      t.push( a*b );
    }
    else {
      t.push( mystoi(s) );
    }
  }
  cout << t.top() << endl;

  return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rgi register int
#define ll long long
#define il inline

using namespace std;

il int read() {
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar()))	f |= ch == '-';
	while(isdigit(ch))	x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main() {
	int a = read(), b = read();
	printf("%d", max(a - b * 2, 0));
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n, a[110];

	cin >> n;

	int max = 0, min = 1000000000;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (max < a[i]) {
			max = a[i];
		}
		if (min > a[i]) {
			min = a[i];
		}
	}

	cout << max - min << endl;

	return 0;
}

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

using namespace std;

int main()
{
	long long N, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		vector<long long> P(4001, 0);

		vector<bool> ok(4001, false);

		int count_ = 0;

		for (int i = 0; i < N; i++)
		{
			cin >> X >> Y >> Z;

			P[X] += Y * Z;

			if (P[X] >= 1000000 && ok[X] == false)
			{
				cout << X << endl; ok[X] = true; count_++;
			}
		}

		if (!count_)
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

ll gcd(ll a, ll b) {
    if (a < b) {
        return gcd(b, a);
    }
    ll c = a % b;
    while (c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ll v, t;
    cin >> a >> v >> b >> w >> t;

    if (v <= w) {
        END("NO")
    }

    ll dist = abs(a - b);
    ll speed = abs(v - w);

    if (dist <= t * speed) {
        END("YES")
    } else {
        END("NO")
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define ll long long int

using namespace std;

int main() {
  int n,k;
  cin >> n >> k;

  vector<int> a(200000);
  int count = 0;

  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    if (a[in] == 0) {
      count++;
    }
    a[in]++;
  }

  sort(a.begin(), a.end());

  int result = 0;
  for (int i = 0; i < a.size(); i++) {
    if(count > k && a[i] != 0) {
      result += a[i];
      count--;
    }
  }

  cout << result << endl;

}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;

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

const int _ = 5e5 + 10, P = 1e9 + 7;
int n, p[_], s[_]; char c[_];

int chk0(int r) {
	int len = r, now = len % (len - p[r]);
	if(!now) return len / (len - p[r]) == 1;
	return 1;
}

int chk1(int l) {
	int len = n - l + 1, now = len % (len - s[l]);
	if(!now) return len / (len - s[l]) == 1;
	return 1;
}

int main () {
	scanf("%s", c + 1), n = strlen(c + 1);
	for(int i = 2; i <= n; ++i) {
		int j = p[i - 1];
		while(j && c[j + 1] != c[i]) j = p[j];
		j += c[j + 1] == c[i], p[i] = j;
	}
	std::reverse(c + 1, c + n + 1);
	for(int i = 2; i <= n; ++i) {
		int j = s[i - 1];
		while(j && c[j + 1] != c[i]) j = s[j];
		j += c[j + 1] == c[i], s[i] = j;
	}
	std::reverse(s + 1, s + n + 1);
	std::reverse(c + 1, c + n + 1);
	int now = n - p[n];
	if(now == 1) return printf("%d\n%d\n", n, 1), 0;
	if(n % now == 0 && n / now > 1) {
		printf("%d\n", 2);
		int ret = 0;
		for(int i = 1; i < n; ++i)
			if(chk0(i) && chk1(i + 1)) ++ret;
		printf("%d\n", ret);
	} else printf("%d\n%d\n", 1, 1);
	return 0;
} 


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define lout cout
#else
stringstream devnull;
#define lout devnull
#endif

int main()
{
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  lout << a << " " << b << " " << c << " " << d << endl;
  string s;
  cin >> s;
  s = "#" + s + "#";

  auto can_reach = [&](int start, int end) {
    for (int i = start; i + 1 <= end; i++)
    {
      if (s[i] == '#' && s[i + 1] == '#')
        return false;
    }
    return true;
  };

  // if (!(can_reach(a, c) && can_reach(b, d)))
  if (!(s.substr(a, c - a + 1).find("##") == string::npos and
      s.substr(b, d - b + 1).find("##") == string::npos))
  {
    puts("No");
    return 0;
  }

  if (c < d)
  {
    puts("Yes");
    return 0;
  }

  bool snuke_can_over = false;
  for (int i = b; i <= d; i++)
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
      snuke_can_over = true;

  // if (!snuke_can_over)

  if (s.substr(b - 1, d - b + 3).find("...") == string::npos)
  {
    puts("No");
    return 0;
  }
  else
  {
    puts("Yes");
    return 0;
  }
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647

int main() {
    int n, w; cin >> n >> w;
    vector<pair<int, int> > items(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int wi, vi; cin >> wi >> vi;
        items.at(i).first = wi;
        items.at(i).second = vi;
        sum += vi;
    }
    vector<int> dp(sum+1, INF);
    dp.at(0) = 0;
    for (int i = 0; i < n; i++) {
        int wi = items.at(i).first;
        int vi = items.at(i).second;
        for (int j = sum; j >= vi; j--) {
            if (dp.at(j-vi) != INF) {
                int weight = dp.at(j-vi) + items.at(i).first;
                if (weight <= w && dp.at(j) > weight) {
                    dp.at(j) = weight;
                }
            }
        }
    }
    for (int i = sum; i >= 0; i--) {
        if (dp.at(i) != INF) {
            cout << i << endl;
            break;
        }
    }
}

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

int main()
{
  int W,H,x,y,r;

  cin >> W >> H >> x >> y >> r;

  if(x+r > W || x-r < 0 || y+r > H || y-r < 0){

    cout << "No" << "\n";
  }
    else{ cout << "Yes" << "\n";}
}

Measured memory_bytes: 1124
a_b_c=input().split()
a=int(a_b_c[0])
b=int(a_b_c[1])
c=int(a_b_c[2])
count=0
yakusuu_list=[]
for i in range(1,c+1):
    if c%i==0:
        yakusuu_list.append(i)
for i in yakusuu_list:
    if i in range(a,b+1):
        count+=1
print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,k;
  cin>>n>>k;
  if((n+1)/2>=k) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
int w,h;
int d[9][9],q[9][9];
int a[4]={-1,0,1,0};
int X,Y,C,t;
int b=0;
int chk(int x,int y){
	int i=0,ans=1;
	if(q[y][x])return 0;
	q[y][x]=1;
	if(d[y][x])return y==Y&&x==X;

	for(;i<4;i++)ans+=chk(x+a[i],y+a[(i+1)%4]);
	return ans;
}
void output(int a[9][9]){
	int i,j;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++)printf("%d",!!a[i][j]);
		puts("");
	}
}
int dfs(int x,int y,int c){
	int i=0;
	if(!c&&x==X&&y==Y)return 1;
	memset(q,0,324);
	if(d[y][x]||chk(x,y) != c+(x!=X||y!=Y))return 0;
	if(b++ > 130000)return 2;
	d[y][x]=1;
	for(;i<4;i++)if(t=dfs(x+a[i],y+a[(i+1)%4],c-1))return t;
	return d[y][x]=0;
}
int main(i,j){
	for(;C=0,b=0,scanf("%d%d\n",&w,&h),h;puts(C>3&&dfs(X,Y,C)==1?"Yes":"No")){
		memset(d,-1,324);
		for(j=1;j<=h;j++)for(i=1;i<=w;i++)scanf("%d",&t),(d[j][i]=t)||(++C,X=i,Y=j);
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
string int2string(int x){
        stringstream ss;
        ss << x;
        string tmp;
        ss >> tmp;
        return tmp;
    }
int string2int(string s){
    stringstream ss;
    ss << s;
    int x;
    ss >> x;
    return x;
}
long long power(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;
}
long long bigpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    ll r= a/gcd(a,b)*b;
    return r;
}
//***********************CODE*****************
int main(){
    
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
int a,b,i;
cin>>a>>b;
for(i=1;i<=1300;i++)
{
	if(floor(double(i)*double(0.08))==a && floor(double(i)*double(0.1))==b)
	{
		cout<<i<<endl;
		break;
	}
}
if(i==1301)cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                    idx = j
                    break
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
                    idx = j
                    break
            if find == False:
                print(ans + 1)
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break

    print(ans + 1)

if __name__ == "__main__":
    main()

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

signed main(){
    std::string s;
    std::cin >> s;
    int ans = 700 ;

    for(int i = 0 ; i < 3 ; i++){
        if (s[i]=='o') {
            ans += 100;
        }
    }
    std::cout << ans << '\n';

    return 0;
}


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

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

int main() {
    int N,num=3;
    char color;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> color;
        if(color=='Y'){
            num = 4;
        }
    }
    if(num==3){
        cout << "Three" << endl;
    }else if(num==4){
        cout << "Four" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define MAX 100000
using namespace std;
ll L = 1000000007;
int cnt[200010] = {};
int main()
{	
	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		cnt[a - 1]++;
	}

	sort(cnt, cnt + n);
	int ans = 0;

	for (int i = 0; i < n - k; i++)
	{
		ans += cnt[i];
	}

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

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int q;
    cin >> q;
    int k;
    while (q--) {
        cin >> k;
        auto p = lower_bound(ALL(a), k);
        auto q = upper_bound(ALL(a), k);
        if (p == a.end()) cout << n;
        else cout << distance(a.begin(), p);
        cout << " ";
        if (q == a.end()) cout << n;
        else cout << distance(a.begin(), q);
        cout << endl;
    }
}



Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  map<string, string> weather;
  weather["Sunny"] = "Cloudy";
  weather["Cloudy"] = "Rainy";
  weather["Rainy"] = "Sunny";
  cout << weather[s] << endl;
}

Measured memory_bytes: 256
using System;

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int H, W;
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                H = int.Parse(str[0]);
                W = int.Parse(str[1]);

                if ((H == 0) && (W == 0))
                    break;

                for (int i = 0; i < H; ++i)
                {
                    for (int j = 0; j < W; ++j)
                    {
                        if ((i % 2) == (j % 2))
                            Console.Write("#");
                        else
                            Console.Write(".");
                    }
                    Console.Write("\n");
                }

                Console.Write("\n");
            }
        }
    }
}

Measured memory_bytes: 7296
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int sum = 0;
		
		for(int i=0; i<n; i++) {
			int x = sc.nextInt();
			sum += 2*Math.min(x, k-x);
		}
		sc.close();
		
		System.out.println(sum);
			

	}

}

Measured memory_bytes: 35996
def draw_char(n):
    return '#' if n%2 == 0 else '.'

def draw(h, w):
    for x in range(0, h):
        print(''.join([draw_char(x+y) for y in range(0, w)]))
    print()

while True:
    h, w = map(int, input().split())

    if h == w == 0:
        break;

    draw(h, w)



Measured memory_bytes: 5628
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

	int x[200005];
	rep(i,n) cin >> x[i];

	int y[200005];
	rep(i,n) y[i] = x[i];

	sort(y, y+n);

	int mid = y[n/2 - 1];
	int mid2 = y[n/2];
	rep(i,n){
		if(x[i] <= mid){
			cout << mid2 << endl;
		}else{
			cout << mid << endl;
		}
	}
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class string>
inline bool chmax(string &a, string b)
{
    if (a == "-")
    {
        a = b;
        return true;
    }
    if (a.size() < b.size())
    {
        a = b;
        return true;
    }
    else if (a.size() == b.size() and 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;
}

int main()
{
   int H,W;
cin >> H>>W;
int ans = H*W;
int h,w;
cin >> h>>w;
ans = ans- h*W - w*H + h*w;
cout << ans<<endl;
   

    // system("pause");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
long long gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}
long long addgcd(int a, int b, int c)
{
    long long result = gcd(a, b);
    result = gcd(result, c);
    return result;
}
 
int main()
{
    int w;
    cin >> w;
    cout << w * 2 * M_PI;
}

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

int main(){
	int d;
	while(cin >> d){
		int sum=0;
		for(int i=1;i*d<=600-d;i++){
			sum += (i*d)*(i*d) * d;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			System.out.printf("%d %d\n", gcd(a,b), lcm(a,b));
		}
		sc.close();
	}
	static long gcd(long n, long m) {
        if(n > m) {
            return gcd(m, n);
        }
        long k = m % n;
        if(k == 0) {
            return n;
        }else {
            return gcd(n, k);
        }
    }
    static long lcm(long n, long m) {
        return n * m / gcd(n, m);
    }
}


Measured memory_bytes: 26672
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final String S[] = new String[N];
        final int T[] = new int[N];
        for (int i=0; i<N; i++) {
            S[i] = sc.next();
            T[i] =  Integer.parseInt(sc.next());
        }
        final String X = sc.next();
        sc.close();

        Map<String, Integer> map = new LinkedHashMap<>();
        for (int i=0; i<N; i++) {
            map.put(S[i], T[i]);
        }

        int total = 0;
        boolean b = false;
        for (int i=0; i<N; i++) {
            if (b)
                total += map.get(S[i]);
            if (X.equals(S[i]))
                b = true;
        }

        System.out.println(total);
    }
}

Measured memory_bytes: 22992
#include<bits/stdc++.h>
#define ll long long int
ll a[1000000+9];
using namespace std;
int main()
{
    ll n,i;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;

    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")

import sys,collections
sys.setrecursionlimit(100000)

INF = float("inf")

V,E,F = map(int,sys.stdin.readline().split())
uvcd = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(E)) # multi line with multi param

#uvcd = [[0,1,1,1],[0,2,3,2],[1,2,1,2],[2,3,2,1]]
capacityG = {i:{} for i in range(V)} #capacity
costG = {i:{} for i in range(V)} #capacity

for u,v,c,d in uvcd:
    capacityG[u][v] = c
    costG[u][v] = d
    if not u in capacityG[v]:
        capacityG[v][u] = 0
        costG[v][u] = -d

def shortest_path(V,costG,capacityG,start=0):
    distances = [INF]*V
    distances[start] = 0
    parents = list(range(V))

    for _ in range(V):
        modified = False
        for src in range(V):
            if distances[src] == INF: continue
            for dst,cost in costG[src].items():
                if capacityG[src][dst] > 0 and distances[dst] > distances[src] + cost:
                    distances[dst] = distances[src] + cost
                    parents[dst] = src
                    modified = True
        if modified == False:
            return distances,parents
    return None,None

rest = F
total_cost = 0
while rest != 0:
    distances,p = shortest_path(V,costG,capacityG,0)
    if not distances or distances[V-1] == INF:
        print(-1)
        exit()
    cur = V-1
    flow = rest
    while cur != 0:
        flow = min(flow,capacityG[p[cur]][cur])
        cur = p[cur]
    rest -= flow
    total_cost += distances[V-1]*flow
    cur = V-1
    while cur != 0:
        capacityG[p[cur]][cur] -= flow
        capacityG[cur][p[cur]] += flow #rev
        cur = p[cur]
print(total_cost)



Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN (int)3e5+5
#if !testing
#define cerr if(0)cout
#endif

int32_t main() {
    IAMSPEED
    string str;cin>>str;
    int n = str.size();
    str = 'A'+str;
    bool can = 1;
    if (str[1]=='0')can = 0;
    db(can);
    if (str[n]=='1')can = 0;
    db(can);
    FOR(i,1,n/2-1) {
		db2(i,n-i);
		if(str[i]!=str[n-i])can=0;
	}
	if (!can) return cout << -1, 0;
	cout << "1 2\n";
	int nown = 2;
	FOR(i,2,n-1) {
		db(str[i]);
		if (str[i]=='1') {
			cout << nown << ' ' << i+1 << '\n';
			nown = i+1;
		} else {
			cout << nown << ' ' << i+1 << '\n';
		}
	}
	
}


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

int n, m, q;
vector<int> a(100), b(100), c(100), d(100);
int ans;

void dfs(vector<int>& v) {
    if (v.size() == n + 1) {
        int sum = 0;
        for (int i = 0; i < q; i++) {
            if (v[b[i]] - v[a[i]] == c[i]) sum += d[i];            
        }
        ans = max(ans, sum);
    }
    else {
        for (int i = v.back(); i <= m; i++) {
            v.emplace_back(i);
            dfs(v);
            v.pop_back();
        }
    }
}

int main()
{
    cin >> n >> m >> q;    
    
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    vector<int> v = { 1 };
    dfs(v);

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

Measured memory_bytes: 3616
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] a = new long[n];
        Map<Long, Long> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            long temp = Long.parseLong(sc.next());
            a[i] = temp;
            if (map.containsKey(temp)) {
                map.put(temp, map.get(temp) + 1);
            } else {
                map.put(temp, 1L);
            }
        }
        long ans = 0;
        for (Map.Entry<Long, Long> e : map.entrySet()) {
            ans += e.getValue() * (e.getValue() - 1) / 2;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ans - (map.get(a[i]) - 1));
        }
    }
}

Measured memory_bytes: 81252
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <vector>
#include <queue>
 
using namespace std;
typedef long long LL;
#define pb push_back
const int maxn = 200005;

vector<int> r[maxn],b[maxn];
int n,X,Y,fa[maxn],dis[maxn],dep[maxn],ans;
bool vis[maxn],safe[maxn];
queue<int> Q;

bool check(int u,int v) {
	return fa[u]==v||fa[u]==fa[v]||u==fa[v]||fa[fa[u]]==v||fa[fa[v]]==u;
}
void dfs(int u) {
	for (int v,j=0;j<b[u].size();j++)
	if ((v=b[u][j])!=fa[u])
		dep[v]=dep[u]+1,fa[v]=u,dfs(v);
}
int main()
{
	#ifdef Amberframe
		freopen("agc005e.in","r",stdin);
		freopen("agc005e.out","w",stdout);
	#endif
	scanf("%d %d %d",&n,&X,&Y);
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),r[u].pb(v),r[v].pb(u);
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),b[u].pb(v),b[v].pb(u);
	
	dfs(Y);
	for (int i=1;i<=n;i++)
	for (int j=0;j<r[i].size();j++)
	if (!check(i,r[i][j]))
		safe[i]=safe[r[i][j]]=true;
	
	Q.push(X);dis[X]=0;vis[X]=true;
	while (!Q.empty()) {
		int u=Q.front();Q.pop();
		if (safe[u]) {puts("-1");return 0;}
		ans=max(ans,dep[u]*2);
		for (int v,j=0;j<r[u].size();j++)
		if (!vis[v=r[u][j]]&&dis[u]+1<dep[v]) {
			Q.push(v);vis[v]=true;dis[v]=dis[u]+1;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 33404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int a, b ,c;
    cin >> a >> b >> c;
    ct((c-(a-b) < 1 ? 0 : c-(a-b)));
}

Measured memory_bytes: 256
n=gets.to_i
as=gets.split.map(&:to_i)
s=as[0]
a=as[1..n-1].inject(:+)
diff=(a-s).abs
(n-2).times do |i|
  s+=as[i+1]
  a-=as[i+1]
  curdiff=(a-s).abs
  diff=curdiff if curdiff<diff
end
puts diff


Measured memory_bytes: 15236
#include <iostream>

using namespace std;

int main(){
	int i,n;
	cin >> n;
	int a[20010],b[20010],p[20010];
	for(i=1;i<=n;i++){
		cin >> p[i];
		b[p[i]] = 20000*(n-p[i])+i;
		a[i] = 20000*i;
	}
	for(i=1;i<=n;i++){
		cout << a[i] << " " ;
	}
	cout << endl;
	for(i=1;i<=n;i++){
		cout << b[i] << " ";
	}
	cout << endl;
}
		

Measured memory_bytes: 896
#include<stdio.h>
int main(void) {
    int H, W, i, j, s, t;
    while(1) {
        scanf("%d%d", &H, &W);
        if(H == 0 && W == 0) break;
        t = 1;
        for(i = 0; i < H; i++) {
            s = t;
            for(j = 0; j < W; j++) {
                if(s > 0) putchar('#');
                if(s < 0) putchar('.');
                s *= -1;
            }
            putchar('\n');
            t *= -1;
        }
        putchar('\n');
    }
    return 0;
}


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

const int MAX = 1 << 17;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int> v(MAX << 1, INT_MAX);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			for (v[x += MAX] = y; x > 1; x >>= 1) {
				v[x >> 1] = min(v[x], v[x ^ 1]);
			}
		}
		else {
			int res = INT_MAX;
			for (x += MAX, y += MAX + 1; x < y; x >>= 1, y >>= 1) {
				if (x & 1) res = min(res, v[x++]);
				if (y & 1) res = min(res, v[--y]);
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



Measured memory_bytes: 3872
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	private static final int N = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Integer, Integer> map = new HashMap<>();
			IntStream.range(0, N).forEach(i -> {
				int a = scanner.nextInt();
				map.put(a, map.getOrDefault(a, 0) + 1);
			});
			System.out.println(((2 == map.getOrDefault(5, 0)) && (1 == map.getOrDefault(7, 0))) ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 26192
#include<iostream>
#include<string>
#include<vector>
#include <math.h>

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

using namespace std;

int main() {

    LL N,K;

    cin >> N >>K;

    LL r = N%K;

    cout << min(r,abs(r-K)) <<endl;

	return 0;
}








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

int main()
{
  string line;
  getline(cin, line);

  for (char c : line)
  {
    if (islower(c))
    {
      c = toupper(c);
    }
    else if (isupper(c))
    {
      c = tolower(c);
    }
    cout << c;
  }
  cout << endl;
}



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

using namespace std;

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if(c - a - b < 0ll) {
		puts("No");
		return 0;
	}
	if(4ll * a * b < (c - a - b) * (c - a - b)) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    X, Y, Z, K = MAP()
    A = sorted(LIST(), reverse=True)
    B = sorted(LIST(), reverse=True)
    C = sorted(LIST(), reverse=True)
    tmp = []
    for aa in range(X):
        for bb in range(Y):
            for cc in range(Z):
                if (aa + 1) * (bb + 1) * (cc + 1) <= K:
                    tmp.append(A[aa] + B[bb] + C[cc])
                else:
                    break
    tmp.sort(reverse=True)
    for kk in range(K):
        print(tmp[kk])

if __name__ == '__main__':
    main()


Measured memory_bytes: 46492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool ans=false;
  while (N>=7){
    if (N%7==0){
      ans=true;
      break;
    }
    else {
      N-=4;
    }
  }
  if (N==4){
    ans=true;
  }
  if (ans){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx_4[]={1,0,-1,0}, dy_4[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n;
	string w[100];
	cin >> n;
	REP(i, n) cin >> w[i];

	vector<string> v;
	string ans = "Yes";
	v.pb(w[0]);
	for(int i = 1;i < n;i++){
		if(w[i-1].back() != w[i].front()) ans = "No";
		REP(j, v.size()){
			if(v[j] == w[i]) ans = "No";
		}
		v.pb(w[i]);
	}

	cout << ans << endl;
	rtn 0;
}

Measured memory_bytes: 256