akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main( void )
{
	int a,b;
	int menseki;
	int syuu;

	scanf("%d %d", &a, &b);

	menseki = a * b;
	syuu = ( a + b ) * 2;

	printf("%d %d\n", menseki, syuu);

	return 0;
}

Measured memory_bytes: 596
N = input()
x = N[-1]
if N[-1] == "2" or N[-1] == "4" or N[-1] == "5" or x == "7" or x == "9":
  print("hon")
elif x == "0" or x == "1" or x == "6" or x == "8":
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c,d;
    while(cin>>a>>b>>c>>d){
        if(max(a,c)-min(a,c)<=d)cout<<"Yes"<<endl;
        else if(max(a,b)-min(a,b)<=d && max(b,c)-min(b,c)<=d)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// 0-indexed
// now node k
// child node k*2+1 and k*2+2
// parent node (k-1)/2
struct data {
  long long a;
};
const long long minint = 0;
data resetdata = {minint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, long long newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  long long pick(int a, int b, int k = 0, int l = 0,
                 int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return minint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    long long nowl, nowr, nextlr = k * 2 + 1,
                          med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return max(nowl, nowr);
  }
};
 
long long n;
long long h[200005] = {0};
long long a[200005] = {0};
RMQ rmq;
 
long long solve();
 
int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> h[i];
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}
 
long long solve() {
  long long ans = 0;
  rmq = RMQ(n + 1);
  for(int i = 0; i < n; ++i) {
    long long now = a[i];
    now += rmq.pick(0, h[i]);
    rmq.update(h[i], now);
    ans = max(ans, now);
  }
  return ans;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){

    int n,m;
    cin >> n >> m;
    vector<int> to[100010];
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n,-1);
    vector<int> pre(n,-1);
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int u : to[v]){
            if(dist[u]!=-1) continue;
            dist[u]=dist[v]+1;
            pre[u]=v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i,n){
        if(i==0) continue;
        int ans=pre[i];
        ans++;
        cout << ans << endl;
    }



 
}

Measured memory_bytes: 10732
#include <iostream>
#include <string.h>

using namespace std;

