akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

    vector<int> a(n);
    vector<int> b(m);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b.at(i);
    }

    vector<ll> c(n + 1);
    vector<ll> d(m + 1);

    c.at(0) = 0;
    for (int i = 1; i <= n; i++)
    {
        c.at(i) = c.at(i - 1) + a.at(i - 1);
    }

    //cout << " ddddddddddddddddddddddddddddddddddddddd" << endl;

    d.at(0) = 0;
    for (int i = 1; i <= m; i++)
    {
        d.at(i) = d.at(i - 1) + b.at(i - 1);
    }

    ll temp;
    int count = d.size() - 1;
    int ans = 0;

    for (int i = 0; i <= n; i++)
    {
        temp = k - c.at(i);
        if (temp < 0)
        {
            break;
        }
        while (temp < d.at(count))
        {
            count--;
        }
        if (ans < i + count)
        {
            ans = i + count;
        }
    }

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


Measured memory_bytes: 7628
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266;
ll g[N],res;
ll G(ll x){
	if(x<=100)return g[x];
	ll k=0;while((1ll<<k)-x<g[k])k++;
	return k;
}

int ans,fac[11]={1,1,2,6,24,120,720};int a[N],len;
int trs[7][727][1<<7|3];
bool ck(int k, int n){
	assert(k<=5);
	static bool ok[1<<6|3];memset(ok,0,1<<k);
	rep(i,1,n)ok[a[i]]=1;
	rep(i,2,fac[k]){
		bool flag=1;
		rep(j,1,n)flag&=ok[trs[k][i][a[j]]];
		if(flag)return 0;
	}
	return 1;
}
void dfs(int k, int n, int s, int cnt){
	if(ans/fac[k]>1000)return;
	if(cnt==n){
		ans+=ck(k,n);
		return;
	}
	if(s>=1<<k)return;
	dfs(k,n,s+1,cnt);
	a[++len]=s;
	dfs(k,n,s+1,cnt+1);
	len--;
}

ll getans(ll k, ll n){//c(k,n)
	cerr<<k<<' '<<n<<endl;
	if(k>n)return getans(n,k);//k<=n
	if(k<=61)assert(n<=(1ll<<k));
	if(k>0&&k<=61&&(n>(1ll<<k-1)))return getans(k,(1ll<<k)-n);
//	if(k<=61)assert(n<=(1ll<<k-1));
	if(k>5)return 1001;
	if(!k)return 1;
	dfs(k,n,0,0);
	cerr<<k<<' '<<n<<' '<<ans/fac[k]<<endl;
	return ans/fac[k];
}
int main() {
	rep(n,1,5){
		static int p[N];int cnt=0;rep(i,1,n)p[i]=i;
		while(cnt<fac[n]){
			cnt++;
			rep(i,0,(1<<n)-1){
				int res=0;rep(j,1,n)if(i>>j-1&1)res|=1<<p[j]-1;
				trs[n][cnt][i]=res;
			}
			next_permutation(p+1,p+n+1);
		}
	}
	
	
	rep(i,2,100)while((1ll<<g[i])-i<g[g[i]])g[i]++;
//	rep(i,2,100)cerr<<i<<' '<<g[i]<<endl;
	ll n;read(n);ll gn=G(n),k=0;
	while(k<gn)k++;
	//while((1ll<<k)-G(k)<n)k++;
	//if(n-1<=10&&k>(1ll<<n-1))k=(1ll<<n)-k;
	//if(k<=60&&n>(1ll<<k-1))n=(1ll<<k)-n;
//	cerr<<k<<' '<<gn<<' '<<n<<endl;
//	assert(k<=n);
//	if(k>=6){cout<<-1;return 0;}
//	assert(k<=n&&n<=(1ll<<k-1));
	res=getans(k,n);//table[k][n];//getans(k,n);
	res+=(n==4)+2*(n==7);
	cout<<(res>1000?-1:res);
	return 0;
}


Measured memory_bytes: 3768
#include <stdio.h>

int main(){
	int a,b,c,chukan;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b){
		chukan = a;
		a = b;
		b = chukan;
	}
	if(b > c){
		chukan = b;
		b = c;
		c = chukan;
	}
	if(a > b){
		chukan = a;
		a = b;
		b = chukan;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);

