akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void func(long long H, long long A)
{
    int cnt = 0;
    while (H > 0)
    {
        H -= A;
        cnt++;
    }
    cout << cnt << endl;
}

int main()
{
    // cout << fixed << setprecision(5);

    long long H;
    scanf("%lld", &H);
    long long A;
    scanf("%lld", &A);
    func(H, A);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

vector<char> ans;
vector<string> s(100010);
void solve(ll& a, ll& b, char c) {
	a++;
	b--;
	ans.push_back(c);
}

bool move(ll& a, ll& b, string c, string s1, string s2) {
	if (a == 0 and b == 0) return false;
	else if (a == 1 and b == 1) s1 == s2 ? solve(a, b, c[0]) : solve(b, a, c[1]);
	else a < b ? solve(a, b, c[0]) : solve(b, a, c[1]);
	return true;
}

int main() {
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	REP(i, n) cin >> s[i];
	bool ok = true;
	REP(i, n) {
		if (s[i] == "AB") if (!move(a, b, "AB", "AC", s[i + 1])) ok = false;
		if (s[i] == "AC") if (!move(a, c, "AC", "AB", s[i + 1])) ok = false;
		if (s[i] == "BC") if (!move(b, c, "BC", "AB", s[i + 1])) ok = false;
	}
	if (!ok) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	REP(i, n) cout << ans[i] << endl;
}



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

int main() {
    //入力
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec.at(i);
    }

    //処理

    bool flag = true;
    int orbit = 0;
    while(flag) { 
      for(int i = 0; i < n; i++) {
          if(vec.at(i) % 2 == 0) {
              vec.at(i) = vec.at(i) / 2;
          } else {
              flag = false;
              break;
          }
      }
      if(flag) {
          orbit++;
      }
    }
    cout << orbit << endl;
}

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

