akhauriyash/Code-Regression huggingface dataset:
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;

const int N = 3e5 + 123;

int n, m, k;
vector < pii > gr[N];
int a[N];
int dp1[N] , cnt1[N], dp2[N], cnt2[N] , w[N] , v[N] , u[N];

main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int s , t;
	cin >> n >> m >> s >> t;

	rep(i , 1 , n)
		dp1[i] = dp2[i] = 1e17;
	dp1[s] = dp2[t] = 0;
	cnt1[s] = cnt2[t] = 1;
	
	for(int i = 1; i <= m; i++){
		cin >> u[i] >> v[i] >> w[i];
		gr[u[i]].pb({v[i],w[i]});
		gr[v[i]].pb({u[i],w[i]});
	}
	set < pii > st;
	st.insert({0 , s});
	
	while(sz(st) != 0){
		int u = (*st.begin()).se;
		st.erase(st.begin());
		for(auto to : gr[u]){
			if(dp1[to.fi] == dp1[u] + to.se)
				cnt1[to.fi] += cnt1[u], cnt1[to.fi] %= mod;
			else if(dp1[to.fi] > dp1[u] + to.se){
				st.erase({dp1[to.fi] , to.fi});
				dp1[to.fi] = dp1[u] + to.se;
				cnt1[to.fi] = cnt1[u];
                st.insert({dp1[to.fi],to.fi});
			}
		}
	}    

	st.insert({0 , t});
	while(sz(st) != 0){
		int u = (*st.begin()).se;
		st.erase(st.begin());
		for(auto to : gr[u]){
			if(dp2[to.fi] == dp2[u] + to.se)
				cnt2[to.fi] += cnt2[u] , cnt2[to.fi] %= mod;
			else if(dp2[to.fi] > dp2[u] + to.se){
				st.erase({dp2[to.fi] , to.fi});
				dp2[to.fi] = dp2[u] + to.se;
				cnt2[to.fi] = cnt2[u];
                st.insert({dp2[to.fi],to.fi});
			}
		}
	}	
	int tot = cnt1[t] * cnt1[t]%mod;
	for(int i = 1; i <= m; i++){
		if(dp1[u[i]] + dp2[v[i]] > dp2[u[i]] + dp1[v[i]])
			swap(u[i],v[i]);
		if(dp1[u[i]] + dp2[v[i]] + w[i] == dp1[t]){
			int l = max(dp1[u[i]],dp2[v[i]]) , r = min(dp1[u[i]],dp2[v[i]])+w[i];
			if(l < r)
				tot -= cnt1[u[i]] * cnt2[v[i]] % mod * cnt1[u[i]] % mod * cnt2[v[i]] % mod , tot += mod , tot %= mod;
		}
	}

	for(int i = 1; i <= n; i++)
		if(dp1[i] + dp2[i] == dp1[t] and dp1[i] == dp2[i])
			tot -= cnt1[i] * cnt2[i] % mod * cnt1[i] %mod * cnt2[i] % mod , tot += mod , tot %= mod;


	ret(tot);
        
}
 


Measured memory_bytes: 39024
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
   int a,b;
   cin>>a>>b;
   a+=b;
   a%=24;
   cout<<a;

}






Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
	int x, i, j, t;
	x = A[r];
	i = p - 1;
	for( j = p; j < r; j++) {
		if(A[j] <= x) {
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i+1]; A[i+1] = A[j]; A[j] = t;
	return i+1;
}

int main() {
	int i, q;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", &A[i]);
	
	q = partition(0,n - 1);
	
	for(i = 0; i < n; i++) {
		if(i) printf(" ");
		if(i == q) printf("[");
		printf("%d", A[i]);
	    if(i == q) printf("]");		
	}
	printf("\n");
	
	return 0;
}

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

int main() {
  int a, b, c;
  int k;
  cin >> a >> b >> c;
  cin >> k;
  while ( k-- > 0 ) {
    if ( a >= b ) {
      b *= 2;
    } else {
      c *= 2;
    }
  }
  string ans = (a < b && b < c) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
N = int(input())
h = [10**10]+list(map(int,input().split()))
dp = [10**10]*(N+1)
dp[1] = 0
for i in range(2,N+1):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i-2]-h[i]))
print(dp[N])


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

struct edge{
    i64 src, to, cost, t;
    edge(i64 to, i64 cost) : src(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : src(src), to(to), cost(cost) {}
    bool operator <(const edge &u){
        return this->cost < u.cost;
    };
};

using Graph = vector<vector<edge>>;
const i64 INF = numeric_limits<i64>::max();

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }
};