signed main(){
    string a,b,c;cin>>a>>b>>c;
    if(a.back()==b[0] && b.back()==c[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    string S, T;
    cin >> S >> T;
    int S_to_T[26];
    for(int i = 0; i < 26; i++){
        S_to_T[i] = -1;
    }
    for(int i = 0; i < S.size(); i++){
        if(S_to_T[S[i] - 'a'] == -1){
            S_to_T[S[i] - 'a'] = T[i] - 'a';
        }
    }
    for(int i = 0; i < 26; i++){
        for(int j = i + 1; j < 26; j++){
            if(S_to_T[i] == S_to_T[j] && S_to_T[i] != -1){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < S.size(); i++){
        if(S_to_T[S[i] - 'a'] != -1 && S_to_T[S[i] - 'a'] != T[i] - 'a'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void)
{
    int N, M;
    int a, b;
    int i;
    cin >> N >> M;
    vector<vector<bool>> E(N, vector<bool>(N, false));
    for (i = 0; i < M; ++i)
    {
        cin >> a >> b;
        E[a - 1][b - 1] = E[b - 1][a - 1] = true;
    }
    vector<int> p(N);
    for (int i = 0; i < N; i++) p[i] = i;
    int ans = 0;
    do
    {
        for (i = 1; i < N; i++)
        {
            if (!E[p[i - 1]][p[i]]) break;
        }
        if (i == N) ans++;
    }
    while (next_permutation(p.begin() + 1, p.end()));    
    cout << ans << endl;
    return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int N_MAX = 100;
    int N;
    int a[N_MAX];
    cin >> N;
    REP(i, N) cin >> a[i];
    sort(a, a + N);
    int alice = 0;
    int bob = 0;
    REP(i, N) {
        if (i % 2 == 0) {
            alice += a[N - 1 - i];
        } else {
            bob += a[N - 1 - i];
        }
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
H = list(map(int,input().split()))
a = 0
b = 0
if len(H) != 1:
    for i in range(N-1):
        if b < H[i]:
            b = H[i]
        if a == 1:
            break
        if H[i]>H[i+1]:
            if H[i]-1>H[i+1]:
                a = 1
            else:
                if b>H[i]:
                    a = 1
                
if a == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14224
#include <iostream>
#include <bits/stdc++.h>
#define MAX_SIZE 500010
#define NIL -1
#define INFTY 2000000000
using namespace std;

struct Node { int p, l, r; };
Node T[MAX_SIZE];
int D[MAX_SIZE], H[MAX_SIZE];

int getDepth(int u) {
    int d = 0;
    while (T[u].p != NIL) {
        u = T[u].p;
        d++;
    }
    return d;
}

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].r, d + 1);
    setDepth(T[u].l, d + 1);
}

int setHeight(int u) {
    if (u == NIL) return -1;
    int h1 = setHeight(T[u].l) + 1;
    int h2 = setHeight(T[u].r) + 1;
    return H[u] = max(h1, h2);
}

int getSibling(int u) {
    if (T[u].p == NIL) return NIL;
    int p = T[u].p;
    if (T[p].r == u) return T[p].l;
    if (T[p].l == u) return T[p].r;
    return NIL;
}

int getDegree(int u) {
    if (T[u].l == NIL) {
        if (T[u].r == NIL) return 0;
        return 1;
    }
    if (T[u].r == NIL) return 1;
    return 2;
}

void printNode(int v) {
    cout << "node " << v << ": ";
    cout << "parent = " << T[v].p << ", ";
    cout << "sibling = " << getSibling(v) << ", ";
    cout << "degree = " << getDegree(v) << ", ";
    cout << "depth = " << D[v] << ", ";
    cout << "height = " << H[v] << ", ";
    if (T[v].p == NIL) cout << "root";
    else if (T[v].l == NIL && T[v].r == NIL) cout << "leaf";
    else cout << "internal node";
    cout << endl;
}

void preorder(int u) {
    if (u == NIL) return;
    cout << " " << u;
    preorder(T[u].l);
    preorder(T[u].r);
}

void inorder(int u) {
    if (u == NIL) return;
    inorder(T[u].l);
    cout << " " << u;
    inorder(T[u].r);    
}

void postorder(int u) {
    if (u == NIL) return;
    postorder(T[u].l);
    postorder(T[u].r);
    cout << " " << u;
}

int main(){
    int i, j, v, k, n, c, l, r;
    cin >> n;
    for (i=0; i < n; i++) T[i].l = T[i].r = T[i].p = NIL;
    for (i=0; i < n; i++) {
        scanf("%d", &v);
        scanf("%d %d", &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }
    for (i=0; i < n; i++) if (T[i].p == NIL) r = i;
    setDepth(r, 0);
    setHeight(r);
    cout << "Preorder" << endl;
    preorder(r); cout << endl;
    cout << "Inorder" << endl;
    inorder(r); cout << endl;
    cout << "Postorder" << endl;
    postorder(r); cout << endl;
    return 0;
} 


Measured memory_bytes: 3176
#include<iostream>
#include<cstring>
#include<iomanip>

int main(){
	int n;
	while(std::cin>>n,n){
		int data[11][11];
		memset(data,0,sizeof(data));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				std::cin>>data[i][j];
				data[i][n]+=data[i][j];
				data[n][j]+=data[i][j];
				data[n][n]+=data[i][j];
			}
		}
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				std::cout<<std::setw(5)<<std::right<<data[i][j];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
ll W[110][110];
ll init[110][110];
ll counts[110][110];
struct edge {
	int v1, v2;
	int value;
}edges[1024];
//#define LOCAL
#define INF 0x3f3f3f3f;
void run() {
	int N, M;
	while(cin >> N >> M) {
		memset(init, 0x3f, sizeof(init));
		memset(W, 0x3f, sizeof(W));
		memset(counts, 0, sizeof(counts));
		int v1, v2, value;
		for(int i = 0; i < M; i++) {
			cin >> v1 >> v2 >> value;
			init[v1][v2] = init[v2][v1] = W[v1][v2] = W[v2][v1] = value;
			edges[i].v1 = v1;
			edges[i].v2 = v2;
			edges[i].value = value;
		}
		#ifdef LOCAL 
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				cout << W[i][j] << " ";
			}
			cout << endl;
		}
		#endif
		for(int l = 1; l <= N; ++l) {
			for(int i = 1; i <= N; i++) {
				for(int j = 1; j <= N; j++) {
					W[i][j] = min(W[i][j], W[i][l] + W[l][j]);
				}
			}
		}
		#ifdef LOCAL 
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				cout << init[i][j] << " ";
			}
			cout << endl;
		}
		#endif
		ll ans = 0;
		for(int i = 0; i < M; i++) {
			#ifdef LOCAL 
			 cout << init[edges[i].v1][edges[i].v2] << " " << edges[i].value << endl;
			#endif
			if(W[edges[i].v1][edges[i].v2] < edges[i].value)
				ans++;
		}
		cout << ans << endl;

	}
}
int main(int argc, char *argv[]) {
	run();
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for(int i= 0; i < N; ++i){
    cin >> H.at(i);
  }
  int plase = 1;
  float Tr = T - H.front();
  for(int i = 0; i < N; ++i){
    float Tp = T - (H.at(i)*0.006);
    if(fabs(Tp - A)  < fabs(Tr -A)){
      Tr = Tp;
      plase = i+1;
    }
  }
  cout << plase << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int x; cin >> x;
  for(ll i = -150; i <= 150; i++){
    for(ll j = -150; j <= 150; j++){
      if(i*i*i*i*i - j*j*j*j*j == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  cout << -1;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
from itertools import accumulate

N,K=map(int,input().split())
S=input()

count=[0]
if S[0]=="0":
    count.append(0)

s=S[0]
cnt=0
for i in range(N):
    if s==S[i]:
        cnt+=1
    else:
        count.append(cnt)
        cnt=1
        s=S[i]
count.append(cnt)
if S[N-1]=="0":
    count.append(0)

l=len(count)
count=list(accumulate(count))
ans=0
for i in range(0,l,2):
    ans=max(ans,count[min(l-1,i+2*K+1)]-count[i])
print(ans)

Measured memory_bytes: 7928
#include <stdio.h>
#include <math.h>
main(){
  int i,j,n,code;
  char cm[7],o,dict[262145];
  for(i=0,scanf("%d",&n);i<n;i++){
    scanf("%s",cm);
    j=code=o=0;
    while(o!='\n'){
      scanf("%c",&o);
      if(o=='A') code+=1*pow(4,j);
      else if(o=='C') code+=2*pow(4,j);
      else if(o=='G') code+=3*pow(4,j);
      else if(o=='T') code+=4*pow(4,j);
      else j--;
      j++;
    }
    if(cm[0]=='i') dict[code] = 1;
    if(cm[0]=='f') dict[code] ? printf("yes\n") : printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 496
use proconio::fastout;
use proconio::input;
use proconio::marker::Usize1;
use std::i64;

#[fastout]
fn main() {
    input! {
        n: usize, k: i64,
        ps: [Usize1; n],
        cs: [i64; n],
    }
    let mut ans = i64::MIN;
    for start in 0..n {
        let mut prev = start;
        let mut v = Vec::new();
        loop {
            prev = ps[prev];
            v.push(cs[prev]);
            if prev == start {
                break;
            };
        }
        let total = v.iter().sum::<i64>();
        let l = v.len();
        let mut t = 0i64;
        for i in 0..l {
            t += v[i];
            if i as i64 + 1 > k {
                break;
            }
            let mut now = t;
            if total > 0 {
                let e = (k - i as i64 - 1) / l as i64;
                now += total * e;
            }
            ans = ans.max(now);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2372
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n;
    int max = 200000;
    int r[max];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> r[i];
    }   

    int cur_max = -2000000000;
    int cur_min = r[0];

    for (int j = 1; j < n; ++j) {
        cur_max = std::max(cur_max, r[j] - cur_min);
        cur_min = std::min(cur_min, r[j]);
    }   

    cout << cur_max << endl;
    return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

    while(1) {
        ll n;
        cin >> n;
        if(!n) break;
        vector<ll> a(n);
        for(auto &e: a) cin >> e;
        sort(a.begin(), a.end());

        ll s = 0;
        for(auto &e: a) s += e;
        s /= n;

        cout << upper_bound(a.begin(), a.end(), s) - a.begin() << endl;;
    }
}



Measured memory_bytes: 3104
#include <cstdio>
#include <set>

using namespace std;

int main() {
    int n, a, cnt = 1;
    multiset<int> s;
    scanf("%d%d", &n, &a);
    s.insert(a);
    for (int i = 1; i < n; ++i) {
        scanf("%d", &a);
        if (*s.begin() >= a) ++cnt;
        else s.erase(--s.lower_bound(a));
        s.insert(a);
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string A = Console.ReadLine();
		int min = 1000000;
		for(var i=0;i<=A.Length-3;i++){
			int B = int.Parse(A.Substring(i,3));
			int C = Math.Abs(753-B);
			if(C < min){
				min = C;
			}
		}
		Console.WriteLine(min);
	}
}

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

int main(){
    int flag[26]={0};
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++){
        flag[s[i]-'a']=1;
    }
    
    if(s.size()<26){
        for(int i=0;i<26;i++){
            if(flag[i]==0){s+=(char)('a'+i);cout<<s<<endl;break;}
        }
    }
    else if(s=="zyxwvutsrqponmlkjihgfedcba"){cout<<"-1"<<endl;}
    else{
        for(int i=24;i>=0;i--){
            if(s[i]<s[i+1]){
                flag[s[i+1]-'a']=0;s.erase(s.begin()+(i+1));
                int t=s[i]-'a';
                flag[s[i]-'a']=0;s.erase(s.begin()+i); 
                            
                for(int i=t+1;i<26;i++){
                    if(flag[i]==0){s+=(char)('a'+i);cout<<s<<endl;break;}
                }
                break;
            }
            else{
                flag[s[i+1]-'a']=0;s.erase(s.begin()+(i+1));
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int ANS(string ans){
  if(ans == "Male") return 1;
  else if(ans == "Female") return -1;
  else return 0;
}

int solve(){
  int N;cin >> N;
  string ans;
  int l = 0, r = N-1;
  int la,ma,ra;
  printf("%d\n",l);
  fflush(stdout);
  cin >> ans;
  la = ANS(ans);
  if(la == 0)return 0;

  printf("%d\n",r);
  fflush(stdout);
  cin >> ans;
  ra = ANS(ans);
  if(ra == 0)return 0;

  while(r-l>1){
    int m = (r+l)/2;
    printf("%d\n",m);
    fflush(stdout);
    cin >> ans;
    ma = ANS(ans);
    if(ma==0) return 0;

    if((l-m)%2 == 0){
      if(la == ma){
        la = ma;
        l = m;
      }else{
        ra = ma;
        r = m;
      }
    }else{
      if(la == ma){
        ra = ma;
        r = m;
      }else{
        la = ma;
        l = m;
      }
    }
  }

  return 1;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  solve();
  return 0;
}


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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod 		1000000007
#define inf 		1e18
#define IOS 		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n;
	cin >> n;

	vector<int> v(n), suf(n);

	for (int i = 0; i < n; i++)
		cin >> v[i];

	suf[n - 1] = v[n - 1];

	for (int i = n - 2; i >= 0; i--) {
		suf[i] = (v[i] + suf[i + 1]) % mod;
	}

	int ans = 0;

	for (int i = 0; i < n - 1; i++) {
		ans = (ans + v[i] * suf[i + 1]) % mod;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
int main(){
  long long n, m, nn, mm, ans=1;
  while(cin>>n>>m){
    nn=n;mm=m;
    ans=1;
    bool l=0;
    for(int i=0; i<n+m; ++i){
      if(l){
        ans*=nn;
        --nn;
        l=!l;
      }
      else{
        ans*=mm;
        --mm;
        l=!l;
      }
      ans%=mod;
    }
    l=1;
    nn=n;mm=m;
    ll tmp=ans;
    ans=1;
    for(int i=0; i<n+m; ++i){
      if(l){
        ans*=nn;
        --nn;
        l=!l;
      }
      else{
        ans*=mm;
        --mm;
        l=!l;
      }
      ans%=mod;
    }
    tmp+=ans;
    tmp%=mod;
    cout<<tmp<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//abc123d cake
//1,2,3のケーキをそれぞれ降順ソート
//3つを比較して最も大きいものの次を参照
// Kのmaxが3000だから
//X,Y,Zの使わない下半分くらいは取り除いていい?
//abc > K


int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;

    vector <ll> a(x);
    vector <ll> b(y);
    vector <ll> c(z);
    REP(i,x)
    {
        cin >> a[i];
    }
    REP(i,y)
    {
        cin >> b[i];
    }
    REP(i,z)
    {
        cin >> c[i];
    }

    sort(a.begin(),a.end(),greater<ll>());
    sort(b.begin(),b.end(),greater<ll>());
    sort(c.begin(),c.end(),greater<ll>());

    //a + b の結果
    vector <ll> vec;

    REP(i,x)
    {
        REP(j,y)
        {
            vec.push_back(a[i] + b[j]);
        }
    }
    vector <ll> res;
    sort(vec.begin(),vec.end(),greater<ll>());

    int tmp = min(k+1 , (int)vec.size());

    REP(i,tmp)
    {
        REP(j,z)
        {
            res.push_back(vec[i] + c[j]);
        }
    }
    sort(res.begin(),res.end(),greater<ll>());


    for(int i = 0; i < k; ++i)
    {
        cout << res[i] << endl;
    }

    return 0;    
}



Measured memory_bytes: 43112
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> X;
    if(X < 100){
        cout << 0 << endl;
        return 0;
    }
    int cnt = X / 100;
    int res = X % 100;
    cnt -= res / 5;
    res %= 5;
    if(res == 0 && cnt >= 0){
        cout << 1 << endl;
        return 0;
    }
    if(cnt < 0){
        cout << 0 << endl;
        return 0;
    }
    //cout << res << endl;
    cnt -= res / 4;
    res %= 4;
    if(res == 0 && cnt >= 0){
        cout << 1 << endl;
        return 0;
    }
    if(cnt < 0){
        cout << 0 << endl;
        return 0;
    }
    cnt -= res / 3;
    res %= 3;
    if(res == 0 && cnt >= 0){
        cout << 1 << endl;
        return 0;
    }
    if(cnt < 0){
        cout << 0 << endl;
        return 0;
    }
    cnt -= res / 2;
    res %= 2;
    if(res == 0 && cnt >= 0){
        cout << 1 << endl;
        return 0;
    }
    if(cnt < 0){
        cout << 0 << endl;
        return 0;
    }
    cnt -= res;
    res = 0;
    if(res == 0 && cnt >= 0){
        cout << 1 << endl;
        return 0;
    }
    if(cnt < 0){
        cout << 0 << endl;
        return 0;
    }

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

def solve(K: int):
    K += 1
    ans = []
    for i in range(1, K):
        for j in range(1, K):
            for k in range(1, K):
                ans.append(math.gcd(i, math.gcd(j, k)))
    print(sum(ans))
    return

def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x
    
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71356
from sys import stdin, setrecursionlimit
from bisect import bisect_left


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    ans = 0

    for i in range(1, k + 1):
        if i < n:
            for j in range(i + 1):
                cand = v[: j] + v[n - i + j:]
                cand.sort()
                idx = min(bisect_left(cand, 0), k - i)
                if idx > 0 or i > 0:
                    ans = max(ans, sum(cand[idx:]))

        else:
            cand = v
            cand.sort()
            idx = bisect_left(cand, 0)
            ans = max(ans, sum(cand[idx:]))

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 41708
#include<iostream>
#include<cmath>
#include<string>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int k,n;
    cin>>k>>n;
    int max_m=0;
    int ai[n];
    for(int i=0;i<n;i++)
    {
        cin>>ai[i];
    }
    sort(ai,ai+n);
    for(int i=0;i<n-1;i++)
    {
        int max=ai[i+1]-ai[i];
        if(max>max_m)
            max_m=max;
    }
    int ni=k-ai[n-1]+ai[0];
    if(ni>max_m)
        max_m=ni;
    cout<<k-max_m<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, K;
int dp[55][55][55 * 55];

const int mod = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if(a >= mod) a -= mod;
}

int mul(int a, int b) {return a * 1LL * b % mod;}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> K;
  dp[0][0][0] = 1;
  for(int i = 1; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      for(int k = 0; k <= N * N; k++) {
        dp[i][j][k] = 0;
        if(k >= 2 * j) add(dp[i][j][k], mul(dp[i - 1][j][k - 2 * j], 2 * j + 1));
        if(k >= 2 * j) add(dp[i][j][k], mul(dp[i - 1][j + 1][k - 2 * j], mul(j + 1, j + 1)));
        if(j > 0 && k >= j) add(dp[i][j][k], dp[i - 1][j - 1][k - 2 * j]);
      }
    }
  }
  cout << dp[N][0][K] << endl;
}


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

int main(){
  int n,m;
  cin >>n>>m;
  long a[n];
  for(int i=0; i<n; i++) cin >>a[i];
  priority_queue<long, vector<long>, less<long>> Q;
  for(int i=0; i<n; i++) Q.push(a[i]);
  int i=0;
  while(i<m){
  	Q.push(Q.top()/2);
    Q.pop();
    i++;
  }
  long ans=0;
  for(int i=0; i<n; i++){
  	ans+=Q.top();
    Q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 2168
from decimal import Decimal, ROUND_HALF_UP
while 1:
    try:
        a,b,c,d,e,f=map(float,input().split())
        x=(c*e-b*f)/(a*e-b*d)+0.0
        y=(c*d-a*f)/(b*d-a*e)+0.0
        print(Decimal(str(x)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP),Decimal(str(y)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP))
    except:break


Measured memory_bytes: 6364
def search(S,n,T):
    L=0
    R=n

    while L<R:
        M=int((L+R)/2)
        if T>S[M]:
            L=M+1
        elif T<S[M]:
            R=M
        elif T==S[M]:
            return 1
    return 0

sum=0

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

q=int(input())
T=list(map(int, input().split()))

for i in range(0,q):
    if search(S,n,T[i])==1:
        sum+=1

print(sum)

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

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

	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
		cout << "YES" << endl;
		return 0;
	}else{
		cout << "NO" << endl;
		return 0;
	}

	return 0;
}

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

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<long long> vll;
typedef long long ll;
typedef vector<int> vi;

const int INF = 1e6;

using namespace std;

#define MOD 998244353 

#define LSOne(S) ((S) & -(S))                    // the key operation

class FenwickTree {                              // index 0 is not used
private:
  vi ft;                                        // internal FT is an array
public:
  FenwickTree(int m) { ft.assign(m+1, 0); }      // create an empty FT

  int rsq(int j) {                                // returns RSQ(1, j)
    int sum = 0;
    for (; j; j -= LSOne(j))
      sum = (sum%MOD + ft[j]%MOD)%MOD;
    return sum;
  }

  int rsq(int i, int j) { return (rsq(j) - rsq(i-1) + MOD)%MOD; } // inc/exclusion

  // updates value of the i-th element by v (v can be +ve/inc or -ve/dec)
  void update(int i, int v) {
    for (; i < (int)ft.size(); i += LSOne(i))
      ft[i] = (ft[i]%MOD + v%MOD)%MOD;
  }
};

int range(int x, int N){
    if(x > N) return N+1;
    else return x;
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
//    freopen("out.txt", "w", stdout);

    int N, K; cin >> N >> K;

    int v[N+5], L[K], R[K];
    fill(v, v + N + 5, 0);
    FenwickTree ft(N+5);
    v[N] = 1; ft.update(N, 1);
    for(int i = 0; i < K; i++) cin >> L[i] >> R[i]; 

    for(int j = N-1; j >= 1; j--){
        for(int k = 0; k < K; k++){
            v[j] = (v[j]%MOD + ft.rsq(range(j+L[k], N), range(j+R[k], N))%MOD)%MOD;
        } 
        ft.update(j, v[j]);
    }

    cout << v[1];

    return 0;

}


Measured memory_bytes: 4784
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())

    ans=0
    i=0
    while ans<n:
        i+=1
        ans+=i

    print(i)
    rem=n-i
    i-=1
    if rem!=0:
        while i>0:

            if rem-i>=0:
                print(i)
                rem -=i
                i-=1
            else:
                i-=1


resolve()

Measured memory_bytes: 41712
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(i())
ans=1
for i in range(a-1):
  if l[i]!=l[i+1]:
    ans+=1
print(ans)

Measured memory_bytes: 49392
#define MYDEBUG
//
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using namespace std;
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "{" << p.first << "," << p.second << "}";
  return out;
}

static const int MAX_LEN = 20000;
static const int MAX_MIZU = MAX_LEN / 2;
static const char DOWN = '\\', FLAT = '_', UP = '/';
char d[MAX_LEN]; //diagram: \\//\\__//
stack<int> st;
stack<pair<int, int> > mizu, mizu_rev;
int n, total;

void solve() {
  scanf("%s", d);
  n = strlen(d);
  rep(i,0,n)
  {
    if (d[i] == DOWN) {
      st.push(i);
    } else if (d[i] == UP) {
      if (st.empty()) {
        continue;
      }
      int left = st.top();
      st.pop();
      int area = i - left;
      while (!mizu.empty()) {
        int l = mizu.top().first;
        if (left <= l) { //水没する水たまりだけマージする
          area += mizu.top().second;
          mizu.pop();
        } else {
          break;
        }
      }
      mizu.push(make_pair(left, area));
    }
  }
  while (!mizu.empty()) {
    mizu_rev.push(mizu.top());
    total += mizu.top().second;
    mizu.pop();
  }
  printf("%d\n", total);
  printf("%lld", mizu_rev.size());
  while (!mizu_rev.empty()) {
    printf(" %d", mizu_rev.top().second);
    mizu_rev.pop();
  }
  printf("\n");
}
int main() {
  solve();
  return 0;
}



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

#define pi 3.1415926536
#define mod 1000000007
#define lli long long int
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repn(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define loop(i, a, b) for(int i = a ; i < b ; i++)
#define mod1 1000003
#define hello "hello"

using namespace std;

//fixed<<setprecision(9);

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}

int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}



int main()
{
	lli n;

	cin>>n;
	lli min = n + 1;


	loop(i, 1, ceil(sqrt(n)) + 10)
	{
		if(n%i == 0)
		{
			if(i + n/i < min)
			{
				min = i + n/i;
			}
		}
	}

	cout<<min-2<<endl;
}	

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] fizzBuzz = new String[n];
    long sum = 0;
    for(int i = 1; i<=n; i++){
      if(i%3==0 && i%5==0){
//        fizzBuzz[i-1] = "FizzBuzz";
      } else if(i%3==0){
//        fizzBuzz[i-1] = "Fizz";
      } else if(i%5==0){
//        fizzBuzz[i-1] = "Buzz";
      } else {
        sum += (long)i;
      }
    }
    System.out.println(sum);
  }
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, W;
  cin >> n >> W;
  int w[n + 1], v[n + 1];
  rep(i, n) cin >> w[i + 1] >> v[i + 1];

  const int mv = n * 1000;
  const int INF = 1001001001;
  int dp[n + 1][mv + 1];
  rep(i, mv + 1) dp[0][i] = INF;
  dp[0][0] = 0;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= mv; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
    }
  }

  int ans = 0;
  rep(i, mv + 1) {
    if (dp[n][i] <= W) ans = max(ans, i);
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int x;
  
  cin >> x;
  
  rep(i, 8){
    if(x >= 400 + i * 200 && x < 400 + (i + 1) * 200){
      cout << 8 - i << endl;
      return 0;
    }
  }

}

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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 1000

int N;
long long T[MAX];
long long A[MAX];

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> T[i] >> A[i];
	}

	long long t = 1;
	long long a = 1;
	for( int i = 0; i < N; i++ ) {
		long long j = max( (t + T[i] - 1) / T[i], (a + A[i] - 1) / A[i] );
		t = T[i] * j;
		a = A[i] * j;
	}
	long long ans = t + a;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder(sc.next());
		StringBuilder sb2 = new StringBuilder();
		
		int op, rev = 0, f;
		char c;
		
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			op = sc.nextInt();
			if(op == 1)
				rev = 1-rev;
			else {
				f = sc.nextInt();
				c = sc.next().charAt(0);
				
				if(rev == 0 && f==1 || rev==1 && f==2) {
					sb2.append(c);
				}
				else {
					sb.append(c);
				}
			}
		}
		StringBuilder res = sb2.reverse().append(sb);
		
		System.out.println(rev == 0 ? res :res.reverse());
		
	}
}