int main() {
	string num;
	while (cin >> num && num != "0") {

		int sum = 0;
		for (int i = 0; i < num.size(); ++i) {
			sum += num[i] - '0';
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,t,a,b,n,c,d,y,temp,m,r,sum,count,k,l,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
        string s1,s2;
        cin>>s1>>s2;
        if(s1.length() < s2.length()){cout << "UNRESTORABLE" << endl; return 0;}
        bool fou=false;
        for(i=0;i<=s1.length()-s2.length();i++)
        {
            for(j=0;j<s2.length();j++)
            {
                if(j==s2.length()-1)break;
                if(s2[j]==s1[i+j] || s1[i+j]=='?')
                    continue;
                else break;
                
            }
            if(j=s2.length() && (s2[j]==s1[i+j] || s1[i+j]=='?'))
            {
                fou=true;
                ans=i;
            }
        }
        if(!fou)
        {
            cout<<"UNRESTORABLE";
            return 0;
        }
        for(i=0;i<s1.length();i++)
        {
            if(i==ans)
            {
                cout<<s2;
                i+=s2.length()-1;
            }
            else if(s1[i]=='?')cout<<'a';
            else cout<<s1[i];
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  string s; cin >> s;
  cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
}

Measured memory_bytes: 764
N,M = map(int,input().split())
S = []
C = []

for a in range(M):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)

a = ["0"]*N
e = []
for b,d in zip(S,C):
    if b in e:
        if str(d) != a[b-1]:
            print(-1)
            exit()
    elif b == 1 and d == 0:
        if N != 1:
            print(-1)
            exit()
    else:
        e.append(b)
        a[b-1] = str(d)

if a[0] == "0" and N != 1:
    a[0] = "1"
answer = ''.join(a)
answer = int(answer)
print(answer)

Measured memory_bytes: 9208
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

string str;
vector<string> v;
int K;

int main(){
    cin >> str;
    scanf("%d", &K);

    int n = str.size();

    rep(i, min(n, 5)){
        REP(j, n-i+1){
            string sub = str.substr(j, i);
            v.push_back(sub);
        }
    }

    sort(v.begin(), v.end());

    set<string> str_set(v.begin(), v.end());

    auto itr = str_set.begin();

    REP(i, K-1) ++itr;

    cout << *itr;

	return 0;
}

Measured memory_bytes: 2300
#include<stdio.h>
#include <stdlib.h>
int cmpfunc (const void * a, const void * b) {
   return (  *(long long int*)b - *(long long int*)a  );
}
int main()
{
       int i,n,k;
    scanf("%d%d",&n,&k);
   long long int h[n],sum=0,sum2=0;
    for ( i = 0; i <n; i++)
    {
         scanf("%lld",&h[i]);
          sum=sum+h[i];
}
 if(k>n)
    {
        printf("%d\n",0);
        return 0;
    }
 qsort(h, n, sizeof(long long int), cmpfunc); 
for ( i = 0; i < k; i++)
{
    sum2=sum2+h[i];
}
 printf("%lld\n",sum-sum2);
}

Measured memory_bytes: 3324
def z_to_n(n):
    m4=n%4
    if m4==0:
        return n
    elif m4==1:
        return 1
    elif m4==2:
        return n+1
    else:
        return 0
a,b=map(int,input().split(" "))
print(z_to_n(a-1)^z_to_n(b))

Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost = 1) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

template<class T>
vector<T> Dijkstra(vector<vector<Edge<T>>> &edges, int st) {

	int V = (int)edges.size();
	const T INF = numeric_limits<T>::max();
	vector<T> cost(V, INF);
	cost[st] = 0;

	priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> p_que;
	p_que.emplace(st, cost[st]);

	while (!p_que.empty()) {

		Edge<T> now(p_que.top().to, p_que.top().cost);
		p_que.pop();

		if (cost[now.to] < now.cost) continue;
		for (const Edge<T> &e : edges[now.to]) {
			T tmp_cost = now.cost + e.cost;
			if (cost[e.to] > tmp_cost) {
				cost[e.to] = tmp_cost;
				p_que.emplace(e.to, cost[e.to]);
			}
		}
	}

	return cost; // min cost to vertex idx from st
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;


	int u, v;
	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> u >> v;
		u--, v--;
		edges[u].emplace_back(v);
		edges[v].emplace_back(u);
	}

	auto Fennec = Dijkstra(edges, 0);
	auto Snuke  = Dijkstra(edges, N - 1);

	DMP(Fennec, Snuke);

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (Fennec[i] <= Snuke[i]) cnt++;
	}

	if (N < 2 * cnt) cout << "Fennec" << "\n";
	else cout << "Snuke" << "\n";

	return 0;
}

Measured memory_bytes: 7392
import itertools
from collections import Counter
import bisect

def main():
    N, K = map(int, input().split())
    S = list(input())

    TYOKU = '0'
    SAKA = '1'

    if S.count(TYOKU) <= K:
        print(N)
        exit()

    asyu = []
    prev = S[0]
    prev_c = 0
    for s in S:
        if prev == s:
            prev_c += 1
        else:
            asyu.append((prev, prev_c))
            prev = s
            prev_c = 1
    asyu.append((prev, prev_c))
    # print(asyu)

    de = []
    for i in range(len(asyu)):
        pair = asyu[i]
        if pair[0] == '0':
            if i > 0:
                prev_pair = asyu[i-1]
                de.append(pair[1] + prev_pair[1])
            else:
                de.append(pair[1])
    # print(de)

    ans = 0
    val = 0
    k = 0
    del_i = 0
    for i in range(len(asyu)):
        pair = asyu[i]
        if pair[0] == '0':
            if k < K:
                val += pair[1]
                k += 1
            else: # max
                val += pair[1]
                val -= de[del_i]
                del_i += 1
        else:
            val += pair[1]
        ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 1e5+10, mod = 2e9+10;

void solve() {
    int n; cin >> n;
    int nn = pow(n, 2);
    int nnn = pow(n, 3);

    cout << n + nn + nnn << endl;
}

