akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

unordered_map<ll, int> get_primes(ll n) {
    unordered_map<ll, int> facs;
    ll n2 = n;
    for(ll i = 2; i*i <= n; i++) {
        while (n2 % i == 0) {
            facs[i] += 1;
            n2 /= i;
        }
    }
    if (n2 > 1)
        facs[n2] += 1;
    return facs;
}

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    bool pairwise = true;
    bool setwise = false;
    unordered_set<ll> used;
    ll glob = arr[0];
    for(int i = n-1; i >= 0; i--) {
        if (pairwise) {
            auto facs = get_primes(arr[i]);
            for(auto [p, freq]: facs) {
                if (used.count(p) > 0)
                    pairwise = false;
                used.insert(p);
            }
        }
        glob = gcd(glob, arr[i]);
    }
        
    if (glob == 1)
        setwise = true;
    if (pairwise)
        cout << "pairwise coprime" << endl;
    else if (setwise)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
    return 0;
}


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

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

	int ans = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 0; j <= 9; j++){
			for(int k = 0; k <= 9; k++){
				if(a <= 10001*i + 1010*j + 100*k && 10001*i + 1010*j + 100*k <= b)
					ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import math

a,b,x = map(int, input().split())

jud = 2 * x / (a**2) - b
if jud > 0:
	ans = math.atan((b - jud) / a) * 180.0 / math.pi
else:
	h = x / a / b * 2
	ans = math.atan(b / h) * 180.0 / math.pi

print(ans)


Measured memory_bytes: 2940
import sys

n = int(input())
a = list(map(int, input().split()))

array = [0 for i in range((10 ** 6)+1)]
for v in a:
  array[v] += 1
  
for i in range(1, len(array)):
  if array[i] == 0:
    continue
    
  for j in range(i*2, len(array), i):
    array[j] = 0
    
count = 0
for v in array:
  if v == 1:
    count += 1
    
print(count)

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    string a,b;
    cin >> a >> b;
    if(a.size() > b.size()) cout << "GREATER" << "\n";
    else if(a.size() < b.size()) cout << "LESS" << "\n";
    else{
        if(a>b) cout << "GREATER" << "\n";
        else if(a<b) cout << "LESS" << "\n";
        else cout << "EQUAL" << "\n";
    }
    return 0;
}

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

double a = 0  , b = 0 ,  f = 0 ;
int aa = 0 , bb = 0 , d = 0 , r = 0 ;

int main()
{
	std::cin >> a >> b ;
	aa = a ;
	bb = b ;
	d = aa / bb ;
	r = aa % bb ;
	f = a / b ;
	std::cout << d << " " << r << " " ;
	printf("%.5f\n", f);
}

Measured memory_bytes: 1284
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> arr(15);
    ll now = 1;
    rep (i, 14) {
        arr[i + 1] = arr[i] + (now *= 26);
        eprintf("%lld ", arr[i]);
    }
    int len = 0;
    while (arr[len] < n) len++;
    eprintf("%d\n", len);
    n -= arr[len - 1] + 1;
    eprintf("%lld\n", n);
    vector<int> ans;
    rep (i, len) {
        ans.push_back(n % 26);
        n /= 26;
    }
    reprev (i, len) cout << (char)('a' + ans[i]);
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3652
def check(N,K):
    while N % K == 0:
        N //= K
    return (N % K == 1)

def divisor(N):
    d = []
    K = 1
    while K*K <= N:
        if N % K == 0:
            d.append(K)
            if K*K != N:
                d.append(N//K)
        K += 1
    #ans += (N - 1)//K
    return d


N = int(input())

divi = divisor(N)

ans = 0

for x in divi:
    if x > 1:
        ans += int(check(N,x))

ans += len(divisor(N - 1)) - 1
print(ans)



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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int n;cin>>n;
  int k = n + (n%2 == 0);
  cout<<n*(n-1)/2 - n/2<<endl;;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1 ; j < n; j++)
    {
      if(i + j +2== k)continue;
      cout<<i+1<<" "<<j+1<<endl;
    }
  }
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

int main() {
  int n,b;
  cin >> n ;
  vector <char> a(100010);
  for (int i=0;i<n;i++)
  cin >> a.at(i);
  b=1;
  for (int i=0;i<n-1;i++){
  if (a.at(i)!=a.at(i+1))
  b++;
  }
  cout << b << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,we;
  cin>>n>>we;
  int w[n+1];
  int v[n+1];
  long long dp[n+1][we+1];
  for(int i=1;i<=n;i++){
  cin>>w[i]>>v[i];
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<=we;j++){
        if((i==0)||(j==0)){
            dp[i][j]=0;
        }
      else{
          if(j>=w[i]){
            dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
        }
        else{
            dp[i][j]=dp[i-1][j];
        }
      }
    }
  }
  cout<<dp[n][we]<<endl;
  return 0;
}

