akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    V<ll>a(n),b(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    ll sum=0;
    for(ll i=0;i<n;i++)sum^=a[i];
    for(ll i=0;i<n;i++)b[i]=sum^a[i];
    for(ll i=0;i<n;i++)cout<<b[i]<<" ";
    cout<<Endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------






























Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a,b;
signed main(){
    cin>>n>>a>>b;
    int ans=n/(a+b)*a+min(a,n%(a+b));
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
const ll INF=1000000000000000;
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;}

int main(){
	ll K; cin>>K;
	vector<ll>A(K);
	vector<ll>L(K+1,INF);
	vector<ll>R(K+1,0);
	L[K]=R[K]=2;
	rep(i,K)cin>>A[i];

	//小 L[0] ......... L[K]=2
	//大 R[0] ......... R[K]=2
	//操作　A[0] ... A[K-1]
	rrep(i,K){
		ll j=(L[i+1]-1)/A[i]+1;
		if(j*A[i]<=R[i+1]) chmin(L[i],A[i]*j);
		j=R[i+1]/A[i];
		if(j*A[i]>=L[i+1]) chmax(R[i],A[i]*(j+1)-1);

		if(L[i]==INF){
			cout<<-1;
			return 0;
		}
	}
	cout<<L[0]<<" "<<R[0];
}

Measured memory_bytes: 2560
'use strict'

const Main = (input) => {
  const tmp = input.trim().split('\n')
  const N = parseInt(tmp[0])
  const Harr = tmp[1].split(' ').map(Number)

  let result = 'Yes'

  for (let i = Harr.length - 1; i >= 1; i -= 1) {
    if (Harr[i] < Harr[i - 1]) {
      Harr[i - 1] -= 1
      if (Harr[i] < Harr[i - 1]) {
        result = 'No'
      }
    }
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 17816
a, b, c = (int(i) for i in input().split())
if a == 7 or b == 7 or c == 7:
    if (a == 5 and b == 5) or (b == 5 and c == 5) or (a == 5 and c == 5):
        print('YES')
        exit()
    else:
        print('NO')
        exit()
else:
    print('NO')
    exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int c=a+b;
    if(a%3==0||b%3==0||c%3==0){cout<<"Possible"<<endl;}
    else{cout<<"Impossible"<<endl;}
    return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, A, B;

int main() {
  INCANT;
  cin >> N >> A >> B;
  cout << min(N*A, B) << "\n";
  return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, K, as[110];
  ll dp[110][100010];

  void init() {
    cin >> N >> K;
    rep(i, N) {
      cin >> as[i];
    }
  }

  void solve() {
    dp[0][0] = 1;
    repc(i, N) dp[i][0] = 1;
    REPC(i, 1, N) REPC(j, 1, K) {
      dp[i][j] = dp[i][j-1] + dp[i-1][j];
      dp[i][j] %= MOD_1_000_000_007;
      if(j-as[i-1]-1 >= 0) {
        dp[i][j] -= dp[i-1][j-as[i-1]-1];
        dp[i][j] += MOD_1_000_000_007;
        dp[i][j] %= MOD_1_000_000_007;
      }
    }
    cout << dp[N][K] << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}


Measured memory_bytes: 79360
// Justice will be served
// شهید حاج قاسم سلیمانی

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

#define all(x) x.begin() , x.end()

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

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

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

const int MAX_N = -1 ;
const int inf = 2e9 + 19 ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        int a , b ;
        cin >> a >> b ;
        cout << max(0 , a - 2 * b) ;
        return (0) ;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x, cnt = 1;
    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> x;
    	if(x == cnt) cnt++;
    }
    cout << (cnt == 1 ? -1 : n - cnt + 1) << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;


#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r)return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}

int nPr(int n, int r){
   // if(n < r)return 0;
   return (nCr(n, r) * fact[r]) % mod;   
}

int deg[N], ans = 1;
int n, k;
vector<int> v[N];

void dfs(int s, int p){
   int cnt = 0;
   for(auto i: v[s]){
      if(i != p){
         dfs(i, s);
         cnt++;
      }
   }

   if(s == 1){
      ans = (ans * (k * nPr(k-1, cnt)%mod) % mod);
   }
   else{
      ans = (ans * nPr(k-2, cnt)) % mod;
   }
}

int32_t main(){_

   cin>>n>>k;   
   pre(N);

   for (int i = 0; i < n-1; ++i)
   {
      int x, y;
      cin>>x>>y;
      v[x].pb(y);
      v[y].pb(x);
   }

   dfs(1, -1);
   cout<<ans;

   return 0;
}

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

using ll = long long;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, a, b; cin >> k >> a >> b;
    REP(i, a, b+1) {
    	if(i%k == 0) {
    		cout << "OK\n";
    		return 0;
    	}
    }
    cout << "NG\n";
    return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int m, dp[N][2], ans[N][2];
vector<int> g[N];

void dfs(int u, int p){
	dp[u][1] = dp[u][0] = 1;
	int b = dp[u][1];
	int w = dp[u][0];
	for(auto i: g[u]){
		if(i == p)	continue;
		dfs(i, u);
		dp[u][0] = (w + dp[i][0] + dp[i][1] - 1 + m) % m;
		dp[u][1] = (b + b*dp[i][1]) % m;
		w = dp[u][0];
		b = dp[u][1];
	}
}

void dfs1(int u, int p){
	vector<pi> v;
	int cw = 1, cb = 1, sz = 0;
	for(int i = g[u].size()-1; i >= 0; i--){
		int x = i;	i = g[u][x];
		if(i == p){i = x;	continue;}
		sz++;
		int tw = (cw + dp[i][0] + dp[i][1] - 1 + m) % m;
		int tb = (cb + cb*dp[i][1]) % m;
		v.push_back(make_pair(tw, tb));
		cw = tw;	cb = tb;
		i = x;
	}
	cw = dp[u][0], cb = dp[u][1];
	reverse(v.begin(), v.end());
	int l = g[u].size();
	for(int i = 0, ct = 0; i < (int)g[u].size(); i++){
		int x = i;	i = g[u][x];
		if(i == p){i = x;	continue;}
		int sw, sb;
		if(ct == sz - 1)
			sb = sw = 1;
		else{
			++ct;
			sw = v[ct].fi; sb = v[ct].se; 
		}
		// MERGE PREFIX SUFFIX
		int mw = (cw + sw - 1 + m) % m;
		int mb = (cb*sb) % m;
		// MERGE ENDS 
		int tw = (cw + dp[i][0] + dp[i][1] - 1 + m) % m;
		int tb = (cb + cb*dp[i][1]) % m;
		ans[i][0] = (dp[i][0] + mw + mb - 1 + m) % m;
		ans[i][1] = (dp[i][1] + dp[i][1]*mb) % m;
		dp[i][0] = (1 + mw + mb - 1 + m) % m;
		dp[i][1] = (1 + mb) % m;
		dfs1(i, u);
		cw = tw;	cb = tb;
		i = x;
	}
}

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	
	cin >> n >> m;
	for(int i = 1; i <= n - 1; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int root = 1;
	dfs(root, 0);
	ans[root][0] = dp[root][0];	ans[root][1] = dp[root][1];
	dp[root][0] = dp[root][1] = 1;
	dfs1(root, 0);
	for(int i = 1; i <= n; i++)
		cout << ans[i][1] << endl;
	return 0;
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;

void solve(){
    vector<double> x(N),y(N);
    rep(i,N){ cin >> x[i] >> y[i]; }

    int ans=1;
    rep(i,N) rep(j,N) if(i!=j){
        //cout << "i,j = " << i << "," << j << endl;
        double vx = x[i]-x[j];
        double vy = y[i]-y[j];
        double d = sqrt(vx*vx+vy*vy);
        if(d+eps>2) continue;
        double r = sqrt(1-(d/2)*(d/2));

        double rx =  -vy*r/d;
        double ry = vx*r/d;

        double cx = (x[i]+x[j])/2 + rx;
        double cy = (y[i]+y[j])/2 + ry;

        int cnt=0;
        rep(k,N){
            double tx = cx-x[k];
            double ty = cy-y[k];
            double dd = sqrt(tx*tx+ty*ty);
            //cout << "dd=" << dd << endl;
            if(dd<=1+eps) cnt++;
        }
        //cout << "cnt : " << cnt << endl;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

int main(){
    while(cin>>N){
        if(N==0) break;
        solve();
    }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        m[x]++;
    }
    int cnt = 0;
    for (auto && x : m) {
        if ((x.first == 0 && x.second != 1) || (x.first != 0 && x.second != 2)) {
            cout << 0 << "\n";
            return 0;
        }
        if (x.first != 0)
            cnt++;
    }
    int ans = 1;
    for (int i = 0; i < cnt; i++) {
        if (ans * 2 > MOD)
            ans = (ans * 2) % MOD;
        else
            ans *= 2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<bool> seen;
vector<vector<pair<ll,ll>>> Z;
vector<ll>G;
void dfs(ll v, ll a) {
  seen[v] = true; // v を訪問済にする
  for (auto next : Z[v]) {
    if(seen[next.first]) continue; // next_v が探索済だったらスルー
    ll s=a;
    s+=next.second;
    G[next.first]=s;
    dfs(next.first, s); // 再帰的に探索
  }
}

int main(){
  ll N,a,b,c,Q,K,x,y; cin>>N;
  Z.assign(N+1,vector<pair<ll,ll>>());
  G.assign(N+1,0);
  for(int i=0; i<N-1; i++){
    cin>>a>>b>>c;
    Z[a].push_back({b,c});
    Z[b].push_back({a,c});
  }
  cin>>Q>>K;
  seen.assign(N+1,false);
  dfs(K,0);
  for(int i=0; i<Q; i++){
    cin>>x>>y;
    cout<<G[x]+G[y]<<endl;
  }
}

Measured memory_bytes: 14336
import copy
h,w=map(int,input().split())
a=[]
deleted=0
for i in range(h):
    l=list(input())
    for j in l:
        if j=='#':
            a.append(l)
            break
    else:
        deleted+=1
h-=deleted

deleted=0
b=copy.deepcopy(a)
for i in range(w):
    for j in range(h):
        if a[j][i]=='#':
            break
    else:
        for j in range(h):
            b[j].pop(i-deleted)
        deleted+=1

s=''
for i in b:
    s+=''.join(i)+'\n'
print(s)

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


int32_t N,X;
int32_t H[100000];
constexpr int64_t INF = 1000000000000000;
struct edge{
	int32_t to,cost;
	edge(){}
	edge(int32_t to,int32_t cost):to(to),cost(cost){}
};
std::vector<edge> graph[100000];
using PASS_TIME = std::pair<int64_t, int32_t>;//cost,height
PASS_TIME D[100000];
void dijk(int32_t s)
{
	static bool used[100000] ={};
	using P = std::pair<PASS_TIME, int32_t>;
	std::priority_queue<P,std::vector<P>,std::greater<P>> que;
	for(auto& i : D){
		i.first = INF;
	}
	D[s].first = 0;
	D[s].second = X;
	que.emplace(D[s], s);
	while(!que.empty())
	{
		auto now_state = que.top();que.pop();
		const auto& pos = now_state.second;
		const auto& height = now_state.first.second;
		const auto& cost = now_state.first.first;
	
		if(used[pos]){continue;}
		used[pos] = true;
		
		for(auto& e : graph[pos])
		{
			auto ncost = cost+e.cost;
			auto nheight = 0;
			if(e.cost <= height){
				nheight = height - e.cost;
				if(H[e.to] < nheight){
					ncost += nheight - H[e.to];
					nheight = H[e.to];
				}
			}
			else{
				if(H[pos] < e.cost){
					#ifdef DEBUG
					std::cout << pos << '>' << e.to << ':' << H[pos] << ' ' << e.cost << "\n";
					#endif
					continue;
					}
				ncost += (e.cost - height);
			}
			if(D[e.to].first > ncost){
				D[e.to].first = ncost;
				D[e.to].second = nheight;
				que.emplace(D[e.to], e.to);
			}
		}
	}
}

int main()
{
	int32_t M;
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);
	std::cin >> N>>M>>X;
	for(int32_t i =0;i < N;++i){
		std::cin >> H[i];
	}
	for(int32_t i =0;i < M;++i){
		int32_t a,b,T;
		std::cin >>a>>b >> T;--a;--b;
		graph[a].emplace_back(b, T);
		graph[b].emplace_back(a, T);
	}
	
	#ifdef DEBUG
	std::cout << "=graph===="<<graph[0].size()<<"=====\n";
	std::cout << "===================\n";
	#endif
	dijk(0);
	#ifdef DEBUG
	for(int32_t i =0;i < N;++i){
	std::cout << "===================\n";
		std::cout << D[i].first << ' ' << D[i].second << std::endl;
	}
	std::cout << "===================\n";
	#endif
	
	if(D[N-1].first < INF){
		std::cout << D[N-1].first + (H[N-1] - D[N-1].second) << std::endl;
	}
	else{
		std::cout << -1 << std::endl;
	}
}

Measured memory_bytes: 18076
# if true

# include <iostream>

int main()
{

    int k{}, d{}, N;
    std::cin >> N;

    for (int i{}; i <= N / 4; ++i)
    {
        if ((N - i * 4) % 7 == 0)
        {
            std::cout << "Yes";
            return 0;
        }
    }

    std::cout << "No";

    return 0;
}


# endif

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;

const int MAX_K = 1000000;
const int MAX_N = 100000;
const int INF = 1000000000;

int K, N;

int main() {

    cin >> K >> N;

    vector<int> A(N);

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    A.push_back(A[0] + K); // 2周目の一番最初の点 0をまたいで一番長い辺があるかを調べるために，最後に挿入
    int l = 0; // 一番長い辺
    for (int i = 0; i < N; i++) {
        l = max(l, A[i + 1] - A[i]);
    }
    int answer = K - l;
    
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int f(int A, int B, int C)
{
    return A * 10 + B + C;
}
void _main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    chmax(ans, f(A, B, C));
    chmax(ans, f(A, C, B));
    chmax(ans, f(B, A, C));
    chmax(ans, f(B, C, A));
    chmax(ans, f(C, A, B));
    chmax(ans, f(C, B, A));
    cout << ans << endl;
}


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

int main(){
  string c1, c2, ans = "NO";
  cin >> c1 >> c2;
  
  if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) ans = "YES";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int sumTime = 0;
	int cookTime[5];
	int tmp, n;
	n = 9;

	for(int i = 0; i < 5; i++){
		scanf("%d", &cookTime[i]);
	}

	for(int i = 0; i < 5; i++){
		if(cookTime[i] % 10 != 0){
			if(n > cookTime[i] % 10){
				n = cookTime[i] % 10;
				tmp = cookTime[4];
				cookTime[4] = cookTime[i];
				cookTime[i] = tmp;
			}
		}
	}

	sumTime += cookTime[0];

	for(int i = 1; i < 5; i++){
		while(sumTime % 10 != 0){
			sumTime++;
		}
		sumTime += cookTime[i];
	}

	printf("%d\n", sumTime);
}

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

int main() {
	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << max({(n+(a-1))/a, (n+(b-1))/b, (n+(c-1))/c, (n+(d-1))/d, (n+(e-1))/e})+4 << endl;
	// cout << max({(n-1)/a, (n-1)/b, (n-1)/c, (n-1)/d, (n-1)/e})+5 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<stack>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

char in[30][30], sw[30][30], bo[30][30];
int d, w, h, s;

void tate(){
	REP(a,h){
		for(int i=0;i+s<=w;i++){
			int e = 1;
			for(int j=0;j<s;j++){
				if(bo[a][i]!=bo[a][i+j]||bo[a][i]=='.'){
					e=0;
					break;
				}
			}
			if(e){
				REP(b,s){
					sw[a][i+b]='.';
					d = 1;
				}
			}
		}
	}
}
void yoko(){
	REP(a,w){
		for(int i=0;i+s<=h;i++){
			int e = 1;
			for(int j=0;j<s;j++){
				if(bo[i][a]!=bo[i+j][a]||bo[i][a]=='.'){
					e=0;
					break;
				}
			}
			if(e){
				REP(b,s){
					sw[i+b][a]='.';
					d = 1;
				}
			}
		}
	}
}

int main(){
	int i, j, k, f, e, ch;
	string ans="NO";
	cin >> h >> w >> s;
	REP(a,h) cin >> in[a];
	REP(x,h){
		REP(y,w-1){
			REP(q,h)REP(z,w)bo[q][z] = in[q][z];
			swap(bo[x][y], bo[x][y+1]);
			d=1;
			while(d){
				d=0;
				REP(a,h)REP(b,w)sw[a][b] = '#';
				f=1;
				while(f){
					f=0;
					for(i=1;i<h;i++){
						REP(a,w){
							if(bo[i-1][a]!='.'&&bo[i][a]=='.'){
								swap(bo[i-1][a],bo[i][a]);
								f=1;
							}
						}
					}
				}
				tate();
				yoko();
				//REP(a,h)cout << sw[a] << endl;
				REP(a,h)REP(b,w)if(sw[a][b] == '.') bo[a][b] = '.';
			}
			//cout << x << "," << y << endl;
			//REP(a,h) cout << bo[a] << endl;
			ch = 1;
			REP(a,h)REP(b,w)if(bo[a][b]!='.') ch=0;
			if(ch) ans = "YES";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;

class Main{
  public static boolean[] lineSet(String str){
    boolean[] line = new boolean[8];
    for (int i = 0; i < 8; i++) {
      if (str.charAt(i) == '0') {
        line[i] = false;
      }
      else {
        line[i] = true;
      }
    }
    return line;
  }

  public static int[] check(boolean[] line){
    for (int i = 0; i < 8; i++) {
      if (line[i]) {
        if (i < 7 && line[i+1]) {
          if (i < 6 && line[i+2]) {
            int[] check = {i,3};
            return check;
          }
          else {
            int[] check = {i,2};
            return check;
          }
        }
        else {
            int[] check = {i,1};
            return check;
        }
      }
    }
    int[] check = {0,0};
    return check;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String str = sc.next();
      int[] chk1 = check(lineSet(str));
      if(chk1[1] == 0) {
        continue;
      }
      else if (chk1[1] == 3) {
        System.out.println("C");
        continue;
      }
      else {
        str = sc.next();
        int[] chk2 = check(lineSet(str));
        if (chk1[1] == 1) {
          if (chk2[1] == 1) {
            System.out.println("B");
            str = sc.next();
            str = sc.next();
            continue;
          }
          else if (chk1[0] == chk2[0]) {
            System.out.println("F");
            str = sc.next();
            continue;
          }
          else {
            System.out.println("D");
            str = sc.next();
            continue;
          }
        }
        else {
          if (chk1[0] == chk2[0]) {
            System.out.println("A");
            continue;
          }
          else if (chk1[0] < chk2[0]) {
            System.out.println("E");
            continue;
          }
          else {
            System.out.println("G");
            continue;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 11000
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}


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

	int a, b;
	cin >> a >> b;

	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	if (a < 0 && b>0) {
		cout << "Zero" << endl;
		return 0;
	}
	if (a < 0 && b < 0) {
		if (abs(a - b) % 2 == 1) {
			cout << "Positive" << endl;
		}
		else {
			cout << "Negative" << endl;
		}
	}
	return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (5006)
ll n, a, b, A[MAXN], dp[2][MAXN], pos[MAXN], co[MAXN]; // dp(i, j) = dp(val i, at pos j -> 0 all the elements are in order);
int main()
{ // can be proven that each element moves once
	FAST
	cin>>n>>a>>b;
	FOR(i,1,n)cin>>A[i],pos[A[i]]=i;
	FOR(i,1,n) {
		mmst(dp[i%2],0);
		ll x=pos[i];
		FOR(j,1,x-1) dp[i%2][j]=dp[i%2^1][j]; // storing history values (won't be changed), but might be referenced in the future
		FOR(j,x,n){ // legit ones
			dp[i%2][j]=min((j==x?LLINF:dp[i%2^1][j]+a), dp[i%2^1][x-1] + b * (co[j] - co[x])); // move all blocking elements to correct position, u'll end up at position i (cos i-p-1 items just got moved)
		}
		FOR(i,x,n) ++ co[i];
		// FOR(j,1,n)cerr<<dp[i%2][j]<<' '; cerr<<'\n';
	}
	cout<<dp[n%2][n]<<'\n';
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記


int main(void) {
   
   int n;
   cin >> n;
   
   vector<pii> d(n);
   rep(i,n) cin >> d[i].first >> d[i].second;
   
   string ans = "No";
   int cnt = 0;
   rep(i,n) {
       if (d[i].first == d[i].second) {
           cnt++;
           //cout << d[i].first << endl;
           if (cnt == 3) {
               ans = "Yes";
               break;
           }
       }
       else cnt = 0;
   }
   cout << ans << endl;
   
   return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int n; cin >> n;
    vector<int> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    int m; cin >> m;
    
    for(int i = 0; i < m; i++){
        int p, x; cin >> p >> x;
        p--;
        int ret = 0;
        for(int i = 0; i < n; i++){
            if(i == p) ret += x;
            else ret += t[i];
        }
        cout << ret << endl;
    }

    return 0;
}



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

int main(){

  int c[3][3];
  for(int i=0; i<3; ++i){
    for(int j=0; j<3; ++j){
      cin >> c[i][j];
    }
  }

  int d1 = c[0][1] - c[0][0];
  int d2 = c[0][2] - c[0][1];
  int d3 = c[1][0] - c[0][0];
  int d4 = c[2][0] - c[1][0];
  for(int i=1; i<3; ++i){
    if(c[i][1]-c[i][0] != d1 || c[i][2]-c[i][1] != d2){
      cout << "No" << endl;
      exit(0);
    }
  }
  for(int i=1; i<3; ++i){
    if(c[1][i]-c[0][i] != d3 || c[2][i]-c[1][i] != d4){
      cout << "No" << endl;
      exit(0);
    }
  }

  cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int a, b, flag=-1;
    cin >> a >> b;
    for(int i=0;i<1300;i++){
        if(a==i*8/100&&b==i*10/100) {
            flag = i;
            break;
        }
    }
    if(flag==-1) cout << flag << endl;
    else cout << flag << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
string a,c="CF";
int q,f;
int main()
{
	cin >>a;
	int b=a.size();
	for (int i=0;i<b;i++)
	{
		if (a[i]==c[q]){q++;}
		if (q==2) break;
	}
	if (q==2) cout <<"Yes"<<endl;
	else cout <<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;

int Main() {
    cin >> N;
    ll sum = 0;
    reps(i, N) {
        reps(j, N) {
            reps(k, N) {
                sum += gcd(i,gcd(j,k));
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

signed main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int start = max(a, c);
  int end = min(b, d);

  int res = end - start;
  cout << (res >= 0 ? res : 0) << endl;
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

int main() {
  string S;
  cin >> S;
  int red = 0, blue = 0;

  vector< int > dp{1};
  for(int i = 0; i < S.size() * 2; i++) {
    if(i < S.size()) {
      if(S[i] == '0') red += 2;
      else if(S[i] == '1') red += 1, blue += 1;
      else blue += 2;
    }
    vector< int > dp2(red + 1);
    for(int red_used = 0; red_used < dp.size(); red_used++) {
      int blue_used = i - red_used;
      if(red_used < red) (dp2[red_used + 1] += dp[red_used]) %= mod;
      if(blue_used < blue) (dp2[red_used] += dp[red_used]) %= mod;
    }
    dp.swap(dp2);
  }
  cout << dp.back() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll d, l, r;
        cin >> l >> r >> d;
        ll start , end;
        start = l / d;
        if(l % d != 0){
            start++;
        }
        end = r / d;
        if(end % d != 0){
            end;
        }
        cout << max(0LL, end - start + 1);
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	int H, W; cin >> H >> W;
	vector<vector<bool>> vec(H, vector<bool>(W, false));
	rep(i,0,H){
		rep(j,0,W){
			char c; cin >> c;
			vec[i][j] = (c == '#');
		}
	}
	int dir[][2] = {{-1,0}, {1,0}, {0, 1}, {0,-1}};
	rep(i,0,H){
		rep(j,0,W){
			if (vec[i][j]){
				bool is_ok = false;
				rep(k,0,4){
					int h = i+dir[k][0], w = j+dir[k][1];
					if (h < 0 || h >=H || w <0 || w >=W)
						continue;
					if (vec[h][w])
						is_ok = true;
				}
				if (!is_ok){
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n);
	REPU(i, 0, n) cin >> a[i];
	vector<int> bs(20, 0);
	int j = 0;
	ll ans = 0;
	REPU(i, 0, n) {
		while (j < n) {
			int found(0);
			REPU(l, 0, 20) if ((a[j] >> l & 1) && bs[l] > 0) {
				found = 1; break;
			}
			if (found) break;
			REPU(l, 0, 20) if (a[j] >> l & 1) {
				bs[l]++;
			}
			j++;
		}
		ans += j - i;
		REPU(l, 0, 20) if (a[i] >> l & 1) {
			bs[l]--;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
	int n, s;
	double m, t;
	while(1){
		t = 0;
		m = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> s;
			m += s;
			t += s*s;
		}
		m /= n;
		t /= n;
		printf("%.8lf\n", sqrt(t - m*m));
	}
	return 0;
}


Measured memory_bytes: 3204
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int a = tmp[0], b = tmp[1];
	WriteLine((a&b&1)==1 ? "Odd" : "Even");
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
 
using namespace std;
 
typedef pair<int, int> P;

set<P> vis[2];
string in[2];
int dy[6] = {1, 0, -1, -1, 0, 1};
int dx[6] = {0, 1, 1, 0, -1, -1};
 
void calc(int p, int d){
  int x = 0, y = 0;
  int mx = 0, my = 0;
  set<P> tmp;
  tmp.insert(P(y, x));
  for(int i=0;i<in[p].size();i++){
    y += dy[(in[p][i]-'a'+d)%6];
    x += dx[(in[p][i]-'a'+d)%6];
    mx = min(mx, x);
    my = min(my, y);
    tmp.insert(P(y, x));
  }
  for(set<P>::iterator ite=tmp.begin();ite!=tmp.end();ite++){
    vis[p].insert(P(ite->first-my, ite->second-mx));
  }
}

bool solve(){
  vis[0].clear();
  calc(0, 0);
  for(int i=0;i<6;i++){
    vis[1].clear();
    calc(1, i);
    if(vis[0] == vis[1]) return true;
  }
  return false;
}
 
int main(){
  int T;
  cin >> T;
  getchar();
  while(T--){
    string s;
    for(int i=0;i<2;i++){
      getline(cin, in[i]);
    }
    getline(cin, s);
    cout << (solve() ? "true" : "false") << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		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;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
  ll k,x,y,z,s;
  ll count=0;
  cin >> k >> s;
  rep(x,k+1) rep(y,k+1) {
    z=s-x-y;
    if(0<=z&&z<=k) count++;
  }
  cout << count << endl;
}

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



int n, m;

int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    char a, b;
    cin >>a>>b;

    if ('H'==a) {
        cout << b << endl;
    } else {
        cout << ('H'==b?'D':'H') << endl;
    }



    return 0;
}


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

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}



signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      
    
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    int mn=1e9;
    for(int i=0;i+m<=n;i++)
    {
        int cnt=0;
        for(int j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])
            {
                cnt++;
            }
        }
        mn=min(mn,cnt);

    }
    cout<<mn;

}

Measured memory_bytes: 3640