Measured memory_bytes: 128868
#include <stdio.h>
int main(void){
    int n,k,i,j,d,x;
    scanf("%d%d",&n,&k);
    int a[n],cnt=n;
    for(i=0;i<n;i++) a[i]=0;
    for(i=0;i<k;i++){
        scanf("%d",&d);
        for(j=0;j<d;j++){
            scanf("%d",&x);
            if(a[x-1]==0){
                a[x-1]=1;
                cnt--;
            }
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 1700
n=int(input())
s=input()
w=[[0]*n for i in range(n)]
ans=chk=0
for i in range(n-1,-1,-1):
    for j in range(n-1,-1,-1):
        if s[i]==s[j]:
            if i==n-1 or j==n-1:
                w[i][j]=1
            else:
                w[i][j]=w[i+1][j+1]+1
for i in range(1,n):
    for j in range(i):
        #ans=max(ans,w[i][j])
        ans=max(ans,w[i][j]-[0,w[i][j]-(i-j-w[i][j]+1)][j+w[i][j]>=i+1])
print(ans)


Measured memory_bytes: 230280
#include <stdio.h>
#include <stdlib.h>
int main(void){
  int i,j,r,c,*a;
  scanf("%d%d",&r,&c);
  a=(int*)calloc((r+1)*(c+1),sizeof(int));
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf(" %d",&a[i*(c+1)+j]);
      a[(i+1)*(c+1)-1]+=a[i*(c+1)+j];
      a[r*(c+1)+j]+=a[i*(c+1)+j];
      a[(r+1)*(c+1)-1]+=a[i*(c+1)+j];
    }
  }
  for(i=0;i<=r;i++)for(j=0;j<=c;j++)printf("%d%c",a[i*(c+1)+j],j==c?'\n':' ');
  return 0;
}

Measured memory_bytes: 648
#include<stdio.h>
#include<math.h>

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

    for(i=0; i<n; i++) {
        for(j=2; j<=sqrt(arg[i]); j++) {
            if(arg[i]%j == 0) {
                arg[i] = 1;
                break;
            }
        }
        if(arg[i] != 1) {
            count++;
        }
    }


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

    return 0;
}


