akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	char ch;
	while (ch = getchar(), !isdigit(ch));
	res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
}

using std::vector;
typedef long long ll;
const int N = 1e5 + 5;

vector<int> e[N];
bool in_cir[N], vis[N], flag;
ll sum[N], b[N];
int col[N], fa[N], sze[N], cir[N];
int n, m, rt, cm, bm;

template <class T>
inline T Abs(T x) {return x < 0 ? -x : x;}

inline void dfs(int x, int Fa)
{
	sum[x] = col[x] == 0 ? 1 : -1;
	for (int i = 0, im = e[x].size(); i < im; ++i)
	{
		int y = e[x][i];
		if (y == Fa)
			continue ;
		col[y] = col[x] ^ 1;
		dfs(y, x);
		sum[x] += sum[y];
	}
}

inline void work1()
{
	for (int i = 1, u, v; i < n; ++i)
	{
		read(u); read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	col[1] = 1;
	dfs(1, 0);
	if (sum[1] != 0)
		puts("-1");
	else
	{
		ll ans = 0;
		for (int i = 1; i <= n; ++i)
			ans += Abs(sum[i]);
		std::cout << ans << std::endl;
	}
}

inline int ufs_find(int x)
{
	if (fa[x] != x)
		return fa[x] = ufs_find(fa[x]);
	return x;
}

inline void ufs_merge(int x, int y)
{
	int tx = ufs_find(x),
		ty = ufs_find(y);
	if (tx != ty)
	{
		if (sze[tx] > sze[ty])
			std::swap(tx, ty);
		fa[tx] = ty;
		sze[ty] += sze[tx];
	}
}

inline void find_circle(int x, int Fa, int des)
{
	cir[++cm] = x;
	if (x == des)
	{
		flag = true; 
		return ;
	}
	for (int i = 0, im = e[x].size(); i < im; ++i)
	{
		int y = e[x][i];
		if (y == Fa)
			continue ;
		find_circle(y, x, des);
		if (flag)
			return ;
	}
	--cm;
} 

inline void work2()
{
	for (int i = 1; i <= n; ++i)
		fa[i] = i, sze[i] = 1;
	for (int i = 1, u, v; i <= n; ++i)
	{
		read(u); read(v);
		if (ufs_find(u) == ufs_find(v))
		{
			rt = u;
			find_circle(u, 0, v);
		}
		else
		{
			ufs_merge(u, v);
			e[u].push_back(v);
			e[v].push_back(u);
		}
	}
	dfs(rt, 0);
	if (cm & 1)
	{
		if (Abs(sum[rt]) & 1)
			puts("-1");
		else
		{
			ll tmp = sum[rt] / 2, ans = 0;
			ans += Abs(tmp);
			for (int i = 1; i <= cm; ++i)
				sum[cir[i]] -= tmp;
			sum[rt] -= tmp;
			for (int i = 1; i <= n; ++i)
				ans += Abs(sum[i]);
			std::cout << ans << std::endl;
		}
	}
	else
	{
		if (sum[rt] != 0)
			puts("-1");
		else
		{
			ll ans = 0;
			for (int i = 1; i <= cm; ++i)
				b[++bm] = sum[cir[i]];
			std::sort(b + 1, b + bm);
			for (int i = 1; i <= cm; ++i)
				sum[cir[i]] = b[bm >> 1] - sum[cir[i]];
			for (int i = 1; i <= n; ++i)
				ans += Abs(sum[i]);
			std::cout << ans << std::endl;
		}
	}
}

int main()
{
	read(n); read(m);
	if (m == n - 1)
		work1();
	else
		work2();
	return 0;
}

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

void dfs(int s, int p, vector<int>& dist, vector<vector<int>>& tree) {
    for (int t : tree[s]) {
        if (t == p)
            continue;

        dist[t] = dist[s] + 1;
        dfs(t, s, dist, tree);
    }
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    vector<vector<int>> tree(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> Udist(N, 0), Vdist(N, 0);
    dfs(u, -1, Udist, tree);
    dfs(v, -1, Vdist, tree);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (Udist[i] < Vdist[i]) {
            int temp = Udist[i];
            temp += Vdist[i] - Udist[i] - 1;
            ans = max(ans, temp);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
#define task "atcoder"
#define lwb lower_bound
#define upb upper_bound
#define ar array
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;

const int N=2e5+5;
int n,k;
ld a[N];

bool check(int deep)
{
    int used=k;
    for(int i=1;i<=n;++i)
    if(a[i]>deep)
    {
        int need=(a[i]+deep-1)/deep-1;
        if(need>used) return 0;
        used-=need;
    }
    return 1;
}
void solve()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>a[i];
    int l=1, r=1e9, ans=0;
//    for(int i=1;i<=10;++i) cout<<check(i);
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check(mid))
        {
            r=mid-1;
            ans=mid;
        }
        else l=mid+1;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solve();
}






Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,m;cin>>n>>m;
    vi v(n);
    vvi g(n);
    rep(i,n)cin>>v[i];
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    ll ans=0;
    rep(i,n){
        bool ok=true;
        for(ll x:g[i])if(v[x]>=v[i])ok=false;
        if(ok)ans++;
    }
    out(ans);
}

Measured memory_bytes: 9772
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define REP(i,N) for(int i = 0; i < N; i++)
typedef long long int ll;
vector<ll> sum_arr;

int main(){
    int n;
    cin >> n;
    vector<ll> num_arr;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        num_arr.push_back(tmp);
    }
    REP(i,n){
        if(i == 0) {
            sum_arr.push_back(num_arr[i]);
        }else{
            sum_arr.push_back(num_arr[i] + sum_arr[i - 1]);
        }
    }

    //戦闘が-の場合
    vector<ll> tmp_arr = sum_arr;
    ll cnt1 = 0;
    ll tmp_sum = 0;
    REP(i,n){
        tmp_sum += num_arr[i];
        if(i % 2 == 0){
            if(tmp_sum >= 0){
                ll add = -1 - tmp_sum;
                // for(int j = i; j < n; j++){
                //     tmp_arr[j] += add;
                //     // cnt1++;
                // }
                tmp_sum += add;
                cnt1 += abs(add);
            }
        }else{
            if(tmp_sum <= 0 ){
                ll add = 1 - tmp_sum;
                // for(int j = i; j < n; j++){
                //     tmp_arr[j] += add;
                //     // cnt1++;
                // }
                tmp_sum += add;
                cnt1 += abs(add);
            }
        }
    }

    //戦闘が+の場合
    tmp_arr = sum_arr;
    ll cnt2 = 0;
    tmp_sum = 0;
    REP(i,n){
        tmp_sum += num_arr[i];
        if(i % 2 == 1){
            if(tmp_sum >= 0){
                ll add = -1 - tmp_sum;
                // for(int j = i; j < n; j++){
                //     tmp_arr[j] += add;
                //     // cnt1++;
                // }
                tmp_sum += add;
                cnt2 += abs(add);
            }
        }else{
            if(tmp_sum <= 0 ){
                ll add = 1 - tmp_sum;
                // for(int j = i; j < n; j++){
                //     tmp_arr[j] += add;
                //     // cnt1++;
                // }
                tmp_sum += add;
                cnt2 += abs(add);
            }
        }
    }
    // cout << cnt1 << " "<< cnt2 <<  endl;
    cout << min(cnt1,cnt2) <<  endl;
    return 0;
}


