akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,x;
vi vec;
int ans=0;

signed main(){
    io();
    in(n,x);
    vec.resize(n);
    rep(i,n){
        in(vec[i]);
    }
    sort(all(vec));
    rep(i,n){
        if(x>=vec[i]){
            if(i==n-1 && x!=vec[i]){
                continue;
            }
            x-=vec[i];
            ans++;
        }else{
            break;
        }
    }

    out(ans);


    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;
using Graph = Vvec<int>;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

void graphParse(Graph& graph, int num_edge, bool is_bidirectional){
    int u, v;
    for(int i=0; i<num_edge; i++){
        cin >> u >> v;
        u--; v--;
        graph[u].emplace_back(v);
        if(is_bidirectional) graph[v].emplace_back(u);
    }
}

void dfs(Graph& graph, Vvec<int>& dp, int tmp, int from){
    if(from != -1 && graph[tmp].size() == 1){
        dp[tmp][0] = 1;
        dp[tmp][1] = 0;
        return;
    }

    vector<ll> bs(graph[tmp].size()+1);
    int j = 0;
    for(auto& to: graph[tmp]){
        if(to != from){
            dfs(graph, dp, to, tmp);
            bs[j++] = dp[to][1];
        }
    }
    bs[j] = true;
    // cout << j <<" " << bs.size() << endl;
    while(j>0){
        bs[j-1] = bs[j-1] & bs[j];
        j--;
    }

    dp[tmp][0] = bs[0];
    bool b = true;
    for(auto& to: graph[tmp]){
        if(to != from){
            dp[tmp][1] |= b & dp[to][0] & bs[++j];
            b &= dp[to][1];
        }
    }
}

int main()
{
    int N;
    cin >> N;
    Graph graph(N);
    graphParse(graph, N-1, true);

    Vvec<int> dp(N, vector<int>(2));
    dfs(graph, dp, 0, -1);

    cout << ((dp[0][1]) ? "Second\n" : "First\n");
}

Measured memory_bytes: 14316
#include<stdio.h>
int main()
    {
        int a[100000]={0},i;
        int n,num;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num);
            a[num]=i;
        }
        
        for(i=1;i<=n;i++)
        printf("%d ",a[i]);
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;


int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    //string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>m;
        num[m]++;
    }
    for(i=1;i<=n;i++) cout<<num[i]<<endl;
    return 0;
}





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

