akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

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

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int diff = 'Z' - 'A' + 1;
    REP(i, s.size()){
        s[i] = (s[i]-'A'+n) % diff + 'A';
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
n,a,b=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0]
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=sorted(a),sorted(b)
if na!=nb:
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if a[i]!=b[i]:
		f[a[i]]=a[i]
f[a[n]]=a[n]
for i in range(n):
	if a[i]!=b[i]:
		ans+=1
		f[find(b[i])]=find(a[i])
for i in f:
	if i==f[i]:
		ans+=1
print(ans-1)

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


struct compare_sa{
	const vector<int> &rank;
	int n, k;
	compare_sa(const vector<int> &rank, int n, int k) : rank(rank), n(n), k(k) {}
		bool operator () (int i, int j) {
		if (rank[i] != rank[j]){
			return rank[i] < rank[j];
		}
		int ri = i + k <= n ? rank[i + k] : -1;
		int rj = j + k <= n ? rank[j + k] : -1;
		
		return ri < rj;
	}
};

vector<int> create_sa(const string& s){
	int n = s.length();
	vector<int> sa(n + 1, -1);
	vector<int> rank(n + 1, -1);
	vector<int> tmp(n + 1, -1);

	for(int i=0;i<=n;i++){
		sa[i] = i;
		rank[i] = i < n ? s[i] : -1;
	}

	for (int k=1;k<=n;k*=2){
		compare_sa cp = compare_sa(rank, n, k);
		sort(sa.begin(),sa.begin()+n+1,cp);
		tmp[sa[0]] = 0;
		for(int i=1;i<=n;i++){
			tmp[sa[i]] = tmp[sa[i - 1]] + (cp(sa[i - 1], sa[i]) ? 1 : 0);
		}
		for (int i=0;i<=n;i++) {
			rank[i] = tmp[i];
		}
	}
	
	return sa;
}

int main(void){
	int k;
	string s;
	cin >> k >> s;
	if (k == 0) {
		cout << s << endl;
		return 0;
	}
	
	int n = s.length();
	vector<int> sa = create_sa(s);
	vector<int> sa_inv(n + 1);
	
	for(int i=0;i<n+1;i++){
		sa_inv[sa[i]] = i;
	}
	
	vector<int> sat;
	int q = (n + k) / (k + 1);
	int r = q * (k + 1) - n;
	
	for(int i=0;i<sa.size();i++){
		int w = sa[i];
		if (w <= n - q) {
			sat.push_back(w);
		}
	}
	
	int lo = -1;
	int hi = n - q + 1;
	while (hi - lo > 1){
		int mid = (hi + lo) / 2;
		int rem = r;
		for(int i=0;i<k+1;i++){
			if (rem < 0){
				break;
			}
			int idx = i * q - r + rem;
			if (idx >= n - q + 1){
				break;
			}
			if (sa_inv[idx] > sa_inv[sat[mid]]) {
				rem--;
			}
		}
		if (rem >= 0){
			hi = mid;
		}
		else {
			lo = mid;
		}
	}
	
	cout << s.substr(sat[hi], q) << endl;
	return 0;
}

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

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

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

// Description: セグメント木　点更新 区間クエリ
// TimeComplexity: 初期化$\mathcal{O}(n \log n)$ 更新とクエリ$\mathcal{O}(\log n)$
// Verifyed: AOJ DSL_2_A

