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

int main(){
    int a, b, h, m; cin >> a >> b >> h >> m;
    int time=60*h+m;
    double diff=(0.5*time)-(6*time%360);//単位は°
    if (diff>=180) diff=-diff;
    double C=abs(diff); 
    //cout << C << endl;
    double d=a*a+b*b-2*a*b*cos(C/180*M_PI);
    cout << fixed << setprecision(15) << sqrt(d) << endl;
}

Measured memory_bytes: 4188
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	int n, l, r;
	while (cin >> n >> l >> r,n) {
		vector<int> v;
		rep(i, n) {
			int a; cin >> a; v.push_back(a);
		}
		int out = 0;
		Rep1(i, l, r) {
			int chk = n;
			per(j, (int)v.size()) {
				if (i%v[j] == 0)chk = j;
			}
			if (chk % 2==0)out++;
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#if 0
2019.10.06

干，如果我容斥再学好那么一点就可以在 AGC 上 A 掉这题了。

一次操作实际就是将 01 串的最后一位翻转后移动到最前面，
那么任何 01 串都能在 2n 次操作后恢复。
那么什么 01 串能在小于 2n 次操作后恢复？
具体的推证略去，事实上一定要存在 k < n 满足以下几点：
1) k 是 n 的因子，且 n / k 是奇数
2) 将 01 串分成 n / k 段，相邻两段互为取反
此时该串能在 2k 次操作后恢复，并且逆命题同样成立。
不难发现 k = n 时同样可以适应上面的条件，
因此，一个 01 串的最小操作次数为满足条件的最小 2k 。

现在考虑统计，明显数位 DP 的套路，
从左到右每次扫到一个 1 就考虑该位选 0 ，前面不变，后面随便的情况的贡献。
枚举可能的每个 k ，若当前扫到的是第 i 位为 1 ，分类讨论，
1) 如果 i <= k ，那么第 i + 1 位到第 k 位随便选，后面的就是不断取反的 n / k 段，
那么贡献就是 2^(k - i) * k * 2 。
2) 否则 k < i ，如果前 i - 1 位加上 0 正好满足 k 的限制的话，那也是有贡献的，
此时由于前 k 位已经确定，后面同样是确定的，贡献为 k * 2 ，
判断是否有贡献的方法可以预处理每个 t[k] 表示满足 k 限制的最大前缀，
那么这种情况有贡献当且仅当 t[k] = i - 1 。

然而上述方法是会算重的，不难发现若某个 01 串的贡献为 2k ，
上述方法会将所有满足 k | x 的 2x 算入贡献，
因为一个 01 串满足 k 的限制也一定能满足 k 的整数倍的限制，
考虑容斥，记 k 的贡献系数为 a[k] 而不是单纯的 2k ，
从大到小计算 a[k] ，每次减去 k 的整数倍 x 的所有 a[x] 即可。

另外，上述方法无法统计到恰输入串本身的贡献，特殊考虑即可。
#endif
#include <cstdio>
#include <cassert>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 200005, mod = 998244353;
char s[maxn];
int X[maxn];
int to[maxn];
lolong p2[maxn];
lolong a[maxn];