int main(void) {
    int n;
    string sp;
    string speech_list[100];
    bool is_follow_rule = true;
    cin >> n >> sp;
    speech_list[0] = sp;

    for (int i = 1; i < n; ++i) {
        cin >> sp;
        speech_list[i] = sp;

        if (speech_list[i - 1][speech_list[i - 1].length() - 1] == speech_list[i][0] && is_follow_rule) {
            for (int j = 0; j < i; ++j) {
                if (speech_list[j].compare(speech_list[i]) != 0) {
                    is_follow_rule = true;
                } else {
                    is_follow_rule = false;
                    break;
                }
            }
        } else {
            is_follow_rule = false;
        }
    }

    if (is_follow_rule) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}

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

 
int main() {
    ll x;
    cin>>x;
    ll ans=2*(x/11);
    ll ama=x%11;
    if(ama==0)cout<<ans<<endl;
    else if(ama<=6)cout<<ans+1<<endl;
    else cout<<ans+2<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

###
# main
if(__name__ == '__main__'):
    # input
    n = input()

    ans = 'No'
    if n[0] == '7':
        ans = 'Yes'
    elif n[1] == '7':
        ans = 'Yes'
    elif n[2] == '7':
        ans = 'Yes'

    print(ans)

# else:
    # do nothing


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    long long m;

    cin >> m;

    long long res=0;

    for(long long i = 0 ; i < n ; i++) {

        long long x;

        cin >> x;

        long long y;

        cin >> y;

        long double dis = sqrtl(x*x + y*y) ;

        if(dis<=m) {

            res++;

        }

    }

    cout << res << '\n';

    return 0;

}



Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
char maz[10];
int main(){
    scanf("%s",maz);
    for (int i=0;maz[i];i++) {
        if (maz[i] == '1') maz[i] ='9';
        else if (maz[i] == '9') maz[i] ='1';
    }
    printf("%s",maz);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

V<int> dist;
V<V<int>> graph;

int main() {
  int n;
  cin >> n;

  graph.resize(n);
  dist.resize(n, -1);

  rep(i, n) {
    int u, k;
    cin >> u >> k;
    u--;

    rep(j, k) {
      int adj;
      cin >> adj;
      adj--;
      graph[u].push_back(adj);
    }

    dist[i] = -1;
  }


  queue<int> will;
  dist[0] = 0;
  will.push(0);

  while(!will.empty()) {
    int current_i = will.front();
    will.pop();

    for(auto next_i : graph[current_i]) {
      if(dist[next_i] != -1) {
        continue;
      }
      dist[next_i] = dist[current_i] + 1;
      will.push(next_i);
    }
  }


  rep(i, n) {
    cout << i + 1 << " " << dist[i] << endl;
  }
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int str_cmp(const void*a,const void*b){
return strcmp((char*)a,(char*)b);}

int main(){
 int n;
 scanf("%d ",&n);
 char s[n][11],t[1][11];
 int a,b,c;
 for(a=0;a<n;a++)
  scanf("%s",s[a]); 
qsort(s,n,sizeof(*s),str_cmp);
/* for(a=0;a<n;a++)
  for(b=a+1;b<n;b++){
   if(strcmp(s[a],s[b])>0){
    strcpy(t[1],s[a]);
    strcpy(s[a],s[b]);
    strcpy(s[b],t[1]);}
  }*/
 int ans=1;
for(a=0;a<n-1;a++){
   if(strcmp(s[a],s[a+1])!=0)ans++;
 }
  
 printf("%d\n",ans);
  
return 0;} 

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

int main() {
    int M; cin >> M;
    for (int i = 0; i < M; i++) {
        string S; cin >> S;
        int N = S.length();
        unordered_set<string> res;
        for (int i = 1; i < N; i++) {
            string L = S.substr(0, i), R = S.substr(i);
            string L2 = L, R2 = R;
            reverse(L2.begin(), L2.end());
            reverse(R2.begin(), R2.end());
            res.insert(L + R);  res.insert(L2 + R);
            res.insert(L + R2); res.insert(L2 + R2);
            res.insert(R + L);  res.insert(R + L2);
            res.insert(R2 + L); res.insert(R2 + L2);
        }
        cout << res.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
from fractions import gcd

a, b = map(int, input().split())
g = gcd(a, b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = set(prime_factorize(g))
print(len(c)+1)





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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int N;
char A[1000], B[1000];

int main(){
  int i, j, k;

  reader(&N,A,B);
  for(i=N;i;i--){
    rep(j,i) if(A[N-i+j]!=B[j]) break;
    if(j==i) break;
  }
  writerLn(2*N-i);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f // -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100 + 5;

int n;
int a[N], vis[N];

int main() {
	read(n);
	int mx = 0, d;
	for (int i = 1; i <= n; i++) read(a[i]), mx = max(mx, a[i]);
	d = (mx + 1) >> 1;
	for (int i = 1; i <= n; i++) if (a[i] < d) {printf("Impossible\n"); return 0;}
	for (int i = 1; i <= n; i++) vis[a[i]]++;
	for (int i = mx; i > d; i--) if (vis[i] < 2) {printf("Impossible\n"); return 0;}
	if (vis[d] != (mx & 1 ? 2 : 1)) {printf("Impossible\n"); return 0;}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;
vvl dp;

int main(){
	cin>>n>>m;
	dp=vvl(m+1,vl(n+1));
	dp[0][0]++;
	for(int i=0;i<n;i++){
		vvl DP(m+1,vl(n+1));
		for(int j=0;j<=m;j++) for(int k=0;k<=n;k++) if(dp[j][k]){
			if(j+2*k-2<=m&&k) (DP[j+2*k-2][k-1]+=dp[j][k]*k*k)%=mod;
			if(j+2*k<=m) (DP[j+2*k][k]+=dp[j][k]*(2*k+1))%=mod;
			if(j+2*k+2<=m&&k<n) (DP[j+2*k+2][k+1]+=dp[j][k])%=mod;
		}
		dp=DP;
	}
	cout<<dp[m][0]<<endl;
}

Measured memory_bytes: 2452
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

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

    int n,k; cin>>n>>k;
    vi a = readVector<int>(n);
    sort(ALL(a));

    vi dp(1e5+5, 0);

    FOR(i,k+1)
    FOR(j,n) {
        int ai = a[j];
        if(ai<=i && dp[i-ai]==0)
            dp[i]=1;
    }
    cout<<(dp[k]==1?"First":"Second")<<endl;

    return 0;
}



Measured memory_bytes: 640
h, w = map(int, input().split())

def checkLine(_h,_w):
  flag = True
  for i in range(0,h):
    if a[i][_w] == '#':
      flag = False

  if flag:
    return True

  flag = True
  for i in range(0,w):
    if a[_h][i] == '#':
      flag = False

  if flag:
    return True

  return False

a = []
for i in range(0,h):
  a += input().split()

for i in range(0,h):
  str = ""
  for j in range(0,w):
    if checkLine(i,j) == False:
      str = str + a[i][j]
  if str != "":
    print(str)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
#pragma GCC optimize(3)
namespace ZDY{
    #define res register
    #define ri res int
    #define ll long long
    #define db double
    #define sht short
    #define il inline
    #define MB template <class T>
    #define Fur(i,x,y) for(ri i=x;i<=y;i++)
    #define fur(i,x,y) for(i=x;i<=y;i++)
    #define Fdr(i,x,y) for(ri i=x;i>=y;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fl(i,x) for(ri i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define inf 2122219134
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdin)
    #define l2(n) (ceil(log2(n)))
    #define fast ios::sync_with_stdio(false)
    MB il T ABS(T x){return x>0?x:-x;}
    MB il T MAX(T x,T y){return x>y?x:y;}
    MB il T MIN(T x,T y){return x<y?x:y;}
    MB il T GCD(T x,T y){return y?GCD(y,x%y):x;}
}using namespace ZDY;using namespace std;
#define N 1010
int n,a[N],t,k,ap;
db ans=inf,p;
int main(){
    cin>>n>>t>>k;
    Fur(i,1,n){
        scanf("%d",&a[i]);
        p=db(t-db(a[i])*0.006);
        if(ABS(p-k)<ans)ans=ABS(p-k),ap=i;
    }
    cout<<ap<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys

import math

def f(a):
    if a % 2 == 0: return a/2
    else: return  3*a + 1

def sol(a):
    dp = [a]
    #print(dp)
    for i in range(1, 1000000+1):
        x = dp[i-1]
        ans = f(x)
        if ans in dp:
            #print(i, ans, dp)
            return i+1
        else:
            dp.append(ans)
    return None




do_submit = True
#do_submit = False
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(int, line.split())) for line in lines]
    a = parsed_lines[0]
    return a[0]


if not do_submit:
    a= input_parse("""
    54
    """)
    print(sol(a))
else:
    # a, b, c = list(map(int, input().split()))
    # print(sol(a, b, c))
    a = list(map(int, input().split()))
    print(sol(a[0]))

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

int solve1(int x, map<int, vector<int>>&m, int* dp) {
	if (dp[x] != -1)return dp[x];
	if (m.find(x) == m.end())return dp[x] = 0;


	for (auto i : m[x]) {
		solve1(i, m, dp);
	}
	int len = 0;
	for (auto i : m[x]) {
		len = max(len, 1 + dp[i]);
	}

	return dp[x] = len;
}


int solve() {
	int n, m1;
	cin >> n >> m1;
	map<int, vector<int>> m;
	int i;
	for (i = 0; i < m1; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		m[x].push_back(y);
	}
	int len = 0;
	int dp[n];
	fill(dp, dp + n, -1);
	for (i = 0; i < n; i++) {
		len = max(len, solve1(i, m, dp));
	}

	return len;
}




int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cout << solve();
	return 0;
}

Measured memory_bytes: 19228
import java.util.*;
public class Main {
	static final Scanner stdin = new Scanner(System.in);
	static final double INF = 1e8;
	public static void main(String[] args) {
		while(stdin.hasNext()){
			String[] line = stdin.nextLine().split(" ");
			int l = Integer.parseInt(line[0]), n = line.length;
			int[] r = new int[n];
			r[0] = 0;
			for(int i = 1; i < n; ++i) r[i] = Integer.parseInt(line[i]);
			double[][] d = new double[n][n];
			for(int i = 0; i < n; ++i)
				for(int j = 0; j < n; ++j)
					d[i][j] = (i == j ) ? 0 : 
						(i == 0) ? r[j] : 
						(j == 0) ? r[i] : 
						Math.sqrt(Math.pow(r[i] + r[j], 2) - Math.pow(r[i] - r[j], 2));
			System.out.println(TSP(d,0).getLength() <= l ? "OK" : "NA");
		}
	}
	@SuppressWarnings("unused") public static class TSPResult{
		private int s;		//source node (???= destination node)
		private double length;	//length of shortest Hamilton cycle
		private int[][] prev;	//back pointers
		public TSPResult(int s, double length, int[][] prev){ set(s, length, prev); }
		final private void set(int s, double length, int[][] prev){ this.s = s; this.length = length; this.prev = prev; }
		final public double getLength(){ return length; }
	}
	static TSPResult TSP(double[][] G, int s){
		int n = G.length, N = 1 << n;
		double[][] DP = new double[N][n];
		int[][] prev = new int[N][n];
		for(int i = 0; i < N; ++i) Arrays.fill(DP[i], INF);
		for(int i = 0; i < n; ++i){
			DP[1<<i][i] = G[s][i];
			prev[1<<i][i] = s;
		}
		for (int S = 1; S < N; ++S) {
			for (int i = 0; i < n; ++i) {
				if ((S & (1<<i)) == 0) continue;
				for (int j = 0; j < n; ++j) {
					if ((S & (1<<j)) != 0 ) continue;
					//i in S, j not in S 
					double newDist = DP[S][i]+G[i][j];
					if(DP[S|(1<<j)][j] > newDist) {
						DP[S|(1<<j)][j] = newDist;
						prev[S|(1<<j)][j] = i;
					}
				}
			}
		} 
		return new TSPResult(s, DP[N-1][s], prev);
	}
}

Measured memory_bytes: 49524
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N >> K;
    if (N == K) {
        cout << N + 1 << endl;
        return 0;
    }
    auto f = [&](ll b, ll n) {
        ll res = 0;
        while (n > 0) {
            res += n % b;
            n /= b;
        }
        return res;
    };
    ans = LLINF;
    ll n = sqrt(N) + 1;
    REPS(i, n) {
        if (i == 1)
            continue;
        if (f(i, N) == K) {
            chmin(ans, (ll)i);
            break;
        }
    }
    REPS(i, n) {
        ll b = (N - K) / i + 1;
        if (b < 2)
            continue;
        if (f(b, N) == K) {
            chmin(ans, b);
        }
    }
    if (ans == LLINF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+100;
const ll mod = 1e9+7;
pair<ll,ll> p[maxn];
ll dp[2100][2100];
int main() {
    int n;
    cin>>n;
    for(int i=1,x;i<=n;i++)
    cin>>x,p[i]={x,i};
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++)
        dp[i][i]=p[1].first*abs(p[1].second-i);
    for(int L = 2;L<=n;L++){
        for(int i=1;i+L-1<=n;i++){
            int j = i+L-1;
            dp[i][j]=max(dp[i+1][j]+p[L].first*abs(p[L].second-i),dp[i][j-1]+p[L].first*abs(p[L].second-j));
        }
    }
    cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 26672
h = int(input())
w = int(input())
n = int(input())

if h > w:
    if n%h == 0:
        print(int(n/h))
    else:
        print(int(n/h) + 1)
else:
    if n%w == 0:
        print(int(n/w))
    else:
        print(int(n/w) + 1)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type node struct {
	value int
	left  int
	right int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	length, _ := strconv.Atoi(sc.Text())
	tree := make([]node, length)

	c := 0
	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")

		switch inputs[0] {
		case "insert":
			num, _ := strconv.Atoi(inputs[1])
			tree[c] = node{value: num, left: -1, right: -1}
			if c != 0 {
				insert(tree, 0, c)
			}
			c++
		case "print":
			printInorder(tree, 0)
			fmt.Println()
			printPreorder(tree, 0)
			fmt.Println()
		}
	}
}

func insert(tree []node, diffPoint int, nodePoint int) {
	if tree[diffPoint].value <= tree[nodePoint].value {
		if tree[diffPoint].right == -1 {
			tree[diffPoint].right = nodePoint
		} else {
			insert(tree, tree[diffPoint].right, nodePoint)
		}
	} else {
		if tree[diffPoint].left == -1 {
			tree[diffPoint].left = nodePoint
		} else {
			insert(tree, tree[diffPoint].left, nodePoint)
		}
	}
}

func printInorder(tree []node, current int) {
	if current == -1 {
		return
	}
	printInorder(tree, tree[current].left)
	fmt.Printf(" %d", tree[current].value)
	printInorder(tree, tree[current].right)
}

func printPreorder(tree []node, current int) {
	if current == -1 {
		return
	}
	fmt.Printf(" %d", tree[current].value)
	printPreorder(tree, tree[current].left)
	printPreorder(tree, tree[current].right)
}



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

map<string,int> m;
int main(){
	int n;
	scanf("%d",&n);
	char str[15];
	for(int i=0;i<n;i++){
		scanf("%s",str);
		m[(string)str]++;
	}
	int maxi=0;
	for(auto it=m.begin();it!=m.end();++it){
		maxi=max(maxi,it->second);
	}
	for(auto it=m.begin();it!=m.end();++it){
		if(it->second==maxi)printf("%s\n",(it->first).c_str());
	}
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define gsort(x,n) sort(x,x+n,greater<int>())
#define rv(s) reverse((s).begin(),(s).end())
#define abs(a) llabs(a)
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define INF 1000000000;
 
int x[1000010],mem[1000010];
int dp(int i){
    if(i == 1) return 0;
    if(i < 1 ) return INF;
    if(mem[i]!=-1) return mem[i];
     
    int a1 = dp(i-1) + abs(x[i-1]-x[i]);
    int a2 = dp(i-2) + abs(x[i-2]-x[i]);
    return mem[i] = min(a1,a2);
}
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int n;
    cin >> n;
     
    memset(mem,-1,sizeof(mem));
    reps(i,n) cin>>x[i];
     
    cout<<dp(n)<<'\n';
}

Measured memory_bytes: 13568
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
	    
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	String str = sc.next();
        StringBuilder strn = new StringBuilder(str);
          	
      	for(int i=0;i<str.length();i++){
            int temp = (int)str.charAt(i) + N;
            String temp_char = "";
            if(temp <= 90)
        	    temp_char += (char)temp;
            else 
                temp_char += (char)(temp - 26);
            
            strn.replace(i, i + 1, temp_char);
        }
      	System.out.println(strn);
		
    }
	
}


Measured memory_bytes: 40044
N,K = map(int,input().split())
V = list(map(int,input().split()))
import heapq 
m = min(N,K)
M = 0
for i in range(m+1):
    for j in range(m-i+1):
        v1 = V[:i]
        v3 = V[N-j:]
        v = v1+v3
        heapq.heapify(v)
        h = K - len(v)
        while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
        tmp = sum(v)
        # print(v,v3)
        M = max(M,tmp)
print(M)

Measured memory_bytes: 3064
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main(void) {
  char c1, c2;
  cin >> c1 >> c2;
  puts(c1 == c2 ? "H" : "D");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

		int N = scanner.nextInt();
		int K = scanner.nextInt();

		int[] arr = new int[N];

		for (int i = 0; i < N; i++) {
			arr[i] = scanner.nextInt();
		}
		
		scanner.close();

		double[] dd = new double[N];
		for (int i = 0; i < N; i++) {
			dd[i] = (1.0+ arr[i]) / 2.0;
		}
		
		double sm = 0.0;
		for (int i = 0; i < K; i++) {
			sm += dd[i];
		}
		double mx = sm;

		for (int j = K; j < N; j++) {
			sm = sm + dd[j] - dd[j-K];
			if (sm > mx) mx = sm;
		}

		System.out.println(mx);
		
	}
}

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