int main(void) {
    int t = 1; 
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 4060
def solve():
    import numpy as np
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    oc = np.array(oc)
    prof = np.array(prof)

    inf = 10 ** 10
    ans = - inf

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        ans = max(ans, tmp)
    print(ans)


solve()



Measured memory_bytes: 27352
#include<bits/stdc++.h>
using namespace std;
#define LL long long

LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL N,M,a[100010];
int main(){
    cin>>N>>M;
    LL g=1,ok=1;
    for(int i=1;i<=N;++i){
        cin>>a[i];
        a[i]/=2;
        if(i==1)g=a[i];
        g=lcm(g,a[i]);
        if(g>M)ok=0;
    }
    for(int i=1;i<=N;++i){
        if(g/a[i]%2==0){ok=0;break;}
    }
    if(!ok){
        cout<<0<<endl;
        return 0;
    }
    LL ans=0;
    LL b=M/g;
    ans=b/2;
    if(b&1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4328
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 1005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n;
string in;
int work()
{
	char buf[30];
	string tmp;

	n = in.length();
	REP(i,0,n*n)
	{
		sprintf(buf, "%d", i);
		tmp = buf;

		auto pos = in.find(tmp);
		if(pos==string::npos)
			return i;
	}
	return -1;
}
int main()
{
	int x;
	while(~scanf("%d",&n))
	{
		in = "";
		REP(i,1,n)
		{
			RI(x);
			in += (char)(x+48);
		}
		printf("%d\n", work());
	}
	return 0;
}

Measured memory_bytes: 3356
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  unordered_set<char> used;

  for (auto &x: s) used.insert(x);

  if (s.length() < 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (used.find(c) == used.end()) {
        cout << s << c << endl;
        return 0;
      }
    }
  }
  else {
    auto sx = s;
    if (!next_permutation(sx.begin(), sx.end())) {
      cout << -1 << endl;
      return 0;
    }
    string next;
    for (int i = 0; i < 26; i++) {
      next.push_back(sx[i]);
      if (s[i] != sx[i]) {
        cout << next << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3668
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Measured memory_bytes: 134396
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll h,w,ans=0;
    cin >> h >> w;
    if (h%2==0){
        for (ll i=0;i<w;i++){
            ans+=h/2;
        }
    }else{
        for (ll i=0;i<w;i++){
            if (i%2){
                ans+=h/2;
            }else{
                ans+=h/2+1;
            }
        }
    }
    if (h==1 or w==1){
        cout << 1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", (a-1) * (b-1));
    return 0;
}


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

int main(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }

    sort(s.begin(), s.end());
    
    string ans;
    for(auto x : s){
        ans += x;
    }

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

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}

import Data.Array
import Data.Array.ST
import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Set as S

type Edge   = [Int]
type Weight = Int
type Vertex = Int
type Graph  = Array Vertex [(Vertex, Weight)] -- adjacent edge list

main = sol <$> get >>= print

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . tail . C.lines <$> C.getContents

sol es = S.size $ foldr upd edges vertices
  where
  g = buildGraph es
  edges = S.fromList $ fmap (\[u,v,_] -> (min u v,max u v)) es
  vertices = indices g
  paths g = fmap (\(u,v) -> (min u v,max u v)) . assocs . snd . dijkstra g
  upd v e = foldr S.delete e $ paths g v

buildGraph :: [Edge] -> Graph
buildGraph es = accumArray accm [] bnds udes
  where
  accm e a = bool (a:e) e (a `elem` e)
  udes = concatMap (\[u,v,c] -> [(u,(v,c)),(v,(u,c))]) es
  bnds = liftM2 (,) minimum maximum $ fst <$> udes

dijkstra :: Graph -> Vertex -> (Array Vertex Weight, Array Vertex Vertex)
dijkstra g v0 = runST $ do
  da <- newArray (bounds g) maxBound :: ST s (STUArray s Vertex Weight)
  writeArray da v0 0
  pa <- newArray (bounds g) ix :: ST s (STUArray s Vertex Vertex)
  let loop q = case S.minView q of
        Nothing -> return ()
        Just ((d,u),q') ->
          let f q (v,w) = do
                d0 <- readArray da v
                if d+w >= d0 then
                  return q
                else do
                  writeArray da v (d+w)
                  writeArray pa v u
                  return . S.insert (d+w,v) $ S.delete (d0,v) q
          in  foldM f q' (g!u) >>= loop
  loop $ S.singleton (0,v0)
  d <- freeze da
  p <- freeze pa
  return (d,p)

ix = 0 -- root sentinel

shortestPath :: Graph -> Vertex -> Vertex -> [Vertex]
shortestPath g fr to = go to [] 
  where
  pa = snd $ dijkstra g fr
  go v vs
    | v == ix   = vs
    | otherwise = go (pa!v) (v:vs)
 

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n, K;
    cin >> n >> K;

    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += p[i];
    }
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int[] w = new int[10];
		int[] k = new int[10];
		for (int i = 0; i < 10; i++){
			w[i] = scanner.nextInt();
		}
		for (int i = 0; i < 10; i++){
			k[i] = scanner.nextInt();
		}
		Arrays.sort(w);
		Arrays.sort(k);
		int sumW = w[7] + w[8] + w[9];
		int sumK = k[7] + k[8] + k[9];
		System.out.println(sumW + " " + sumK);
	}

}



Measured memory_bytes: 26240
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int n = Integer.parseInt(W);
		int[] A = new int[n];
		int[] B = new int[n];
		int[] C = new int[n];

		W = in.readLine();
		String[] Ws = W.split(" ");
		for(int i=0;i<n;i++){
			A[i] = Integer.parseInt(Ws[i]);
		}

		W = in.readLine();
		Ws = W.split(" ");
		long point = 0;
		for(int i=0;i<n;i++){
			B[i] = Integer.parseInt(Ws[i]);
			point+=B[i];
		}

		W = in.readLine();
		Ws = W.split(" ");
		for(int i=0;i<n-1;i++){
			C[i] = Integer.parseInt(Ws[i]);
		}

		for(int i=0;i<n;i++){
			if(i != 0 && A[i-1] == A[i]-1){
				point+=C[A[i]-2];
			}
		}
		System.out.println(point);
	}
}


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