lolong power(lolong x, int k) {
	if(k < 0) k += mod - 1;
	lolong res = 1;
	while(k) {
		if(k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

int main() {
	int n = input();
	scanf("%s", s + 1);

	p2[0] = 1;
	for(int i = 1; i <= n; i ++)
		p2[i] = (p2[i - 1] << 1) % mod;

	int p = 0;
	for(int x = 1; x * x <= n; x ++)
		if(!(n % x)) {
			if((n / x) & 1)
				X[++ p] = x;
			if(x & 1 and x * x != n)
				X[++ p] = n / x;
		}

	std::sort(X + 1, X + p + 1);

	for(int k = 1; k <= p; k ++) {
		int x = X[k];
		int &t = to[x];
		t = x;
		while(t < n and s[t + 1] != s[t + 1 - x])
			t ++;
		/* debug("%d -> %d\n", x, t); */
	}

	for(int k = p; k; k --) {
		int x = X[k];
		a[x] = x << 1;
		for(int l = k + 1; l <= p; l ++) {
			int y = X[l];
			if(!(y % x))
				a[x] += mod - a[y];
		}
		a[x] %= mod;
		/* debug("%d : %lld\n", x, a[x]); */
	}

	lolong ans = 0;

	for(int i = 1; i <= n; i ++)
		if(s[i] == '1') {
			for(int k = 1; k <= p; k ++) {
				int x = X[k];
				if(i <= x) {
					/* for(int l = 1; l <= p; l ++) */
					/* 	if(!(X[l] % x)) */
					/* 		assert(i <= X[l] or to[X[l]] == i - 1); */
					/* debug(">%d %d %lld\n", i, x, p2[x - i]); */
					ans += a[x] * p2[x - i] % mod;
				}
				else if(to[x] == i - 1) {
					/* for(int l = 1; l <= p; l ++) */
					/* 	if(!(X[l] % x)) */
					/* 		assert(to[X[l]] == i - 1 or i <= X[l]); */
					/* debug(">>%d %d\n", i, x); */
					ans += a[x];
				}
			}
			ans %= mod;
			/* debug("%lld\n", ans); */
		}

	for(int k = 1; k <= p; k ++)
		if(to[X[k]] == n)
			ans += a[X[k]];
	ans %= mod;

	printf("%lld\n", ans);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int a[10000001];
inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int main(){
	int n=read(),s=0;
	for(int i=1;i<=n;i++){
		a[i]=i;
		s+=i;
		if(s>n)
		break;
	}
	int t=s-n;
	for(int i=1;i<=n;i++){
		if(a[i]){
			if(a[i]!=t)
			{
				write(a[i]);
				printf("\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for ( int i = 0; i < n ; i ++)
int N, K;
vector<int> p;
int main()
{
	int t = 0, m = 0;
	double ans = 0;
	scanf("%d %d", &N, &K);
	rep(i, N)scanf("%d", &t), p.push_back(t);
	t = 0;
	rep(i, K)t += p[i];
	m = t;
	rep(i, N - K) {
		t += p[i + K] - p[i];
		if (m < t)m = t;
	}
	printf("%f", (double)(m + K) / 2);
	return 0;
}

Measured memory_bytes: 1400
S=list(map(int,list(input())))
K=int(input())

if S[0]==1:
  if K==1:
    print(1)
  else:
    for i in range(1,len(S)):
      if S[i] != 1:
        print(S[i])
        exit(0)
      if i == K-1:
        print(1)
        exit(0)
else:
  print(S[0])

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int maxn=2000005;
int p[maxn];
int sz[maxn];
int cnt=0;
void clear(int n=maxn){
    rep(i,0,n+1)p[i]=i,sz[i]=1;
    cnt=n;
}
int root(int x){
   while(x!=p[x]){
       p[x]=p[p[x]];
       x=p[x];
   }
   return x;  
}
void merge(int x,int y){
    int p1=root(x);
    int p2=root(y);
    if(p1==p2)return;
    cnt--;
    if(sz[p1]>=sz[p2]){
        p[p2]=p1;
        sz[p1]+=sz[p2];
        sz[p2]=0;
    }
    else{
        p[p1]=p2;
        sz[p2]+=sz[p1];
        sz[p1]=0;
    }
}

int solve(){
 	int n;cin>>n;
 	int s=0;
 	int p=0;
 	rep3(n){
 		int t;cin>>t;
 		s=(s+t)%hell;
 		p=(p+t*t%hell)%hell;
 	}
 	cout<<((s*s%hell-p+hell)%hell*500000004)%hell<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3564
/**
 *   author: sahushivam
 *   created: 18 August 2019 (Sunday)  18:13:47
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int timer=0;
int dfs(int parent,int v,vector<int> &size,vector<vector<int>> &adj,vector<int> &pos)
{
    timer++;
    pos[v]=timer;
    for (int u : adj[v]) {
        if (u!=parent)
            size[v]+=dfs(v,u,size,adj,pos);
    }
    return size[v];
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n,q,a,b;
    cin>>n>>q;
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++) 
    {
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> size(n,1),pos(n,0);
    dfs(-1,0,size,adj,pos);
    vector<int> prefix(n+1,0);
    for(int i=0;i<q;i++)
    {
        cin>>a>>b;
        prefix[pos[a-1]]+=b;
        prefix[pos[a-1]+size[a-1]]-=b;
    }
    for(int i=1;i<n+1;i++)
        prefix[i]+=prefix[i-1];
    for(int i=0;i<n;i++)
        cout<<prefix[pos[i]]<<" ";
return 0;
}

Measured memory_bytes: 34432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
//#define int long long
using namespace std;
const int maxn=5e5+1000;
typedef long long ll;
int n,m;
const int mod=998244353;
int fr[maxn],ans;
inline int ksm(int num,int t){
	int res=1;
	for(;t;t>>=1,num=1ll*num*num%mod){
		if(t&1)res=1ll*res*num%mod;
	}
	return res;
}
inline int c(int m,int n){
	return 1ll*fr[n]*ksm((1ll*fr[m]*fr[n-m])%mod,mod-2)%mod;	
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	fr[0]=fr[1]=1;
	for(int i=2;i<maxn;i++)fr[i]=1ll*fr[i-1]*i%mod;	
	for(int i=0;i<=min(n,m);i++){
		ans=(ans+1ll*ksm(-1,i)*(1ll*c(i,n)*c(i,m)%mod*fr[i]%mod*ksm(m+1,n-i)%mod*ksm(n+1,m-i)%mod)%mod)%mod;	
	}
	ans=(ans%mod+mod)%mod;
	cout<<ans;
	return 0;
}////

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

const int INF = 1 << 28;
inline void chmin(int &a, int b){a = min(a, b);}

int n;
int p[41], t[41];
int dp[42][4];

int calc()
{
	fill_n(*dp, 42 * 4, INF);
	dp[0][0] = 0;
	
	int pp = 0, pt = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			int nt = pt + abs(p[i] - pp) * (j + 1);
			if (t[i] >= nt){
				chmin(dp[i + 1][j + 1], dp[i][j] + abs(p[i] - pp));
			}
		}
		for (int j = 1; j < 4; j++){
			int nt = pt + (pp * (j + 1)) + p[i];
			if (t[i] >= nt){
				chmin(dp[i + 1][1], dp[i][j] + pp + p[i]);
			}
		}
		bool f = false;
		for (int j = 0; j < 4; j++) f |= dp[i + 1][j] != INF;
		if (!f) return -i - 1;
		pp = p[i], pt = t[i];
	}
	
	return dp[n][1];
}

int main()
{
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++) scanf("%d %d", p + i, t + i);
		p[n] = 0, t[n] = 1 << 28;
		n++;
		int res = calc();
		if (res > 0) printf("OK %d\n", res);
		else printf("NG %d\n", -res);
	}
}

Measured memory_bytes: 1188
ans = []
n = int(input())
while(n != 0):
    if(n % 2 == 0):
        ans = ans + ["0"]
        n = -(n // 2)
    else:
        ans = ans + ["1"]
        n = -(n // 2)
u = ""
if ans == []:
    u = "0"
else:
    for x in ans:
        u = x + u
print(u)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
n, k, q = map(int, input().split())
scores = [0 for _ in range(n)]

for _ in range(q):
    p = int(input()) - 1
    scores[p] += 1

for s in scores:
    if k - q + s <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 4672
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define MOD2 998244353
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;

template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

int main(){
    FAST;
    ll n, k;
    cin >> n >> k;
    n = n%k;
    ll m = abs(n-k);
    n = min(n,m);
    cout << n << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n; 
    ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  SORT(A);
  REV(A);
  ll ans=0;

  if(n%2==0){
    FOR(i,0,n/2-1){
      ans+=2*A[i];
    }
    ans+=A[n/2-1];
    ans-=A[n/2];
    FOR(i,n/2+1,n){
      ans-=2*A[i];
    }
  }

  else{
    FOR(i,0,n/2){
      ans+=2*A[i];
    }
    ans-=A[n/2];
    ans-=A[n/2+1];
    FOR(i,n/2+2,n){
      ans-=2*A[i];
    }
    ll carry=ans;
    ans=0;

    FOR(i,0,n/2-1){
      ans+=2*A[i];
    }
    ans+=A[n/2-1];
    ans+=A[n/2];
    FOR(i,n/2+1,n){
      ans-=2*A[i];
    }
    chmax(ans,carry);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e5 + 5)], ans[int(2e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%lld", A + i);

  ll sum = 0;
  for (int i = 0; i < N; i+=2){
    ll now = A[i] ^ A[i + 1];
    sum = sum ^ now;
  }

  for (int i = 0; i < N; i++){
    ans[i] = sum ^ A[i];
    cout << ans[i];
    if (i == N - 1) cout << endl;
    else cout << " ";
  }

  return 0;
}


Measured memory_bytes: 6740
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<string.h>

#define		MXCD		52
#define		CCD			13

int		main(void)
{
	int		n;
	int		atai;
	int		i;
	int		s[CCD+1]={0};
	int		h[CCD+1]={0};
	int		c[CCD+1]={0};
	int		d[CCD+1]={0};
	char	syubetu[10];

	scanf("%d",&n);

	for(i=0; i<n; i++)
	{
		scanf("%s",syubetu);
		scanf("%d",&atai);

		if( strcmp("S",syubetu)==0 )
		{
			s[atai] = 1;
		}
		else if( strcmp("H",syubetu)==0 )
			h[atai] = 1;

		else if( strcmp("C",syubetu)==0 )
			c[atai] = 1;

		else
			d[atai] = 1;
	}

	for(i=1; i<=CCD; i++)
	{
		if(s[i] ==0 )
		{
			//printf("%d %d\n",i,s[i]);
			printf("S %d\n",i);
		}
	}
	for(i=1; i<=CCD; i++)
	{
		if(h[i] ==0 )
		{
			printf("H %d\n",i);
		}
	}
	for(i=1; i<=CCD; i++)
	{
		if(c[i] ==0 )
		{
			printf("C %d\n",i);
		}
	}
	for(i=1; i<=CCD; i++)
	{
		if(d[i] ==0 )
		{
			printf("D %d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
a=list(map(int,input().split()))

x=a[2]-a[0]
y=a[3]-a[1]
x3=a[2]-y
y3=a[3]+x
print(x3,y3,end=' ')
x=x3-a[2]
y=y3-a[3]
x4=x3-y
y4=y3+x
print(x4,y4)

Measured memory_bytes: 3064
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmn=[](auto&x,auto y){if(x>y){x=y;return true;}return false;};
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    vec<i32> a(2);
    for (i32& x: a) std::cin >> x;

    i32 ans = numr<i32>::max();
    for (usize bs=0; bs<4; bs++) {
        vec<i32> b = a;
        for (usize i=0; i<2; i++) if (bs>>i&1) {
            b.at(i) = -b.at(i);
        }
        if (b.at(0) <= b.at(1)) {
            cmn(ans, __builtin_popcount(bs) + b.at(1) - b.at(0));
        }
    }

    std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define pb push_back
using ll = long long;
const ll M = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> is;
ll power(ll x,ll y){
    if(y==0)
    return 1;
    ll res=power(x,y/2);
    res=(res*res)%M;
    if(y&(ll)1)
    res=(res*x)%M;
    return res;
}


int n;vector<int> h,h1;
vector<vector<int>> gr,bl;
int dfs(int c,int co)
{
    h[c]=co;
    int ans=0;
    for(int i=0;i<gr[c].size();i++)
    {
        if(h[gr[c][i]]==0)
        ans+=dfs(gr[c][i],co);
    }
    return 1+ans;
}
void solve(){
    int m,k,u,v;
    cin>>n>>m>>k;
    gr.resize(n+1);
    bl.resize(n+1);
    h.resize(n+1,0);
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    for(int i=0;i<k;i++)
    {
        cin>>u>>v;
        bl[u].pb(v);
        bl[v].pb(u);
    }
    int co=1;
    for(int i=1;i<n+1;i++)
    {
        if(h[i]==0)
        {
            int ans=dfs(i,co);
            co++;
            h1.pb(ans);
            //cout<<ans<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
        int ans=h1[h[i]-1]-gr[i].size()-1;
        for(int j=0;j<bl[i].size();j++)
        {
            if(h[bl[i][j]]==h[i])
            ans--;
        }
        cout<<max(0,ans)<<" ";
    }
    cout<<endl;
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int>P(N);
  for(int i=0; i<N; i++)cin >> P.at(i);
  sort(P.begin(), P.end());
  
  int ans =0; 
  for(int i=0; i<K; i++)ans += P.at(i);
  
  cout << ans << endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int X = sc.nextInt();
    	int Y = sc.nextInt();
    	int Z = sc.nextInt();
    	sc.close();
    	X = X - Z;
    	int ans = 0;
    	while(X >= 0){
    		X = X - (Y + Z);
    		ans++;
    	}
    	System.out.println(ans == 0 ? 0 : ans-1);
    }
}

Measured memory_bytes: 22860
#include <iostream>
#include <string>
using namespace std;
int main(){
  string a,b;
  cin >> a>> b;
  if(a.size()>b.size()){
    cout <<"GREATER"<<endl;
    return 0;
  }
  if(a.size()<b.size()){
    cout <<"LESS"<<endl;
    return 0;
  }
  if(a==b) {
    cout <<"EQUAL"<<endl;
    return 0;
  }
  if(a.size()==b.size()){
    for(int i=0;i<a.size();i++){
        if(a[i]>b[i]){
          cout <<"GREATER"<<endl;
          return 0;
        }
        if(a[i]<b[i]){
          cout <<"LESS"<<endl;
          return 0;
        }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int N;
    ll C;
    cin >> N >> C;
    vector<ll> x(N), v(N);
    rep(i,N) cin >> x[i] >> v[i];
    vector<ll> cum(N+1, 0);
    vector<ll> max_cum(N+1,-INF);
    vector<ll> rcum(N+1, 0);
    vector<ll> max_rcum(N+1,-INF);

    rep(i,N){
        cum[i+1] = cum[i] + v[i];
        max_cum[i+1] = max(max_cum[i], cum[i+1]-x[i]);
    }
    rep(i,N){
        rcum[i+1] = rcum[i] + v[N-i-1];
        max_rcum[i+1] = max(max_rcum[i], rcum[i+1]-(C-x[N-i-1]));
    }

    ll ans = 0;
    for(int i = 0; i <= N; i++){
        if (i == 0) ans = max(ans, max_rcum[N]);
        else ans = max(ans, cum[i]-2*x[i-1]+max_rcum[N-i]);
    }
    for(int i = 0; i <= N; i++){
        if (i == 0) ans = max(ans, max_cum[N]);
        else ans = max(ans, rcum[i]-2*(C-x[N-i])+max_cum[N-i]);
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 7984
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int h;
    cin >> h;
    int w;
    cin >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++)
    {
        cin >> a[i];
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
            {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        if (row[i])
        {
            for (int j = 0; j < w; j++)
            {
                if (col[j])
                {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall

"""
def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] =min(d[i][j],d[i][k] + d[k][j])            
    return d
"""
N, M, L = map(int, input().split())

d = [[0 for i in range(N)] for i in range(N)]

for i in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = C
    d[B-1][A-1] = C

d = floyd_warshall(d, directed = False)
S = [[0 for i in range(N)] for i in range(N)]


for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            S[i][j] = 1
            S[j][i] = 1
            
S = floyd_warshall(S, directed = False)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if S[s-1][t-1] == float("inf"):
        print(-1)
    else: 
        print(int(S[s-1][t-1]-1))

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

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

int main() {
    int n; cin >> n;
    vector<int> w(n);

    int sum = 0;
    rep(i, n) {
        cin >> w.at(i);
        sum += w.at(i);
    }

    int minv = 0;
    int s1 = 0;
    rep(i, n) {
        s1 += w.at(i);
        if (i == 0) minv = abs(sum-s1 -s1);
        minv = min(minv, abs(sum-s1 -s1));
    }
    cout << minv << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int w, n, a[31], tmp, x, y, i;
  for(i = 1; i < 31; i++)
    a[i] = i;
  scanf("%d\n%d\n", &w, &n);
  for(;n--;){
    scanf("%d,%d", &x, &y);
    tmp = a[x];
    a[x] = a[y];
    a[y] = tmp;
  }
  for(i = 1; i < w+1; i++)
    printf("%d\n", a[i]);
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void){
    int k,n,max=0;
    scanf("%d %d",&k,&n);
    int a[n];
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(int i=0; i<n-1; i++){
        if(a[i+1]-a[i]>max)
            max=a[i+1]-a[i];
    }
    if(k+a[0]-a[n-1]>max)
            max=k+a[0]-a[n-1];
    printf("%d",k-max);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int sum(string j)
{
long long int s1=0,i=0;
while(j[i])
{
s1=s1+(int(j[i])-48);
i++;
}
  
return s1;
}
main()
{
string s;
  cin>>s;
  if(sum(s)%9==0)
    cout<<"Yes";
  else
    cout<<"No";

}

Measured memory_bytes: 3828
package main

import (
	"fmt"
	// "math"
)

func main() {
	var s string
	fmt.Scan(&s)

	if s == "Sunny" {
		fmt.Println("Cloudy")
	} else if s == "Cloudy" {
		fmt.Println("Rainy")
	} else if s == "Rainy" {
		fmt.Println("Sunny")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100];
	int b[26];
	int i,j,l,flag;
	for(i=0;i<26;i++)
	{
		b[i]=0;
	}
	scanf("%s",a);
	l=strlen(a);
	for(j=0;j<l;j++)
	{
		b[a[j]-'a']++;
	}
	for(i=0;i<26;i++)
	{
			if(b[i]%2==0)
			{
				flag=1;
			}
			else
			{
				flag=0;
				printf("No\n");
				break;
			}
	}
	if(flag==1)
	{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
n=gets.to_i
hs=gets.split.map(&:to_i)
ans=0
n.times do |i|
  if i==0
    ans+=1
  else
    cur=hs[i]
    ans+=1 if hs[0..i-1].all?{|hi| hi<=cur}
  end
end
puts ans


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

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var acc = new bool[n];
        var wac = new int[n];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var p = int.Parse(line[0]) - 1;
            if (line[1] == "WA" && !acc[p]) wac[p]++;
            else if (line[1] == "AC" && !acc[p]) { acc[p] = true; }
        }
        var ans1 = acc.Count(x => x == true);
        var ans2 = 0;
        for (int i = 0; i < n; i++)
            if (acc[i]) ans2 += wac[i];
        Console.WriteLine("{0} {1}", ans1, ans2);
    }
}


Measured memory_bytes: 17612
#include <stdio.h>
#include <stdlib.h>

int qs(const void *,const void *);

int main()
{
    int N,a[100],i;
    int alice=0,bob=0;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,N,sizeof(int),qs);

    // for(i=0;i<N;i++){
    //     printf("%d\n",a[i]);
    // }

    for(i=0;i<N;i++){
        if(i%2==0){
            alice += a[i];
        }else{
            bob += a[i];
        }
    }

    printf("%d\n",alice-bob);

    return 0;
}

int qs(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}

Measured memory_bytes: 128
<?php

$input = explode(' ', trim(fgets(STDIN)));
$a = (int)$input[0];
$b = (int)$input[1];
$c = (int)$input[2];

$can = (int)floor($b / $a);
if ($can >= $c) {
	echo $c;
}else{
	echo $can;
}

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

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> cake(H);
    for (int i = 0; i < H; i++) cin >> cake[i];
    int t = 0;
    while (count(cake[t].begin(), cake[t].end(), '#') == 0) t++;
    vector<vector<int>> cut(H, vector<int>(W, 0));
    int num = 1;
    int u = count(cake[t].begin(), cake[t].end(), '#');
    for (int i = 0; i < W; i++) {
        cut[t][i] = num;
        if (num < u && cake[t][i] == '#') num++;
    }
    num++;
    for (int i = 0; i < t; i++) {
        for (int j = 0; j < W; j++) {
            cut[i][j] = cut[t][j];
        }
    }
    for (int i = t+1; i < H; i++) {
        if (count(cake[i].begin(), cake[i].end(), '#') == 0) {
            for (int j = 0; j < W; j++) cut[i][j] = cut[i-1][j];
        }else{
            u = count(cake[i].begin(), cake[i].end(), '#');
            int v = 1;
            for (int j = 0; j < W; j++) {
                cut[i][j] = num;
                if (v < u && cake[i][j] == '#') {
                    num++;
                    v++;
                }
            }
            num++;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << cut[i][j] << (j == W-1 ? "\n" : " ");
        }
    }
    return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector <pair<int, int>> vec;
int dp[3001][3001];

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

    int N, T;
    cin >> N >> T;

    int A, B;
    vec.resize(N);
    rep (i, N)
    {
        cin >> A >> B;
        vec[i] = pair<int, int>(A, B);
    }

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

    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= T; ++j)
        {
            A = vec[i - 1].first;
            B = vec[i - 1].second;
            if (j >= A)
            {
                dp[i][j] = MAX(dp[i - 1][j - A] + B, dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
            ans = MAX(ans, dp[i - 1][j - 1] + B);
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 35456
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}


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


	int N = getint();
	ll XL[100000];
	const ll k = 1e9;
	rep(i, N) {
		int x = getint(), l = getint();
		XL[i] = (x - l + k << 32) + x + l;
	}
	pakuri_sort(N, XL);

	ll mae = -2e9;
	int kotae = 0;
	const ll m = (1ll << 32) - 1;
	rep(i, N) {
		if (mae <= (XL[i] >> 32) - k) {
			kotae++;
			mae = XL[i] & m;
		}
	}
	printf("%d\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

string s;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>s;
    int sum = 0;
    for(char i: s){
        sum += (i-'0');
    }
    if(sum%9==0){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>


using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int a[n][m];
    int b[m];
    
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;++i){
        cin>>b[i];
    }
    
    for(int i=0;i<n;++i){
        int sum=0;
        for(int j=0;j<m;++j){
            sum+=a[i][j]*b[j];
        }
        cout<<sum<<endl;
        
    }
    
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n,m;
ll x;
vector<pair<int,ll>> G[10010];
int t[10010];
ll d[10010][610];

int f(int tem) {
    if (tem < 0) return -tem;
    if (tem == 0) return 300;
    return tem + 300;
}

int go(int tem, ll cost) {
    if (abs(tem) <= cost) return 0;
    if (tem < 0) return tem + cost;
    return tem - cost;
}

bool ok(int tem, int type) {
    if (type == 1) return 1;
    if (type == 0) return tem <= 0;
    return tem >= 0;
}

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

    cin >> n >> m >> x;
    REP(i,n) {
        cin >> t[i];
    }
    REP(i,m) {
        int from, to;
        ll cost;
        cin >> from >> to >> cost;
        from--;
        to--;
        G[from].pb({to,cost});
        G[to].pb({from,cost});
    }

    REP(i,10010) {
        REP(j,610) {
            d[i][j] = INF;
        }
    }

    // コスト，温度，ノード
    priority_queue<pair<pair<ll,int>,int>,
                    vector<pair<pair<ll,int>,int>>,
                    greater<pair<pair<ll,int>,int>>> pq;
    pq.push({{0,-x},0});
    d[0][f(-x)] = 0;
    while (!pq.empty()) {
        pair<pair<ll,int>,int> tp = pq.top();
        pq.pop();
        ll c = tp.fi.fi;
        int tem = tp.fi.se;
        int v = tp.se;
        if (d[v][f(tem)] < c) continue;
        for  (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i].fi;
            ll cost = G[v][i].se;
            int type = t[to];
            int tt = go(tem, cost);
            if (!ok(tt, type)) continue;
            if (type == 0) tt = -x;
            else if (type == 2) tt = x;
            if (d[to][f(tt)] > c + cost) {
                d[to][f(tt)] = c + cost;
                pq.push({{d[to][f(tt)], tt}, to});
            }
        }
    }
    ll ans = INF;
    for (int i = 0; i <= x; i++) {
        ans = min(ans, d[n-1][f(i)]);
        ans = min(ans, d[n-1][f(-i)]);
    }
    cout << ans << endl;
}


int main(int argc, char *argv[]){

    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }

    /* AOJ */
    solve();

    return 0;
}


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

const int MAX = 1e5;

int N, M;
vector<int> G[MAX];

ll dp[MAX];

int it;
ll memo[MAX * 2];

ll dfs1(int v, int prev) {
	ll res = 1;
	for (auto to : G[v]) if (to != prev) {
		int id = it++;
		memo[id] = dfs1(to, v);
		(res *= memo[id] + 1) %= M;
	}
	return res;
}

vector<ll> x[MAX];

void get(int v, int prev) {
	int sz = G[v].size();
	x[v].assign(sz - (prev != -1), 0);
	int id = 0;
	for (auto to : G[v]) if (to != prev) {
		x[v][id++] = memo[it++];
		get(to, v);
	}
}

void dfs2(int v, int prev, ll tmp) {
	int sz = G[v].size() + (prev == -1);
	vector<ll> l(sz, 1), r(sz, 1);
	for (int i = 1; i < sz; i++) {
		l[i] = l[i - 1] * (x[v][i - 1] + 1) % M;
	}
	for (int i = sz - 1; i > 0; i--) {
		r[i - 1] = r[i] * (x[v][i - 1] + 1) % M;
	}
	int id = 0;
	for (auto to : G[v]) if (to != prev) {
		int i = id++;
		ll t = (tmp * l[i] % M * r[i + 1] + 1) % M;
		dp[to] = x[v][i] * t % M;
		dfs2(to, v, t);
	}
}

int main()
{
	cin >> N >> M;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dp[0] = dfs1(0, -1); it = 0;
	get(0, -1);
	dfs2(0, -1, 1);
	for (int i = 0; i < N; i++) {
		cout << dp[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 24320
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO ()
main = do
  {[r] <- getDoubles
  ; let area = pi * r^2
  ; let peri = 2 * pi * r
  ; putDoubles [area, peri]
   }
  
--

getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords. map show

getDoubles :: IO[Double]
getDoubles = map read. words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""



Measured memory_bytes: 4108
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(n: int, k: int, a: "List[int]"):
    num = 2 ** (max(int(math.log2(max(a))) + 1, int(math.log2(k + 0.0001)) + 1))
    num2 = int(math.log2(num))
    for i in range(n):
        a[i] = bin(a[i] + num)[3:]
    binary = [[i,0,0] for i in range(num2)]
    for i in range(n):
        for j in range(num2):
            if a[i][j] == "0":
                binary[num2 - j - 1][1] += 1
            else:
                binary[num2 - j - 1][2] += 1
    binary.sort(reverse = True)
    ans = 0
    check = 0
    for i in range(len(binary)):
        if binary[i][1] > binary[i][2]:
            check += 2 ** binary[i][0]
            if check <= k:
                ans += binary[i][1] * (2 ** binary[i][0])
            else:
                check -= 2 ** binary[i][0]
                ans += binary[i][2] * (2 ** binary[i][0])
        else:
            ans += binary[i][2] * (2 ** binary[i][0])
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  cin >> a;
  cin >> b;
  if ((0<a) && (a<10) && (0<b) && (b<10)){
    cout << a*b << endl;
  }else{
    cout << "-1" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();

        if(d == 25){
            System.out.println("Christmas");
        } else if(d == 24){
            System.out.println("Christmas Eve");

        } else if(d == 23){
            System.out.println("Christmas Eve Eve");

        } else {
            System.out.println("Christmas Eve Eve Eve");

        }
    }
}

//
//class Gauss {
//    //連立方程式の係数
//    //a[N][N](係数行列)とb[1](定数)を一緒にしたもの
//    double a[][];
//    int N;
//
//    Gauss(double[][] a, int N){
//        a = a;
//        N = N;
//    }
////    double a[][]={{1.0,1.0,1.0,1.0,10,0},
////            {2.0,1.0,3.0,2.0,21.0},
////            {1.0,3.0,2.0,1.0,17.0},
////            {3.0,2.0,1.0,1.0,14.0}};
////    int N=a.length;
//
//    //Gaussの消去法で連立方程式を解く
//    void gauss(){
//        //前進消去
//        double s;
//        for(int k=0; k<N-1; k++){
//            for(int i=k+1; i<N; i++){
//                s=a[i][k]/a[k][k];
//                for(int j=k+1; j<=N; j++){
//                    a[i][j] -= s * a[k][j];
//                }
//            }
//        }
//        //後退代入
//        for(int i=N-1; i>=0; i--){
//            s=a[i][N];
//            for(int j=i+1; j<N; j++){
//                s -= a[i][j] * a[j][N];
//            }
//            a[i][N] = s/a[i][i];
//        }
//    }
//    public static void run() {
//        Gauss gs= new Gauss();
//        gs.gauss();
//        //解の表示
//        System.out.println("ガウスの消去法による連立1次方程式の解");
//        for(int i=0; i<gs.N; i++){
//            System.out.println("x["+i+"] = "+gs.a[i][gs.N]);
//        }
//    }
//}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    string s; cin >> s;
    int n = s.size();
    ll res = 0;
    vl cnt(26);
    rep(i,n){
        rep(j,26){
            if(s[i] - 'a' != j)res+=cnt[j];
        }
        cnt[s[i]-'a']++;
    }
    out(res + 1);
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>> 
#define vll vector <pair<ll,ll>> 
#define vi vector <int> 
#define vl vector <ll> 
#define mp(a,b) nake_pair(a,b)
#define F first
#define S second
using namespace std;



int main()
{
    ll a,b;
    cin>>a>>b;

    ll c=a+b;
    ll d=a-b;
    ll e=a*b;
    cout<<max(c,max(d,e));
    return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);

int main(void) {
	int   N,i;
	char  str[4];
	double coin,total=0;
	
	i_cin(N);
	rept(i, 0, N) {
		scanf("%lf %s", &coin, str);
		if (!memcmp(str, "JPY", 3)) total += coin;
		else {
			total +=(coin*380000.0);
		}
	}
	
	f_cout(total);

	return 0;
}

//降順
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
//
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	rept(i, 0, n) {
		i_cin(*(a + i));
	}
	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int k,t,i,j,ans=0;
  cin>>k>>t;
  int a[t];
  P p,b;
  priority_queue<P> q;
  for(i=0;i<t;i++) {
    cin>>a[i];
    q.push(P(a[i],i));
  }
  for(i=0;i<k;i++){
    if(q.empty()) {
      ans++;
      continue;
    }
    p=q.top();q.pop();
    if(b.first) q.push(b);
    a[p.second]--;
    b=P(a[p.second],p.second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256