#include <string.h>

using namespace std;

bool isPrime(int x){
    for (int i = 2; i <= sqrt(x); ++i)
    {
        if(x%i==0){return false;}
    }
    return true;


}

void solve(){

    int x;
    cin>>x;
    while(true){
        if(isPrime(x)){
            cout<<x;
            break;

        }
        x++;
    }   


}




int main() {

    solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	int n;
	cin>>n;
	int a[n],b[n-1];
	for (int i = 0; i < n-1; ++i)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		if(i==0)
			a[0]=b[0];
		else if(i==n-1)
		{
			a[n-1]=b[n-2];
		}
		else
		{
			a[i]=min(b[i],b[i-1]);
		}	
			
	}	
	int s=0;
	for(int i=0;i<n;i++)
	{
//		cout<<a[i]<<endl;
		s+=a[i];
	}	
		
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int w[1000000],v[1000000],dp[1000000];
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,W;
    cin>>n>>W;
    for(int i=1; i<=n; i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1; i<=100000; i++)
    {
        dp[i]=1900000000;
    }
    dp[0]=0;
    for(int j=1; j<=n; j++)
    {
        for(int i=100000; i>=0; i--)
        {
            if(i+v[j]<=100000)
            {
                dp[i+v[j]]=min(dp[i+v[j]],dp[i]+w[j]);
            }
        }
    }
    int m=0;
    for(int i=1; i<=100000; i++)
    {
        if(dp[i]<=W)
        {
            m=max(m,i);
        }
    }
    cout<<m<<endl;
    return 0;
}


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