int main()
{
    char c;
    string ans = "consonant";
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    {
        ans = "vowel";
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);

    ll n,a;
    cin >> n >> a;
    ll x[n];
    for(ll i = 0; i < n; i++) {
        cin >> x[i];
    }

    ll dp[n+5][n+5][2505];
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;


    for(ll i = 1; i <= n; i++) {
        for(ll j = 0; j <= i; j++) {
            for(ll k = 0; k <= 2500; k++) {
                if(k<x[i-1])dp[i][j][k]=dp[i-1][j][k];
                else if(j>=1 && k>=x[i-1]) dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
                else dp[i][j][k]=0;
            }
        }
    }



    ll ans=0;
    for(ll i = 1; i <= n; i++) {
        ll tmp=dp[n][i][i*a];
        ans+=tmp;
//        cout << i << " " << tmp << "\n";
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 62800
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    map<string, int> mp;
    int n;
    cin >> n;
    rep(i, n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3608
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define T3I tuple<int, int, int>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

const int MAXN = 2e5+1;
const ll mod = 998244353ll;
int R[MAXN], n;

int dat[1<<19], N;
void rmq_init(int n_)
{
    N = 1;
    while(N < n_) N <<= 1;
}
void rmq_update(int k, int x)
{
    k += N-1;
    dat[k] = x;
    while(k > 0) {
        k = (k-1)/2;
        dat[k] = max(dat[k*2+1], dat[k*2+2]);
    }
}
int rmq_query(int a, int b, int i, int j, int k)
{
    if(a >= j || b <= i) return -1;
    if(a <= i && j <= b) return dat[k];
    int vl = rmq_query(a, b, i, (i+j)>>1, k*2+1);
    int vr = rmq_query(a, b, (i+j)>>1, j, k*2+2);
    return max(vl, vr);
}

ll dp[MAXN];
ll solve(int i)
{
    if(dp[i] != 0) return dp[i];
    if(i == n) return 1;
    return dp[i] = (solve(i+1) + solve(R[i]+1))%mod;
}

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

    cin >> n;
    vector<PII> A(n);
    for(int i = 0; i < n; ++i) {
        int p, d;
        cin >> p >> d;
        A[i].x = p;
        A[i].y = p+d-1;
    }
    sort(A.begin(), A.end());
    rmq_init(n);
    for(int i = (int)A.size()-1; i >= 0; --i) {
        int r = A[i].y;
        r = upper_bound(A.begin(), A.end(), PII(r, INF)) - A.begin();
        --r;
        int v = i;
        if(r > i) {
            v = rmq_query(i, r+1, 0, N, 0);
        }
        v = max(i, v);
        rmq_update(i, v);
        R[i] = v;
    }
    cout << solve(0) << endl;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N],head[N*2],tot,k,c[N],Q,b[N],d[N],e[N];
struct node
{
	int vet,nxt; 
}edge[N*2];
void add(int u,int v)
{
	edge[++tot].vet=v;
	edge[tot].nxt=head[u];
	head[u]=tot;
}
void dfs(int u,int fa)
{
	a[++k]=u;
	for(int i=head[u];i;i=edge[i].nxt)
	{
		int v=edge[i].vet;
		if(v==fa)continue;
		dfs(v,u);
	}
	c[u]=k;
}
int main()
{
	scanf("%d%d",&n,&Q);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)d[a[i]]=i;
	while(Q--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		b[d[x]]+=y;b[c[x]+1]-=y;
	}
	for(int i=1;i<=n;i++)b[i]+=b[i-1];
	for(int i=1;i<=n;i++)e[a[i]]=b[i];
	for(int i=1;i<=n;i++)cout<<e[i]<<" ";cout<<endl;
	return 0;
}

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

typedef long long lint;
typedef long double louble;

#define lf ('\n')

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 53 , __ = _<<1;

struct edges
{
	set<int> e[_];
	inline set<int>& operator [] (int x){return e[x];}
	inline void adde(int a,int b){e[a].emplace(b);}
	inline void addde(int a,int b){adde(a,b),adde(b,a);}
	void cls(){for(auto &i:e)i.clear();}
}e1,e2;

int n,du[_];
int fa1[_],fa2[_];
int col1[_],col2[_];

void dfsfa2(int x,int ff){fa2[x]=ff;for(auto b:e2[x])if(b!=ff)dfsfa2(b,x);}

int nowans;

void dfs(int x)
{
	col1[x]=col2[x]=2,nowans--;
	for(auto b2:e2[x])
	{
		if(b2==fa2[x])continue;
		if(e1[x].count(b2))dfs(b2);
		else col2[b2]=1;
	}
}

inline int able()
{
	for(int i=1;i<nowans;i++)
	{
		int x=0;
		for(int j=1;j<=n;j++)if(col1[j]==1 && col2[j]==1){x=j;break;}
		if(!x)return 0;
		col1[x]=col2[x]=2;
		for(auto b:e1[x])if(--du[b]==1 && col1[b]==0)col1[b]=1;
		for(auto b:e2[x])if(b!=fa2[x])col2[b]=1;
	}
	return 1;
}

int duBuf[_];

void finder()
{
	e1.cls(),e2.cls();
	memset(duBuf,0,sizeof(duBuf));
	
	n=ty();
	for(int i=1,a,b;i<n;i++)a=ty(),b=ty(),e1.addde(a,b),duBuf[a]++,duBuf[b]++;
	for(int i=1,a,b;i<n;i++)a=ty(),b=ty(),e2.addde(a,b);
	
	if(n<=2){cout<<0<<lf;return;}

	int ans=1e9;
	for(int i=1;i<=n;i++)
	{
		memset(col1,0,sizeof(col1)),memset(col2,0,sizeof(col2));
		nowans=n,col2[i]=1,dfsfa2(i,0),memcpy(du,duBuf,sizeof(du));
		for(int j=1;j<=n;j++)if(du[j]==1)col1[j]=1;
		if(able()){ans=n;break;}
	}
	for(int i=1;i<=n;i++)
	{
		memset(col1,0,sizeof(col1)),memset(col2,0,sizeof(col2));
		nowans=n,dfsfa2(i,0),dfs(i),memcpy(du,duBuf,sizeof(du));
		for(int j=1;j<=n;j++)if(!col1[j] && du[j]==1)col1[j]=1;
		if(nowans<ans && able())ans=nowans;
	}

	if(ans>n)ans=-1;
	cout<<ans<<lf;
}

int main()
{//
	ios::sync_with_stdio(0),cout.tie(0);
	
	int t=ty();
	while(t--)finder();

	return 0;
}


Measured memory_bytes: 256
use std::io;
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n:usize = read();
    for i in 3..n+1 {
        if i % 3 ==0 || i.to_string().contains("3") { print!(" {}", i); }

    }
    println!();
}