Measured memory_bytes: 2676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int total = scan.nextInt();
		int people = scan.nextInt();
		int margin = scan.nextInt();

		int count = 0;
		for (int i = 1;; i++) {
			if (margin * (i + 1) + i * people > total) {
				break;
			}
			count++;
		}

		System.out.println(count);



	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 1073741823;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	string s, t; cin >> s >> t;
	int ans = 0;
	rep(i, s.size()){
		if(s[i]!=t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3916
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

const int inf = (int)1e8;

vector<int> calc_dist(const vector<vector<int> > &a, int s)
{
	vector<int> dist(a.size(), inf);
	priority_queue<pair<int, int> > q;

	q.push({0, s});

	while(!q.empty()) {

		int d = -q.top().first;
		int v = q.top().second;
		q.pop();
		if(dist[v] <= d)
			continue;
		dist[v] = d;

		for(int i = 0; i < a.size(); ++i) {
			if(a[v][i] >= inf)
				continue;
			q.push({-(d + a[v][i]), i});
		}
	}

	return dist;
}

vector<int> calc_idx(const vector<int> &dist)
{
	vector<int> idx(dist.size(), -1);
	int cur = 0;
	for(int i = 0; i < dist.size(); ++i) {
		if(dist[i] < inf)
			idx[i] = cur++;
	}
	return idx;
}

vector<double> solve_mat(vector<vector<double> > mat)
{
	int n = mat.size();
	vector<double> ans;

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

		int t = p;
		for(int i = p + 1; i < n; ++i) {
			if(abs(mat[i][p]) > abs(mat[t][p]))
				t = i;
		}
		swap(mat[t], mat[p]);

		if(mat[p][p] == 0)
			return ans;
		double r = mat[p][p];

		for(int x = 0; x < n; ++x) {
			if(x == p)
				continue;
			double k = mat[x][p] / r;
			mat[x][p] = 0;
			for(int i = p + 1; i < n + 1; ++i)
				mat[x][i] -= mat[p][i] * k;
		}
		for(int i = p; i < n + 1; ++i)
			mat[p][i] /= r;
	}

	ans.resize(n);
	for(int i = 0; i < n; ++i) {
		ans[i] = mat[i][n];
		//printf("%.3lf\n", ans[i]);
	}

	/*for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n + 1; ++j)
			printf("%.3lf ", mat[i][j]);
		printf("\n");
	}*/

	return ans;
}

int main()
{
	while(true) {

		int n, s, t;
		vector<int> q;
		vector<vector<int> > a;

		scanf("%d%d%d", &n, &s, &t);
		if(n == 0)
			break;
		s -= 1; t -= 1;
		q.resize(n);
		for(int i = 0; i < n; ++i)
			scanf("%d", &q[i]);
		a.resize(n);
		for(int i = 0; i < n; ++i) {
			a[i].resize(n);
			for(int j = 0; j < n; ++j) {
				scanf("%d", &a[i][j]);
				if(a[i][j] == 0)
					a[i][j] = inf;
			}
		}

		vector<int> dist = calc_dist(a, t);
		vector<int> idx = calc_idx(dist);
		int nnn = *max_element(idx.begin(), idx.end()) + 1;

		if(idx[s] == -1) {
			printf("impossible\n");
			continue;
		}

		vector<vector<double> > mat;

		mat.resize(nnn);
		for(int i = 0; i < nnn; ++i)
			mat[i].resize(nnn + 1, 0);

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

			if(idx[v] == -1)
				continue;
			if(v == t) {
				mat[idx[v]][idx[v]] = 1;
				continue;
			}

			int k = 0;
			int total = 0;

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

				if(a[v][i] >= inf)
					continue;
				if(q[v] == 1 && (dist[i] + a[v][i] != dist[v]))
					continue;
				k += 1;
				mat[idx[v]][idx[i]] = -1;
				total += a[v][i];
			}

			mat[idx[v]][nnn] = total;

			for(int i = 0; i < nnn + 1; ++i)
				mat[idx[v]][i] /= k;
			mat[idx[v]][idx[v]] += 1;
		}

		vector<double> ans = solve_mat(mat);
		if(ans.size() == nnn)
			printf("%.10lf\n", ans[s]);
		else
			printf("impossible\n");

		/*for(int i = 0; i < nnn; ++i) {
			for(int j = 0; j < nnn + 1; ++j)
				printf("%.3lf ", mat[i][j]);
			printf("\n");
		}*/
	}

	return 0;
}