Measured memory_bytes: 79104
n = int(input())
a = list(map(int,input().split()))
ruiseki = [0]*(n+1)

for i in range(1,n+1):
  ruiseki[i] = a[i-1] + ruiseki[i-1]

#右側が大きいときにTrueを返す。
def judge(begin,mid,end):
  if ruiseki[mid]-ruiseki[begin] < ruiseki[end]-ruiseki[mid]:
    return True
  else:
    return False

def solvediff(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] - (ruiseki[end]-ruiseki[mid]) )

def solve_num1(begin,mid,end):
  return abs( ruiseki[mid]-ruiseki[begin] )

def solve_num2(begin,mid,end):
  return abs( ruiseki[end]-ruiseki[mid] )


ans = float("inf")
for i in range(2,n-1):
  
  #PQの探索
  ok = i
  ng = 0
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(0,mid,i):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(0,mid,i):
      min_num = solvediff(0,mid,i)
      num1 = solve_num1(0,mid,i)
      num2 = solve_num2(0,mid,i)
  
  #RSの探索
  ok = n
  ng = i
  min_num = float("inf")
  while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if judge(i,mid,n):
      ng = mid
    else:
      ok = mid
    if min_num > solvediff(i,mid,n):
      min_num = solvediff(i,mid,n)
      num3 = solve_num1(i,mid,n)
      num4 = solve_num2(i,mid,n)
      
  ans = min(ans, max(num1,num2,num3,num4) - min(num1,num2,num3,num4))
  
print(ans)

Measured memory_bytes: 96388
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class G>
struct Scc {
  const G& g;
  vector<vector<int>> rev_g, red_g;
  vector<int> ord, dec;
  vector<bool> vis;

  Scc(const G& g) : g(g) {}

  void run() {
    int n = g.size();
    vis.resize(n);
    for (int u = 0; u < n; ++u) {
      dfs_ord(u);
    }
    rev_g.resize(n);
    for (int u = 0; u < n; ++u) {
      for (int v : g[u]) {
        rev_g[v].push_back(u);
      }
    }
    dec.resize(n, -1);
    int i = 1;
    while (!ord.empty()) {
      if (dfs_dec(ord.back(), i)) ++i;
      ord.pop_back();
    }
    red_g.resize(i);
    set<pair<int, int>> added;
    for (int u = 0; u < n; ++u) {
      int ru = dec[u];
      for (int v : g[u]) {
        int rv = dec[v];
        if (added.count({ ru, rv }) == 0) {
          red_g[ru].push_back(rv);
          added.insert({ ru, rv });
        }
      }
    }
  }

  void dfs_ord(int u) {
    if (vis[u]) return;
    vis[u] = true;
    for (int v : g[u]) {
      dfs_ord(v);
    }
    ord.push_back(u);
  }

  bool dfs_dec(int u, int i) {
    if (dec[u] >= 0) return false;
    dec[u] = i;
    for (int v : rev_g[u]) {
      dfs_dec(v, i);
    }
    return true;
  }
};

template<class G>
pair<vector<int>, vector<vector<int>>> scc(const G& g) {
  Scc<G> scc(g);
  scc.run();
  return { scc.dec, scc.red_g };
}

int n, m;
vector<vector<int>> g;
int main() {
  cin >> n >> m;
  init_n(g, n);
  for (int i = 0; i < m; ++i) {
    int s, t; cin >> s >> t;
    g[s].push_back(t);
  }
  auto cs = scc(g).first;
  int q; cin >> q;
  while (q--) {
    int s, t; cin >> s >> t;
    cout << (cs[s] == cs[t] ? "1" : "0") << '\n';
  }
  return 0;
}



Measured memory_bytes: 4428
_,*s=open(0).read().split()
a=b=c=d=0
for S in s:
 c+=S.count('AB')
 if S[-1]=='A':
  a+=1
  if S[0]!='B':d=1
 if S[0]=='B':
  b+=1
  if S[-1]!='A':d=1
print(c+max(min(a,b)+d-1,0))


Measured memory_bytes: 67564
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
 

int main(){
  double ans=0.0;
  cout << fixed << setprecision(6);
  int n;
  cin>>n;
  vector<double> a(n);
  rep(i,n)cin>>a.at(i);
  sort(ALL(a));
  
  rep(i,n-1){
      ans=(a.at(i)+a.at(i+1))/2;
      a.at(i+1)=ans;
  }
  cout<<ans<<endl;
  
  
}