const int N = 1010;
const int moder = 1e9 + 7;

int min[N], n;
std::vector <int> prime;

int main(){
	for (int i = 2; i < N; ++ i){
		if (!min[i]){
			min[i] = i;
			prime.push_back(i);
		}
		for (int j = 0; j < prime.size() && prime[j] <= i; ++ j){
			if (prime[j] * i >= N)
				break;
			min[prime[j] * i] = prime[j];
		}
	}
	scanf("%d", &n);
	int ans = 1;
	for (int i = 0; i < prime.size(); ++ i){
		if (prime[i] > n){
			break;
		}
		int x = n, cnt = 0;
		while (x){
			cnt += x / prime[i];
			x /= prime[i];
		}
		ans = 1ll * ans * (cnt + 1) % moder;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 764
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);
    auto p = readln.split.to!(double[]);

    auto dp = new double[](N + 1);
    dp[] = 0;
    dp[0] = 1;

    foreach (i ; 0 .. N) {
        foreach_reverse (j ; 0 .. N + 1) {
            if (j > 0) {
                dp[j] = (1 - p[i]) * dp[j] + p[i] * dp[j - 1];
            }
            else {
                dp[j] = (1 - p[i]) * dp[j];
            }
        }
    }

    double ans = 0;

    foreach (i ; 0 .. N + 1) {
        if (i > N - i) {
            ans += dp[i];
        }
    }

    writefln("%.12f", ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  if (s.substr(0, 4) == "YAKI") Yes();
  else No();
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

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

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

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

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);  
	return s + n;  
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

//だから私は～
//#define int long long
// ===============================================================

/*signed*/int main() {
	vl a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	ll x;
	cin >> x;
	sort(a.begin(), a.end());
	if (a[4] - a[0] <= x) {
		cout << "Yay!" << endl;
	}
	else cout << ":(" << endl;
}

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

vector<int> num;
int k;
string s;
int DP[103][5][2];

int call(int pos, int cnt, int f)
{
	if (cnt > k)
		return 0;

	if (pos == num.size())
	{
		if (cnt == k)
			return 1;
		return 0;
	}

	if (DP[pos][cnt][f] != -1)
		return DP[pos][cnt][f];
	int res = 0;

	int LMT;

	if (f == 0)
	{

		LMT = num[pos];
	}
	else
	{

		LMT = 9;
	}

	for (int dgt = 0; dgt <= LMT; dgt++)
	{
		int nf = f;
		int ncnt = cnt;
		if (f == 0 && dgt < LMT)
			nf = 1;
		if (dgt != 0)
			ncnt++;
		if (ncnt <= k)
			res += call(pos + 1, ncnt, nf);
	}

	return DP[pos][cnt][f] = res;
}

int solve(string b)
{
	num.clear();
	for (int i = 0; i < s.size(); i++)
	{
		num.push_back((s[i] - '0'));
	}
	//reverse(num.begin(), num.end());
	//for (int i : num)
	//	cout << i << " ";

	memset(DP, -1, sizeof(DP));
	int res = call(0, 0, 0);
	return res;
}

int main()
{

	cin >> s >> k;
	int res = solve(s);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))