Measured memory_bytes: 1284
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

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

		x -= m;
		minm = min(minm, m);
	}

	cout << (n + x / minm) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d=b+a+c;
    e=min(a,min(b,c));
    c=max(a,max(b,c));
    b=d-e-c;
    cout<<e<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3076
import itertools
N = int(input())
result = 10**18
for six in itertools.product(range(6), repeat=6):
    ans = 0
    SUM = 0
    for i in range(1, 7):
        SUM += (6**i) * six[i-1]
    if SUM <= N:
        ans += sum(six)
        rem = N-SUM
        for j in range(1, 6):
            if rem >= 9**(6-j):
                ans += rem // (9**(6-j))
                rem -= (rem // (9**(6-j))) * (9**(6-j))
        ans += rem
        result = min(ans, result)
print(result)


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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)


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

int digit_sum(int num, int A, int B);

int main()
{
    int N, A, B, i, sum = 0;
    cin >> N >> A >> B;

    for ( i=1; i<=N; i++ ) sum += digit_sum(i, A, B);
    cout << sum;
}

int digit_sum(int num, int A, int B)
{
    int temp = num, sum = 0;

    while (temp) {
        sum += temp%10;
        temp /= 10;
    }
    if ( (sum>=A) && (sum<=B) ) return num;
    else return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{ 
	char a;
	cin >> a;
	char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
	int i;
	for (i = 0;;i++) {
		if (alphabet[i] == a) {
			break;
		}
	}
	cout << alphabet[i + 1];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int last = 0;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < n-1; i++){
        if(h[i] >= h[i+1]){
            last++;
            ans = max(last, ans);
        }else{
            last = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
/* C ????§????: ?????? */
#include<bits/stdc++.h>
#define dump(a) cout << (#a) << (a) << endl
using namespace std;

#define MAX_SIZE 2000002

//pollok
int memo[MAX_SIZE]; //MAX_SIZE??????
int memo_kisu[MAX_SIZE]; //MAX_SIZE??????
vector<int> all_pks;
vector<int> kisu_pks;

//P=pk??????, index=pks????????¨?????´???
int dfs(const int P, int memo_cnt[MAX_SIZE], vector<int> &pks)
{
	//dump(level);
	if (P == 0) { return 0; }
	if (memo_cnt[P] != -1) { return memo_cnt[P]; } //?????¢????????\
	
	int min_depth = INT_MAX;
	//100??????
	for(int i=0; i<pks.size(); i++) { //??§?????????
		int next_P = P-pks[i];
		if (next_P >= 0) {
			int depth = dfs(next_P, memo_cnt, pks) + 1; //????????°???????????????
			min_depth = min(min_depth,depth); //????°????????????°
		}
		//?????????????????´???????¬?
	}
	//???????????¢???
	memo_cnt[P] = min_depth;
	
	return min_depth;
}

int main() {
	int n=1;
	while(true) {
		int pk = n * (n+1) * (n+2) / 6;
		if (pk >= MAX_SIZE){ break; }

		all_pks.push_back(pk);
		if (pk % 2 != 0) { kisu_pks.push_back(pk); }
		n++;
	}
	reverse(begin(all_pks),end(all_pks));
	reverse(begin(kisu_pks),end(kisu_pks));

	memset(memo,-1,sizeof(memo));
	memset(memo_kisu,-1,sizeof(memo_kisu));

	int P;
	while(cin >> P) {
		if (P == 0) { break; }

		int index=0; //
		int left=0,right=0;
		left = dfs(P, memo, all_pks);
		right = dfs(P,memo_kisu, kisu_pks);
		cout << left << " " << right << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 16848
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s[sz(s)-1]=='s'){
    cout<<s<<"es"<<endl;
  }
  else{
    cout<<s<<'s'<<endl;
  }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int H,W,A,B;
	cin>>H>>W>>A>>B;

	vector<vint>fld(H,vint(W,1));
	
	rep(i,H)rep(j,A)fld[i][j]=0;
	rep(i,B){
		rep(j,W)fld[i][j]^=1;
	}

	rep(i,H){
		rep(j,W){
			printf("%lld",fld[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 9088
#include<stdio.h>

int min(int n, int m);


int main() {
	int N, M, D[1001], C[1001];
	int ew[1001][1001] = { 0 };

	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &D[i]);
	}
	for (int i = 1; i <= M; i++) {
		scanf("%d", &C[i]);
	}

	for (int i = 1; i <= M; i++) {
		ew[i][i] = ew[i - 1][i - 1] + C[i] * D[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= M; j++) {
			ew[i][j] = min(ew[i][j - 1], ew[i - 1][j - 1] + D[i] * C[j]);
		}
	}
	
	printf("%d\n", ew[N][M]);
	return 0;
}

int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 6652
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
//#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define izryt bool
#define fi first
#define se second
#define res resize
const llint mod=1000000007;
const llint gya=500000004;//mod modで2の逆元
const llint big=1e9;
const llint red=0xE869120;
const llint pro=1002001;
//10,7,4,1,0,0,0,0,0,0
//aaabbbbaaa
int main(void){
	string str;
	int i,j,H,W;
	cin>>H>>W;
	for(i=0;i<W+2;i++){
		cout<<'#';
	}cout<<endl;
	for(i=0;i<H;i++){
		cout<<'#';
		cin>>str;
		cout<<str;
		cout<<'#'<<endl;
	}
	for(i=0;i<W+2;i++){
		cout<<'#';
	}cout<<endl;
	return 0;
}
		

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main() {
    char chk;
    while(1){
        scanf("%c", &chk);
        if (isalpha(chk)){
            if (islower(chk)){
                printf("%c", toupper(chk));
            } else {
                printf("%c", tolower(chk));
            }
        } else {
            printf("%c", chk);
        }
        if (chk == '\n') break;
    }
    return 0;
}


Measured memory_bytes: 3140
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	sort(all(a));
	
	double ans = -(double)inf;
	rep(i, n) {
		FOR(j, i + 1, n) {
			int cd = a[j] - a[i];
			VI v_ab;
			for (int k = n - 1; k >= 0; --k) {
				if (k != i && k != j)v_ab.pb(a[k]);
				if (sz(v_ab) == 2)break;
			}
			int ab = v_ab[0] + v_ab[1];

			ans = max(ans, (double)ab / cd);
		}
	}
	printf("%.20f\n", ans);
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int B=0;
  int C=0;

  
  vector<int> A(N);
  for(int i=0; i<N;i++)
  {
    cin >> A.at(i);
  }
  for(int k=0; k<N;k++)
  {


      if( A.at(k)>(B+1) )
      {
        A.at(k)=-1;
      }
      

        if(A.at(k)==B+1)
        {
        B++;
        continue;
        
        }
      if( A.at(k)<(B+1) )
      {
        A.at(k)=-1;
      }   
  }
  for(int l=0;l<N;l++)
  {
    if(A.at(l)>-1)
    {
    C++;
    }
  }
  if (C==0)
  {
    cout << -1 << endl;
  }
  else
  {
  cout << (N-C) << endl;
  }
}

Measured memory_bytes: 3988
#include <iostream>
#include <string>

static const int MONEY = 1000; 

int main() 
{
    unsigned int goods = 0;
    unsigned int num = 0;

    std::cin >> goods;
    if (1 > goods || 10000 < goods)
    {
        std::cout << "No goods" << std::endl;
        return -1;
    }
    num = goods % MONEY;

    if (0 == num) {
        std::cout << "0" << std::endl;
    }
    else
    {
        num = MONEY - num;
        std::cout <<  num;
    }
    return 0;
}

Measured memory_bytes: 3608
n = int(input())
m = []

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    m.append(tmp)

#辺を全て持つリストを作る
edge_list = [] 
j = 1
for i in range(n-1):
    for k,x in enumerate(m[i][j:]):
        if x != -1:
            edge_list.append((x,i,k+j))
        else:
            pass
    j += 1
edge_list.sort()

root_list = [i for i in range(n)]

def root(x):
    path_to_root = []
    while root_list[x] != x:
        path_to_root.append(x)
        x = root_list[x]
    for node in path_to_root:
        root_list[node] = x
    return x

def is_same_root(x,y):
    return root(x) == root(y)

def unite(x,y):
    root_list[root(x)] = root(y)

cost = 0
for x in edge_list:
    w,p,q = x
    if is_same_root(p,q):
        continue
    else:
        cost += w
        unite(p,q)

print(cost)



Measured memory_bytes: 6196
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

S=input()
SN=sum(map(int, S))
print("No" if int(S)%SN else "Yes")


Measured memory_bytes: 3064
N = input()
T, A = map(int, input().split(" "))
H = map(int, input().split(" "))

def tempAve(x):
    return T - x * 0.006

aveH = map(tempAve, H)
aveMin = float('inf')
result = 0
for i, val in enumerate(aveH):
    diff = abs(val-A)
    if diff < aveMin:
        aveMin = diff
        result = i
print(result + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// int64_tは9*10^18まで、intは2*10^9まで

int main() {
  int n;
  cin >> n;
  mp::cpp_int a, ans=0, asum=0, a2sum=0;
  for(int i=0; i<n; i++){
    cin >> a;
    asum+=a;
    a2sum+=a*a;
  }
  ans=(asum*asum)-a2sum;
  ans/=2;
  ans%=1000000007;
  cout << ans;
  return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll N;
    int list[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    scanf("%lld", &N);

    // ll ans = N * (N - 1) / 2 + M * (M-1) / 2;

    printf("%d\n", list[N-1]);

    return 0;

}

Measured memory_bytes: 256
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: u32,
        k: u32,
    }
    
    for i in 0..n {
        if k.pow(i) <= n && k.pow(i + 1) > n {
            println!("{}", i + 1);
            break;
        }
    }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int A,B;
  cin>>A>>B;
  if(A%2&&B%2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;
#define prev pre
const int N = (int) 1e6 + 5, mod = (int) 0, oo = (int) 1e9;
int cnt, to[N], cap[N], mark[N], en, prev[N], head[N];
void add_edge(int u, int v, int uv, int vu = 0) {
	int &e = en;
	to[e] = v, cap[e] = uv, prev[e] = head[u], head[u] = e++;
	to[e] = u, cap[e] = vu, prev[e] = head[v], head[v] = e++;
}
int dfs(int v, int dest, int f = 1e9) {
	if (v == dest) return f;
	if (mark[v]++) return 0;
	for (int e = head[v]; ~e; e = prev[e]) {
		int u = to[e];
		if (cap[e]) {
			int x = dfs(u, dest, min(f, cap[e]));
			if (x) {
				cap[e] -= x;
				cap[e ^ 1] += x;
				return x;
			}
		}
	}
	return 0;
}
int max_flow(int src, int snk) {
	int res = 0;
	while (true) {
		for (int j = 0; j < cnt; ++j) mark[j] = 0;
		int x = dfs(src, snk);
		if (!x) break;
		res += x;
	}
	return res;
}
int n, m;
int f(int x, int y) { return x * m + y; }
int main() {
	memset(head, -1, sizeof head);
	cin >> n >> m;
	int src = n * m * 2 + n + m, snk = src + 1;
	for (int a = 0; a < n; ++a) {
		for (int b = 0; b < m; ++b) {
			char c;
			cin >> c;
			if (c != '.') {
				add_edge(f(a, b) << 1 | 0, f(a, b) << 1 | 1, 1);
				add_edge(f(a, b) << 1 | 1, n * m * 2 + a, oo);
				add_edge(n * m * 2 + a, f(a, b) << 1 | 0, oo);
				add_edge(n * m * 2 + n + b, f(a, b) << 1 | 0, oo);
				add_edge(f(a, b) << 1 | 1, n * m * 2 + n + b, oo);
			}
			if (c == 'S') {
				add_edge(src, f(a, b) << 1 | 1, oo);
			}
			if (c == 'T') {
				add_edge(f(a, b) << 1 | 0, snk, oo);
			}
		}
	}
	cnt = snk + 1;
	int x = max_flow(src, snk);
	if (x > n * m * 2) {
		cout << -1 << endl;
	} else {
		cout << x << endl;
	}
}


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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
using namespace std;
int fact(int n) {
	if (n == 0)return 1;
	return n * fact(n - 1);
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int a[114]; int n, x, ans = 0, cnt = 0;
signed main() {
	cin >> n >> x;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n)cnt += a[i];
	if (cnt >= x) {
		rep(i, n) {
			x -= a[i];
			if (x >= 0)ans++;
		}
		cout << ans << endl;
	}
	else cout << n - 1 << endl;
	getchar(); getchar(); return 0;
}

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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n,m,a,b;
        cin>>n>>m;
        vll v(n),good(n,true);
        rep(i,0,n-1) cin>>v[i];
        rep(i,0,m-1)
        {
        	cin>>a>>b; --a;--b;
        	if(v[a]==v[b])good[a]=false,good[b]=false;
        	if(v[a]>v[b])good[b]=false;
        	else good[a]=false;
        }
        int ans=0;
        rep(i,0,n-1)if(good[i])++ans;
        cout<<ans;

        cout<<'\n';
    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
//cout<<"Yes"<<endl;
//cout<<"No"<<endl;
int main(){
  int n;
  cin>>n;
  ll sum=1;
  vector <ll> v;
  REP(i,n){
    ll tmp;
    cin>>tmp;
    if(tmp==0){
      cout<<0<<endl;
      return 0;
    }
    v.push_back(tmp);
  }
  REP(i,n){
    ll a;
    a=v[i];
    if(1000000000000000000/sum>=a){
      sum*=a;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 4320
using System;
using System.Linq;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();

            var odd = Enumerable.Range(1,s.Length).Where(i => i % 2 != 0).Select(i => s[i-1]);
            var even = Enumerable.Range(1,s.Length).Where(i => i % 2 == 0).Select(i => s[i-1]);

            var isOddGood = odd.All(c => c == 'R' || c == 'U' || c == 'D');
            var isEvenGood = even.All(c => c == 'L' || c == 'U' || c == 'D');

            Console.WriteLine(isOddGood & isEvenGood ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, d;
    cin >> n >> d;
    int x[n][d];
    repi(i, n, 0)
    {
        repi(j, d, 0)
        {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    repi(i, n, 0)
    {
        repi(j, n, i+1)
        {
            double dist = 0;
            repi(k, d, 0)
            {
                dist += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
            }
            dist = sqrt(dist);
            if (dist == int(dist))
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define int ll

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int ITER_MAX = 1E6, LMT = 2E9;
int n, val[10];

int BFS(int s = n) {
	set<int> vis = {s};
	map<int, int> cost;
	set<pi> best = {{0, s}};
	int iter = 0;
	while(!best.empty()) {
		int nr = (*best.begin()).sd;
		best.erase(best.begin());
		for(int x : {2, 3, 5}) {
			//decrease
			int maybe = (nr % x) * val[1] + val[x];
			if(nr/x < LMT)
				maybe = min(maybe, (nr - nr/x) * val[1]);
			if(!vis.count(nr/x) || cost[nr/x] > cost[nr] + maybe) {
				vis.insert(nr/x);
				cost[nr/x] = cost[nr] + maybe;
				best.insert({cost[nr/x], nr/x});
			}
			if(nr/x < LMT)
				maybe = min(maybe, (nr - (nr + x - 1)/x * val[1]));
			maybe = ((x - nr % x) % x) * val[1] + val[x];
			if(!vis.count((nr + x - 1)/x) || cost[(nr + x - 1)/x] > cost[nr] + maybe) {
				vis.insert((nr + x - 1)/x);
				cost[(nr + x - 1)/x] = cost[nr] + maybe;
				best.insert({cost[(nr + x - 1)/x], (nr + x - 1)/x});
			}
		}	
		++iter;
	}
	return cost[1] + val[1];
}

void solve() {
	cin >> n >> val[2] >> val[3] >> val[5] >> val[1]; 
	cout << BFS() << '\n';
}

int32_t main() {
	int t;
	cin >> t;
	while(t--)
		solve();
}


Measured memory_bytes: 4952
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int n ;
  cin >> n ;
  int h, w ;
  cin >> h >> w ;
  
  cout <<(n-h+1)*(n-w+1)<<endl ;


  return 0 ;
}




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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  if (l%d != 0) {
    cout << r/d - l/d << endl;
  }
  else cout << r/d - l/d + 1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b;
string s;
vector<int>v;
int main(){

	cin >> n >> k;
	for(int i =0;i<k;i++){
		cin >> x;
		v.push_back(x);
	}

	int mx = 0;
	for(int i =1;i<k;i++){
		mx = max(v[i]-v[i-1],mx);
	}
	mx = max(n-v.back()+v[0],mx);
	cout << n-mx;

	return 0;
}

Measured memory_bytes: 1400
#include <iostream>

#include <fstream>

#include <vector>
#include <set>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#include <algorithm>
#include <iomanip>
#include <cmath>
#include <random>
#include <cstdlib>
#include <ctime>
#include <utility>

#include <limits>

using namespace std;

typedef long long ll;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(clock());
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; ++j) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 8) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

/*

 */

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.algorithm;

void main() {
	auto s = readln.chomp;
	size_t begin, end = 1, cnt;
	string cache = "";
	while (end < s.length) {
		if (cache != s[begin..end]) {
			++cnt;
			cache = s[begin..end];
			begin = end;
			end = end + 1;
		}
		else {
			++end;
		}
	}
	if (cache == s[begin..end])
		write(cnt);
	else
		write(cnt+1);
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ran 222222
int n,m;
vector<int> e[ran];
bool vis[ran];
void dfs(int x){
	if(vis[x])return;
	vis[x] = true;
	for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){
		dfs(*it);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++){
		int x,y;
		for(scanf("%d",&x); x--;){
			scanf("%d",&y);
			y += n;
			e[i].push_back(y);
			e[y].push_back(i);
		}
	}
	dfs(1);
	bool fl = true;
	for(int i=1; i<=n; i++)if(!vis[i])
		fl = false;
	puts(fl?"YES":"NO");
	return 0;
}


Measured memory_bytes: 9216
def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return 1^x
    else:
        return 0

def main():
    import sys
    input = sys.stdin.readline
    a, b = map(int, input().split())
    print(f(a-1)^f(b))
    

if __name__ == '__main__':
    main()

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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

int main() {
    int n;
    cin >> n;
    int a = n / 100;
    int b = n / 10 - a * 10;
    int c = n % 10;
    vector<int> vec = {a, b, c};

    for (int& i : vec) {
        if (i == 1)
            i = 9;
        else if (i == 9)
            i = 1;
    }
    print(vec[0] * 100 + vec[1] * 10 + vec[2]);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define sc scanf
#define pf printf
#define se second
#define sq(x) x * x
#define ll long long
#define pb push_back
#define mk make_pair
#define ld long double
#define pr pair<int,int>
#define sz(s) int(s.size())
#define piip pair< pair<ll,ll>,ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e9;
const ll N = 2e2+7;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;
ll a, b, n , cnt ,mx,ans,c;
ll used[ N ];
string s;
int main()
{
        TIME;
        cin >> a >> b;
        cout << a + b /2;
}


/* MADE BY
//________________________________________________________
//________________________________________________________ //
                                                           //
// ██╗   ██╗     ██████╗     ███████╗    ██╗    ███╗   ██╗ //
// ╚██╗ ██╔╝    ██╔═══██╗    ██╔════╝    ██║    ████╗  ██║ //
//  ╚████╔╝     ██║   ██║    ███████╗    ██║    ██╔██╗ ██║ //
//   ╚██╔╝      ██║   ██║    ╚════██║    ██║    ██║╚██╗██║ //
//    ██║       ╚██████╔╝    ███████║    ██║    ██║ ╚████║ //
//    ╚═╝        ╚═════╝     ╚══════╝    ╚═╝    ╚═╝  ╚═══╝ //
//________________________________________________________ //
//________________________________________________________ */


Measured memory_bytes: 256