Measured memory_bytes: 5040
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 510;
char G[maxn][maxn];
int vis[maxn][maxn];

int main()
{
    int h,w;
    while (cin >> h >> w) {
        FOR(i,0,h) FOR(j,0,w)
            cin >> G[i][j];
        memset(vis,0,sizeof(vis));
        FOR(i,0,h) {
            bool good = true;
            FOR(j,0,w)
                good &= G[i][j] == '.' && !vis[i][j];
            if (good) {
                FOR(j,0,w)
                    vis[i][j]++;
            }
        }
        FOR(j,0,w) {
            bool good = true;
            FOR(i,0,h)
                good &= G[i][j] == '.' || vis[i][j];
            if (good) {
                FOR(i,0,h)
                    vis[i][j]++;
            }
        }
        int cnt = 0;
        FOR(i,0,h) FOR(j,0,w) if (vis[i][j])
            cnt++;
        if (cnt == h*w)
            cout << endl;
        else {
            FOR(i,0,h) {
                int cnt = 0;
                FOR(j,0,w) if (!vis[i][j]) {
                    cout << G[i][j];
                    cnt++;
                }
                if (cnt)
                    cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m,x;
    int ans = inf;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m)cin >> a[i][j];
    }
    for(int bit = 0 ;bit < (1<<n);bit++){
        vector<int> und(m);
        int sum = 0;
        for(int i=0;i<n;i++){
            if( (bit>>i) & 1 ) {
                // i番目の本を使う
                sum += c[i];
                rep(j,m)und[j] += a[i][j];
            }
        }
        bool ok = 1;
        rep(j,m)if(und[j]<x) ok = 0;
        if(ok) chmin(ans,sum);
    }
    cout << (ans==inf?-1:ans) << endl;
}

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

void solve() {
  int a;
  cin >> a;
  int ans = 0;
  for (int i = 1; i <= 3; i++) {
    ans += pow(a, i);
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
 }


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=2e9;
double EPS=1e-10;
int n;
int dp[1<<17];
int t[16][17];
int main(){
      while(cin>>n&&n){
            REP(i,1<<17)dp[i]=INF;
            REP(i,n)REP(j,n+1)cin>>t[i][j];
            dp[0]=0;
            REP(i,1<<n){
                  REP(j,n){
                        if(i>>j&1)continue;
                        int mi=t[j][0];
                        REP(k,n){
                              if(i>>k&1){
                                    mi=min(mi,t[j][k+1]);
                              }
                        }
                        dp[i|(1<<j)]=min(dp[i|(1<<j)],dp[i]+mi);
                  }
            }
            cout<<dp[(1<<n)-1]<<endl;
      }
}

Measured memory_bytes: 1672
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long x, y, z;
	cin >> x >> y >> z;
	x -= z;
	cout << x / (y + z) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    string s;
    int y = 0, m = 0;
    bool yf, mf;

    cin >> s;


    for (int i = 0; i < 2; i++) {
        y = 10 * y + (s[i] - '0');
    }

    for (int i = 2; i < 4; i++) {
        m = 10 * m + (s[i] - '0');
    }

    if (y < 1 || y > 12) {
        yf = 0;
    }
    else if (y >= 1 || y <= 12) {
        yf = 1;
    }

    if (m < 1 || m > 12) {
        mf = 0;
    }
    else if (m >= 1 || m <= 12) {
        mf = 1;
    }
    
    if (yf && !(mf)) {
        cout << "MMYY" << endl;
    }
    else if (!(yf) && mf) {
        cout << "YYMM" << endl;
    }
    else if (mf && yf) {
        cout << "AMBIGUOUS" << endl;
    }
    else if (!(mf) && !(yf)) {
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
n,m,x=map(int,input().split())
price_points=[]
for i in range(n):
    line=list(map(int,input().split()))
    price_points.append(line)
sum_list=[]
for i in range(2**n):
    i=bin_str = format(i, 'b')
    # i=str(i)
    i_len=len(i)
    i_n_bit="0"*(n-i_len)+i
    sum_=0
    points=[0]*m
    for j in range(n):
        if i_n_bit[j]=="0":
            continue
        else:
            sum_+=price_points[j][0]
            for k in range(m):
                points[k]+=price_points[j][k+1]
    counter=0
    for l in range(m):
        if points[l]>=x:
            counter+=1    
    if counter==m:
        sum_list.append(sum_)
if len(sum_list)==0:
    print(-1)
else:
    print(min(sum_list))

Measured memory_bytes: 9252
#include<stdio.h>

int main(void)
{

    int n, r[50], t[50], x, y, i;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
        scanf("%d %d", &r[i], &t[i]);

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

        x = 1 + 5 * (t[i] / 30);
        y = r[i] / 100 - 1;

        if(r[i] % 100 == 0) {
            if(t[i] % 30 == 0)
                printf("%d", x + y);
            else
                printf("%d %d", x + y, x + y + 5);
        }
        else {
            if(t[i] % 30 == 0)
                printf("%d %d", x + y, x + y + 1);
            else
                printf("%d %d %d %d", x + y, x + y + 1, x + y + 5, x + y + 6);
        }
        printf("\n");
    }

    return 0;
}

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

void solve(){
   int k;
   cin>>k;
   while(k--){
       cout<<"ACL";
   }
   

}
int main()
{
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    } 
    
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    //long long int x,y,z,k;
    char i;
    //long long int count=2e9;
    //long long int n;
    std::cin >> i;
    char ans;
  if(i=='A')ans='T';
  if(i=='T')ans='A';
  if(i=='C')ans='G';
  if(i=='G')ans='C';
    std::cout <<ans << std::endl;
    }


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a[200000] = {0};
    int request_num;
    int num;
    int rear=0;
    int i;
    int q;

    scanf("%d", &request_num);
    
    for(i=0;i<request_num;i++){
        scanf("%d", &q);
        switch(q){
            case 0: scanf("%d", &num);a[rear++] = num;
                break;
            case 1: scanf("%d", &num);printf("%d\n", a[num]);
                break;
            case 2: rear--;
                break;
            default: break;
        }
    }
    return 0;
}


Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q,i,j,t,f1,s1=0;
	deque <int> d;
	char ch;
	string s;
	cin>>s;
	for(i=0;i<s.size();++i){
		d.push_back(s[i]);
	}
	cin>>q;
	for(i=0;i<q;++i){
		cin>>t;
		if(t==1){
			s1=(s1+1)%2;
		}
		else{
			cin>>f1>>ch;
			if(s1==1){
				if(f1==1){
					d.push_back(int(ch));
				}
				else{
					d.push_front(int(ch));
				}
			}
			else{
				if(f1==1){
					d.push_front(int(ch));
				}
				else{
					d.push_back(int(ch));
				}
			}
		}
	}
	if(s1&1){
		reverse(d.begin(),d.end());
	}
	while(!d.empty()){
		cout<<char(d.front());
		d.pop_front();
	}
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include <iostream>
#include <string>
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 vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  ll X=0;
  rep(i,n) cin>>a[i];
  vll b(0);
  if(n%2==0){
    for(int i=n-1;i>=1;i-=2){
      b.pb(a[i]);
    }
    ll k=0;
    while(k<=n-2){
      b.pb(a[k]);
      k+=2;
    }
    
  }
  else{
    ll k=n-2;
    while(k>=1){
      b.pb(a[k]);
      k-=2;
    }
    for(int i=0;i<n;i+=2){
      b.pb(a[i]);
    }
    reverse(all(b));
  }
  rep(i,n) cout<<b[i]<<" ";
}