using namespace std;
string a,b;

int main(){
  cin >> a >> b;
  string ans = "GREATER";
  if(b.size()>a.size()) ans = "LESS";
  else if(b.size()==a.size()){
    if(b>a) ans = "LESS";
    else if(b==a) ans = "EQUAL";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int z[200005]={0},y[200005]={0};
		int max=0;
		int s[20000];
 		int j=0;
 		int p=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&z[i]);
			y[i]=z[i];
		}
		sort(z,z+n);
		for(int i=0;i<n;i++)
		{
			if(y[i]==z[n-1])
			printf("%d\n",z[n-2]);
			else
			printf("%d\n",z[n-1]);
		}
	}
}


Measured memory_bytes: 3200
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "queue"

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

int main()
{
  int n;
  cin >> n;
  double p[3010];
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  double subp[3001][3001];	//最初のi枚でj枚表
  fill(subp[0], subp[3000], 0);
  subp[0][0] = 1;
  for (int i = 0; i < n; i++)
  {
    subp[i + 1][0] = subp[i][0] * (1 - p[i]);
    for (int j = 1; j < n + 1; j++)
    {
      subp[i + 1][j] = subp[i][j - 1] * p[i] + subp[i][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = n / 2 + 1; i < n + 1; i++)
  {
    ans += subp[n][i];
  }
  printf("%.10f\n", ans);
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  ll q;
  cin>>q;
  ll cu=0;
  vc a(0);
  vc b(0);
  rep(i,q){
    ll t;
    cin>>t;
    if(t==1){
      cu++;
    }
    else{
      ll f;
      char c;
      cin>>f;
      cin>>c; 
      if(cu%2==0){
        if(f==1){
          a.pb(c);
        }
        else{
          b.pb(c);
        }
      }
      else{
        if(f==1){
          b.pb(c);
        }
        else{
          a.pb(c);
        }
      }
    }
  }
  if(cu%2==0){
    for(int i=sz(a)-1;i>=0;i--){
      cout<<a[i];
    }
    cout<<s;
    rep(i,sz(b)){
      cout<<b[i];
    }
  }
  else{
    for(int i=sz(b)-1;i>=0;i--){
      cout<<b[i];
    }
    reverse(all(s));
    cout<<s;
    rep(i,sz(a)){
      cout<<a[i];
    }
  }
}
  
      


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

int main()
{
  long long a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  
  if (v <= w)
  {
    cout << "NO";
    return 0;
  }
  
  a -= b;
  v -= w;
  if (a < 0) a *= -1;
  
  if (a > v * t)
    cout << "NO";
  else
    cout << "YES";
  
  return 0;
}

Measured memory_bytes: 3036
from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)

Measured memory_bytes: 8564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int W,H,N;
    cin >> W >> H >> N;
    int xl=W,yl=H,xr=0,yr=0;
    rep(i,N) {
        int x,y,a;
        cin >> x >> y >> a;
        if(a==1){
            xr=max(x,xr);
        }else if(a==2){
            xl=min(x,xl);
        }else if(a==3){
            yr=max(y,yr);
        }else{
            yl=min(y,yl);
        }
    }
    int ans=0;
    if(xl-xr>0 && yl-yr>0){
        ans=(xl-xr)*(yl-yr);
    }
    cout << ans << endl;

    



}


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

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

    string ans = "YES";

    sort(A.begin(),A.end());
    /*
    for (ll i=0; i<N; i++) {
        cout << A[i];
    }
    cout << endl;
    */
    for (ll i=0; i<N-1; i++) {
        if (A[i]==A[i+1]) {
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;
    
}

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

template <typename T> int lcs_restore(const T &a, const T &b, T &ret){
  const int n = a.size(), m = b.size();
  std::vector<std::vector<int>> dp(n+1, std::vector<int>(m+1, 0));
  std::vector<std::vector<std::pair<int,int>>> restore(n+1, std::vector<std::pair<int,int>>(m+1, std::make_pair(-1,-1)));
  
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      if(a[i] == b[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
        restore[i+1][j+1] = std::make_pair(i,j);
      }else{
        if(dp[i][j+1] > dp[i+1][j]){
          dp[i+1][j+1] = dp[i][j+1];
          restore[i+1][j+1] = restore[i][j+1];
        }else{
          dp[i+1][j+1] = dp[i+1][j];
          restore[i+1][j+1] = restore[i+1][j];
        }
      }
    }
  }

  std::pair<int,int> cur(n,m);

  while(1){
    cur = restore[cur.first][cur.second];
    if(cur == std::make_pair(-1,-1)) break;
    ret.push_back(a[cur.first]);
  }

  std::reverse(ret.begin(), ret.end());
    
  return dp[n][m];
}


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

  std::string s,t; std::cin >> s >> t;

  std::string ans;
  lcs_restore(s, t, ans);
  
  std::cout << ans << std::endl;
  
  return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, n) for(auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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

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

void solve();

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

    solve();
    
    return 0;
}