template <int depth> struct Segment_tree {
	const static int h = depth;
	const static int n = 1 << h;

	using T = long long;
	T data[2 * n];
	const T out = 0LL;

	inline T vmerge(T l, T r) {return max(l, r);}

	void init() {
		fill_n(data, 2 * n, out);
	}

	void update(int p, T x) { // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(int l, int r) {  // sum on interval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};

const int limit = 100010;
const int inf = 1 << 30;
int ary[limit];

multiset<int> st;
vector<int> s[limit], t[limit];

Segment_tree<17> seg;

int main(void) {
	int n, m, q;
	cin >> n >> m >> q;

	st.insert(inf);

	rep(i, m) {
		int d, a, b;
		cin >> d >> a >> b;
		a--, b--;
		s[a].push_back(d);
		t[b].push_back(d);
	}

	rep(i, n - 1) {
		for (auto &elem : t[i]) {
			auto it = st.find(elem);
			st.erase(it);
		}

		for (auto &elem : s[i]) {
			st.insert(elem);
		}

		ary[i] = *begin(st);
		//cerr << i << " " <<  ary[i] << endl;
	}

	seg.init();

	rep(i, n - 1) seg.update(i, ary[i]);

	rep(loop, q) {
		int e, a, b;
		cin >> e >> a >> b;
		a--, b--;

		//cerr << seg.query(a, b) << endl;

		if (a >= b or seg.query(a, b) < e) {
			puts("Yes");
		} else {
			puts("No");
		}
	}

	return 0;
}

// 1 2 3



Measured memory_bytes: 18192
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

#define MAX_N   (1000)                  // 10^5
// #define MAX_N   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

struct edge{
  int to; ll cost;
  edge(int to, ll cost) : to(to), cost(cost) {}
};

int N, M;
vector<edge> G[MAX_N], G_INV[MAX_N];
ll DIST[MAX_N];
set<int> REACH;

bool set_member(set<int> &st, int x) {
  return st.find(x) != st.end();
}

set<int> calc_reachable(vector<edge> g[], int s) {
  set<int> st;
  st.insert(s);
  stack<int> stk;
  stk.push(s);
  while (!stk.empty()) {
    int v = stk.top(); stk.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int u = g[v][i].to;
      if (!set_member(st, u)) {
        stk.push(u);
        st.insert(u);
      }
    }
  }
  return st;
}

string bellman_ford() {
  set<int> st_s = calc_reachable(G, 0);
  set<int> st_t = calc_reachable(G_INV, N - 1);

  for (int i = 0; i < N; i++) DIST[i] = -INFL;
  DIST[0] = 0;

  for (int x = 0; x < N; x++) {
    bool update = false;
    for (int v = 0; v < N; v++) {
      for (int i = 0; i < G[v].size(); i++) {
        edge e = G[v][i];
        int u = e.to;
        if (DIST[u] < DIST[v] + e.cost) {
          if (x == N - 1 && set_member(st_s, u) && set_member(st_t, u))
            return "inf";
          DIST[u] = DIST[v] + e.cost;
          update = true;
        }
      }
    }
    if (!update) break;
  }
  return to_string(DIST[N - 1]);
}

void solve() {
  cout << bellman_ford() << endl;
}

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

  solve();

  return 0;
}


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

int main(){
   int a,b;
   cin >> a >> b;
   int p = a+b;
   int m = a-b;
   int k = a*b;
   if(p>m){
     if(p>k){
          cout << p << endl;
       }else{
           cout << k << endl;
       }
   }else if(m<k){
       cout << k << endl;
   }else{
       cout << m << endl;
   }

}

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

int main() {
 int K; int X; int Y; cin>>K>>X>>Y;
  int N=0;
  for(int i=X;i<Y+1; i++){
    if(i%K==0)
      N++;
    else continue;
  }
  if(N!=0) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


Measured memory_bytes: 3592
def get_int_array
    gets.strip.split(' ').map(&:to_i)
end

n,k = get_int_array
sum = 0
logk = Math.log10(k)
log2 = Math.log10(2)
n.times{|i|
    c = if i < k
        result = (logk - Math.log10(i + 1)) / log2
        result.ceil
    else
        0
    end
    pn = 1.0 / (2 ** c)
    sum += pn
}
puts sum / n

Measured memory_bytes: 14504
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int count = 0;
    vector<int> P(n);
    REP(i, n) cin >> P[i];
    FOR(i, 1, n - 1){
        int numMin, numMax;
        numMin = min(P[i - 1], P[i]);
        numMin = min(numMin, P[i + 1]);
        numMax = max(P[i - 1], P[i]);
        numMax = max(P[i + 1], numMax);
        if(P[i] != numMax and P[i] != numMin) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};
//上のコードの引用元https://qiita.com/hakomo/items/fd7212d71269cea311e5
int main() {
    Radix r;
    int N, K;
    string R;
    cin >> N >> K;
    R = r.to(N, K);
    cout << R.size() << endl;
}


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

#define hell 1000000007
#define PI acos(-1.0)
#define S second
#define F first
#define pb push_back
#define endl '\n'
#define lli long long int
#define li long int
#define ld long double
#define all(v) v.begin(), v.end()


#define run(j, n) for(auto ii=j;ii!=n;ii++)
#define out(j, n) for(auto ii=j;ii!=n;ii++) cout<<(*ii)<<" ";
const int sz = 1e3+5;



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);

int n, m;cin>>n>>m;
lli k, ar[n], arr[m];cin>>k;
for(int i=0;i<n;i++) cin>>ar[i];
for(int j=0;j<m;j++) cin>>arr[j];
for(int i=1;i<n;i++) ar[i]+=ar[i-1];
for(int j=1;j<m;j++) arr[j]+=arr[j-1];

int ans = 0;