Measured memory_bytes: 256
#python3
import numpy as np
N = int(input())
A = np.array([int(_) for _ in input().split()])
mod = 10**9 + 7
ans = 0
for b in range(60):
    B = (A >> b) & 1
    M = np.count_nonzero(B)
    ans += 2**b * M * (N - M)
    ans %= mod
print(ans)


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

#define fs first
#define sc second
#define mp make_pair
#define eb emplace_back
#define sz(s) ((int) s.size())
#define all(s) s.begin(), s.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef unsigned long long ull;

const ll linf = (ll) 1e18;

const int A = 26;
const int L = 17;
const int B = 315;
const int N = 109;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

const int di[] = {-1, +0, +1, +0};
const int dj[] = {+0, +1, +0, -1};

const double pi = acos(-1.0);
const double eps = 1e-11;

int n;
int m;

int p[N * N];
int s[N * N];

int cnt[A];

char a[N][N];

inline bool read() {
	if (!(cin >> n >> m)) {
		return false;
	}	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	return true;
}
inline void init() {

}
inline int get(int v) {
	return v == p[v] ? v : p[v] = get(p[v]);
}
inline void unite(int a, int b) {
	a = get(a);
	b = get(b);
	if (a != b) {
		if (s[a] < s[b]) {
			swap(a, b);
		}
		p[b] = a;
		s[a] += s[b];
	}
}
inline int index(int i, int j) {
	return (i - 1) * m + j;
}
inline void solve() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int let = a[i][j] - 'a';
			cnt[let]++;
		}
	}
	for (int i = 1; i <= n * m; i++) {
		p[i] = i;
		s[i] = 1;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			set<ii> s;
			s.insert({i, j});
			s.insert({i, m - j + 1});
			s.insert({n - i + 1, j});
			for (auto p : s) {
				unite(index(i, j), index(p.fs, p.sc));				
			}
		}
	}
	set<int> c;
	for (int i = 1; i <= n * m; i++) {
		c.insert(get(i));		
	}
	int odd = -1;
	for (int i = 0; i < A; i++) {
		if (cnt[i] & 1) {
			if (odd == -1) {
				odd = i;
			} else {
				puts("No");
				return;
			}		
		}
	}
	bool one = (n & 1) && (m & 1);
	if (one) {
		if (odd == -1) {
			puts("No");
			return;
		}
		cnt[odd]--;
	} else {
		if (odd != -1) {
			puts("No");
			return;
		}
	}
	int fours = 0;
	for (int i = 0; i < A; i++) {
		fours += cnt[i] >> 2;
	}
	for (auto x : c) {
		fours -= s[x] == 4;
		if (fours < 0) {
			puts("No");
			return;			
		}		
	}
	puts("Yes");
}
int main() {
    #ifdef LOCAL
    	#define name ""
    	freopen(name".in", "r", stdin);
    	freopen(name".out", "w", stdout);
    #endif
    while (read()) {
    	init();
    	solve();
    }
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍


int main(){
	ll n,m,x,y;cin>>n>>m>>x>>y;
    ll xx[n];rep(i,0,n)cin>>xx[i];
    ll yy[m];rep(i,0,m)cin>>yy[i];
    sort(xx,xx+n);sort(yy,yy+m);
    if(x >= y || xx[n-1] >= yy[0] || xx[n-1] >= y || x >= yy[0]) cout<<"War"<<ednl;
    else cout<<"No War"<<ednl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<double> _v(N);
  auto * const v = &_v[0];
  for (int i = 0; i < N; ++i)
    cin >> v[i];
  sort(v, v + N);
  double den = 2.;
  double sum = 0.;
  for (int i = N - 1; 1 <= i; --i)
  {
    v[i] /= den;
    sum += v[i];
    den *= 2.;
  }
  v[0] /= (den/2.);
  sum += v[0];
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=inf,e=0,f=0,g=0,h=0,j=0;
  string s;
  cin >>a;
  cout <<24+24-a<<'\n';
  return (0);
}


Measured memory_bytes: 256
def kruskal():
    '''
    最小全域木のコストを求める
    '''
    cost = 0
    edge.sort()

    for c, u, v in edge:
        if same(u, v):
            continue
        union(u, v)
        cost += c

    return cost


def find(x):
    '''
    xの根を求める
    '''
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def union(x, y):
    '''
    xとyの属する集合を併合する
    '''
    x = find(x)
    y = find(y)
    
    if x == y:
        return False

    if par[x] > par[y]:
        x, y = y, x

    par[x] += par[y]
    par[y] = x
    return True


def same(x, y):
    '''
    xとyが同じ集合に属するかを判定する
    '''
    return find(x) == find(y)


n = int(input())
x, y = [], []
for i in range(n):
    tmp_x, tmp_y = map(int, input().split())
    x.append([tmp_x, i])
    y.append([tmp_y, i])

x.sort()
y.sort()
edge = []
for i in range(n-1):
    edge.append([x[i+1][0]-x[i][0], x[i+1][1], x[i][1]])
    edge.append([y[i+1][0]-y[i][0], y[i+1][1], y[i][1]])

par = [-1] * n
print(kruskal())

Measured memory_bytes: 64852
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, x; cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n-1) {
        if (a[i]+a[i+1] > x) {
            ll tmp = (a[i]+a[i+1]) - x;
            a[i+1] -= tmp;
            chmax(a[i+1], 0ll);
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string s; cin >> s;
  int l = 0, r = s.size(), cnt = 0;
  bool f = true;

  while(l < r) {
    if(s[l] == s[r-1]) l++, r--;
    else if(s[l] == 'x') cnt++, l++;
    else if(s[r-1] == 'x') cnt++, r--;
    else {
      f = false;
      break;
    }
  }

  if(!f) cout << -1 << endl;
  else cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll h, w;
    cin >> h >> w;

    if(h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    } 

    if(h%2 && w%2) {
        cout << (h/2) * (w/2) + (h-h/2) * (w-w/2) << endl;
    } else {
        cout << h*w/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []

x,y = [],[]
for i in range(1,n+1):
    if i % 2 == 0:
        x.append(a[i-1])
    else:
        y.append(a[i-1])
if n % 2 == 0:
    print(" ".join(map(str,x[::-1])), " ".join(map(str,y)))
else:
    print(" ".join(map(str,y[::-1])), " ".join(map(str,x)))


Measured memory_bytes: 26180
calc :: Integral a => Char -> a -> a -> a
calc op = case op of
  '+' -> (+)
  '-' -> (-)
  '*' -> (*)
  '/' -> div

main :: IO ()
main = do
  input <- getLine
  let [stra, op, strb] = words input
  if op == "?"
    then do return ()
    else do
    let [a, b] = map read [stra, strb] :: [Int]
    putStrLn $ show $ calc (head op) a b
    main

Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
typedef pair<mp,mp> mmp;

int main(){
    while(1){
	int n,m,h,k;
	cin>>n>>m>>h>>k;
	if(n==0)break;
	vector<vector<mmp> >  g(n);
	for(int i=0;i<m;i++){
	    int a,b,c,h,r;
	    cin>>a>>b>>c>>h>>r;
	    a--,b--,r--;
	    g[a].push_back( mmp(mp(c,h),mp(r,b) ) );
	    g[b].push_back( mmp(mp(c,h),mp(r,a) ) );
	}
	int s,t;
	cin>>s>>t;
	s--,t--;
	int p;
	cin>>p;
	vector<int> l(p,0),d(p);
	for(int i=0;i<p;i++){
	    int num;
	    cin>>num;
	    cin>>d[i];
	    for(int j=0;j<num;j++){
		int tmp;
		cin>>tmp;
		tmp--;
		l[i] |= (1<<tmp);
	    }
	}
	vector<int> lc(1<<k,inf);
	lc[0] = 0;
	for(int i=0;i<(1<<k);i++){
	    for(int j=0;j<p;j++){
		lc[ i|l[j] ] = min( lc[ i|l[j] ] ,lc[i] + d[j] );
	    }
	}
	vector<vector<vector<bool> > > used( n , vector<vector<bool> > (h+1,vector<bool>((1<<k),false ) ) );
	priority_queue<mmp,vector<mmp>,greater<mmp> > q;
	for(int i=0;i<(1<<k);i++){
	    if( lc[i] != inf ) {
		//used[s][0][i] = true;
		q.push( mmp(mp(lc[i],0),mp(i,s ) ) );
	    }
	}
	bool flag = true;
	while( !q.empty() ){
	    //cout<<"OK"<<endl;
	    mmp now = q.top();
	    q.pop();
	    ll nn = now.second.second;
	    ll pass = now.second.first;
	    ll time = now.first.second;
	    ll cost = now.first.first;
	    if( nn == t){
		cout<<cost<<endl;
		flag = false;
		break;
	    }
	    if(nn > n)continue;
	    if(time > h)continue;
	    if(used[nn][time][pass])continue;
	    used[nn][time][pass] = true;
	    for(int i=0;i<g[nn].size();i++){
		ll next = g[nn][i].second.second;
		ll ntime = time + g[nn][i].first.second;
		ll ncost = cost;
		ll nr = g[nn][i].second.first;
		//cout<<i<<endl;
		if( ( (pass>>nr) & 1 ) == 0 )ncost += g[nn][i].first.first; 
		if( ntime > h  )continue;
		if(used[next][ntime][pass])continue;
		q.push( mmp(mp(ncost,ntime ) , mp(pass,next )  )  );
	    }
	}
	if(flag) cout<<-1<<endl;
    }
    return 0;
}



Measured memory_bytes: 18952
#include<stdio.h>


int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(a>b||(n==1&&b!=a)){
		printf("0");
	}else{
		printf("%lld\n",(long long )(b-a)*(n-2)+1);
	}
}

Measured memory_bytes: 128
#include <cstdio>
#include <set>
using namespace std;

int main()
{
  int n, h;
  while (~scanf("%d %d\n", &n, &h)) {
    if (n == 0 && h == 0)
      break;
    char c1, c2;
    int a, b;
    pair<pair<int, int>, int> p;
    set<pair<pair<int, int>, int> > cnt;
    for (int i = 0; i < h; ++i) {
      scanf("%c%c %d %d\n", &c1, &c2, &a, &b);
      if (c1 == 'x') {
	if (c2 == 'y') {
	  p.first.first = a;
	  p.first.second = b;
	  for (int j = 1; j <= n; ++j) {
	    p.second = j;
	    cnt.insert(p);
	  }
	} else {
	  p.first.first = a;
	  p.second = b;
	  for (int j = 1; j <= n; ++j) {
	    p.first.second = j;
	    cnt.insert(p);
	  }
	}
      } else {
	  p.first.second = a;
	  p.second = b;
	  for (int j = 1; j <= n; ++j) {
	    p.first.first = j;
	    cnt.insert(p);
	  }
      }
    }

    printf("%d\n", n*n*n-cnt.size());
  }
  return 0;
}

Measured memory_bytes: 2228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

vll memo(10, -1);

ll calc(vvll& c, ll i, unordered_set<ll>& seen) {
  if(memo[i] != -1) {
    return memo[i];
  }
  
  if(i == 1) {
    return 0;
  }
  
  //追加コスト最小を探す
  ll mcost = LLINF;
  rep(j, 10) {
    if(seen.find(j) == seen.end()) {
      seen.emplace(j);
      chmin(mcost, c[i][j] + calc(c, j, seen));
      seen.erase(j);
    }
  }
  
  return mcost;
}

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

  ll H, W;
  cin >> H >> W;
  
  vvll c(10, vll(10));
  rep(i, 10) {
    rep(j, 10) {
      cin >> c[i][j];
    }
  }
  
  vvll A(H, vll(W));
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
    }
  }
  
  memo[1] = 0;
  
  vll mincost(10);  
  for(int i=0; i<=9; i++) {
    //if(i == 1) continue;
    unordered_set<ll> seen;
    seen.emplace(i);
    
    mincost[i] = calc(c, i, seen);
    memo[i] = mincost[i];
  }

  ll totalcost = 0;
  rep(i, H) {
    rep(j, W) {
      if(A[i][j] != -1) {
        totalcost += mincost[A[i][j]];
      }
    }
  }
  
  fin(totalcost);
}

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