Measured memory_bytes: 2044
from itertools import product

INF = float("inf")

H, W, K = map(int, input().split())
S = [[int(i) for i in input()] for _ in range(H)]

T = [t for t in zip(*S)]
if sum(map(sum, T)) <= K:
    print(0)
    quit()

ans = INF
for P in product([0, 1], repeat=H - 1):
    cnt = sum(P)
    if cnt >= ans:
        continue

    II = [[0]]
    for i, p in enumerate(P, 1):
        if p:
            II.append([])
        II[-1].append(i)

    A = [0] * len(II)
    for t in T:
        for i, I in enumerate(II):
            A[i] += sum(t[x] for x in I)

        if any(a > K for a in A):
            cnt += 1
            if cnt >= ans:
                break

            A = [sum(t[x] for x in I) for I in II]
            if any(a > K for a in A):
              cnt = INF
              break

    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define ins insert
#define all(x) (x).begin(), (x).end()
#define fr(i, n) for(int i = 0; i < n; i++)
#define rall(x) (x).rbegin(), (x).rend()
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
 
 
void solve(){
    int n;
    cin >> n;
    ll sum = 0;
    int i = 1;
    while(true){
        if(i % 5 != 0 and i % 3 != 0){
            sum += i;
            // cout << i << " ";
        }
        if(i >= n){
            break;
        }
        i++;
    }
    cout << sum;
    
    
}
 
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    int di;
    int Ai;
    set<int> member; 

    for(int i = 0; i< K; i++){
        cin >> di;
        for(int j = 0; j < di; j++){
            cin >> Ai;
            member.insert(Ai); 
        }
    }

    cout << N - member.size() <<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int main()
{   int N,X,i,j,sum=1;

scanf("%d",&N);
scanf("%d",&X);
int L[N],D[N+1];
for(i=0;i<N;i++)
{scanf("%d",&L[i]);}
D[0]=0;
for(j=1;j<=N;j++)
{
    D[j]=D[j-1]+L[j-1];
    if(D[j]<=X)
        sum++;
    else
        break;
}
    printf("%d\n",sum);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
#define ll long long
ll n;
int main()
{
	scanf("%lld",&n);
	ll s=sqrt(n)+1;
	for(ll i=s;i>0;i--)
		if(n%i==0)
		{
			printf("%lld",i+n/i-2);
			return 0;
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


struct UnionFind {
    vector<int> par, rank, sz;

    UnionFind(int n) {
        par.resize(n), rank.resize(n, 0), sz.resize(n, 1);
        for(int i = 0; i < n; i++) par[i] = i; 
    }

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

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

    int size(int x) {
        return sz[root(x)];
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        }
        else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vpair e;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        e.emplace_back(a, b);
    }

    vll ans(m);
    ans[m-1] = (n) * (n-1) / 2;

    UnionFind uf(n);
    for (int i = m-1; i > 0; --i) {
        if (uf.same(e[i].fi, e[i].se)) ans[i-1] = ans[i];
        else ans[i-1] = ans[i] - (ll)uf.size(e[i].fi) * (ll)uf.size(e[i].se);
        uf.unite(e[i].fi, e[i].se);
    }
    
    rep(i, m) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4084