int main(){
    i64 n, m;
    cin >> n >> m;
    Graph G(n);
    UnionFind uf(n);
    rep(i, m){
        i64 l, r, d;
        cin >> l >> r >> d;
        --l; --r;
        uf.unite(l, r);
        G[l].push_back(edge(l, r, d));
        G[r].push_back(edge(r, l, -1 * d));
    }
    vector<i64> dist(n);
    vector<bool> used(n);
    rep(i, n){
        if(used[i]) continue;
        queue<i64> que;
        que.push(i);
        while(!que.empty()){
            i64 t = que.front();
            que.pop();
            for(auto e : G[t]){
                i64 v = e.to;
                if(!used[v]){
                    dist[v] = dist[t] + e.cost;
                    used[v] = true;
                    que.push(v);
                }else{
                    if(dist[v] != dist[t] + e.cost){
                        //cout << t << " " << v << endl;
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;
}


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

int main()
{
    int n;
    cin >> n;
    int a[200005];
    for(int i = 0; i < n; i++) cin >> a[i];
    int x = 0;
    for(int i = 1; i < n; i++) x ^= a[i];
    cout << x << " ";
    for(int i = 1; i < n; i++){
        x ^= a[i] ^ a[i - 1];
        cout << x << " ";
    }
    cout << endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string o,e;
    cin >> o >> e;

    string ans;
    for(int i=0;i<e.size();i++){
        ans+=o[i];
        ans+=e[i];
    }

    if(o.size()-e.size()==1){
        ans+=o[o.size()-1];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <math.h>
int main(void){
    double r, c, s;
    
    while(scanf("%lf", &r) != EOF)
    {
        c = 2.0 * r * M_PI;
        s = r * r * M_PI;
        
        printf("%.6lf %.6lf\n", s, c);
        
    }
    
   return 0;
}


Measured memory_bytes: 2124
#include<stdio.h>
    int main(){
        int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
                if(a == b){
                    printf("%d", c);
                }else if(a == c){
                    printf("%d", b);
                }else{
                    printf("%d", a);
                }
        return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n{0};
	ll x{0};
	ll t{0};
	cin>>n>>x>>t;

	ll temp{0};
	if(n%x==0)
		temp=n/x;
	else
		temp=n/x+1;

	cout<<(temp*t)<<endl;

	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S, T;
    cin >> S >> T;
    int s = S.size(), t = T.size();
    rep(t, i, s + 1)
    {
        string sub = S.substr(s - i, t);
        bool flag = true;
        rep(0, j, t)
        {
            if ((sub.at(j) != '?') && (sub.at(j) != T.at(j)))
            {
                flag = false;
            }
        }
        if (flag)
        {
            rep(0, j, s)
            {
                if (S.at(j) == '?')
                {
                    S.at(j) = 'a';
                }
            }
            for (int j = s - i; j < s - i + t; j++)
            {
                S.at(j) = T.at(j - s + i);
            }
            cout << S << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN=5100;
const ll MAXK=17;
const ll INF=1e18;
const ll MOD=1e9+7;
ll N,T,a,b,c,d,e,f;
ll memo[MAXN][MAXN];


int main(){
    cin>>a>>b>>c>>d>>e;
    ll tar=abs(a-c);
    if (b<d){
    	cout<<"NO";
    }else{
    	ll ds = (b-d)*e;
    	if(ds>=tar){
    		cout<<"YES";
    	}else{
    		cout<<"NO";
    	}
    }
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int a, b, c;

void read() {
  cin >> a >> b >> c;
}

void solve() {
  cout << (a + b >= c ? "Yes" : "No");
}


int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t;           // PLEASE REMOVE IT IF NEEDED
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
//-----------------------------------------------------------------------------------
 
    int A, B, C;
 
    cin >> A >> B >> C;
 
    if(C-(A-B) > 0){
        cout << C-(A-B) << "\n";
    }else{
        cout << 0 << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(int argc, char const *argv[])
{
    int n=0, m, f, r, data[50][3];
    rep(i, 50){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        data[i][0] = m;
        data[i][1] = f;
        data[i][2] = r;
        n++;
    }

    rep(i, n) {
        int sum = data[i][0] + data[i][1];
        if(data[i][0]== -1 || data[i][1]==-1) cout << 'F' << endl;
        else if(sum>=80) cout << 'A' <<endl;
        else if(sum>=65 && sum < 80) cout << 'B' <<endl;
        else if(sum>=50 && sum < 65) cout << 'C' <<endl;
        else if(sum>=30 && sum < 50 && data[i][2] >= 50) cout << 'C' <<endl;
        else if(sum>=30 && sum < 50) cout << 'D' <<endl;
        else cout << 'F' << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3076
#include <stdio.h>

#define N_MAX 100000
#define M_MAX 20

int N, M;
int nuigurumi[N_MAX + 1];

int ncount[M_MAX];

int haiti[M_MAX][N_MAX + 1];

int memo[1 << M_MAX];

int search(int done, int pos) {
	int ret = -1;
	int candidate;
	int i;
	if (done == (1 << M) - 1) return 0;
	if (memo[done]) return ~memo[done];
	for (i = 0; i < M; i++) {
		if (!(done & (1 << i))) {
			candidate = ncount[i] - (haiti[i][pos + ncount[i] - 1] - haiti[i][pos - 1]);
			candidate += search(done | (1 << i), pos + ncount[i]);
			if (ret < 0 || candidate < ret) ret = candidate;
		}
	}
	return ~(memo[done] = ~ret);
}

int main(void) {
	int i, j;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &nuigurumi[i]) != 1) return 1;
		ncount[--nuigurumi[i]]++;
		haiti[nuigurumi[i]][i]++;
	}
	for (i = 0; i < M; i++) {
		for (j = 1; j <= N; j++) {
			haiti[i][j] += haiti[i][j - 1];
		}
	}
	printf("%d\n", search(0, 1));
	return 0;
}

Measured memory_bytes: 12892
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

template <ll MOD>
class Combination {
private:
    template <typename T> using V = vector<ll>;
    ll N;
    V<ll> factv, rfactv;

public:
    /*
     * MOD must be a prime number.
     */
    Combination<MOD> (ll N)
        : N(N), 
          factv(N + 1, 1),
          rfactv(N + 1)
    {
        for(ll i = 1; i <= N; i++) {
            factv[i] = factv[i - 1] * i % MOD;
        }
        for(ll i = 0; i <= N; i++) {
            rfactv[i] = pow(factv[i], MOD - 2);
        }
    }

    ll fact(ll n) {
        return factv[n];
    }

    ll rfact(ll n) {
        return rfactv[n];
    }

    ll pow(ll a, ll b) {
        return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1;
    }

    ll comb(ll n, ll k) {
        return factv[n] * rfactv[n - k] % MOD * rfactv[k] % MOD;
    }
};

const ll mod = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;

    Combination<mod> comb(1e5);

    for(ll i = 1; i <= K; i++) {
        ll split = N - K + 1;
        if(split < i) {
            cout << 0 << endl;
            continue;
        }
        ll line = i - 1;
        ll rest = K - (line + 1);
        ll ans = comb.comb(line + rest, rest);
        (ans *= comb.comb(N - K + 1, line + 1)) %= mod;
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  int x = n;
  bool flag = (n%2 == 0);
  rep(i, m) {
    if (flag && x-i-1 <= n/2) {
      --x;
      flag = false;
    }
    cout << i+1 << " " << x-- << endl;
  }
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>

using namespace std;
int N,M,A,B,C,D,x1,x2,y1,y2;
const int inf=1000000000;
int K[32][32];

int main(){
	for(int i=0;i<32;i++){
		for(int j=0;j<32;j++){
			if(i==j){
				K[i][j]=0;
			}else{
				K[i][j]=inf;
			}
		}
	}
	scanf("%d%d",&N,&M);
	for(int i=0;i<M;i++){
		scanf("%d,%d,%d,%d",&A,&B,&C,&D);
		K[A][B]=C;
		K[B][A]=D;
	}
	scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
	for(int k=1;k<N+1;k++){
		for(int i=1;i<N+1;i++){
			for(int j=1;j<N+1;j++){
				int temp=K[i][k]+K[k][j];
				if(K[i][j]>temp){
					K[i][j]=temp;
				}
			}
		}
	}

	cout << y1-K[x1][x2]-K[x2][x1]-y2 << endl;
}


Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10];
char s[10],c[10];

int main()
{
	scanf("%s",&s);
	for(int i=0;i<4;i++)
	{
		a[i]=s[i]-'0';
	}
	for(int i=1;i<=3;i++)
	{
		a[i]*=(-1);
		if(a[0]+a[1]+a[2]+a[3]==7)
		{
			for(int i=1;i<=3;i++)
			{
				if(a[i]<0) {c[i]='-';a[i]*=(-1);}
				else c[i]='+';
			}
			
			printf("%d%c%d%c%d%c%d=7",a[0],c[1],a[1],c[2],a[2],c[3],a[3]);
			return 0;
		}
	}
	for(int i=1;i<=3;i++)
	{
		a[i]*=(-1);
		if(a[0]+a[1]+a[2]+a[3]==7)
		{
			for(int i=1;i<=3;i++)
			{
				if(a[i]<0) {c[i]='-';a[i]*=(-1);}
				else c[i]='+';
			}
			
			printf("%d%c%d%c%d%c%d=7",a[0],c[1],a[1],c[2],a[2],c[3],a[3]);
			return 0;
		}
	}
	a[2]*=(-1);
	if(a[0]+a[1]+a[2]+a[3]==7)
	{
		for(int i=1;i<=3;i++)
		{
			if(a[i]<0) {c[i]='-';a[i]*=(-1);}
			else c[i]='+';
		}
		printf("%d%c%d%c%d%c%d=7",a[0],c[1],a[1],c[2],a[2],c[3],a[3]);
	}
	for(int i=1;i<=3;i++)
	{
		a[i]*=(-1);
		if(a[0]+a[1]+a[2]+a[3]==7)
		{
			for(int i=1;i<=3;i++)
			{
				if(a[i]<0) {c[i]='-';a[i]*=(-1);}
				else c[i]='+';
			}
			
			printf("%d%c%d%c%d%c%d=7",a[0],c[1],a[1],c[2],a[2],c[3],a[3]);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,M;
    cin>>N>>M;

    map<int,vector<int>> m;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        a--;
        m[a].push_back(b);
    }
    int ans=0;
    priority_queue<int> q;
    rep(i,M){
        for(auto p:m[i]){
            q.push(p);
        }
        if(q.empty())continue;
        ans+=q.top();
        q.pop();
    }
    cout << ans << endl;






    



}


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

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

long long MOD = 10000000000 + 7;

template<typename T>
T gcd(T a, T b) {
  if(a < b) swap(a,b);
    
  if(b == 0) return a;
  return gcd(b, a % b);
}


int main(){
  cout << setprecision(10);

  ll K; cin >> K;

  ll ans = 0;
  for(ll i = 1; i <= K; i++){ 
    for(ll j = i; j <= K; j++){ 
      for(ll k = j; k <= K; k++){ 

        ll tmp = gcd(i, gcd(j,k));
        if(i == j && j == k){
          ans += tmp;
        } else if(i == j || j == k){
          ans += tmp * 3;
        } else { 
          ans += tmp * 6;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;
int A[100000];
int f[100000], b[100000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	int x = 0;
	for (int i = 0; i < N; i++) {
		if (i > 0) f[i] += f[i - 1];
		f[i] += abs(A[i] - x);
		x = A[i];
	}
	x = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (i + 1 < N) b[i] += b[i + 1];
		b[i] += abs(A[i] - x);
		x = A[i];
	}
	for (int i = 0; i < N; i++) {
		int sum = 0;
		if (i > 0) sum += f[i - 1];
		if (i + 1 < N) sum += b[i + 1];
		if (i == 0) sum += abs(A[1]);
		else if (i == N - 1) sum += abs(A[N - 2]);
		else sum += abs(A[i + 1] - A[i - 1]);
		cout << sum << endl;
	}
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,u,sum[200010];
    vector<int> t(n);
    string s;
    bool can=false,can1=false;
    cin>>n>>s;
    sum[0]=0;
    for(int i=0;i<n;i++){
        if(s[i]=='#'){
            sum[i+1] =sum[i]+1;
        }
        else sum[i+1]=sum[i];
    }
    ll ans =INF;
    bool flag=false;
    ll cnt=0;
    rep(i,n){
        if(s[i]=='#'){
            flag =true;
            cnt++;
            ans =min(ans,sum[i]+(n-i-1)-(sum[n]-sum[i+1]));
        }
    }
    if(!flag) ans=0;
    cout<<min(cnt,ans)<<endl;
    return 0;
}

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

int main() {
  stack<int> sta;
  int temp;
  
  while(cin >> temp){    
    if (temp==0){
      if (sta.empty()==false){
	cout << sta.top() <<endl;
	sta.pop();
      }
    }else{
      sta.push(temp);
    }
  }
    
  return 0;
  
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}




int main() {
	Int N; cin >> N;
	//Int X; cin >> X;
	vector<int> an(N),sum(N-1);
	for (int i = 0; i < N; i++) {
		cin >> an[i];
	}
	
	int a = 0, b = 0;
	for (int i = 1; i < N ; i++) {
		a = accumulate(an.begin(), an.end()-i, 0);
		//cout << a << endl;
		b = accumulate(an.end()-i, an.end(), 0);
		//cout << b << endl;
		sum[i-1] = abs(a - b);
		//cout << i << " " << a << " " << b << endl;
	}
	//printVec(sum);
	int mins;
	mins = *min_element(sum.begin(), sum.end());
	cout << mins << endl;

	return 0;
}

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

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    let N: usize = read();
    let vec = (0..N).map(|_| read::<usize>()).collect::<Vec<usize>>();
    if vec[0] != 0 {
        println!("-1");
        return;
    }
    for v in vec.windows(2) {
        let before = v[0];
        let now = v[1];
        if now > before + 1 {
            println!("-1");
            return;
        }
    }
    let mut ans = 0;
    use std::collections::{BinaryHeap, HashSet};
    let mut set = HashSet::new();
    let mut heap: BinaryHeap<Rev<usize>> = BinaryHeap::new();

    for (minus_val, &v) in vec.iter().rev().enumerate() {
        if v == 0 {
            set.clear();
            heap.clear();
            continue;
        }
        let mut remove_flag = false;
        if let Some(min) = heap.peek() {
            let Rev(min) = *min;
            if (min - minus_val) == 0 {
                remove_flag = true;
            }
        }
        if remove_flag {
            let min = heap.pop().unwrap().0;
            set.remove(&min);
        }
        if !set.contains(&(v + minus_val)) {
            set.insert(v + minus_val);
            heap.push(Rev(v + minus_val));
        }
        ans += set.len();
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int m, n;
  cin >> m >> n;
  int a[m][n];
  REP(i, m) {
    REP(j, n) {
      cin >> a[i][j];
    }
  }
  int b[n];
  REP(i, n) cin >> b[i];

  REP(i, m) {
    int sum = 0;
    REP(j, n) {
      sum += a[i][j] * b[j];
    }

    cout << sum << "\n";
  }
}



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

int main() {
  int n, x;
  cin >> n >> x;
  int l[n];
  for ( int i = 0; i < n; i++ ) { cin >> l[i]; }

  int ct = 1, d = 0;  
  for ( int i = 0; i < n; i++ ) {
    d += l[i];
    if ( d > x ) { break; }
    ct++;
  }

  cout << ct << endl;
  return 0;
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

vector<int> to[2001];
map<int, int> mp;

void rec(int cur, int depth, vector<bool> &used) {
    if (used[cur]) return;
    used[cur] = true;
    mp[depth]++;

    for (auto t : to[cur]) {
        rec(t, depth + 1, used);
    }
}

void solve(long long N, long long X, long long Y) {
    rep(i, N - 1) {
        to[i].push_back(i + 1);
        to[i + 1].push_back(i);
    }
    to[Y - 1].push_back(X - 1);
    to[X - 1].push_back(Y - 1);

    rep(i, N) {
        vector<bool> used(N);
        queue<pii> que;
        que.emplace(i, 0);
        while (!que.empty()) {
            auto p = que.front();
            que.pop();
            int cur = p.first, depth = p.second;
            if (used[cur]) continue;
            used[cur] = true;
            mp[depth]++;
            for (auto next : to[cur]) {
                que.emplace(next, depth + 1);
            }
        }
    }

    for (int i = 1; i < N; i++) {
        cout << mp[i] / 2 << endl;
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
        long long int i,j,temp,n,*a;
	cin>>n;
	a = new long long int[n];
        for(i=0;i<n;i++)
		cin>>a[i];

	for(i=1;i<n;i++)
        {
           j=i-1;
	   temp=a[i];
	   while(j>=0&&a[j]>temp)
	   {
		   a[j+1]=a[j];
		   j--;
	   }
	   a[j+1]=temp;
        }

	if(n&1)cout<<0;
	else
	{
           int index;
	   index = n/2-1;
	   cout<<a[index+1]-a[index];
	}


	
}


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

string S;
long long K;

int main() {
    cin >> S >> K;
    int count = 1;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != '1') {
            count = i + 1;
            break;
        }
    }
    
    if (K < count) {
        cout << '1' << endl;
        return 0;
    }
    
    cout << S[count - 1] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int m,n,a[100],b[100],c[100],i,j,l,sum=0,k,d;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    scanf("%d",&m);
    for(i=0;i<m;i++)
        scanf("%d%d",&b[i],&c[i]);
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(b[i]==j+1)
            {
                k=a[j]-c[i];
                d=sum-k;
                printf("%d\n",d);
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
q=int(input())
sum1=sum(a)
d={}
for x in range(n):
  s=a[x]
  if s not in d:
    d[s]=0
  d[s]+=1

for y in range(q):
  h,g=map(int,input().split())
  if h in d:
    r=d[h]
    sum1=sum1-r*h
    
    if g not in d:
      d[g]=0
    d[g]+=r
    sum1+=r*g
    d[h]=0
    
  print(sum1)

Measured memory_bytes: 20816
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a),n/2));
    }
    return power((a*a),n/2);
}
int lcm(int a,int b)
{
  return (a*b)/__gcd(a,b);
}

map<int,vector<int>>adj;
map<int,bool>vis;
void dfs(int u)
{
  vis[u]=1;
  for(auto ch:adj[u])
    if(!vis[ch])
      dfs(ch);
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  int n ,m;
  cin>>n>>m;

  for(int i = 0;i<m ;i++)
  {
    int u,v;
    cin>>u>>v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int cnt = 0;
  for(int i= 1;i<= n;i++)
  {
    if(!vis[i])
    {
      dfs(i);
      cnt++;
    }
  }
  cout<<cnt-1<<endl;
}

//

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.resize(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int X;
  cin >> X;
  vector<int> v;
  v.push_back(1);
  for (int i = 2; i <= X; i++) {
    for (int j = 2; pow(i, j) <= X; j++) {
      v.push_back(pow(i, j));
    }
  }
  sort(v.begin(), v.end(), ::greater<int>());
  cout << v[0] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
  
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  
  if (S.at(K-1) == 'A') {
    S.at(K-1) = 'a';
  }
  else if (S.at(K-1) == 'B') {
    S.at(K-1) = 'b';
  }
  else if (S.at(K-1) == 'C') {
    S.at(K-1) = 'c';
  }
  cout << S << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = LI()
L = [0]
for i in range(n):
    L += [(L[-1] + A[i] - 1) % k]

D = defaultdict(int)
ans = 0
for i in range(n + 1):
    if i >= k:
        D[L[i - k]] -= 1
    ans += D[L[i]]
    D[L[i]] += 1

print(ans)

Measured memory_bytes: 133344
import math


def simple_sol(N, A):
    is_pairwise_coprime = True
    for i in range(N - 1):
        for j in range(i + 1, N):
            g = math.gcd(A[i], A[j])
            if g == 1:
                continue
            is_pairwise_coprime = False
            break
        if not is_pairwise_coprime:
            break
    if is_pairwise_coprime:
        return 'pairwise coprime'
    g = A[0]
    for i in range(1, N):
        g = math.gcd(g, A[i])
        if g == 1:
            return 'setwise coprime'
    return 'not coprime'



def factorial(n): 
    f = []
    c = 0
    r = int(n**0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c !=0 :
            f.append([i, c])
            c = 0
    if n != 1:
        f.append([n, 1])
    return f


def main():
    N = int(input())
    A = list(map(int, input().split()))
    # print(simple_sol(N, A))
    exponents = [0] *  (10 ** 6 + 1)
    is_pairwise_coprime = True
    for a in A:
        for x, e in factorial(a):
            if exponents[x] > 0:
                is_pairwise_coprime = False
                break
            exponents[x] = e
        if not is_pairwise_coprime:
            break
    if is_pairwise_coprime:
        print('pairwise coprime')
        return
    g = A[0]
    for i in range(1, N):
        g = math.gcd(g, A[i])
        if g == 1:
            print('setwise coprime')
            return
    print('not coprime')


if __name__ == '__main__':
    main()


Measured memory_bytes: 205568
s = raw_input()
count = 0
num = 0
i = 0
length = len(s)
while i < length:
	if s[i] == 'A':
		num += 1
		i += 1
	elif i+1 < len(s) and s[i] == 'B' and s[i+1] == 'C':
		count += num
		i += 2
	else:
		num = 0
		i += 1
print count


Measured memory_bytes: 85536
#include <iostream>
#include <vector>
using namespace std;
long long MOD = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<long long> cnt(60, 0);
    for(int i = 0; i < N; i++){
        int cn = 0;
        long long t = A[i];
        while(t > 0){
            if(t % 2 == 1) cnt[cn]++;
            cn++;
            t >>= 1;
        }
    }
    long long ans = 0;
    for(int i = 0; i < 60; i++){
        ans += (1LL << i) % MOD * cnt[i] % MOD * (N - cnt[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5648
#include <stdio.h>
#include <stdlib.h>
#define int long long

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int A, B, C;
	scanf("%lld%lld%lld", &A, &B, &C);
	printf("%lld\n", B + min(C, A + B + 1));
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;sc.hasNext();) {
			double x[] = new double[4];
			double y[] = new double[4];
			for(int i=0;i<4;i++) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
			}
			
			x[0] -= x[1];
			y[0] -= y[1];
			x[2] -= x[3];
			y[2] -= y[3];
			if( x[0] * x[2] + y[0] * y[2] == 0 ) 
				System.out.println("YES");
			else System.out.println("NO");
		}
	}
	

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 19;

int a[N];
int b[N][N];

int main() {
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    for (int j = 0; j < m; ++j) {
      scanf("%d", b[i] + j);
    }
  }
  const int inf = 1'000'000'000;
  int ans = inf;
  for (int mask = 0; mask < (1 << n); ++mask) {
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      int sum = 0;
      for (int i = 0; i < n; ++i) {
        if (mask >> i & 1) {
          sum += b[i][j];
        }
      }
      if (sum < x) {
        ok = false;
      }
    }
    if (!ok) {
      continue;
    }
    int cur = 0;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        cur += a[i];
      }
    }
    ans = min(ans, cur);
  }
  if (ans == inf) {
    ans = -1;
  }
  printf("%d\n", ans);
}


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

int main(){
	int animals,legs;
  cin>>animals>>legs;
  for(int i=0;i<=animals;i++){
  	if(i*2 + (animals-i)*4 == legs){
    	cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1, 105):
    for j in range(1, 105):
        for k in range(1, 105):
            v = i*i+j*j+k*k+i*j+j*k+k*i;
            if v < 10050:
                ans[v] += 1
for i in range(n):
    print(ans[i+1])


Measured memory_bytes: 9264
#include <iostream>

using namespace std;

int W,H;

bool table[50][50];


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

void dfs(int x,int y){
	table[x][y]=0;
	for(int i=0;i<8;i++){
		if(0<=x+dx[i]&&x+dx[i]<W&&0<=y+dy[i]&&y+dy[i]<H&&table[x+dx[i]][y+dy[i]])
			dfs(x+dx[i],y+dy[i]);
	}
	return ;
}


int main(void){
	while(cin >> W >> H,W|H){
		for(int y=0;y<H;y++)
			for(int x=0;x<W;x++)
				cin >> table[x][y];
		int num=0;
		for(int y=0;y<H;y++)
			for(int x=0;x<W;x++)
				if(table[x][y])
					num++,dfs(x,y);
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
typedef tuple<double,double,double> T;

T operator-(const T Ta, const T Tb){
    double Xa,Ya,Za,Xb,Yb,Zb;
    tie(Xa,Ya,Za)=Ta;
    tie(Xb,Yb,Zb)=Tb;
    return T(Xa-Xb,Ya-Yb,Za-Zb);
}

double inner_cross(T Ta, T Tb){
    double Xa,Ya,Za,Xb,Yb,Zb;
    tie(Xa,Ya,Za)=Ta;
    tie(Xb,Yb,Zb)=Tb;
    return Xa*Xb+Ya*Yb+Za*Zb;
}

typedef tuple<T,T,double,double> Star;
typedef tuple<double,int,int> Event;


int main(){
    int N;
    cout<<fixed;
    cout.precision(10); 
    while(cin>>N,N){
        vector<Star> V;
        vector<Event> E;
        vector<double> lifetime(N);
        for(int i=0;i<N;i++){
            double px,py,pz,vx,vy,vz,r,vr;
            cin>>px>>py>>pz>>vx>>vy>>vz>>r>>vr;
            E.emplace_back(r/vr,i,i);
            V.emplace_back(T(px,py,pz),T(vx,vy,vz),r,vr);
        }
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                T Pa,Pb,Va,Vb;
                double ra,rb,vra,vrb;
                tie(Pa,Va,ra,vra)=V[i];
                tie(Pb,Vb,rb,vrb)=V[j];
                double A=inner_cross(Va-Vb,Va-Vb)-pow(vra+vrb,2);
                if(A==0) continue;
                double B=2.0*inner_cross(Pa-Pb,Va-Vb)+2.0*(ra+rb)*(vra+vrb);
                double C=inner_cross(Pa-Pb,Pa-Pb)-pow(ra+rb,2);
                if(B*B-4*A*C<0) continue;
                double t=(-B-sqrt(B*B-4*A*C))/(2*A);
                // cout<<A<<' '<<B<<' '<<C<<' '<<t<<endl;
                if(t<0) continue;
                E.emplace_back(t,i,j);
            }
        }
        sort(E.begin(), E.end());
        bool alive[N];
        fill(alive,alive+N,true);
        for(auto e:E){
            double t;
            int a,b;
            tie(t,a,b)=e;
            if(alive[a]&&alive[b]){
                lifetime[a]=lifetime[b]=t;
                alive[a]=alive[b]=false;
            }
        }
        for(auto l:lifetime){
            cout<<l<<endl;
        }
    }
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int h,w,k,num;
int cnt[309];
char c[309][309];
int a[309][309];

void solve(int cl, int cr){
    vector<int> P;
    for(int i=cl;i<=cr;i++){
        rep(j,w){
            if(c[i][j]=='#') P.push_back(j);
        }
    }
    sort(all(P));

    rep(i,P.size()){
        int v1=0,v2=w;
        if(i>=1) v1=P[i-1]+1;
        if(i<P.size()-1) v2=P[i];
        num++;
        for(int j=cl;j<=cr;j++){
            for(int k=v1;k<=v2;k++) a[j][k]=num;
        }

    }
}

int main() {
    cin>>h>>w>>k;
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
            if(c[i][j]=='#') cnt[i]++;
        }
    }

    vector<int> vec;
    rep(i,h){
        if(cnt[i]>=1) vec.push_back(i);
    }
    rep(i,vec.size()){
        int v1=0,v2=h-1;
        if(i>=1) v1=vec[i-1]+1;
        if(i<vec.size()-1) v2=vec[i];

        solve(v1,v2);
    }

    rep(i,h){
        rep(j,w){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }

}



Measured memory_bytes: 1280
n = int(input())

INF = 10**9

dp = [INF] * (n+1)
dp[0] = 0

for i in range(n):
    dp[i+1] = min(dp[i+1], dp[i] +1)
    six = 6
    while i + six <= n:
        dp[i + six] = min(dp[i+six], dp[i] + 1)
        six *= 6
    nine = 9
    while i + nine <= n:
        dp[i + nine] = min(dp[i+nine], dp[i] + 1)
        nine *= 9
print(dp[-1])

Measured memory_bytes: 3828
//B - Product Max
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define INF 0x3f3f3f3f
using namespace std;
LL read() {
	int x = 0,f = 0;char ch = getchar();
	while(!isdigit(ch)) {if(ch=='-')f=1;ch=getchar();}
	while(isdigit(ch)) {x = x * 10 + ch - '0';ch = getchar();}
	return f?-x:x;
}

const int N = 1e6 + 10,inf = 0x3f3f3f3f;
LL a,b,c,d;
int main()
{
	a= read();b = read();c = read();d = read();
	cout << max(max(a*c,a*d),max(b*c,b*d));
	return 0;
}

Measured memory_bytes: 3640
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a*b%2==0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    } 
}

Measured memory_bytes: 21844
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,M;
	cin >> N>>M;
	ll A[N][M];
	REP(i,N)REP(j,M){
		cin>>A[i][j];A[i][j]--;
	}
	
	// 解法
	// まず、すべてのスポーツを実施すると仮定して、
	// どのスポーツに何人の人が参加するか調べます。
	// ここで、最も参加人数の多いスポーツがスポーツ P で、
	// その参加人数が Q 人だとします。
	bool do_list[M];REP(i,M)do_list[i] = true; // 実施する種目のリスト
	ll num_sport = M; // 実施種目数
	ll best_Q = N+1; // その参加人数
	while (num_sport>0){
		// printf("num_sport: %lld\n", num_sport);
		ll P = 0; // もっとも参加人数が多いスポーツ
		ll Q = 0; // その参加人数
		ll map[M] = {0}; //各種目の出場人数
		REP(i,N){
			REP(j,M){
				ll sanka = A[i][j]; // 参加種目番号
				// printf("i: %lld, j: %lld, sanka: %lld\n", i,j,sanka);
				if (do_list[sanka]==false) continue;
				map[sanka]++; // 種目出場人数加算
				if (map[sanka]>Q){ //参加種目番号が最大規模の種目なら
					P = sanka;
					Q = map[sanka];
				}
				break;
			}
		}
		if (Q<best_Q){
			best_Q = Q;
		}
		do_list[P] = false; // Pを実施スポーツから外して再起
		num_sport--;
		// printf("P: %lld, Q: %lld, best_Q: %lld\n", P, Q, best_Q);
	}
	//出力
	cout << best_Q << endl;
}


Measured memory_bytes: 896