Measured memory_bytes: 5488
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll A,B,N;
ll f(ll x){
	return A*x/B-x/B*A;
}
int main(){

	scan(A>>B>>N);
	if(N<=100000000){
		ll ans=0;
		rep(x,N+1){
			ans=max(ans,f(x));
		}
		prin(ans);
		return 0;
	}
	else if(N<B){
		prin(f(N));
	}
	else prin(f(B-1));
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> div2;
    int a;
    for(int i=0;i<N;i++){
        int ct=0;
        cin >> a;
        for(int j=0;j<2;j++){
            if(a%2==0){
                ct++;
                a/=2;
            }else break;
        }
        div2.push_back(ct);
    }
    sort(div2.begin(),div2.end());
    int ct0,ct1,ct2;
    ct0=(int)(lower_bound(div2.begin(),div2.end(),1)-div2.begin());
    ct2=(int)(div2.end()-lower_bound(div2.begin(),div2.end(),2));
    ct1=N-ct0-ct2;

    bool flag=false;
    if(ct1==0){
        if(ct2-ct0>=-1) flag=true;
    }else{
        if(ct2-ct0>=0) flag=true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 892
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    arr = [A, B, C, D, E]
    minimum = min(arr)
    if N % minimum == 0:
        a = N // minimum
    else:
        a = N // minimum + 1

    print(a+4)


if __name__ == '__main__':
    main()


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  string S,T;
  cin >> S >> T;
  cout << T << S << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>


int main()
{
	int a, b,c,d,temp,i,k = 0;
	int num[100] = { 0 };

	while (scanf("%d %d", &a, &b) != EOF)
	{
		if ((a > 0 && a <= 2000000000) && (b > 0 && b <= 2000000000))
		{
			c = a;
			d = b;
			while (temp = a%b)
			{
				a = b;
				b = temp;
			}

			num[k] = b;
			++k;
			num[k] = (c/ b)*d;
			++k;
		}
	}

	for (i = 0; i < k;)
	{
		printf("%d %d\n", num[i], num[i + 1]);
		i += 2;
	}

	return 0;
}


Measured memory_bytes: 596
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    K,N = map(int,input().split())
    A_list = list(map(int,input().split()))
    A_list = [i-A_list[0] for i in A_list]
    dist_list = []

    A_list.append(K)
    for i in range(1,len(A_list)):
        d = (A_list[i]-A_list[i-1])
        dist_list.append(d)
    d_sorted = sorted(dist_list)
    print(int(sum(d_sorted[0:N-1])))

main()


Measured memory_bytes: 26444
#include <stdio.h>

int main(){
  int N,i,j,minj,cnt=0,a[100],t;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  
  for(i = 0;i < N;i++){
    
    minj=i;
    
    for(j = i;j < N;j++){
      
      if(a[j] < a[minj]){
	minj = j;}
    }  
      t = a[minj];
      a[minj] = a[i];
      a[i] = t;	
      if(i!=minj){
	cnt += 1;
      }
  }
  
    
  for(i=0;i<N;i++){
    printf("%d",a[i]);
    
    if(i==N-1){
      printf("\n");
    }
    
    else printf(" ");
  }
  
  printf("%d\n",cnt);
  
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#include <algorithm> //next_permutation

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

int main(){
string s,t,u;
int a,b;
cin>>s>>t;
cin>>a>>b;
cin>>u;
if (!s.compare(u)) a-=1;
if (!t.compare(u)) b-=1;
cout<<a<<' '<<b;

}


Measured memory_bytes: 256