akhauriyash/Code-Regression huggingface dataset:
// D - XXOR

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll dp[51][2]; // dp[i][j]: fの左からi桁目までの和の最大値（j:未満フラグ）
ll B[51]; // S[i][j]: Kの左からi桁目がjのときのfのi桁目が1の数
ll S[51][2]; // S[i][j]: Kの左からi桁目がjのときのfのi桁目の和
ll k[51];

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

	for (int i=0; i<N; i++) {
		ll A;
		cin >> A;
		for (int i=50; i>0; i--) {
			B[i] += A % 2;
			A /= 2;
		}
	}

	/*
	// **** debug ****
	for (int i=0; i<=50; i++) {
		cout << "B[" << i << "] = " << B[i] << endl;
	}
	*/

	for (int i=1; i<=50; i++) {
		S[i][0] = B[i] * pow(2, 50-i);
		S[i][1] = (N - B[i]) * pow(2, 50-i);
	}

	/*
	// **** debug ****
	for (int i=0; i<=50; i++) {
		cout << "S[" << i << "][0] = " << S[i][0] << endl;
		cout << "S[" << i << "][1] = " << S[i][1] << endl;
	}
	*/


	for (int i=50; i>0; i--) {
		k[i] = K % 2;
		K /= 2;
	}

	for (int i=1; i<=50; i++) {
		// 未満フラグ1からの遷移
		if (dp[i-1][1] > 0) {
			dp[i][1] = dp[i-1][1] + max(S[i][0], S[i][1]);
		}

		// 未満フラグ0からの遷移
		if (k[i] == 1) {
			dp[i][0] = dp[i-1][0] + S[i][1];
			dp[i][1] = max(dp[i][1], dp[i-1][0] + S[i][0]);
		} else {
			dp[i][0] = dp[i-1][0] + S[i][0];
		}

		/*
		// **** debug ****
		cout << "i=" << i << endl;
		cout << "k[i]=" << k[i] << endl;
		cout << "dp[i][0]=" << dp[i][0] << endl;
		cout << "dp[i][1]=" << dp[i][1] << endl;
		*/
	}

	ll ans = max(dp[50][0], dp[50][1]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

int main(){
	vector<int> num(3);
	int rc, lc;
	rc = lc = 0;
	while( ~scanf("%d,%d,%d", &num[0], &num[1], &num[2]) ){
		if( num[0] == num[1] ) lc++;
		else if( num[0]*num[0]+num[1]*num[1] == num[2]*num[2] ) rc++;
	}
	cout << rc << endl;
	cout << lc << endl;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
ll A[112345];
ll dp[112345][2];

ll solve() {
	fill(dp[0], dp[N + 1], -1);
	dp[0][0] = 0;
	REP(i, N) REP(j, 2) {
		if (dp[i][j] == -1) continue;
		
		chmax(dp[i + 1][1], dp[i][j] + A[i] * (j ^ 1 ? -1 : 1));
		chmax(dp[i + 1][0], dp[i][j] + A[i] * (j ? -1 : 1));
	}
	
	return dp[N][0];
}

int main() {
	cin >> N;
	REP(i, N) scanf("%lld", A + i);
	
	ll ans = solve();
	reverse(A, A + N);
	chmax(ans, solve());
	
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int s;
  cin >> s;
  ll dp[s + 1] = {};
  dp[0] = 1;
  for (int i = 1; i <= s; ++i)
    for (int j = 0; j <= i - 3; ++j) (dp[i] += dp[j]) %= mod;

  cout << dp[s] << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,k;
  cin >> n >> k;
  set<int> s;
  rep(i,10)s.insert(i);
  rep(i,k){
    int u;
    cin >> u;
    s.erase(u);
  }
  while(true){
    int o=n;
    int h=0;
    while(o){
      int j=o%10;
      o/=10;
      if(s.count(j)){
        j++;
      }
      else{
        h=1;
        break;
      }
    }
    if(h==0){
      cout << n << endl;
      return 0;
    }
    n++;
  }
}


Measured memory_bytes: 256
def t(v)
  v / 9.8
end

def y(t)
  4.9 * (t ** 2)
end

def n(h)
  (h + 5) / 5
end

while line=gets
  v = line.chomp.to_f
  t = t(v)
  y = y(t)
  p n(y).ceil
end

Measured memory_bytes: 8644
///
// File:  alds1_4_d.cpp
// Author: ymiyamoto
//
// Created on Sat Oct  7 23:43:34 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static vector<int64_t> array;

uint32_t packages(int64_t tracks, uint64_t P)
{
  size_t num = 0, weight = 0;
  for (uint32_t i = 0; i < tracks; i++) {
    while (array[num] + weight <= P) {
      weight += array[num];
      num++;
      if (num == array.size()) return num;
    }
    weight = 0;
  }

  return num;
}

uint32_t binary_search(uint32_t k)
{
  uint64_t left = 0;
  uint64_t right = 100000 * 10000 + 1;
  while (left + 1 < right) {
    uint64_t mid = (left + right) / 2;
    uint32_t num = packages(k, mid);
    if (num >= array.size()) {
      right = mid;
    } else {
      left = mid;
    }
  }

  return right;
}

int32_t main()
{
  uint32_t n, k;
  cin >> n >> k;

  for (uint32_t i = 0; i < n; i++) {
    int64_t w;
    cin >> w;
    array.push_back(w);
  }

  cout << binary_search(k) << endl;

  return 0;
}

Measured memory_bytes: 3868
S = input()

if S == "SUN":
  print(7)
elif S == "MON":
  print(6)
elif S == "TUE":
  print(5)
elif S == "WED":
  print(4)
elif S == "THU":
  print(3)
elif S == "FRI":
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
from collections import deque

N = int(input())
# 有向グラフと見る、G[親] = [子1, 子2, ...]
G = [[] for _ in range(N + 1)]
# 子ノードを記録、これで辺の番号を管理
G_order = []
# a<bが保証されている、aを親、bを子とする
for i in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    G[a].append(b)
    G_order.append(b)

# どこでも良いが、ここでは0をrootとする
que = deque([0])

# 各頂点と「親」を結ぶ辺の色
# 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる
colors = [0] * N
# BFS
while que:
    # prt = 親
    # 幅優先探索
    prt = que.popleft()
    color = 0

    # cld = 子
    for cld in G[prt]:
        color += 1
        # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする
        if color == colors[prt]:
            color += 1
        colors[cld] = color
        que.append(cld)

# それぞれの頂点とその親を結ぶ辺の色
# print(colors)

# 必要な最小の色数
print(max(colors))

# 辺の番号順に色を出力
for i in G_order:
    print(colors[i])


Measured memory_bytes: 92004
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    return N - K + 1


def main():
    # N = read_int()
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7108
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll a[maxn];
int main()
{
   int n;ll m;
   while(~scanf("%d",&n))
   {
       scanf("%lld",&m);
       for(int i = 1; i <= n; i++)
       {
           scanf("%lld",a+i);
           if(i!=1)a[i] += a[i-1];
       }
       ll da = 0;
       map<ll,ll>p;
       for(int i = 1; i <=n; ++i)
       {
           a[i] %= m;
           if(p.count(a[i]))
           {
               da += p[a[i]];
           }
           else
            p[a[i]] = 0;
           p[a[i]]++;
           if(!a[i])
            da++;

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

}
















Measured memory_bytes: 4992
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

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

ll calc(ll n, ll x, ll m) {
    vector<ll> a(n);
    ll ret = 0;
    ll cur = x;
    rep(i,n) {
        ret += cur;
        // cout << cur << ' ';
        cur = (cur*cur)%m;
    }
    // cout << '\n';
    return ret;
}

int main(int argc, char const *argv[]) {
    ll n,x,m; cin>>n>>x>>m;
    if (n <= 50000000ll) {
        cout << calc(n,x,m) << '\n';
        return 0;
    }

    vector<ll> idx(114514, -1);
    ll cur = x;
    ll cycle = 0;
    ll start = 0;
    vector<ll> a(114514);
    vector<ll> tmp;
    rep(i,n) {
        a[i] = cur;
        if (idx[cur] != -1) {
            cycle = i-idx[cur];
            for (int j = idx[cur]; j < i; ++j) tmp.push_back(a[j]);
            start = idx[cur];
            break;
        }
        idx[cur] = i;
        cur = (cur*cur)%m;
    }
    
    ll cycle_sum = accumulate(tmp.begin(), tmp.end(), 0ll);
    ll tail = n-start;
    ll cycle_cnt = tail/cycle;
    ll amari = tail%cycle;

    ll ans = cycle_sum * cycle_cnt;
    for (int i = 0; i < start; ++i) ans += a[i];
    for (int i = 0; i < amari; ++i) ans += tmp[i];

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

Measured memory_bytes: 10908
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int S[1001000];


int cmp(const void *a,const void *b){
	return *(int*)a- *(int *)b;
}
int main(){
	int n,q;
	int a[100100],b[100100],c[100100];

	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)scanf("%d",a+i);
	for(i=0;i<n;i++)scanf("%d",b+i);
	for(i=0;i<n;i++)scanf("%d",c+i);
	qsort(a,n,sizeof(int),cmp);
	qsort(b,n,sizeof(int),cmp);
	qsort(c,n,sizeof(int),cmp);	
	/*printf("\n");
	for(i=0;i<n;i++)printf("%d ",a[i] );
	printf("\n");
	for(i=0;i<n;i++)printf("%d ",b[i] );printf("\n");
	for(i=0;i<n;i++)printf("%d ",c[i] );printf("\n");*/
	long ans=0;
	
	for(i=0;i<n;i++){
		int k=b[i];
		long now;
		int l,r,m;
		l=0,r=n-1;
		
		while(l<=r){
			m=(l+r)/2;
			//printf("a:%d %d %d ,%d,>=,%d\n",l,m,r,a[m],k);
			if(a[m]>=k)r=m-1;else l=m+1;
		}
		//printf("a:%d ..\n",l);
		now = l;
		
		l=0;r=n-1;
		while(l<=r){
			m=(l+r)/2;
			//printf("c:%d %d %d ,%d,>,%d\n",l,m,r,c[m],k);
			if(c[m]>k)r=m-1;else l=m+1;
		}
		//printf("c:%d ..\n",n-l);
		now *=n-l;
		ans+=now;
		//printf("now:%ld\n",now);
	}
	printf("%ld\n",ans);
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int maxn = 10010;

int main() {
    int N;
    V<int> num(maxn);
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int a = x * x + y * y + z * z + x * y + y * z + z * x;
                if (a < maxn) num[a]++;
            }
        }
    }
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cout << num[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main()
{	ios_base::sync_with_stdio(false);
// 	cin.tie(NULL);
// 	cout.tie(NULL);
// 	#ifndef ONLINE_JUDGE
//     	freopen("input.txt", "r", stdin);
//     	freopen("output.txt", "w", stdout);
// 	#endif
    int n;cin>>n;
    int a[n];
    int pre[n]={0},suf[n]={0};
    for(int i = 0;i<n;i++){
    	cin>>a[i];
        if(i!=0)
    	   pre[i]=__gcd(a[i],pre[i-1]);
        if(i==0)
            pre[i]=a[0];
    }
    suf[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i]=__gcd(a[i],suf[i+1]);
    }
    int ans = 0;
    for(int i=1;i<n-1;i++){
        ans=max(ans,__gcd(pre[i-1],suf[i+1]));
    }
    ans=max(ans,pre[n-2]);
    ans=max(ans,suf[1]);
    
    cout<<ans;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 92233720000000000ll;
string s;
int n;
int power(int base,int n,int m)
 {
  if(n == 0)
     return 1;
  if(n&1)
     {
      int y = power(base,n-1,m);
      return (y*base)%m;
     }
  else
     {
      int y = power(base,n/2,m);
      return (y*y)%m;
     }
 }
int calc(int x)
 {
  int steps = 0;
  while(x!=0)
     {
      int one = __builtin_popcount(x);
      x %= one;
      steps++;
     }
  return steps;
 }
void solve()
  {
   cin>>n>>s;
   int one = 0;
   loop(i,0,n)
    one += (s[i] == '1');
   int lo=0, hi=0;
   loop(i,0,n)
    if(s[i] == '1')
      { 
        if(one>1)
          (lo+=power(2ll,n-i-1,one-1))%=(one-1);
        (hi+=power(2ll,n-i-1,one+1))%=(one+1);
      }
   loop(i,0,n)
     {
      int ans,num;
      if(s[i] == '1')
         {
          if(one == 1)
             ans = 0;
          else
             {
              num = lo;
              int now = power(2,n-i-1,one-1);
              num = (num - now + one - 1)%(one-1);
              ans = calc(num) + 1;
             }
         }
      else
         {
          num = hi;
          int now = power(2,n-i-1,one+1);
          num = (num + now)%(one+1);
          ans = calc(num) + 1;
         }
      cout<<ans<<END;
     }
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<1.0*clock();

  return 0;
} 

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x) memset(x,0,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 1000000
/*------------------------------------------------------------*/
 
int main(){
	int a,b;
in2(a,b);
	if(a<b)out(0);
	 else out(a-b);
}

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

int main() {
   int N , M ;
   int a ;//受け取り用
  int sum = 0  ;
  cin >> N >> M ;
  for(int i=0 ; i < M ; i++){
    cin >> a ;
    sum += a ;
  }
  
  if (sum > N){
    cout << "-1" << endl;
  }
  else {
    cout << N - sum << endl;
  }
}



Measured memory_bytes: 3616
s = input()
t = input()
s_len = len(s)
t_len = len(t)

ans = 99999

for i in range(-~s_len-t_len):
    cnt = 0
    for j in range(t_len):
        if s[i+j] != t[j]:
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 8944
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 3e5 + 10;
int n , a[N];
#define left Left
#define right Right
ll left[N] , right[N] , sum[N];
#define cost(j,i) (i-j+1)*(i-j)/2-(sum[i]-sum[j])+f[j]
#define K(j) (-j)
#define B(j) (ll(j-1)*j/2+sum[j]+f[j])
#define R(i) (ll(i+1)*i/2-sum[i])
typedef pair<ll,ll> pll;
pll p[N];
inline ll get(pll t,ll x) {return t.fi*x+t.se;}
inline ll cross(pll a,pll b,pll c) {
  return (b.fi-a.fi)*(c.se-a.se)-(c.fi-a.fi)*(b.se-a.se);
}

void Dp(ll *f) {
  rep(i,1,n+1) sum[i]=sum[i-1]+a[i];
  int _ = 0;
  p[_++]=mp(K(0),B(0));
  rep(i,1,n+1) {
    while(_>1&&get(p[_-2],i)>=get(p[_-1],i)) --_;
    f[i]=max(f[i-1],get(p[_-1],i)+R(i));
    pair<ll,ll> pts=mp(K(i),B(i));
    while(_>1&&cross(p[_-2],p[_-1],pts)<=0) --_;
    p[_++]=pts;
  }
  //rep(i,1,n+1) printf("%lld%c",f[i]," \n"[i==n]);
}
ll tmp[N] , best[N];

void solve(int l,int r) {
  if(l==r) return;
  int m=(l+r)>>1;
  int _=0;ll *f=left;
  rep(i,l,m+1) {
    pair<ll,ll> pts=mp(K(i),B(i));
    while(_>1&&cross(p[_-2],p[_-1],pts)<=0) --_;
    p[_++]=pts;
  }
  rep(i,m+1,r+1) {
    while(_>1&&get(p[_-2],i)>=get(p[_-1],i)) --_;
    tmp[i]=get(p[_-1],i)+R(i)+right[i+1];
  }
  per(i,m+1,r+1) {
    if(i!=r) tmp[i]=max(tmp[i],tmp[i+1]);
    best[i]=max(best[i],tmp[i]);
  }
  solve(l,m);
  solve(m+1,r);
}

int main(){
  scanf("%d",&n);
  rep(i,1,n+1) scanf("%d",a+i);
#define rev(a) reverse(a+1,a+1+n)
  Dp(left);rev(a);
  Dp(right);rev(a);rev(right);
  rep(i,1,n+1) best[i]=-8e18;
  rep(i,0,2) {
    rep(i,1,n+1) sum[i]=sum[i-1]+a[i];
    solve(0 , n);
    rev(best);rev(a);rev(left);rev(right);
    rep(i,1,n+1) swap(left[i],right[i]);
  }
  int m;
  scanf("%d",&m);
  rep(i,0,m) {
    int x,k;
    scanf("%d%d",&x,&k);
    printf("%lld\n",max(left[x-1]+right[x+1],best[x]+a[x]-k));
  }
  return 0;
}


Measured memory_bytes: 18176
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int b = in.nextInt();
            int ans = (int) (Math.log(n)/Math.log(b)) + 1;
            out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 21460
command=raw_input()
final=[-1]*10
i=0
for var in command:
    if var=="0":
        final[i]="0"
        i+=1
    elif var=="1":
        final[i]="1"
        i+=1
    elif var=="B":
        if i!=0:        
            i-=1
print "".join(final[0:i])

Measured memory_bytes: 2568
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;
  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> R[i];

  int maxv = R[1] - R[0];
  int minv = R[0];

  for ( int i = 1; i < n; i++ ) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}



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

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

    ll a = n % k;

    if(a == 0){
        cout << 0 << endl;
    }else{
        ll z = abs(a - k);
        if(z <= a){
            cout << z << endl;
        }else{
            cout << a << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int N;
    static int[] a;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        scanner.close();

        int ntmp = N;
        int digitSum = 0;
        while (0 < ntmp) {
            digitSum += ntmp % 10;
            ntmp /= 10;
        }

        if(N % digitSum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21204
n,m = map(int, input().split())
l, r = [], []
x = 0
c = 0

a = []
for _ in range(n):
    a.append(0)

for _ in range(m):
    l,r = map(int, input().split())
    a[l-1] += 1
    if r != n:
        a[r] -= 1

for i in range(n):
    x += a[i]
    if(x == m):
        c += 1

print(c)


Measured memory_bytes: 4112
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        long k = inp.nextLong();
        long s = 100;
        long c = 0;
        while (true) {
            c++;
            s = ( long ) ( ( ( double )s ) * 1.01);
            if (s >= k) {
                System.out.println(c);
                break;
            }
        }
    }
}

Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, i, sum;
  cin >> n ;

  for ( i = n ; i > 0;) {
    sum += i%10;
    i = i/10;
  }

  if (n%sum == 0) {
    cout << "Yes" << endl;  
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int plus = a + b;
        int minus = a - b;
        int mult = a * b;
        int ans = Math.max(plus,Math.max(minus, mult));
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n = int(input())
ac = 0
tle = 0
wa = 0
re = 0
for i in range(n):
    s = input()
    if s == 'AC':
        ac += 1
    elif s == 'TLE':
        tle += 1
    elif s == 'WA':
        wa += 1
    elif s == 'RE':
        re += 1

print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))

Measured memory_bytes: 9140
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

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

  LL N, K;
  cin >> N >> K;
  string s;
  cin >> s;

  vector<LL> v;

  v.push_back(0);

  //1010101
  REP(i,s.size()){
    if(s[i]=='0'){
      if(v.size()%2==0){
        v[v.size() - 1]++;
      }
      else
      {
        v.push_back(1);
      }
    }else{
      if(v.size()%2!=0){
        v[v.size() - 1]++;
      }
      else
      {
        v.push_back(1);
      }
    }
  }

  v.push_back(0);
  v.push_back(0);

  vector<LL> ruiseki;

  ruiseki.push_back(0);

  REP(i,v.size()){
    ruiseki.push_back(ruiseki[i] + v[i]);
  }

  LL max = 0;

  LL i = 0;

  if(!(2 * i+1+2*K<ruiseki.size())){
    max = ruiseki[ruiseki.size() - 1];
  }
  else
  {

    while (2 * i + 1 + 2 * K < ruiseki.size())
    {
      LL val = ruiseki[2 * i + 1 + 2 * K] - ruiseki[2 * i];
      if (val > max)
      {
        max = val;
      }
      i++;
    }
  }

  cout << max << endl;
}


Measured memory_bytes: 2676
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	rep(i, 19) {
		if (S[i] == ',') {
			cout << ' ';
		}
		else {
			cout << S[i];
		}
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    string S,T;
    cin >> S >> T;

    int ans = 0;
    REP (i, S.size()) {
        if ( S[i] != T[i] ) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    string a;

    cin >> a;

    long long i=0;

    long long j=a.length()-1;

    long long res=0;

    while(i<j) {

        if(a[i]=='W' and a[j]=='R') {

            res++;

            swap(a[i],a[j]);

            i++;

            j--;

        } else {

            if(a[i]=='W' and a[j]=='W') {

                j--;

            } else if(a[i]=='R' and a[j]=='R') {

                i++;

            } else {

                i++;

                j--;

            }

        }

    }

    cout << res << '\n';

    return 0;

}



Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class UF{
public:
  vector<int> u;
  vector<int> r;

  void init(int n){
    u.resize(n, 0);
    r.resize(n, 0);
    for(int i=0; i<n; i++) u[i] = i;
  }
  int root(int x){
    // if( u[x] == x ) return x;
    // else return root(u[x]);
    return u[x] == x ? x : u[x] = root(u[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] ){
      u[x] = y;
    }else{
      u[y] = x;
      if( r[x] == r[y] ) r[x]++;
    }
  }
};

int main(void) {

  int n, m;
  cin >> n >> m;
  UF uf;
  uf.init(n);
  int s, t;
  for(int i=0; i<m; i++){
    scanf("%d %d", &s, &t);
    uf.unite(s, t);
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    scanf("%d %d", &s, &t);
    cout << ( uf.same(s, t) ? "yes" : "no" ) << endl;
  }



  return 0;
}

// EOF

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<int> k(M), p(M);
  vector<vector<int>> s(M, vector<int>(N));
  for (int i = 0; i < M; ++i) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) cin >> s[i][j];
  }
  for (int i = 0; i < M; i++) cin >> p[i];
  
  //bit全探査
  int out=0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int check = 0;
    for (int i = 0; i < M; i++) {
      int cnt = 0;
      for (int j = 0; j < N; ++j) {
        if (bit & (1 << s[i][j])) {
          cnt++;
        }
      }
      if (cnt % 2 == p[i]) {
        check++;
      }
    }
    if (check == M) out++;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vl = vector<ll>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

int main() {
    ll N, W;
    cin >> N >> W;
    vl w(N), v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }
    vvl dp(N + 1, vl(W + 1, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j - w[i] >= 0)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int A;
	VI a;
	REP(i,3){
		cin >> A;
		a.PB(A);
	}
	sort(a.begin(),a.end());
	if(a[0]==5 && a[1]==5 && a[2]==7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
for bit in range(1 << 3):
    start = S[0]
    sumS = int(S[0])
    for i in range(3):
        if bit & (1 << i):
            sumS += int(S[i+1])
            start += "+"
            start += S[i+1]
        else:
            sumS -= int(S[i+1])
            start += "-"
            start += S[i+1]
    if sumS == 7:
        start += "=7"
        print(start)
        exit()


Measured memory_bytes: 10356
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	vector<int> L;
	for (int i = 0; i <= N; i++) {
		vector<int> X = L;
		for (int j = 0; j + i <= N && i + j <= K; j++) {
			vector<int> T = X;
			sort(T.begin(), T.end());
			int sum = 0;
			for (int k = 0; k < T.size(); k++) {
				sum += T[k];
				if (sum < 0 && T.size() + k + 1 <= K) {
					sum = 0;
				}
			}

			//cerr << i << " " << j << " " << sum << endl;
			res = max(res, sum);



			if (j < N) X.push_back(A[N - 1 - j]);
		}


		if(i < N)L.push_back(A[i]);
	}
	cout << res << endl;
}

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


int main(){
	long N;
	cin >> N;
	int A[100001];
	for(int i=0;i<100001;i++){
		A[i] = 0;
	}
	long sum = 0;
	for(int i=0;i<N;i++){
		long x;
		cin >> x;
		A[x]++;
		sum += x;
	}
	long Q;
	cin >> Q;
	for(long i=0;i<Q;i++){
		long B, C;
		cin >> B >> C;
		sum -= B * A[B];
		sum += C * A[B];
		cout << sum << endl;
		A[C] += A[B];
		A[B] = 0;
	}
}


Measured memory_bytes: 4020
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>

using namespace std;

int map[1000][1000];
queue<pair<int,int>> b;
queue<pair<int,int>> b2;
int H,W;


void update(){
    int dx[] = { 1, 0, 0, -1 };
    int dy[] = { 0, 1, -1, 0 };
    while(b.size() != 0){
        int y = b.front().first;
        int x = b.front().second;
        REP(i,4){
            if(x+dx[i]>=0 && x+dx[i]<=W-1 && y+dy[i]>=0 && y+dy[i]<=H-1){
                if(map[y+dy[i]][x+dx[i]] == 1){
                    map[y+dy[i]][x+dx[i]] = 0;
                    b2.push(make_pair(y+dy[i],x+dx[i]));
                }
            }
        }
        b.pop();
    }
}


int main(){
    int ans = 0;

    cin >> H >> W;
    REP(i,1000){
        REP(j, 1000){
            map[i][j] = -1;
        }
    }


    REP(i,H){
        REP(j, W){
            char c;
            cin >> c;
            if(c=='#'){
                b.push(make_pair(i,j));
                map[i][j]=0;
            }else{
                map[i][j]=1;
            }
        }
    }

    while(!b.empty()){
        update();
        b = b2;
        if(!b2.empty()){
            ans++;
            while(!b2.empty())b2.pop();
        }
    }

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

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n;

ll a[120000];
ll k;

int main() {
    scanf("%d%lld", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    sort(a, a + n);
    ll g = a[0];
    for (int i = 1; i < n; ++i) {
        g = __gcd(g, a[i]);
    }
    if (k % g != 0 || k > a[n - 1])
        cout << "IMPOSSIBLE\n";
    else
        cout << "POSSIBLE\n";
    return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF INT_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	string s;
	cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])puts("Bad");
	else puts("Good");
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
using namespace std;

int main(){
    int A,B,C,X,counter;
    counter=0;
    cin>>A>>B>>C>>X;
    if(X<=500*A+100*B+50*C){
        for(int i=A;0<=i;i--){
            for(int j=B;0<=j;j--){
                for(int k=C;0<=k;k--){
                    if(X==500*i+100*j+50*k) counter++;
                }
            }
        }
        cout<<counter<<endl;
    }
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  ll h,w;cin >> h >> w;
  ll ans =0;
  if(h==1 || w==1){
    cout << 1;return 0;
  }
  if(!(h%2) || !(w%2)){
    ans = (h*w)/2;
  }else {
    ans = (h*w)/2+1;
  }
  cout << ans;
}

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

int main(){
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++){
		x=i;
		if(x%3==0){
				cout<<" "<<i;
				continue;
			}
			if(x%10==3){
				cout<<" "<<i;
				continue;
			}
		for(x;x>1;x/=10){
			if(x%10==3){
				cout<<" "<<i;
				break;
			}
		}
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

int main(void)
{
  int P,Q,R;
  cin >> P >> Q >> R;
  if(P >= Q && P >= R)
    cout << Q+R;
  else if( Q >= P && Q >= R)
    cout << P+R;
  else
    cout << P+Q;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std ;
const int maxn = 1e5+5, maxm = 4e5+5, inf = 2e4 ;
int e, n, m, cnt[maxn], Begin[maxn], Next[maxm], To[maxm], W[maxm] ;
LL dis[maxn] ;
void add ( int x, int y, int z ) {
	To[++e] = y ;
	Next[e] = Begin[x] ;
	Begin[x] = e ;
	W[e] = z ;
}
bool inq[maxn], fg ;
void spfa ( int x ) {
	int i, u ;
	if (fg || inq[x]) return ;
	inq[x] = 1 ;
	for ( i = Begin[x] ; i ; i = Next[i] ) {
		u = To[i] ;
		if (dis[u] > dis[x] + W[i]) {
			dis[u] = dis[x] + W[i] ;
			if (inq[u] || fg) {
				fg = 1 ;
				return ;
			}
			spfa(u) ;
		}
	}
	inq[x] = 0 ;
}
int main() {
	scanf ( "%d%d", &n, &m ) ;
	int i, x, u, v ;
	for ( i = 1 ; i <= m ; i ++ ) {
		scanf ( "%d%d%d", &x, &u, &v ) ;
		add(x, u, v) ;
		add(u, x, -v) ;
	}
	for ( i = 1 ; i <= n ; i ++ )
		dis[i] = inf ;
	fg = 0 ;
	for ( i = 1 ; i <= n ; i ++ )
		if (!inq[i]) spfa(i) ;
	if (!fg) puts("Yes") ;
	else puts("No") ;
	return 0 ;
}

Measured memory_bytes: 9088
/*input
2
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

int f(int n){
  if(n == 1)return 1;
  return 2*f(n/2)+1;
}

void solve(){
    int n;cin >> n;
    cout << f(n);
} 

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
class Node:
    def __init__(self,key,left,right,parent):
        self.key = key
        self.left = left
        self.right = right
        self.p = parent

    def __repr__(self):
        return str(self.key)

def insert(T, z):
    y = None
    x = T 
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.p = y
    #print(x,y,z)
    if y == None:
        #print("Y==None")
        T = z
        print(T)
    elif z.key<y.key:
        #print("z.key<y.key")
        y.left = z
    else:
        #print("z.key<y.key")
        y.right = z

def find(T, k):
    y = None
    x = T 
    while x != None:
        y = x
        if k == x.key:
            print('yes')
            return
        if k < x.key:
            x = x.left
        else:
            x = x.right
    print('no')
    


def printPreorder(x):
    if x == None:
        return
    printPreorder(x.left)
    print(end=' ')
    print(x,end='')
    printPreorder(x.right)

def printMidorder(x):
    if x == None:
        return
    print(end=' ')
    print(x,end='')
    printMidorder(x.left)
    printMidorder(x.right)

def printal(x):
    printPreorder(x)
    print()
    printMidorder(x)
    print()


N = int(input())
Q = input().split()
T = Node(int(Q[1]),None,None,None)
for i in range(N-1):
    Q = input().split()
    if Q[0] == "print":
        printal(T)
        continue
    elif Q[0] == "find":
        find(T,int(Q[1]))
        continue
    insert(T,Node(int(Q[1]),None,None,None))



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

int main(){

    int h,w;

    while(1){
        cin >> h >> w;
        if((h==0)&&(w==0)) break;

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){

                if(i%2==0){
                    if(j%2==0) cout << "#";
                    else cout << ".";
                }else{
                    if(j%2==0) cout << ".";
                    else cout << "#";
                }

            }
            cout << endl;
        }
        cout << endl;
    }
    
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll N;
  cin>>N;
  ll A,B;
  cin>>A>>B;
  ll ans=0;
  ans+=N/(A+B)*A;
  N-=N/(A+B)*(A+B);
  if(N>A)
    ans+=A;
  else
    ans+=N;
  cout<<ans<<endl;
}


Measured memory_bytes: 256