int main(){
  int N,a = 0;
  cin >> N;
  vector<int> c(N);
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
    for(int j = 0; j <= i; j++){
      if(s.at(j) == s.at(i)){
        c.at(j)++;
        break;
      }
    } 
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++){
    cin >> t.at(i);
    for(int j = 0; j < N; j++){
      if(s.at(j) == t.at(i)){
        c.at(j)--;
        break;
      }
    }
  }
  	
  int max = 0;
   for(int i = 0; i < N; i++){
     if(max < c.at(i)){
       max = c.at(i);
     }
   }
  cout << max << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), W = sc.nextInt();
		long[] w = new long[n], v = new long[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextLong();
			v[i] = sc.nextLong();
		}
		long[][] dp = new long[n][W + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < W + 1; j++) {
				if (i > 0) {
					if (j >= w[i]) {
						dp[i][j] = Math.max(dp[i-1][j], v[i] + dp[i-1][j-(int)w[i]]);
					} else {
						dp[i][j] = dp[i-1][j];
					}
				} else {
					if (j >= w[i]) dp[i][j] = v[i];
					else dp[i][j] = 0;
				}
			}
		}
		System.out.println(dp[n-1][W]);
	}
}


Measured memory_bytes: 124884
#include <stdio.h>
#include <string.h>