int main(int argc, char const* argv[]) {
	int N;
	scanf("%d", &N);
	int T[100];
	for (int i = 0; i < N; i++) {
		scanf("%d", &T[i]);
	}
	int M;
	scanf("%d", &M);
	for (int i = 0; i < M; i++) {
		int P, X;
		scanf("%d %d", &P, &X);
		int ans = 0;
		for (int j = 0; j < N; j++) {
			if (j == P - 1) ans += X;
			else ans += T[j];
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 3824
function main(input){
    let nums = input.split(" ").map(item=>parseInt(item));
    for(let i=0;i<2;i++){
        for(let j=0;j<2;j++){
            if(nums[j]>nums[j+1]){
                let temp=nums[j];
                nums[j] = nums[j+1];
                nums[j+1] = temp;
            }
            
        }
    }
    console.log(""+nums[0]+" "+ nums[1]+" "+nums[2]);
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15120
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define DEC(i, x, y) for (ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
 
// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<ii> vii;
 
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
 
ll lcm(ll a, ll b) { return (a * (b / __gcd(a, b))); }
 
// Some contants
const ll inf = 1e12 + 7;
const double eps = 1e-9;
const long double pi = 1.00 * acos(-1.00);
 
ll dp[3001][3001];
ll A, B, C, D; 
ll MOD = 998244353;




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

    cin >> A >> B >> C >> D;
    memset(dp, 0, sizeof(dp));

    dp[A][B] = 1;

    FOR(i,B+1,D+1){
        dp[A][i] = dp[A][i-1]*A;
        dp[A][i] %= MOD;
    }
    FOR(i,A+1,C+1){
        dp[i][B] = dp[i-1][B]*B;
        dp[i][B] %= MOD;
    }

    FOR(i,A+1,C+1){
        FOR(j,B+1,D+1){

            dp[i][j] = (((dp[i-1][j]*j)%MOD + (dp[i][j-1]*i)%MOD - (dp[i-1][j-1]*(j-1)*(i-1))%MOD)+MOD)%MOD;

            
        }
    }

    cout << dp[C][D]%MOD <<endl;



    return 0;
 
 
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    ll n,m;
    cin>>n>>m;
    vector<pair<int,int>> vp;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        vp.push_back(make_pair(a,b));
    }
    reverse(all(vp));
    ll now=((n-1)*n)/2;
    UnionFind uf(n+1);
    vll ans;
    rep(i,m){
        ans.push_back(now);
        int x=vp[i].first;
        int y=vp[i].second;
        if (uf.issame(x,y))continue;
        else{
            ll xs=uf.size(x);
            ll ys=uf.size(y);
            now-=xs*ys;
            uf.merge(x,y);
        }
    }
    rep(i,m){
        cout<<ans[m-1-i]<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3444
#include <stdio.h>

void
to_card(int idx, char *suit, int *rank)
{
	switch (idx/13)
	{
	case 0: *suit = 'S'; break;
	case 1: *suit = 'H'; break;
	case 2: *suit = 'C'; break;
	case 3: *suit = 'D'; break;
	}
	*rank = idx%13 + 1;
}

void
to_idx(char suit, int rank, int *idx)
{
	switch (suit)
	{
	case 'S': *idx = 0*13 + (rank-1); break;
	case 'H': *idx = 1*13 + (rank-1); break;
	case 'C': *idx = 2*13 + (rank-1); break;
	case 'D': *idx = 3*13 + (rank-1); break;
	}
}

int
main()
{
	int n_exists;
	scanf("%d\n", &n_exists);

	int idx;
	int rank;
	char suit;
	int is_exists[4*13] = {0};

	int i;
	for (i = 0; i < n_exists; i++)
	{
		scanf("%c %d\n", &suit, &rank);
		to_idx(suit, rank, &idx);
		is_exists[idx] = 1;
	}
	for (idx = 0; idx < 4*13; idx++)
	{
		if (!is_exists[idx])
		{
			to_card(idx, &suit, &rank);
			printf("%c %d\n", suit, rank);
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, f, s;
    f = s = 0;
    for(int i = 0; i < 3; ++i){
        cin >> a;
        if(a == 5){
            ++f;
        }
        else if(a == 7){
            ++s;
        }
    }
    
    if(f == 2 && s == 1){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3568
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 5e5 + 5;
int n;
int a[maxn];
char tmp[maxn];

bool read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  string s = tmp;
  n = sz(s);
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  return true;
}

void solve() {
  {
    int carry = 0;
    for (int i = 0; i < n; i++) {
      a[i] = a[i] * 9 + carry;
      carry = a[i] / 10;
      a[i] %= 10;
    }
    if (carry) {
      a[n++] = carry;
    }
  }
  int k = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  while (k < sum) {
    int carry = 1;
    for (int i = 0; i < n; i++) {
      sum -= a[i];
      a[i] += carry;
      carry = (a[i] >= 10);
      if (carry) {
        a[i] -= 10;
        sum += a[i];
      } else {
        sum += a[i];
        break;
      }
    }
    if (carry) {
      a[n++] = carry;
      sum += carry;
    }
    k++;
  }
  printf("%d\n", (k + 8) / 9);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

//ifstream fin("date.in");
//ofstream gout("date.out");

const int NMax = 1e6 + 5;
const int mod = 1e9 + 7;

int main()
{
	string S;

	cin >> S;
	int n = S.size();

	for(int i = 0; i < n - 1; ++i) {
		if(S[i] == 'A' && S[i + 1] == 'C'){
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";

	return 0;
}

Measured memory_bytes: 256
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" ( fun n -> n)
let d, x = Scanf.sscanf (read_line ()) "%d %d" ( fun d x -> d, x)
let lst = List.init n ( fun _ -> Scanf.sscanf (read_line ()) "%d" ( fun a -> a))

let f a = (List.range 0 `To 100)
          |> List.map (fun elmnt -> (a * elmnt) + 1)
          |> List.filter (fun elmnt -> elmnt <= d)

let rec f2 lst =
        match lst with
                  [] -> x
                | first :: rest -> 
                        List.length (f first) + (f2 rest)

let () =
        f2 lst 
        |> Printf.printf "%d\n"


Measured memory_bytes: 1792
# encoding: "utf-8"

from collections import defaultdict
from functools import reduce
from itertools import groupby, chain

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = chain.from_iterable([[x-1, x, x+1] for x in xs])
    ys = sorted(list(ys))
    m = max([len([1 for _ in x]) for (i, x) in groupby(ys)])
    print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 27784
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count=0
for r in range(a+1):
    for y in range(b+1):
        for z in range(c+1):
            price=500*r+100*y+z*50
            if price==x:
                count+=1
            
print(count)






Measured memory_bytes: 3060
s=input()
A=[]
B=[]
for i in range(0,len(s)):
    if s[i]=='A':
        a=i
        break
S=list(reversed(s))
for j in range(0,len(S)):
    if S[j]=='Z':
        b=j
        break
print(len(s)-a-b)

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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int x1, x2, x3, x4, x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
    vi a({x1,x2,x3,x4,x5});
    for(int i : {0,1,2,3,4}){
        if(a[i] != i + 1){
            cout << i + 1 << '\n';
            return;
        }
    }
}


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

Measured memory_bytes: 3608
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n;
	cin >> n;
	vll a(n);
	rep(i,n)cin >> a[i];

	int cnt = 0;

	rep(i,n){
		int a1 = a[i];
		int a2 = a[a1-1];
		if(a2 == i+1) cnt++;
	}
	cout << cnt/2 << endl;




	


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc046.contest.atcoder.jp/tasks/abc046_b

Measured memory_bytes: 4012
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = Array(n) { readLine()!![0] }.filter { it in listOf('M', 'A', 'R', 'C', 'H') }.groupBy { it }

    if (ss.entries.size < 3) {
        println(0)
        return
    }

    val keys = ss.keys.toList()
    var cnt = 0L

    for (i in 0..keys.size-3) {
        for (j in i+1..keys.size-2) {
            for (k in j+1..keys.size-1) {
                val key1 = keys[i]
                val key2 = keys[j]
                val key3 = keys[k]

                cnt += ss[key1]!!.size.toLong() * ss[key2]!!.size.toLong() * ss[key3]!!.size.toLong()
            }
        }
    }

    println(cnt)
}

Measured memory_bytes: 41640
#include<iostream>
#include<cstring>
using namespace std;
int a[25][2005],b[25],c[25][1005],f[2005];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			scanf("%1d",&a[i][j]);
	}
	int ans=10000000;
	for(int q=0;q<((1<<n)-1);q++){
		int t=0;
		memset(b,0,sizeof(b));
		memset(f,0,sizeof(f));
		for(int j=0;j<n-1;j++) if((q>>j)&1) b[j+1]=1,t++;
		memset(c,0,sizeof(c));
		for(int i=0;i<m;i++){
			int x=0,j=0,last=0;
			while(x<=t){
				while(!b[j]&&j<n) j++;
				int s=0;
				for(int k=last;k<j;k++) s+=a[k][i];
				last=j;
				c[x++][i]=s;
				j++;
			}
		}
		int	z=0;
		for(int i=0;i<=t;i++) for(int j=0;j<m;j++) if(c[i][j]>k) z=1;
		if(z) continue;
		int s=0,l=t;
		for(int i=0;i<m;i++){
			int x=0;
			for(int j=0;j<=t;j++){
				if(f[j]+c[j][i]>k) x=1;
			}
			if(x){
				for(int j=0;j<=t;j++) f[j]=0;
				l++;
			}
			for(int j=0;j<=t;j++) f[j]+=c[j][i];
		}
		ans=min(l,ans);
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  ll N, M;
  cin >> N >> M;

  if (N * 2 < M) {
    // c あまりの時
    ll rest = M - (N * 2);
    ll created = rest / 4;
    cout << (N + created) << endl;
  } else if (N * 2 > M) {
    // s あまりの時 (ばらせない)
    ll ret = M / 2;
    cout << ret << endl;
  } else {
    // 割合ピッタリ
    cout << N << endl;
  }
}


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


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




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string str, a, b, ans="Yes";
  int l;
    cin >> str;
    l = str.size();
    a = str.substr(0, (l-1)/2);
    b = str.substr((l+3)/2-1, l);
    if(a != b) ans = "No";
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int A,B,C,D,E,F;
	cin>>A>>B>>C>>D>>E>>F;
	cout<<(A+B*5+C*10+D*50+E*100+F*500>=1000?1:0)<<endl;
	return 0;
}



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

string s;

int main() {
	cin>>s;
	int l=s.length();
	int sum=0;
	for(int i=0;i<l;++i)
		sum+=s[i]-'0';
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<vector>

using namespace std;

int TableNewOctal[] = { 0,1,2,3,5,7,8,9 };
vector<int> Result;

int main() {
	int num;

	while (cin >> num, num) {
		while (num > 0) {
			Result.push_back(TableNewOctal[num % 8]);
			num /= 8;
		}
		while (!Result.empty()) {
			cout << Result.back();
			Result.pop_back();
		}
		cout << endl;
	}

	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    set<string> ss;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        ss.insert(str);
    }

    cout << ss.size() << endl;
}

Measured memory_bytes: 15548
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;
typedef pair<pl, ii> pli;
const int MAX = 2e5+5;

int main(int argc, char * * argv) {
	vector<int> a(3);
  	for(auto &x : a)
      	scanf("%d", &x);
  	sort(all(a));
  	if(a[0] == 5 && a[1] == 5 && a[2] == 7)
		puts("YES");
  	else puts("NO");
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if (a%2 == 0 && a%3 && a%5) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

if k == 0:
  print(n * n)
else:
  x = 0
  for b in range(k, n + 1):
    x += (n // b) * (b - k)
    r = n % b
    if r >= k:
      x += r - k + 1
  print(x)

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

int main() {
  
  int N;
  cin >> N;
  
  vector<long long> lis(N);
  for(int i=0; i<N; i++){ cin >> lis[i]; }
  
  sort(lis.begin(), lis.end());
  
  cout << lis.at(N-1) - lis.at(0) << endl;

}



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

int main(void)
{
    int count = 0;
    string s, t;
    cin >> s >> t;
    rep(i, s.size()) {
        if (s[i] != t[i])
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3912
// キュー
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

//const int MAX_N = 100000;
const int STR_LEN = 10;

// キュー関連の定義
const int Max_Queue = 100000;
const int Queue_Error = -2147483648;

// キューの要素の構造体
typedef struct q_e
{
    // 配列の要素No.
    int id;
    // プロセス名
    char process_name[STR_LEN];
    // プロセスの時間
    int process_time;
}queue_element;

queue_element ary_queue[Max_Queue];

// キューの情報の構造体
typedef struct q_i
{
    int head;
    int tail;
}queue_info;

queue_info que_info;

void create_queue(void);
int enqueue(queue_element element);
queue_element dequeue(void);

int main(void)
{

    int N, cpu_time, total_time = 0;
    char str[STR_LEN];
    queue_element que_ele;

    // キューの初期化
    create_queue();

    scanf("%d %d", &N, &cpu_time);

    for(int i = 0; i < N; i++)
    {
    	que_ele.id = i;

        scanf("%s", &str[0]);
        strcpy(&(que_ele.process_name[0]), &str[0]);

        scanf("%s", &str[0]);
        que_ele.process_time = atoi(str);

        // キューに挿入する
        enqueue(que_ele);
    }

    // cpuの時間を割り当てる
    while( que_info.head != que_info.tail )
    {
        // キューからポップする
        que_ele = dequeue();

        if( 0 < que_ele.process_time
            && que_ele.process_time <= cpu_time )
        {
            total_time += que_ele.process_time;
            que_ele.process_time = 0;

            printf("%s %d\n", que_ele.process_name, total_time);
        }
        else
        {
            total_time += cpu_time;
            que_ele.process_time -= cpu_time;

            enqueue(que_ele);
        }
    }

    return 0;

}

// キューを作成する関数
void create_queue(void)
{
    int i;

    for(i = 0; i < Max_Queue; i++)
    {
        // キュー要素の初期化
    	ary_queue[i].id = 0;
        ary_queue[i].process_name[0] = '\0';
        ary_queue[i].process_time = 0;
    }

    que_info.head = 0;
    que_info.tail = 0;

    return;
}

// キューへプッシュする関数
int enqueue(queue_element element)
{

    if( que_info.head == ( que_info.tail + 1 ) % Max_Queue )
    {
        // キューが満杯
        return Queue_Error;
    }

    if( que_info.tail == Max_Queue - 1 )
    {
        // 配列をラウンド型にする
        que_info.tail = -1;
    }

    // キューに追加する
    ary_queue[que_info.tail++] = element;

    return 0;
}

// キューからポップする関数
queue_element dequeue(void)
{
    queue_element ret;

    if( que_info.head == que_info.tail )
    {
        // キューが空の時
        ret.id = Queue_Error;
    }
    else
    {
        if( que_info.head == Max_Queue - 1 )
        {
            // 配列をラウンド型にする
            que_info.head = -1;
        }

        // キューから取り出す
        ret = ary_queue[que_info.head++];
    }

    return ret;
}



Measured memory_bytes: 5168
#include<stdio.h>
int main() {
  int n, s=0;
  scanf("%d", &n);
  int d[n];
  for(int i=0; i<n; i++)
    scanf("%d", &d[i]);
  for(int i=0; i<n; i++){
	for(int j=i+1; j<n; j++){
      s += d[i]*d[j];
    }
  }
  printf("%d", s);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int i=0; i<n; i++) {
		double x1,x2,x3,x4,y1,y2,y3,y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if ((y2-y1)/(x2-x1) == (y4-y3)/(x4-x3)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0;i<N;i++) cin >> A[i];
	
	ll ma = 0;
	for(int i=0;i<N;i++){
		for(int j=i + 1;j<N;j++){
			ma = max(ma, abs(A[i] - A[j]));
		}
	}
	cout << ma << endl;
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
N = int(input())

P = list(map(int, input().split()))

out_range = 10**18

ans=1
if  0 in P:
    print(0)
    exit()

for i in range(N):
    tmp = P[i]
    ans *= tmp
    if  ans > out_range:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 21660
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c


N = int(input())
X = input()
pc = X.count('1')
if pc == 0:
    for i in range(N):
        print(1)
elif pc == 1:
    if X[-1] == '1':
        for i in range(N-1):
            print(2)
        print(0)
    else:
        for i in range(N-1):
            if X[i] == '1':
                print(0)
            else:
                print(1)
        print(2)
else:
    modX1 = 0
    modX2 = 0
    Xi = [None] * N
    x1 = 1
    x2 = 1
    for i in range(N):
        if X[-i-1] == '1':
            Xi[-i-1] = x1
            modX1 = (modX1+x1) % (pc-1)
            modX2 = (modX2+x2) % (pc+1)
        else:
            Xi[-i-1] = x2
        x1 = x1 * 2 % (pc-1)
        x2 = x2 * 2 % (pc+1)
    for i in range(N):
        ans = 1
        x = (modX1 - Xi[i]) % (pc-1) if X[i] == '1' else (modX2 + Xi[i]) % (pc+1)
        while x != 0:
            x = x % popcnt(x)
            ans += 1
        print(ans)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

ll n,z,w;
ll a[2001];
ll dp[2001][2];
int flag[2001][2];


ll ddpp(int i,int b){
    if(flag[i][b]){
        return dp[i][b];
    }
    else{
        flag[i][b]=1;
        if(b==0){
            if (i==n){
                dp[i][b]=abs(a[n]-a[n-1]);
                if (i==1){
                  dp[i][b]=abs(a[n]-w);
                  return abs(a[n]-w);
                }
                return abs(a[n]-a[n-1]);
            }
            else{
                ll ans1=0;
                for (int x=i+1;x<n+1;x++){
                    ans1=max(ans1,ddpp(x,1-b));
                }
                if (i==1){
                    //cout<<abs(w-a[n])<<" "<<1<<endl;
                    ans1=max(ans1,abs(w-a[n]));
                }
                else{
                ans1=max(ans1,abs(a[i-1]-a[n]));}
                dp[i][b]=ans1;
                return ans1;
            }
        }
        else{
            if (i==n){
                if (i==1){
                  dp[i][b]=abs(a[n]-z);
                  return abs(a[n]-z);
                }
                dp[i][b]=abs(a[n]-a[n-1]);
                //cout<<dp[i][b]<<" "<<12<<endl;
                return dp[i][b];
            }
            else{
                ll ans1=10000*MOD+MOD+MOD;
                for (int x=i+1;x<n+1;x++){
                    ans1=min(ans1,ddpp(x,1-b));
                }
                if (i==1){
                    ans1=min(ans1,abs(z-a[n]));
                }
                else{
                ans1=min(ans1,abs(a[i-1]-a[n]));}
                dp[i][b]=ans1;
                return ans1;
            }
        }
    }

}

int main() {
    cin>>n>>z>>w;
    rep(i,n){
        cin>>a[i+1];
    }
    ddpp(1,0);
    cout<<dp[1][0]<<endl;
  /*rep(i,n){
rep(j,2){
cout<<dp[i+1][j]<<" ";
}
    cout<<endl;}*/
    

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template <typename T>
T gcd(T a, T b) {
    if (a == 0) return b;
    return gcd(b % a, a);
}

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int g = 0;
    vector<int>c(n+1);
    for(int i = 0; i < n; i++){
        c[i+1] = gcd(c[i],a[n-1-i]);
    }
    show(c);
    int ans = c.back();
    for(int i = 0; i < n; i++){
        ans = max(ans, gcd(g, c[n-i-1]));
        g = gcd(g, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int n,q;
    cin >> n >> q;
    ve<pair<int,pair<int,int>>> t;
    rep(i,n){
        int ss, tt ,x;
        cin >> ss >> tt >> x;
        t.push_back({ss-x, {1, x}});
        t.push_back({tt-x, {-1, x}});
    }
    sort(all(t));
    ve<int> d(q);
    rep(i,q) cin >> d[i];
    
    set<int> S;
    int j = 0;
    rep(i,q){
        while ((t[j].fi) <= d[i] && j < 2*n) {
            if((t[j].se.fi) == 1) S.insert(t[j].se.se);
            if((t[j].se.fi) == -1) S.erase(t[j].se.se);
            j++;
        }
        if(S.empty()) out(-1);
        else out(*begin(S));
        
        
        
        
    }


    return 0;
}


Measured memory_bytes: 16108
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <typeinfo>
using namespace std;

int main()
{
    int N;
    long long W;
    scanf("%d", &N);
    scanf("%lld", &W);
    int values[N];
    long long weights[N];
    long long MAX = W + 1;
    int total_value = 0;
    for (int i = 0; i < N; i++){
        cin>> weights[i] >> values[i];
        total_value += values[i];
    }
    long long dp[total_value + 1];
  	fill(dp, dp + (total_value + 1), MAX);
    dp[0] = 0;
  	for (int i=0; i<N; ++i) {
        for (int j=total_value; j>=values[i]; --j){
            // if (j != values[i])
                dp[j] = min(dp[j], dp[j-values[i]] + weights[i]);
            // else if (j == values[i])
            //     dp[j] = weights[i];
        }
    }  
  
  	for (int i = total_value; i>=0; --i) {
        if (dp[i] < MAX){
            cout << i << endl;
            break;
        }
    }
    // for (int i = 0; i<=total_value; ++i) {
    //     cout << dp[i] << " ";
    // }
    
  	
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace Dice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] d = Console.ReadLine().Split(' ');
            int i = int.Parse(Console.ReadLine());
            for (int j = 0; j < i; j++)
            {
                string[] _t = Console.ReadLine().Split(' ');
                int[] _sh = new int[2];
                for(int k = 0; k < 2; k++)
                     _sh[k] = d.Select((e, v) => _t[k] == e ? v : -1).Where(e => e > -1).First();          
                string o = string.Format("{0} {1}", _sh[0], _sh[1]);
                Console.WriteLine("{0}",
                new Regex("1 2|2 4|3 1|4 3").IsMatch(o) ? d[0] :
                new Regex("0 3|3 5|2 0|5 2").IsMatch(o) ? d[1] :
                new Regex("0 1|1 5|4 0|5 4").IsMatch(o) ? d[2] :
                new Regex("0 4|1 0|4 5|5 1").IsMatch(o) ? d[3] :
                new Regex("0 2|2 5|3 0|5 3").IsMatch(o) ? d[4] : d[5]);
            }
        }
    }
}

Measured memory_bytes: 11576
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

int dfs(vector<int> &nums,int k,vector<int> &dp){
	if(k<=0) return 0;
	if(dp[k] != -1) return dp[k];
	dp[k] = 0;
	for(auto &item:nums){
		if(k<item) break;
		if(dfs(nums,k-item,dp)==0) {
			dp[k] = 1;
			break;
		}
	}
	return dp[k];
}


void solve(){
	int n,k;
	cin>>n>>k;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	vector<int> dp(k+1,0);
	for(int i=0;i<nums[0];i++) dp[i] = 0;
	for(int i=0;i<=k;i++){
		dp[i] = 0;
		for(auto item:nums){
			if(i<item) break;
			if(dp[i-item]==0){
				dp[i] = 1;
				break;
			}
		}
	}
	if(dp[k]){
		cout<<"First"<<endl;
	}else{
		cout<<"Second"<<endl;
	}
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

using namespace std;

int main(){
    int N, a, b, n, sum, ans=0;
    cin >> N >> a >> b;

    for (n=1; n<=N; n++) {
        sum = 0;
        sum += (n%10); // 1の桁
        sum += ((n/10)%10); // 10の桁
        sum += ((n/100)%10); // 100の桁
        sum += ((n/1000)%10); // 1000の桁
        sum += ((n/10000)%10); // 10000の桁

        if ((sum >= a) && (sum <=b)) {
            ans += n;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int A, B;
    std::cin >> A >> B;
    if((A + B) % 2 == 1) {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
    else {
        std::cout << (A + B) / 2 << std::endl;
    }


    return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int s;
	cin >> s;

	set<int> st;
	st.insert(s);

	int last = s;

	for(int i = 1; i < 1e7+1; i++) {
		int now = last&1?3*last+1:last/2;
	   if(st.find(now) != st.end()) {
			cout << i + 1;
			exit(0);
	   }
	   st.insert(now);
	   last=now;
	}

	assert(false);

	return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::collections::VecDeque;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple() -> (usize, usize, char) {
  let v: Vec<String> = read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();

  let mut res = (0, 0, 'a');
  res.0 = v[0].parse().ok().unwrap();
  if res.0 == 2 {
      res.1 = v[1].parse().ok().unwrap();
      res.2 = v[2].chars().collect::<Vec<char>>()[0];
  }
  res
}

fn main() {
  let s: Vec<char> = read::<String>().chars().collect();
  let n = s.len();
  let Q: usize = read();
  let mut querry = vec![];
  for i in 0..Q {
    let t = read_touple();
    querry.push(t);
  }

  let mut ans = VecDeque::new();

  for i in 0..n {
    ans.push_back(s[i]);
  }

  let mut rev = false;

  for &(t, f, c) in &querry {
    if t == 1 {
       rev = !rev;
       continue
    }

    // 初期状態から反転なし
    if rev == false {
       if f == 1 {
          ans.push_front(c);
       } else {
         ans.push_back(c);
       }
    }

    // 初期値から反転あり
    if rev == true {
      if f == 1 {
        ans.push_back(c);
      } else {
        ans.push_front(c);
      }
    }
  }

  let mut res = vec![];
  for e in ans {
    res.push(e);
  }

  let d: String = if rev == false {
    res.into_iter().collect()
  } else {
    res.into_iter().rev().collect()
  };


  //println!("{:?}",querry);
  println!("{}", d);
}


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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL<<60;

int main()
{
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> rw(N + 1, 0);
  for (int i = 1; i < N; i++) {
    if (S[i] == 'C' && S[i - 1] == 'A') {
      rw[i + 1] = rw[i] + 1;
    } else {
      rw[i + 1] = rw[i];
    }

  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << rw[r] - rw[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
fun main (args : Array<String>) {
	val s = readLine()
	val S : String = s.toString()
	var count : Int = 0
	var result : Int = 0
	for (i in S) {
		if (i.toString() == "A" || i.toString() == "C" || i.toString() == "G" || i.toString() == "T") {
			count++
			if (result < count) {
				result = count
			}
		} else {
			count = 0
		}
	}
	println("${result}")
}

Measured memory_bytes: 33892
#include<stdio.h>
#include<algorithm>
using namespace std;
int ret[310000];
int used[310000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a==b){
		printf("Yes\n");
		for(int i=0;i<a*2-1;i++)printf("%d\n",i+1);
			return 0;
	}
	if(a==2||b==1||b==a*2-1){
		printf("No\n");return 0;
	}
	printf("Yes\n");
	if(b>a){
		ret[a-1]=a*2-1;
		ret[a-2]=1;
		ret[a]=b;
		ret[a+1]=b-1;
		used[a*2-1]=used[1]=used[b]=used[b-1]=1;
	}else{
		ret[a-1]=1;
		ret[a-2]=a*2-1;
		ret[a]=b;
		ret[a+1]=b+1;
		used[a*2-1]=used[1]=used[b]=used[b+1]=1;
	}
	int at=1;
	for(int i=0;i<a*2-1;i++){
		if(ret[i])continue;
		while(at<=a*2-1){
			if(used[at]){at++;continue;}
			ret[i]=at;
			at++;
			break;
		}
	}
	for(int i=0;i<a*2-1;i++)printf("%d\n",ret[i]);
}

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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int sum = A + B + C;
    if(sum < 22){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=1e5;

int n,dizi[N],ans;

int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>dizi[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans+=dizi[i]*dizi[j];
		}
	}
	cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC087C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[,] ame = new int[2,N];
            for(int i=0;i<2;i++){
                var target = Console.ReadLine().Split(' ');
                for(int j=0;j<N;j++)
                    ame[i,j] = int.Parse(target[j]);
            }
            int max_ame = 0;
            for(int i=0;i<N;i++){
                int count = 0; 
                for(int j=0;j<N;j++){
                    if(j<i) count += ame[0,j];
                    if(j==i) count += ame[0,j] + ame[1,j];
                    if(j>i) count += ame[1,j];
                }               
                if(max_ame < count) max_ame=count;
            }
            Console.WriteLine(max_ame);
        }
    }
}


Measured memory_bytes: 11092
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var t = 1L;
            var a = 1L;
            for (var i = 0; i < N; ++i)
            {
                (long T, long A) = Slice2<long>();
                var mag = Max((t + T - 1) / T, (a + A - 1) / A);
                t = mag * T;
                a = mag * A;
            }
            WriteLine(t + a);
        }
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#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(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n, m;
	cin >> n;
		REP(_, n){
			int32 cnt = 0;
			int32 Y, M, D;
			cin >> Y >> M >> D;
			while(Y != 1000 || M != 1 || D != 1){
				cnt++; D++;
				if((Y%3==0 && D==21) || (Y%3 && D==(M%2?21:20))){
					D = 1; M++;
				}
				if(M == 11){
					M = 1; Y++;
				}
			}
			cout << cnt << endl;
		}
}


Measured memory_bytes: 3080