void solve() {
    string S;
    cin >> S;
    map<char, int> M;
    M['a'] = 0;
    M['b'] = 0;
    M['c'] = 0;
    const int n = S.size();
    rep(i, n) ++M[S[i]];

    if (M['a'] == M['b'] && M['b'] == M['c'] && M['a'] == M['c']) {
        cout << "YES" << endl;
    } else {
        int max_cnt = -1, min_cnt = inf;
        rep(i, 3) {
            chmax(max_cnt, M['a' + i]);
            chmin(min_cnt, M['a' + i]);
        }

        if (max_cnt - min_cnt >= 2) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
}

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

int main() {
  string S;
  int x = 0;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == '1') {
      x++;
    }
  }
  cout << x << endl;
}


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

signed main(){
  int X,A,B;
  cin>>X>>A>>B;
  string ans="dangerous";
  if(B-A<=X)ans="safe";
  if(A-B>=0)ans="delicious";
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    int n,A[100];
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];
    int j=0;

    for(int i=0;i<n;i++){
        for(int s=n-1;s>i;s--){
            if(A[s]<A[s-1]){
                int a=A[s];
                A[s]=A[s-1];
                A[s-1]=a;
                j++;
            }
           
        }
    }
    
    for(int b=0;b<n;b++){
        if(b== n-1)cout << A[b] << endl;
        else cout << A[b] << " " ;
    }

    cout << j << endl;
    return 0;
}


Measured memory_bytes: 3084
button1, button2 = gets.split.map(&:to_i)
count = 0

if button1 > button2 then
  count += button1
  button1 -= 1
else
  count += button2
  button2 -= 1
end

if button1 > button2 then
  count += button1
  button1 -= 1
else
  count += button2
  button2 -= 1
end

print count

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	if (n == 0)
		cout << "1\n";
	else
		cout << "0\n";

	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    char S;
    cin >> S;
    if(isupper(S)){
        cout << 'A' << endl;
    }else{
        cout << 'a' << endl;
    }
    return 0;
}

Measured memory_bytes: 3564