int not_double(char *str, int n)
{
	int i = 0;
	while (i < n)
	{
		if (str[i] == str[n])
			return 0;
		i++;
	}
	return 1;
}

int main(void)
{
	char str[100001];
	scanf("%s", str);
	int alpha[26];
	int c = 97;
	int i = 0;
	int j;
	while (i < 26)
	{
		alpha[i] = c + i;
		i++;
	}
	i = 0;
	while (str[i])
	{
		if (not_double(str, i) == 1)
		{
			j = 0;
			while (j < 26)
			{
				if (alpha[j] == str[i])
					alpha[j] = 0;
				j++;
			}
		}
		i++;
	}
	i = 0;
	while (i < 26)
	{
		if (alpha[i] != 0)
		{
			printf("%c", alpha[i]);
			return 0;
		}
		i++;
	}
	printf("None\n");
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

vector<int> G[100010];
short arr[100010];

ll cnt;

bool dfs(int c, int p, short v) {
	bool jd = 0;
	for (int i : G[c]) {
		if (i == p)continue;
		if (arr[i] == 3 - v) {
			jd = 1;
			continue;
		}
		if (arr[i] == v) {
			continue;
		}
		arr[i] = v;
		cnt++;
		if (dfs(i, c, 3 - v))jd = 1;
	}
	return jd;
}

int main() {
	ll N, M, a, b;
	cin >> N >> M;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	ll lef = N * N, ed = 0;
	ll cone = 0, alc = 0;
	bool rt;
	for (int i = 0;i < N;i++) {
		if (arr[i])continue;
		cnt = 1;
		arr[i] = 2;
		rt = dfs(i, -1, 1);
		if (cnt == 1)continue;
		if (rt) {
			alc++;
			ed += cnt;
		}
		else {
			cone++;
			alc++;
			ed += cnt;
		}
	}
	lef -= ed * ed;
	lef += alc * alc + cone * cone;
	cout << lef << endl;
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

set<ll> mp[50];
vi a;
void f(int i, ll mask) {
	if (mp[i].count(mask)) return;
	mp[i].insert(mask);
	if (i == sz(a)) return;
	f(i+1, mask);
	int x = a[i];
	for (int j = x; j <= 32; j += x) mask |= (1LL<<j);
	f(i+1, mask);
}

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

	int n; cin >> n;
	vi t(101);
	FOR (i,1,25) a.push_back(i), t[i]=1;
	FOR (i, 13,16) a.push_back(2*i), t[2*i]=1;
	f(0, 0);
	vi c(n+1); FOR (i, 1, n) cin >> c[i];
	ll sum = accumulate(all(c), 0LL);
	ll ans = sum;
	for (int &i : c) i *= -1;

	for (auto mask : mp[sz(a)]) {
		ll cur = 0;
		vi yo(n+1);
		FOR (i, 1, 32) if (mask&(1LL<<i)) {
			for (int j = i; j <= n; j += i) yo[j] = 1;
		}
		NFOR (i, n, 1) {
			if (yo[i]) cur += c[i];
			else if (!t[i]) {
				ll here = c[i];
				if (i*2 <= n and !yo[i*2]) here += c[i*2];
				if (i*3 <= n and !yo[i*3]) here += c[i*3];
				if (here > 0) {
					cur += here;
					yo[i]=1;
					if (i*2 <= n) yo[i*2]=1;
					if (i*3 <= n) yo[i*3]=1;
				}
			}
		}
		ans = max(ans, sum+cur);
	}
	cout << ans;


	return 0;
}


Measured memory_bytes: 63616
#include <iostream>
#include <numeric>
#include <algorithm>

using namespace std;

int main()
{
    int a[4], b[4];
    for( int i=0; i<4; ++i )
        cin >> a[i];

    for( int i=0; i<4; ++i )
        cin >> b[i];

    cout << max( accumulate( a, a+4, 0 ), accumulate( b, b+4, 0 ) ) << endl;
}

Measured memory_bytes: 1160
def b():
    # A = list(map(int, input().split()))
    import math
    a_hp, a_atk, b_hp, b_atk = map(int, input().split())

    kill_a = math.ceil(a_hp/b_atk)
    kill_b = math.ceil(b_hp/a_atk)
    if kill_b <= kill_a:
        print('Yes')
    else:
        print('No')


##########
if __name__ == "__main__":
    b()


Measured memory_bytes: 9168
import java.util.Scanner;
//import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
        long m = stdIn.nextLong();
        long d = stdIn.nextLong();

        int count= 0;
        for(int i = 1;i <= m;i++){
            for(int j = 1;j <= d;j++) {
                if(j >= 22) {
                    if(j%10 >= 2 && (j/10)*(j%10) == i){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);

        
    }

}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	deque<int> dq;
	for(int i = 1,j; i<=n; i++)
	{
		cin>>j;
		if(i%2==n%2)
			dq.push_front(j);
		else
			dq.push_back(j);
	}
	while(!dq.empty())
	{
		cout<<dq.front()<<" ";
		dq.pop_front();
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<algorithm>
#include <numeric>
using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N];
  a[-1]=-1;
  for(int i=0;i<N;i++){
   cin >> a[i]; 
  }
  int ans=0;
  for(int i=0;i<N;i++){
    int j=i;
    if(a[i]!=a[i-1]){
   while(a[i]==a[i+1]){
    i++; 
   }
   ans+=(i-j+1)/2;
    }
  }
    cout << ans << endl;
  return 0;}

Measured memory_bytes: 256
import math

n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
a = 0
b = 0

for i in range(0,n,1):
    a += (p[i]-1)*math.factorial(n-i-1)
    b += (q[i]-1)*math.factorial(n-i-1)
    for  j in range(i+1,n,1):
        if p[j] > p[i]:
            p[j] -= 1
        if q[j] > q[i]:
            q[j] -= 1

print(abs(a-b))

Measured memory_bytes: 9220
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct word{
	char s[32];
	int p[110],pn;
}WORD;
WORD a[110];

int comp_str(const void *a,const void *b){
	WORD *p=(WORD *)a,*q=(WORD *)b;
	//return strcmp((char *)a,(char *)b);
	return strcmp((char *)p->s,(char *)q->s);
}
int comp_int(const void *a,const void *b){
	return *(int *)a - *(int *)b;
}
int main(){
	int i,j,wn=0,p;
	char s[32];
	while(scanf("%s",s)!=EOF){
		scanf("%d",&p);
		for(i=0;i<wn;i++)if(strcmp(s,a[i].s)==0)break;
		if(i==wn){
			strcpy(a[wn].s,s);
			a[wn].p[0]=p;
			a[wn].pn=1;
			wn++;
		}else{
			a[i].p[a[i].pn]=p;
			a[i].pn++;
		}
	}
	qsort(a,wn,sizeof(WORD),comp_str);
	for(i=0;i<wn;i++){
		printf("%s\n",a[i].s);
		qsort(a[i].p,a[i].pn,sizeof(int),comp_int);
		for(j=0;j<a[i].pn;j++)printf("%s%d",(j==0)?"":" ",a[i].p[j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!

x=int(input())

if 400<=x<=599 :
    print("8")

elif 600<=x<=799:
    print("7")

elif 800<=x<=999 :
    print("6")

elif 1000<=x<=1199:
    print("5")

elif 1200<=x<=1399:
    print("4")
    
elif 1400<=x<=1599:
    print("3")
    
elif 1600<=x<=1799:
    print("2")

elif 1800<=x<=1999:
    print("1")

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

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

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	_, _, k := r.nextInt(), r.nextInt(), r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()
	r.Scan(true)
	b := r.nextStringArray().toInts()

	an := len(a)
	for i, ai := range a {
		if ai > k {
			an = i
			break
		}
		k -= ai
	}

	ans := an
	bn := 0
loop:
	for _, bi := range b {
		for {
			if bi > k {
				if an <= 0 {
					break loop
				}
				an--
				k += a[an]
			}
			k -= bi
			bn++
			if ans < an+bn {
				ans = an + bn
			}
			break

		}
	}

	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 20708
#include <stdio.h>
int main(void)
{
	int r,c,hairetu[100][100],i,j,l=0,m=0,o=0;

	scanf("%d %d",&r,&c);

	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&hairetu[i][j]);	
		}

	}



	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			l = l + hairetu[i][j];

			printf("%d ",hairetu[i][j]);

			if(j == c-1 )
			{
				printf("%d\n",l);

				o = o + l;
				l = 0;
			}

			
			
		}
	
		
	}

	for(j=0;j<c;j++)
	{
		for(i=0;i<r;i++)
		{
			m = m + hairetu[i][j] ;
		}
	
		printf("%d ",m);
		
		m = 0;

		
	} 




	printf("%d\n",o);

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int modpow(ll a, ll n, ll p){
  if(n==0) return 1;
  if(n==1) return a%p;
  if(n%2 == 1) return (a*modpow(a,n-1,p))%p;
  ll t = modpow(a,n/2, p);
  return (t*t)%p;
 }

ll modnCa(ll n, ll a, ll p){
  ll upper = 1;
  ll lower = 1;
  for(ll i = 1; i <= a; i++){
    upper *= n-i+1;
    upper %= p;
    lower *= i;
    lower %= p;
  }
  ll inv_lower = modpow(lower, p-2, p);
  return (upper * inv_lower)%p;
}


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

  for(ll i = 1; i<k+1; i++){
    ll ans = modnCa(n-k+1,i,mod)*modnCa(k-1,i-1,mod);
    ans %= mod;
    cout << ans  << endl;
  }
  
  
}


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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int a;
  string s;
  cin >> a >> s;

  cout << (a >= 3200 ? s : "red") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll m , k;
    cin >> m >> k;
    if(k < (1<<m)){
        ll x = 0;
        for(int i = 0 ;i < (1<<m ) ; i++){
            if(i == k)
                continue;
            x ^= i;
        }
        if(k == 0){
            for(int i = 0 ;i < (1<<m) ; i++)
                cout << i << " " << i << " ";
            cout << endl;
        }
        else{
            if(x == k){
                cout << 0 << " " << k <<  " " << 0 << " ";
                for(int i = 1 ;i < (1<<m) ; i++){
                    if(i == k)
                        continue;
                    else
                        cout << i << " ";
                }   
                cout << k << " ";
                for(int i = (1<<m)-1 ;i >= 1; i--){
                    if(i == k)
                        continue;
                    else
                        cout << i << " ";
                }
                cout << endl;   
            }
            else
                cout << -1 << endl;
        }

    }
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int*,int,int,int,int);
llong mergeSort(int*,int,int,int);