for(int i=0;i<n;i++)
{
  if(k-ar[i]<0) break;
  auto it = upper_bound(arr, arr+m, k-ar[i]);
  ans = max(ans, i+1+int(it-arr));

}
//cout<<ans<<" ";  
for(int i=0;i<m;i++)
{
  if(k-arr[i]<0) break;
  auto it = upper_bound(ar, ar+n, k-arr[i]);
  ans = max(ans, i+1+int(it-ar));
  //cout<<ans<<" ";
}  

cout<<ans;
return 0;
}

Measured memory_bytes: 6796
#include <stdio.h>

int convexcheck(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
{
    int a, b, c, d;
    int flag1, flag2;
    // p = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1) crossproduct application
    if (((x1 - x3) * (y2 - y1) - (y1 - y3) * (x2 - x1)) > 0){
        a = 1;
    }else {
        a = 0;
    }
    if (((x1 - x3) * (y4 - y1) - (y1 - y3) * (x4 - x1)) > 0){
        b = 1;
    }else {
        b = 0;
    }

    if(a != b) flag1 = 1;
    else flag1 = 0;

    if (((x2 - x4) * (y3 - y2) - (y2 - y4) * (x3 - x2)) > 0){
        c = 1;
    }else {
        c = 0;
    }
    if (((x2 - x4) * (y1 - y2) - (y2 - y4) * (x1 - x2)) > 0){
        d = 1;
    }else {
        d = 0;
    }

    if(c != d) flag2 = 1;
    else flag2 = 0;

    if(flag1 == 1 && flag2 == 1) return 1;
    else return 0;
}


int main(void)
{
    int flag;
    float x[4], y[4], dist1, dist2, dist3, dist4, dist5, dist6;
    while(scanf("%f,%f,%f,%f,%f,%f,%f,%f", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF){
        flag = convexcheck(x[0], y[0], x[1], y[1], x[2], y[2], x[3], y[3]);
        if(flag == 1) printf("YES\n");
        else printf("NO\n");        
    }
    return (0);
}


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

int main(){
  string s;
  cin>>s;
  size_t n=s.length();
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[(n+2)/2+i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int saishou=0;
  int saidai=0;
  int iro1=0;
  int iro2=0;
  int iro3=0;
  int iro4=0;
  int iro5=0;
  int iro6=0;
  int iro7=0;
  int iro8=0;
  int iro9=0;
  for(int i=0;i<n;i++){
    if(a[i]<400)iro1=1;
    else if(a[i]<800)iro2=1;
    else if(a[i]<1200)iro3=1;
    else if(a[i]<1600)iro4=1;
    else if(a[i]<2000)iro5=1;
    else if(a[i]<2400)iro6=1;
    else if(a[i]<2800)iro7=1;
    else if(a[i]<3200)iro8=1;
    else iro9++;
  }
  saishou=iro1+iro2+iro3+iro4+iro5+iro6+iro7+iro8;
  saidai=iro1+iro2+iro3+iro4+iro5+iro6+iro7+iro8+iro9;
  if(saishou==0&&iro9!=0)saishou=1;
  cout<<saishou<<" "<<saidai<<endl;
  return 0;
}
    



Measured memory_bytes: 3600
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
def distance(x1, x2):
    ans = 0
    for d1, d2 in zip(x1, x2):
        ans += (d1 - d2) ** 2
    return float(sqrt(ans)).is_integer()

res = 0

for i in range(n):
    for j in range(n):
        if j == i:
            continue
        if distance(x[i], x[j]):
            res += 1

print(res // 2)


Measured memory_bytes: 3064
//https://apc001.contest.atcoder.jp/tasks/apc001_b

#include<bits/stdc++.h>
#define int long long
const int N = 10005;
using namespace std;

int n, a[N], b[N], sum, cnt, cnt2;

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) a[i] -= b[i], sum += a[i];
    if (sum > 0) return cout << "No", 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > 0) {
            sum += a[i];
            cnt += a[i];
        }
        else{
            cnt2 += (-a[i]) / 2;
        }
    }
    if (sum > 0) return cout << "No", 0;
    if (cnt2 < cnt) return cout << "No", 0;
    cout << "Yes";
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
#define MAX 10010

int areanum[MAX];

int getarean(int n)
{
    return (areanum[n]!=0)? areanum[n] : getarean(n-1)+n;
}

int main()
{
    areanum[1] = 2;
    int n;
    while(cin >> n)
    {
        cout << getarean(n) <<endl;
    }
    return 0;
}

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

int main(){
  string S;
  cin >> S;

  int64_t sum = 0;

  int len = S.length();

  for(int i = 1;i <= len;i++){
    for(int j = 0;j < len - i + 1;j++){
      sum += std::stoull(S.substr(j, i).c_str())*pow(2, max(0, len - (j + i - 1) - 2))*pow(2, max(0, j - 1));
      // std::cout << S.substr(j, i) << " " << max(0, j - 1) << " " << pow(2, max(0, j - 1)) << " " << max(0, len - (j + i - 1) - 2) << " " << pow(2, max(0, len - (j + i - 1) - 2)) << " " << sum << " sub_l_r" << std::endl;
    }
  }
  // 12656242944
  // 4066308352
  // 9999999999

  std::cout << sum << std::endl;

}


Measured memory_bytes: 256
N = int(input())
a_ls=list(map(int, input().split()))

a_ls+=[0]

m=1000
k=0

for i in range(N-1):
	m+=k*a_ls[i]
	k=0
	if a_ls[i]<a_ls[i+1]:
		k=m//a_ls[i]
		m-=(m//a_ls[i])*a_ls[i]
	


print(m+k*a_ls[N-1])

# 2darray [[0] * 4 for i in range(3)]

Measured memory_bytes: 9196
#include <cstdio>

static const int MAXN = 50;
static const int MAXD = 12;
static const int MAXT = 24;

static int n;
static int d[MAXN];
static int ct[MAXD + 1];

static bool sel[MAXT] = { false };

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

    if (ct[0] >= 1 || ct[MAXD] >= 2) { puts("0"); return 0; }
    for (int i = 1; i < MAXD; ++i) if (ct[i] >= 3) { puts("0"); return 0; }

    int base_mask = 1 | (ct[MAXD] ? (1 << MAXD) : 0);
    for (int ans = 12; ans > 0; --ans) {
        bool valid;
        for (int i = 0; i < (1 << (MAXD - 1)); ++i) {
            valid = true;
            int mask = base_mask, time;
            for (int j = 1; j < MAXD; ++j) switch (ct[j]) {
                case 0: default: break;
                case 1:
                    time = (i & (1 << (j - 1))) ? j : MAXT - j;
                    if (mask & (1 << time)) { valid = false; break; }
                    mask |= (1 << time);
                    break;
                case 2:
                    if (mask & (1 << j)) { valid = false; break; }
                    if (mask & (1 << (MAXT - j))) { valid = false; break; }
                    mask |= (1 << j) | (1 << (MAXT - j));
                    break;
            }
            if (!valid) continue;
            for (int j = 0; j < MAXT; ++j) sel[j] = (mask & (1 << j));
            for (int j = 0; j < MAXT; ++j) if (sel[j]) {
                for (int k = 1; k < ans; ++k) {
                    if (sel[(j - k + MAXT) % MAXT] || sel[(j + k) % MAXT]) {
                        valid = false; break;
                    }
                }
            }
            if (valid) break;
        }
        if (valid) { printf("%d\n", ans); return 0; }
    }

    puts("0"); return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, dp[200005];
ll ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  n = s.length();
  int cur = 0, last = 0;
  for (int i=0; i<n; i++) {
    if (s[i] != s[i-1] || last == 2) {
      last = 1;
      ans++;
    } else if (i+1<n){
      i++;
      last = 2;
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 720
N = int(input())
K = list(map(int, input().split()))
count = 0

for m in range(N):
    for n in range(m+1, N):
        for l in range(n+1, N):
            if K[m] != K[n] and K[m] != K[l] and K[l] != K[n]:
                now_list = sorted([K[m], K[n], K[l]])
                if now_list[2] < now_list[0] + now_list[1]:
                    count += 1

print(count)

Measured memory_bytes: 68488
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

MOD = 10**9 + 7
 
N = read()
A = reads()

fact = [1] * N
for i in range(1, N):
  fact[i] = (fact[i-1] * i) % MOD 
invfact = [0] * N; invfact[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(N-2, -1, -1):
  invfact[i] = invfact[i+1] * (i+1) % MOD
def comb(n, k):
  return fact[n] * invfact[n-k] * invfact[k] % MOD  

cnt = Counter(A)
q = next(i for i in range(1,N+1) if cnt[i] == 2)
i1 = A.index(q); i2 = A.index(q, i1+1)
m = N - (i2 - i1)
# print(m)

print(N)
for k in range(2, N+1):
  ans = comb(N-1, k-1) * 2 + comb(N-1, k-2)
  if m >= k-1:
    ans -= comb(m, k-1)
  if k <= N-1:
    ans += comb(N-1, k)
  print(ans % MOD)
print(1)

Measured memory_bytes: 67560
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();
 
    int ans = 0;
    Arrays.sort(ss);
    for(int i=0; i<S.length()-1; i++) {
    	if(ss[i] <= ss[i+1]-2) {
    		ans = ss[i]+1;
    		break;
    	}
    	}
    
    if(ss[0] != 'a') {
    	System.out.println("a");
    }else if(ans != 0){
    	System.out.println((char)ans); 
    }else if(ss[S.length()-1] == 'z'){
    	System.out.println("None");   	
    }else {
    	System.out.println((char)(ss[S.length()-1]+1));
    }
    }
}


Measured memory_bytes: 39684
void main() {
	auto s = rs, K = ri;
	auto rbt = new RedBlackTree!string("");
	foreach(i; 0..s.length) {
		foreach(j; i..s.length+1) {
			if(j - i > 5) continue;
			rbt.insert(s[i..j]);
		}
	}
	rbt.array[K].writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

T[] deepcopy(T)(T[] a) {
	static if(isArray!T) {
		T[] res;
		foreach(i; a) {
			res ~= deepcopy(i);
		}
		return res;
	} else {
		return a.dup;
	}
}

Measured memory_bytes: 1404
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int x1,x2,x3,x4;
    int a,b,c,d,e,f,s1=0,s2=0,p,t;
    double s,sum=0.0,q;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    q=(double)e/(100+e);
    for(x1=0;x1*a*100<=f;x1++)
    for(x2=0;x2*b*100+x1*a*100<=f;x2++)
    for(x3=0;x3*c+x1*a*100+x2*b*100<=f;x3++)
    for(x4=0;x4*d+x3*c+x1*a*100+x2*b*100<=f;x4++)
    {
    s=(double)(x3*c+x4*d)/(x3*c+x4*d+x1*a*100+x2*b*100);
    if(s<=q)
    {
        if(s>=sum)
        {
        s1=x3*c+x4*d+x1*a*100+x2*b*100;
        s2=x3*c+x4*d;
        sum=s;
        }
    }
    }
    printf("%d %d\n",s1,s2);
    return 0;
}


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

const int MAX_N = 101;

int m, n, d[MAX_N][MAX_N];
bool a[MAX_N][MAX_N], f[MAX_N][MAX_N][MAX_N][MAX_N], g[MAX_N][MAX_N][MAX_N][MAX_N];
char s[MAX_N];

int main()
{
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= m; ++i)
	{
		scanf("%s", s);
		for (int j = 0; j < n; ++j)
			a[i][j + 1] = s[j] == '#';
	}
	f[0][0][1][1] = !a[1][1];
	g[0][0][1][1] =  a[1][1];
	for (int i = 1; i <= m; ++i)
		for (int j = 1; j <= n; ++j)
		{
			f[0][0][i][j] |= !a[i][j] && (f[0][0][i - 1][j] || f[0][0][i][j - 1]);	
			g[0][0][i][j] |=  a[i][j] && (g[0][0][i - 1][j] || g[0][0][i][j - 1]);	
			for (int x = 1; x <= i; ++x)
				for (int y = 1; y <= j; ++y)
					if (x != i || y != j)
					{
						f[x][y][i][j] = !a[i][j] && (f[x][y][i - 1][j] || f[x][y][i][j - 1]);	
						g[x][y][i][j] =  a[i][j] && (g[x][y][i - 1][j] || g[x][y][i][j - 1]);	
					}
			f[i - 1][j][i][j] = !a[i][j];
			f[i][j - 1][i][j] = !a[i][j];
			g[i - 1][j][i][j] =  a[i][j];
			g[i][j - 1][i][j] =  a[i][j];
		}
	for (int i = 1; i <= m; ++i)
		for (int j = 1; j <= n; ++j)
		{
			d[i][j] = MAX_N * 2;
			if (f[0][0][i][j])
				d[i][j] = std::min(d[i][j], d[0][0]);
			if (g[0][0][i][j])
				d[i][j] = std::min(d[i][j], d[0][0] + 1);
			for (int x = 1; x <= i; ++x)
				for (int y = 1; y <= j; ++y)
					if (x != i || y != j)
					{
						if (f[x][y][i][j])
							d[i][j] = std::min(d[i][j], d[x][y]);
						if (g[x][y][i][j])
							d[i][j] = std::min(d[i][j], d[x][y] + 1);
					}
			//printf("%d %d = %d\n", i, j, d[i][j]);
		}
	printf("%d\n", d[m][n]);
	return 0;
}

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

using namespace std;

int main(void) {
	int a,p,num=0;
	cin>>a>>p;

	num=(a*3+p)/2;

	cout<<num<<"\n";


	return 0;
}


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

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

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

using namespace std;

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

const long long INF = LLONG_MAX/3;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

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

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

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

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

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	if(p==2||p==5){
		int re=0;
		if(p==2){
			rep(i,n){
				if((s[i]-'0')%2==0)re+=i+1;
			}
		}else{
			rep(i,n){
				if((s[i]-'0')%5==0)re+=i+1;
			}
		}
		cout<<re<<endl;
		return 0;
	}
	int c[10010]={};
	c[0]=1;
	int a=1;
	int re=0;
	int ss[200010];
	ss[0]=(s[0]-'0')%p;
	rep(i,1,n){
		ss[i]=(ss[i-1]*10+(s[i]-'0'))%p;
	}
	rep(i,n){
		int t=ss[i]*modinv(a,p)%p;
		//cout<<ss[i]<<" "<<a<<" "<<t<<" "<<c[t]<<endl;
		re+=c[t];
		c[t]++;
		a*=10;
		a%=p;
	}
	cout<<re<<endl;
}


Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		//ALDS1_1_A(); 
		//ALDS1_2_A();
		//ALDS1_2_B();
		//ALDS1_2_C();
		//ALDS1_2_D();
		//ALDS1_3_A();
		//ALDS1_3_B();
		ALDS1_3_C();
	}

	public static void ALDS1_3_C() {

		Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//LinkedList<Integer> link = new LinkedList<Integer>();
		//Deque<Integer> link = new ArrayDeque<Integer>();
		Deque<String> link = new ArrayDeque<String>();
		StringBuilder ans = new StringBuilder();
		String input_str[] = new String[2];
		try {
			int n = Integer.parseInt(br.readLine());
			//int n = sc.nextInt();
			for(int i = 0; i < n; i++) {
				//String command = sc.next();
				input_str = br.readLine().split("\\s+");
				if(input_str[0].equals("insert")) {
					//int x = sc.nextInt();
					//link.addFirst(x);
					link.addFirst(input_str[1]);
				}else if(input_str[0].equals("delete")) {
					//int x = sc.nextInt();
					//link.removeFirstOccurrence(x);
					link.remove(input_str[1]);
				}else if(input_str[0].equals("deleteFirst")) {
					link.removeFirst();
				}else if(input_str[0].equals("deleteLast")) {
					link.removeLast();
				}

				/*
				if(command.equals("insert")) {
					int x = sc.nextInt();
					link.addFirst(x);
				}else if(command.equals("delete")) {
					int x = sc.nextInt();
					link.removeFirstOccurrence(x);
				}else if(command.equals("deleteFirst")) {
					link.removeFirst();
				}else if(command.equals("deleteLast")) {
					link.removeLast();
				}
				 */
			}

			if(!link.isEmpty()) {
				ans.append(link.getFirst());
				link.removeFirst();
			}
			while(!link.isEmpty()) {
				ans.append(" ").append(link.getFirst());
				link.removeFirst();
			}
			System.out.println(ans.toString());
			
			
			/*
			String tmp;
			boolean notFirst = false;
			while((tmp = link.poll()) != null) {
				if(notFirst)
					System.out.print(" ");
				System.out.print(tmp);
				notFirst = true;
			}
			System.out.println();
			*/
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}



Measured memory_bytes: 599724
if __name__ == '__main__':

	n = int(input())
	A = []
	cnt = 1
	A.append(n)

	while True:
		if n % 2 == 0:
			n = n // 2
		else:
			n = 3 * n + 1
		cnt += 1
		if n in A:
			print(cnt)
			break
		A.append(n)
	

Measured memory_bytes: 8868
#include<iostream>
#include<algorithm>

using namespace std;

int a[100000];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    if (i > 0 && a[i-1] + 1 >= a[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a, a+m);
  int p = 0;
  if (m == 0) {
    a[0] = 10000000;
  }
  long long dp[2];
  dp[0] = 1;
  if (a[0] != 1) {
    dp[1] = 1;
  } else {
    dp[1] = 0;
    p++;
  }
  for (int i = 2; i <= n; i+=2) {
    dp[0] = dp[0] + dp[1];
    dp[1] = dp[0] + dp[1];
    if (i == a[p]) {
      dp[1] -= dp[0];
      dp[0] = 0;
    }
    if (i == a[p] - 1) {
      dp[1] = 0;
    }
    if (i == a[p] || i == a[p] - 1) {
      p++;
    }
    dp[0] %= 1000000007;
    dp[1] %= 1000000007;
    if (i == n) {
      cout << dp[0] << endl;
      return 0;
    } else if (i == n - 1) {
      cout << dp[1] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 384
use std::convert::TryInto;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        antenna: [i32; 5],
        k: i32,
    };

    let mut ans: bool = true;
    for i in 0..5 {
        for j in i+1..5 {
            if antenna[j] - antenna[i] <= k {
                ans &= true;
            }
            else {
                ans &= false;
            }
        }
    }

    println!("{}", if ans { "Yay!" } else { ":(" });
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;	
  cin>>n;
  if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9)
    cout<<"hon";
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
    cout<<"pon";
  else cout<<"bon";
  return 0;
}

Measured memory_bytes: 3592
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int64 N; cin >> N;
    vector<int64> pos, neg;
    for(int i=0; i<N; i++) {
        int64 v; cin >> v;
        if(v >= 0) pos.push_back(v);
        if(v <  0) neg.push_back(v);
    }

    int64 ans = 0;
    vector< pair<int64, int64> > op;

    // pos だけ
    if(neg.size() == 0) {
        sort(pos.begin(), pos.end());
        int64 v = pos[0];
        for(int i=1; i<N; i++) {
            if(i + 1 != N) {
                op.emplace_back(v, pos[i]);
                v = v - pos[i];
            }
            else {
                op.emplace_back(pos[i], v);
                v = pos[i] - v;
            }
        }
        ans = v;
    }
    // neg だけ
    else if(pos.size() == 0) {
        sort(neg.rbegin(), neg.rend());
        int64 v = neg[0];
        for(int i=1; i<N; i++) {
            op.emplace_back(v, neg[i]);
            v = v - neg[i];
        }
        ans = v;
    }
    else {
        int64 p = pos[0], n = neg[0];
        
        // n - pos[i] (negative)
        for(size_t i=1; i<pos.size(); i++) {
            op.emplace_back(n, pos[i]);
            n = n - pos[i];
        }
        // p - neg[i] (positive)
        for(size_t i=1; i<neg.size(); i++) {
            op.emplace_back(p, neg[i]);
            p = p - neg[i];
        }

        op.emplace_back(p, n);
        ans = p - n;
    }

    cout << ans << endl;
    for(auto e : op) {
        cout << e.first << " " << e.second << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    int k = 1, c = 0;
    while (true)
    {
        if(k>=B) break;
        k = k - 1 + A;
        c++;
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mygcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return mygcd(b, a % b);
    }
}

signed main()
{
    int w,h,n;
    cin >> w >> h >> n;
    int xmin=0;
    int xmax=w;
    int ymin=0;
    int ymax=h;
    rep(i,n){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1){
            chmax(xmin, x);
        }
        else if(a==2){
            chmin(xmax, x);
        }
        else if(a==3){
            chmax(ymin, y);
        }
        else {
            chmin(ymax, y);
        }
    }
    if(xmin>=xmax || ymin>=ymax){
        cout << 0 << endl;
    }
    else {
        cout << (xmax - xmin) * (ymax - ymin) << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

class dis{
    public:
        int x, y;

    int getDis(){ return abs(x) + abs(y); }
};

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

int N;
vector<dis> D;

int main(){
    cin >> N;
    rep(i, N){
        int x, y;
        cin >> x >> y;
        dis d;
        d.x = x;
        d.y = y;
        D.push_back(d);
    }

    int maxi = 0;
    rep(i, N - 1){
        int a = D[i].getDis();
        int b = D[i + 1].getDis();
        if(a % 2 != b % 2){
            cout << -1 << endl;
            return 0;
        }
        maxi = max(maxi, a);
    }
    maxi = max(maxi, D[N - 1].getDis());
    
    vector<ll> m;
    ll sum = 0;
    if(maxi % 2 == 0){
        m.push_back(1);
        sum++;
    }
    for(ll i = 1; sum < maxi; i*=2){
        m.push_back(i);
        sum += i;
    }

    sort(m.begin(), m.end(), greater<ll>());
    cout << m.size() << endl;
    for(auto i : m) cout << i << " ";
    cout << endl;
    rep(i, N){
        dis d = D[i];
        string s;
        ll res = sum;
        rep(j, m.size()){
            res -= m[j];
            ll nx, ny;

            nx = d.x + m[j];
            ny = d.y;
            if(abs(nx) + abs(ny) <= res){
                s.push_back('L');
                d.x = nx;
                d.y = ny;
                continue;
            }

            nx = d.x - m[j];
            if(abs(nx) + abs(ny) <= res){
                s.push_back('R');
                d.x = nx;
                d.y = ny;
                continue;
            }

            nx = d.x;
            ny = d.y + m[j];
            if(abs(nx) + abs(ny) <= res){
                s.push_back('D');
                d.x = nx;
                d.y = ny;
                continue;
            }

            ny = d.y - m[j];
            if(abs(nx) + abs(ny) <= res){
                s.push_back('U');
                d.x = nx;
                d.y = ny;
                continue;
            }
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int a;
    double b;
    cin >> a >> b;
    int count = 1,aa;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1;;i++){
        count += a-1;
        aa = i;
        if(count >= b){
            break;
        }
    }
    cout << aa << endl;

    return 0;
}

Measured memory_bytes: 384
S = input()
N = int(input())

s = S
for _ in range(0, N):
	C = input().split()
	l, r = int(C[1]), int(C[2]) + 1
	if C[0] == "replace":
		s = s[:l] + C[3] + s[r:]
	elif C[0] == "reverse":
		s = s[:l] + s[l:r][::-1] + s[r:]
	elif C[0] == "print":
		print(s[l:r])



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

using namespace std;
typedef long long LL;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    LL tot = 0;
    priority_queue<LL> pq;

    for (int i = 1; i <= n; i++) {
        LL tmp;
        cin >> tmp;
        pq.push(tmp);
    }

    while (m) {
        for (int i = 1; i <= n && m; i++) {
            LL tmp = pq.top();
            pq.pop();
            pq.push(tmp / 2);
            m--;
        }
    }
    for (int i = 1; i <= n; i++) {
        tot += pq.top();
        pq.pop();
    }
    cout << tot << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define mo 924844033
#define pi 3.1415926535898 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n,i,a[250005],top,sum;
struct nyh{
	long long x,id;
}o[250005];
bool cmp(nyh u,nyh v){
	return u.x>v.x;
}
bool cmp2(nyh u,nyh v){
	return u.x<v.x;
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();
   	for(i=1;i<=n;i++){
		o[i].x=read();
		o[i].id=i;
	}
	sort(o+1,o+n+1,cmp);
	top=n*n;
	for(i=1;i<=n;i++){
		sum=0;
		if(a[o[i].x]!=0){
			printf("No\n");
			return 0;	
		}
		else
			a[o[i].x]=o[i].id;
		while(sum!=n-o[i].id&&top!=0){
			if(a[top]==o[i].id){
				printf("No\n");
				return 0;
			}
			if(a[top]==0){
				a[top]=o[i].id;
				sum++;
			}
			if(sum==n-o[i].id)
				break;
			top--;
		}
		if(top==0){
			printf("No\n");
			return 0;
		}
	}
	sort(o+1,o+n+1,cmp2);
	top=1;
	for(i=1;i<=n;i++){
		sum=0;
		while(sum!=o[i].id-1&&top!=0){
			if(a[top]==o[i].id){
				printf("No\n");
				return 0;
			}
			if(a[top]==0){
				a[top]=o[i].id;
				sum++;
			}
			if(sum==o[i].id-1)
				break;
			top++;
		}
		if(top==n*n+1){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for(i=1;i<=n*n;i++)
		pus(a[i],1);
	cout<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N + 1);
  vector<long long> sumA(N + 1);
  rep(i, N + 1)
  {
    cin >> A[i];
    sumA[i] = A[i];
  }
  REVERSE(sumA);
  rep(i, N)
  {
    sumA[i + 1] += sumA[i];
  }
  REVERSE(sumA);

  long long max_node = 1;
  rep(i, N + 1)
  {
    if (sumA[i] > max_node)
      sumA[i] = max_node;

    if (i < 60)
      max_node *= 2;
  }

  rep(i, N)
  {
    long long can_node = 2 * (sumA[i] - A[i]);
    if (sumA[i + 1] > can_node)
      sumA[i + 1] = can_node;
  }

  long long ans = 0;
  rep(i, N + 1)
  {
    if (A[i] > sumA[i])
    {
      cout << -1 << endl;
      return 0;
    }
    ans += sumA[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4844
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: i32,
        a: i32,
        b: i32,
    }
    println!("{}", (x - a) % b);
}


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

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

    long long n, m;
    cin >> n >> m;

    long long ans = 0;
    long long h = min(n, m / 2);
    ans += h;
    n -= h;
    m -= h * 2;

    if(m > 0) ans += m / 4;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using ll =long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    map<int,int> a,b;
    rep(i,n){
        int t;
        cin >> t;
        if(i%2==0){
            a[t]++;
        }else{
            b[t]++;
        }
    }
    int ama=0,ama2=0,bma=0,bma2=0;
    int ai,bi;
    for(auto t : a){
        if(ama<t.second){
            ama = t.second;
            ai = t.first;
        }
    }
    for(auto t : a){
        if(ama2<t.second && t.first!=ai){
            ama2 = t.second;
        }
    }for(auto t : b){
        if(bma<t.second){
            bma = t.second;
            bi = t.first;
        }
    }
    for(auto t : b){
        if(bma2<t.second && t.first!=bi){
            bma2 = t.second;
        }
    }
    //cout << ai <<" " << bi << endl;
    if(ai==bi){
        cout << n - max(ama+bma2,bma+ama2) << endl;;
    }else{
        cout << n - (ama + bma) << endl;
    }
}

Measured memory_bytes: 4992