int main(){
  int A[MAX],n,i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  llong ans=mergeSort(A,n,0,n);

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

  return 0;
}

llong merge(int *A,int n,int left,int mid,int right){
  int i,j,k;
  llong cnt=0;
  int n1=mid-left;
  int n2=right-mid;

  for(i=0;i<n1;i++) {
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++) {
    R[i]=A[mid+i];
  }

  L[n1]=R[n2]=SENTINEL;
  i=j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]) A[k]=L[i++];
    else{
      A[k]=R[j++];
      cnt+=n1-i;
    }
  }

  return cnt;
}

llong mergeSort(int *A,int n,int left,int right){
  int mid;
  llong v1,v2,v3;

  if(left+1<right){
    mid=(left+right)/2;
    v1=mergeSort(A,n,left,mid);
    v2=mergeSort(A,n,mid,right);
    v3=merge(A,n,left,mid,right);

    return v1+v2+v3;
  }
  else return 0;
}


Measured memory_bytes: 3264
main = interact $ (flip (++) "\n") . show . length . filter prime . (\(x:ys) -> take x ys) . map read . lines

primes50 = filter (\x -> (x == 2 || odd x) && null [y | y <- [2..100], y /= x, rem x y == 0]) [2..100]

twoOrOdd x = (x == 2 || odd x)
no50Dividing x = null [y | y <- primes50, rem x y == 0]
noDivisors x = null [z | z <- [3..((ceiling . sqrt . fromIntegral) x)], (rem (z - 1) 6 == 0 || (rem (z + 1) 6 == 0)), rem x z == 0]

prime x = (elem x primes50) || (twoOrOdd x && no50Dividing x && noDivisors x)

Measured memory_bytes: 5724
list1 = list(map(int,input().split()))
p1 = [list1[0],list1[1]]
p2 = [list1[2],list1[3]]
dv = [-(p2[1]-p1[1]),p2[0]-p1[0]]
p3 = [x1+x2 for x1,x2 in zip(p2,dv)]
p4 = [x1+x2 for x1,x2 in zip(p1,dv)]
[print(x,end=" ") for x in p3+p4]

Measured memory_bytes: 38384
from collections import defaultdict


def burger(lv, x):
    if d[(lv, x)] >= 0:
        return d[(lv, x)]

    if x < 1 or x > cnt[lv]:
        d[(lv, x)] = 0
        return d[(lv, x)]

    # base case
    if (lv, x) == (0, 1):
        d[(lv, x)] = 1
        return d[(lv, x)]

    half = (cnt[lv] - 1) // 2
    if x <= half:
        d[(lv, x)] = burger(lv - 1, x - 1)
        return d[(lv, x)]
    else:
        d[(lv, x)] = burger(lv - 1, half - 1) + 1 + burger(lv - 1, min(x - 1 - half, half - 1))
        return d[(lv, x)]


n, x = map(int, input().split())
cnt = [1]
for lv in range(1, 50 + 1):
    cnt.append(cnt[-1] * 2 + 3)
d = defaultdict(lambda: -1)

print(burger(n, x))
# print(d)


Measured memory_bytes: 3444