akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let s = scan.chars();
    let t = scan.chars();
    let mut ret = vec![];
    for i in 0..n {
        ret.push(s[i]);
        ret.push(t[i]);
    }
    println!("{}", join(&ret, ""));
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
list_T = [int(input()) for _ in range(n)]

print(lcm_list(list_T))


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int n,k,u,v,ans=0,d[N],h[N];
vector<int>G[N];
queue<int>q;
int main(){
    int n;cin>>n;
    while(n--) cout<<"ACL";
    return 0;
}


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

int main(void){
  int coins[] = {500, 100, 50, 10, 5, 1};

  while(1){
  int ans = 0, n; cin >> n;
  if(n == 0) return 0;
  n = 1000 - n;
  for(int i=0; i < 6; i++){
    while(n >= coins[i]){
      ans++;
      n -= coins[i];
    }
  }
  cout << ans << endl;
  }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		String t = sc.next();
		int sLen = s.length();
		int tLen = t.length();
		int[][] len = new int[sLen+1][tLen+1];

		for (int i=1;i<=sLen;i++) {
			for (int j=1;j<=tLen;j++) {
				if(s.charAt(i-1)==t.charAt(j-1)) {
					len[i][j]=len[i-1][j-1]+1;
				} else {
					len[i][j]=Math.max(len[i-1][j], len[i][j-1]);
				}
			}
		}
		String ans = "";
		int ansLen = len[sLen][tLen];
		int i = sLen;
		int j = tLen;
		while (ans.length()<ansLen) {
			if (s.charAt(i-1)==t.charAt(j-1)) {
				ans = s.charAt(i-1)+ans;
				i--;
				j--;
			} else if (len[i-1][j] > len[i][j-1]) {
				i--;
			} else {
				j--;
			}
		}
		System.out.println(ans);
	}	
}

Measured memory_bytes: 86580
#include <iostream>
#include <string>

using namespace std;
int main(void){
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            if (a % 2 == 1) {
                a--;
            }
            b += a/2;
            a /= 2;
        } else {
            if (b % 2 == 1) {
                b--;
            }
            a += b/2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

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

    bool comp(const pair_t &a , const pair_t &b){
        if(a.first == b.first){
            return a.second < b.second;
        }
        return a.first < b.first;
    }

        
    int main(){
        int n ;
        cin >> n;
        long x , y;
        long ans;
        ans = n;
        vector<pair_t> v;
        for(int i = 0 ; i < n ; i++){
            cin >> x >> y;
            pair<long , long> p;
            p = make_pair(x , y);
            v.push_back(p);
        }
        sort(v.begin(), v.end() , comp);
        long pt , qt , t;
        vector<long> vt;
        vector<pair_t> v2;
        for(int i = 0 ; i < n - 1 ; i++){
            for(int j = i + 1; j < n ; j++){
                pt = v[j].first - v[i].first;
                qt = v[j].second - v[i].second;
                pair<long , long> pp;
                pp = make_pair(pt , qt);
                v2.push_back(pp);
            }
        }
        
        for(int i = 0 ; i < v2.size() ; i++){
            pt = v2[i].first;
            qt = v2[i].second;
            t = n;
            vt.assign(n , 0);
            
            for(int j = 0; j < n ; j++){
                for(int k = j + 1; k < n ; k++){
                    if(vt[k] == 0 && j != k){
                        if( (v[j].first - v[k].first == pt) && (v[j].second - v[k].second == qt)){
                            t -= 1;
                            vt[k] = 1;
                        }else if((v[j].first - v[k].first == -pt) && (v[j].second - v[k].second == -qt)){
                            t -= 1;
                            vt[k] = 1;
                        }
                    }
                }
                
            }
            //cout << i << " " << pt << " " << qt <<  " " << t << endl;
            ans = min(ans, t);
        }
        
        cout << ans << endl;
        return 0;
    }

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

cumw = [0]
for c in S:
    cumw.append(cumw[-1] + int(c=='W'))

cumr = [0]
for c in S[::-1]:
    cumr.append(cumr[-1] + int(c=='R'))
cumr.reverse()

ans = N
for a,b in zip(cumw,cumr):
    ans = min(ans, max(a,b))
print(ans)

Measured memory_bytes: 25224
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

ll add(ll a,ll b){
    return (a+b)%MD;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> v(m),pos(n+10);
    for(int i=0;i<m;i++) cin>>v[i];
    for(int i=0;i<m;i++) pos[v[i]]=1;
    vector<ll> ans(n+10);
    ans[0]=1;
    if(pos[1]!=1) ans[1]=1;
    for(int i=2;i<=n;i++){
        if(pos[i-1]==0&&pos[i-2]==0){
            ans[i]=add(ans[i-1],ans[i-2]);
        }else if(pos[i-1]==0){
            ans[i]=ans[i-1];
        }else if(pos[i-2]==0){
            ans[i]=ans[i-2];
        }
    }
    cout<<ans[n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
$d[1]=1;map{if(!$p[$i=$_]){@p[map$i*$_,@@]=@@;$k=-$_,map$d[$k*++$_]+=$d[$k],1..map{grep$'%$i**$_<1,//..9}@@for-75..-1}}@@=2..<>;print$d[75]+0

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

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

const int MAX_L=1001;//?????????????????§??????

vector<vector<int> > DP(MAX_L, vector<int>(MAX_L, -1));
string A;//?????????????????????????????????
string B;
string chars;//???????????????????????¨????????????????????????


//A???a???????????¨????????\??????B???b???????????¨????????\??????????????§????????§?????¨????????????????????????????????????
//m?????????????????????????????±??????????????????
int dev(int a, int b){
	if(DP[a][b]<0){
		int maxi= 0;
		//???????????????????????§??????
		for(char c: chars){
			int posa = A.find(c,a);
			int posb = B.find(c,b);
			if(posa>=0 && posb>=0){
				int tmp = dev(posa+1,posb+1);
				maxi = max(maxi, tmp+1);
			}
		}
		DP[a][b]=maxi;
	}
	return DP[a][b];
}

void make_list(){
		//???????????????????????§??????
		for(int c='a'; c<='z'; ++c){
			int posa = A.find(c,0);
			int posb = B.find(c,0);
			if(posa>=0&&posb>=0){
				chars.push_back(c);
			}
		}
		for(int c='A'; c<='Z'; ++c){
			int posa = A.find(c,0);
			int posb = B.find(c,0);
			if(posa>=0&&posb>=0){
				chars.push_back(c);
			}
		}
}

int main(){
	int q;
	cin >> q;
	vector<int> ans(q);
	REP(i,q){
		REP(k,MAX_L){
			REP(l,MAX_L){
				DP[k][l] = -1;
			}
		}
		chars="";
		cin>>A>>B;
		make_list();
		ans[i]=dev(0,0);
	}
	REP(i,q){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6660
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1,0);
    rep(i,1,1+n)cin >> a[i];
    int cnt=0;
    for(int i=n;i>0;--i){
        int tmp=a[i];
        int j=2*i;
        while(j<=n){
            tmp^=b[j];
            j+=i;
        }
        b[i]=tmp;
        cnt+=tmp;
    }
    cout << cnt << endl;
    rep(i,1,1+n)if(b[i]>0)cout << i << " ";
    return 0;
}

Measured memory_bytes: 2432
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const N = parseInt(input[0], 10);
const points = [];
const outOfBounds = [];

for (let i = 1; i <= N; i++) {
  const line = input[i].split(" ").map((val) => parseInt(val, 10));
  if (line[2] > 0) {
    points.push({ x: line[0], y: line[1], h: line[2] });
  } else {
    outOfBounds.push({ x: line[0], y: line[1], h: line[2] });
  }
}

points.push(...outOfBounds);

for (let x = 0; x <= 100; x++) {
  for (let y = 0; y <= 100; y++) {
    let found = true;
    let estimate = {
      x,
      y,
      h: 0,
    }
    for (let i = 0; i < points.length; i++) {
      const point = points[i];

      if (estimate.h <= 0) {
        estimate.h = estimateTopHeight(point, estimate);
        continue;
      }

      if (!isValidHeight(point, estimate)) {
        found = false;
        break;
      }
    }

    if (found) {
      console.log(`${estimate.x} ${estimate.y} ${estimate.h}`);
      return;
    }
  }
}

function estimateTopHeight(current, top) {
  return current.h + Math.abs(top.x - current.x) + Math.abs(top.y - current.y);
}

function isValidHeight(current, top) {
  return Math.max(top.h - Math.abs(top.x - current.x) - Math.abs(top.y - current.y), 0) === current.h;
}


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

using namespace std;

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

int main(){
	int a,b,c;
	int u=0,v=0;
	while (scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if (a*a+b*b==c*c){
			u++;
		}
		if (a==b){
			v++;
		}
	}
	printf("%d\n%d\n",u,v);
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<stdio.h>
using namespace std;
int i,x,y,ans;
string a;
int main()
{
	cin>>a;
	for(i=0;i<a.length();i++)
	{
		if(x==y)
		{
			x++;
			if(a[i]=='p') ans--;
		}
		else if(x>y)
		{
			y++;
			if(a[i]=='g') ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string w;
  vector<int> v(23, 0);
  cin >> w;
  for (int i = 0; i < w.size(); i++) {
    v[w[i] - 'a']++;
  }
  for (int i = 0; i < 23; i++) {
    if (v[i] % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
/* ex 7_1
   KitamoriFumiya */
 
#include <stdio.h>
 
// 頂点の構造体を作る
typedef struct point{
	int x_elem;
	int y_elem;
}point;
 
// ある頂点をx軸,y軸について移動させた頂点を返す関数
point shift_point(point move_vertex, point center_vertex){
	point next_vertex; // 移動させた頂点
	next_vertex.x_elem = move_vertex.y_elem - center_vertex.y_elem + center_vertex.x_elem;
	next_vertex.y_elem = -(move_vertex.x_elem - center_vertex.x_elem) + center_vertex.y_elem;
	
	return next_vertex;
}
 
int main(){
	point vertex1, vertex2, vertex3, vertex4;
	// 頂点1,2を入力
	scanf("%d %d %d %d", &vertex1.x_elem, &vertex1.y_elem, &vertex2.x_elem, &vertex2.y_elem);
	// 頂点3を求めて出力（改行せず）
	vertex3 = shift_point(vertex1, vertex2);
	printf("%d %d", vertex3.x_elem, vertex3.y_elem);
	// 頂点4を求めて出力（最後に改行）
	vertex4 = shift_point(vertex2, vertex3);
	printf(" %d %d\n", vertex4.x_elem, vertex4.y_elem);
	
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
class FenWick {
	int idx, N;
	vector<ll> bit;
	public:
	FenWick(int n) {
		N = n;
		bit.resize(N+1,0);
	}
	ll sum(int id) {
		ll ret = 0;
		for(;id>0;id-=(id&(-id))) {
			ret+=bit[id];
		}
		return ret;
	}
	ll sum(int l, int r) {
		return sum(r) - sum(l-1);
	}
	void update(int id, ll val) {
		for(;id<=N;id+=(id&(-id))) {
			bit[id]+=val;
		}
	}
};
struct Query {
		int l, r, idx;
		bool operator<(const Query & rhs) const {
			return r<rhs.r;
		}
};
int main() {
	int N,Q;
	cin>>N>>Q;
	vector<int> vals(N);
	for(auto &i:vals) {
		cin>>i;
	}
	vector<Query> queries(Q);
	for(int i=0;i<Q;i++) {
		cin>>queries[i].l>>queries[i].r;
		queries[i].idx = i;
	}
	sort(queries.begin(),queries.end());
	FenWick bit(N);
	int qno =0;
	vector<int> last(N+10,-1), ans(Q);
	for(int i=1;i<=N;i++) {
		if(last[vals[i-1]]!=-1) {
			bit.update(last[vals[i-1]],-1);
		}
		bit.update(i,1);
		last[vals[i-1]]= i;
		while(queries[qno].r==i && qno<Q) {
			ans[queries[qno].idx] = bit.sum(queries[qno].l, queries[qno].r);
			qno++;
		}
		if(qno > Q) break;
	}
	for(auto it:ans) {
		cout<<it<<"\n";
	}
}


Measured memory_bytes: 19296
#include <iostream>

using namespace std;

int main(){
    int x;
    int a;
    
    for(a = 1;a <= 10000;a++){
        cin >> x;
        
        if(x == 0)break;
        
        cout << "Case "<< a <<": "<< x <<endl;
    }
    return 0;
}


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

long long LCM(long long a, long long b){
  return a / std::__gcd(a, b) * b;
}

int main(){
  int n;
  long long temp;
  long long t[100];

  std::cin >> n;
  for(int i = 0; i < n; i++) std::cin >> t[i];

  temp = t[0];
  for(int i = 0; i < n - 1; i++){
    temp = LCM(temp, t[i+1]);
  }

  std::cout << temp;

  return 0;
}

Measured memory_bytes: 256
l1 = [i for i in range(10)]
l2 = [int(str(c) + str(c)) for c in range(1, 10)]
l3 = [int(str(c1) + str(c2) + str(c1)) for c1 in range(1, 10) for c2 in range(10)]
l4 = [int(str(c1) + str(c2) + str(c2) + str(c1)) for c1 in range(1, 10) for c2 in range(10)]
l5 = [10001]
lst = l1 + l2 + l3 + l4 + l5
n = int(input())
dist = 10 ** 6
ans = -1
for num in lst:
  if abs(num - n) < dist:
    dist = abs(num - n)
    ans = num
  elif abs(num - n) == dist and num < ans:
    ans = num
print(ans)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  string s, t;
  cin >> s >> t;
  vi start(26,-1);
  vi goal(26,-1);
  rep(i,s.size()) {
    int a = s[i] - 'a';
    int b = t[i] - 'a';
    if (start[a] != -1 || goal[b] != -1) {
      if (start[a] != b || goal[b] != a) {
        puts("No");
        return 0;
      }
    }
    else {
      start[a] = b;
      goal[b] = a;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 776
import java.util.Scanner;

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

        int n = sc.nextInt();
        int j;

        for(int i = 1; i <= n; i++){
            if(i % 3 == 0)
                System.out.print(" " + i);
            else{
                j = i;
                while(j != 0){
                    if(j % 10 == 3){
                        System.out.print(" " + i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println();
    }
}



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

const int MAX_N=101;

int N,M,K,p,l;
vector<set<int>> know(MAX_N);
vector<int> victim(MAX_N),ans;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N,N){
        ans.clear();
        for (int i=0;i<N;++i){
            cin >> M; know[i].clear();
            for (int j=0;j<M;++j){
                cin >> p; know[i].insert(p);
            }
        }
        cin >> K;
        for (int i=0;i<K;++i) cin >> victim[i];
        for (int i=0;i<N;++i){
            for (int j=0;j<K;++j){
                if (!know[i].count(victim[j])){
                    break;
                    cout << i+1 << ' ' << victim[j] << endl;
                }
                if (j==K-1) ans.emplace_back(i+1);
            }
        }
        cout << (ans.size()==1?ans[0]:-1) << '\n';
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));


#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(itr, v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

signed main(){
  int N; cin >> N;
  vector<int> x(N);
  REP(i, N) cin >> x.at(i);  

  int sum = 0;
  REP(i, N) {
    sum += x.at(i);
  }

  int ans = 0;
  if (sum % N == 0) {
    dl(31);
    int center = sum / N; 
    REP(i, N) {
      int cost = center - x.at(i);  
      ans += cost * cost; 
    }
  } else {
    dl(38);
    int center1 = ceil((double)sum / N);
    int center2 = floor((double)sum / N);
    int costSum1 = 0;
    int costSum2 = 0;
    REP(i, N) {
      int cost1 = center1 - x.at(i);
      costSum1 += cost1 * cost1; 
      int cost2 = center2 - x.at(i);
      costSum2 += cost2 * cost2; 
    }
    ans = min(costSum1, costSum2);
  }

  cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cnt = 0;

    bool flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1; j > 0; j--){
            if(a[j] < a[j-1]){
                int tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3116
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC=[]
for i in range (0, Q):
    BC.append([int(i) for i in input().split()])

#print(BC)
yoso_count=[]
for i in range(1,10**5+1):
    yoso_count.append([i,0])

sum = 0
for a in A:
    yoso_count[int(a)-1][1] += 1
    sum += a

#print(yoso_count,sum)

for bc in BC:
    sum += (bc[1] - bc[0])*yoso_count[bc[0]-1][1]
    yoso_count[bc[1]-1][1] += yoso_count[bc[0]-1][1]
    yoso_count[bc[0]-1][1] = 0
    print(sum)

Measured memory_bytes: 105856
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,d;
    cin>> n>>d ;

    if(n%(1+d+d)!=0){
        cout<<n/(1+d+d) +1<<endl;
    }
    else {
        cout<<n/(1+d+d) <<endl;
    }

}



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

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        String str = readLineStandardInput();
        int N = Integer.parseInt(str);
        char[] S = str.toCharArray();
        int digitSum = 0;
        for(char s: S){
            int d = Character.getNumericValue(s);
            digitSum += d;
        }
        int mem = N / digitSum;
        if(N == mem * digitSum){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
            System.out.println(e);
        }
        return str;
    }
}

Measured memory_bytes: 19156
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define REP(i,l,r) for(int i=l;i<r;++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int,int> P;
//other libs

signed main(int argc, char * argv[]) {
	int n,q;
	cin>>n>>q;
	vector<vector<int>> edge(n+1);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	vector<int> memo(n+1);
	fill(memo.begin(),memo.end(),0);
	rep(i,q){
		int p,x;
		cin>>p>>x;
		memo[p]+=x;
	}
	vector<bool> bo(n+1);
	fill(bo.begin(),bo.end(),false);
	queue<int> que;
	que.push(1);
	bo[1]=true;
	while(!que.empty()){
		int now=que.front();que.pop();
		rep(i,edge[now].size()){
			int ne = edge[now][i];
			if(!bo[ne]){
				memo[ne]+=memo[now];
				que.push(ne);
				bo[ne]=true;
			}
		}
	}
	rep(i,n){
		cout<<memo[i+1];
		if(i+1!=n)cout<<" ";
		else cout<<endl;
	}
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define arr array

template<typename T> void umin(T& a,T b){a = min(a,b);}
template<typename T> void umax(T& a,T b){a = max(a,b);}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e18+5;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

void pre(){


    
}

void solve(){

    int x;
    cin >> x;
    if(x==0){
        cout << 1;
    }      else{
        cout << 0;
    }

}

int32_t main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	int N, mxm = 0;
    ll res = 0;
    cin >> N >> mxm;
    for (int i = 1; i < N; ++i){
        int a;
        cin >> a;
        if (mxm > a){
            res += mxm - a;
        } else {
            mxm = a;
        }
    }

    cout << res << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void){

    int a, b, i=0, count1=0, count2=0;
    scanf("%d",&a);

    while(i<a){
        scanf("%d",&b);

        if(b%2==0){
            count2++;
        }

        if(b%2==0 && b%3==0){
            count1++;
        }else if(b%2==0 && b%5==0){
            count1++;
        }
        i++;
    }

    if(count1 == count2){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }

    return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <sstream>
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[])
{
    int n, a, b;
    string s;
    std::cin >> n >> a >> b >> s;
    int tuuka = 0;
    int kaigai = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (tuuka+1 <= a+b) {
                tuuka++;
                std::cout << "Yes" << std::endl;
            } else {
                std::cout << "No" << std::endl;
            }
        } 
        else if (s[i] == 'b') {
            if (tuuka+1 <= a+b && kaigai+1 <= b) {
                tuuka++;
                kaigai++;
                std::cout << "Yes" << std::endl;
            } else {
                std::cout << "No" << std::endl;
            }
        } else {
            std::cout << "No" << std::endl;
        }
       //std::cout << "tuuka : " << tuuka << std::endl;
    }
    return 0;
}

Measured memory_bytes: 896
def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = {}
    for i,a in enumerate(A):
        d[a]=i
    for i in range(1,N+1):
        print(d[i]+1,end=" ")
    print()

if __name__=='__main__':
    main()


Measured memory_bytes: 19700
#include<stdio.h>
#include<string.h>
int a[5];
int main()
{
    int p,q,r,i,j,mmin,mmax;
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
    }
     for(i=0;i<3;i++)
    {
       for(j=i+1;j<=3;j++)
       {
           if(a[i]>a[j])
           {
               int temp=a[i];
               a[i]=a[j];
               a[j]=temp;
           }
       }
    }
        printf("%d\n",a[1]+a[2]);
    return 0;
}


Measured memory_bytes: 128
#[allow(dead_code)]
fn main() {
    let (n, m, q) = i::u3();
    let abcd = i::uv4(q);

    println!("{}", search(Vec::new(), &abcd, n, m));
}

fn search(
    current: Vec<usize>,
    abcd: &Vec<(usize, usize, usize, usize)>,
    n: usize,
    m: usize,
) -> usize {
    if current.len() == n {
        let mut score = 0;
        for (a, b, c, d) in abcd {
            if current[*b - 1] - current[*a - 1] == *c {
                score += *d;
            }
        }
        return score;
    }
    let mut ans = Vec::new();
    for i in 1..=m {
        let last = if current.len() > 0 {
            current[current.len() - 1]
        } else {
            0
        };
        if last <= i {
            let mut v = current.clone();
            v.push(i);
            ans.push(search(v, abcd, n, m))
        }
    }
    return *ans.iter().max().unwrap();
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }
    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
char c[100003];
int n,ans,l,r;
int main()
{
  scanf("%s",c);
  l=0;
  r=strlen(c)-1;
  while (l<=r)
  {
    if (c[l]==c[r])
    {
      l++;
      r--;
      continue;
    }
    if (c[l]=='x')
    {
      l++;
      ans++;
      continue;
    }
    if (c[r]=='x')
    {
      r--;
      ans++;
      continue;
    }
    printf("-1\n");
    return 0;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int res = abs(x - a[0]);
    rep(i, n){
        res = GCD(res, abs(x - a[i]));
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Unionfind
struct UF {
	vector<int> p;
	UF() = default;
	explicit UF(int n) : p(n + 1, -1) { p.back() = n; }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		p[y] = x;
		p.back()--;
		return true;
	}
	int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -p[find(x)]; }
	int count() { return p.back(); }
};

void _main() {
    int N, M;
    cin >> N >> M;
    UF uf(N);
    REP (i, M) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        X--; Y--;
        uf.unite(X, Y);
    }
    cout << uf.count() << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

class Dice{
public:
     //  コンストラクタ
     Dice();
     //  デストラクタ
     ~Dice();
     //  メソッド
     int east();
     int west();
     int south();
     int north();
     int side();
     void set(int sai[6]);
     int look(int men);
private:
     int me[7];
};

//  コンストラクタ
Dice::Dice()
{
}
//  デストラクタ
Dice::~Dice()
{
}
void Dice::set(int sai[6])
{
    int i;
    for(i = 0;i<6; i++) {
//        cout << sai[i] << endl;
        me[i+1] = sai[i];
    }
}
int Dice::east()
{
    int tmp = me[4];
    me[4] = me[6];
    me[6] = me[3];
    me[3] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::west()
{
    int tmp = me[3];
    me[3] = me[6];
    me[6] = me[4];
    me[4] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::south()
{
    int tmp     = me[5];
    me[5] = me[6];
    me[6] = me[2];
    me[2] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::north()
{
    int tmp     = me[2];
    me[2] = me[6];
    me[6] = me[5];
    me[5] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::side()
{
    int tmp     = me[3];
    me[3] = me[5];
    me[5] = me[4];
    me[4] = me[2];
    me[2] = tmp;
    return(tmp);
}
int Dice::look(int men)
{
    return(me[men]);
}
int main() {
    int sai[6];
    int i, l, n, t, f, flg=1;
    char c;
    for(i =0; i < 6; i++){
        cin >> l;
        sai[i] = l;
    }
    Dice d;
    d.set(sai);
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> t >> f;
        for (l = 0; l < 3; l++) {
            if (t == d.east())  break;
            if (t == d.north()) break;
        }
//        cout <<  d.look(1) << "  ";
        l = d.look(2);
        while (l != f) {
            l = d.side();
        }
//        cout <<  d.look(2) << "  ";
        cout <<  d.look(3) << endl;
    }
    return 0;
}



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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, bool>> a(n, make_pair(0, false)); 
    rep (i, m) {
        int p;
        string str;
        cin >> p >> str;
        p--;
        if (get<1>(a.at(p)) == false && str == "WA") get<0>(a.at(p))++;
        if (get<1>(a.at(p)) == false && str == "AC") get<1>(a.at(p)) = true;
    }
    int ac = 0;
    int penal = 0;
    rep(i, n) {
        
        if (get<1>(a.at(i)) == true) {
            penal += get<0>(a.at(i));
            ac++;
        }
    }
    cout << ac << " " << penal << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

llong xor128() {
    static llong x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    llong t;

    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;

    return( w = (w^(w>>19)) ^ (t^(t>>8)) );
}

int main() {
  llong N;
  vector<llong> A, B;
  map<llong, llong> used;
  
  cin >> N;
  A.resize(N);
  B.resize(N);
  for (auto &in: A) {
    cin >> in;
    used[in]++;
  }
  for (auto &in: B) {
    cin >> in;
    used[in]++;
  }

  llong res = 0;
  for (auto it: used) {
    res = max(res, it.second);
  }

  if (res > N) {
    cout << "No\n";
  }
  else {
    queue<llong> same;
    for (int i = 0; i < N; i++) {
      if (A[i] == B[i]) {
        same.push(i);
      }
    }

    while (same.size() > 0) {
      llong now = same.front();
      same.pop();
      llong next = xor128() % N;
      if (A[now] != B[next] && A[next] != B[now]) {
        swap(B[next], B[now]);
      }
      else {
        same.push(now);
      }
    }

    cout << "Yes" << endl;
    for (int i = 0; i < N; i++) {
      cout << B[i] << " \n"[i == N - 1];
    }
  }

  return 0;
}

Measured memory_bytes: 20280
from heapq import heappush, heappop

N, M = map(int, input().split())
job = []

for i in range(N):
  a, b = map(int, input().split())
  job += [(a,b)]
job.sort(key=lambda x:x[0])
ls = []
ans = 0
j = 0
a = -1
for i in range(1,M+1):
  while a<=i and j<len(job):
    a, b = job[j]
    if a>i:
      break
    heappush(ls, -b)
    j += 1
  if ls:
    x = (-1)*heappop(ls)
#    print(x, i)
    ans += x
print(ans)

Measured memory_bytes: 20428
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vi a(n);
  for (int& ai: a) cin >> ai;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      ans += a[i - 1] - a[i];
    }
    a[i] = max(a[i], a[i - 1]);
  }
  cout << ans << '\n';
  return (0);
}


Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
using namespace std;
int a[1<<17],t,d,l;
main()
{
	while(cin>>t>>d>>l,t)
	{
		for(int i=0;i<t;i++)
		{
			int x;cin>>x;
			a[i]=x<l?0:d;
		}
		int ans=0;
		for(int i=0;i<t-1;i++)
		{
			ans+=!!a[i];
			a[i+1]=max(a[i+1],a[i]-1);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3488
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a;
    int po=0;
    while((cin>>a)!=0){
    	if(po==a[0]-65){po=a[2]-65;}
	else if(po==a[2]-65){po=a[0]-65;}	
    }
    cout<<char(65+po)<<endl;
}

Measured memory_bytes: 0
<?php
  fscanf(STDIN, "%s %s", $s,$t);
  fscanf(STDIN, "%d %d", $a,$b);
  fscanf(STDIN, "%s", $u);
 if($s == $u){
   $a =$a-1;
   echo $a ." ". $b;
 }else{
      $b =$b-1;
   echo $a ." ". $b;
 }
?>

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

using namespace std;
const int V = 1e5 + 5;
vector<int> to[V*2];
bool visited[V*2];

vector<int> cnt;
void dfs(int v) {
  if (visited[v]) return;
  visited[v] = true;
  cnt[v/V]++;
  for (int u: to[v]) dfs(u);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  long long ans = 0;
  for (int i = 0; i < V * 2; ++i) {
    if (visited[i]) continue;
    cnt = vector<int>(2);
    dfs(i);
    ans += (long long)cnt[0] * cnt[1];
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll q,x,f,cnt=0;
	char c;
	string s,h="",t="";
	cin >> s >> q;
	rep(i,q){
		cin >> x;
		if(x==1) cnt++;
		else{
			cin >> f >> c;
			if(f==1){
				if(cnt%2==0) h+=c;
				else t+=c;
			}
			else{
				if(cnt%2==0) t+=c;
				else h+=c;
			}
		}
	}
	reverse(all(h));
	string ans=h+s+t;
	if(cnt%2==1) reverse(all(ans));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70,M=2e17,i,a,b;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}for(L i;i<2;i++){L c=0;for(W x:T[!i])c^=(2*x[0]+x[1])%3+1;if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;W A=S(p);A[0]--;return A;}int main(){cin>>i;V<W>p(i);while(i--){cin>>a>>b;p[i]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
while True:
    n,x=[int(i) for i in input().split()]
    if n==x==0:
        break
    c = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if (i+j+n >= x):
                for k in range(j+1,n+1):
                    if(i+j+k == x):
                        c+=1
                        break

    print(c)

Measured memory_bytes: 7724
#include <iostream>
using namespace std;
int main() {
	int n, a, b, c, d, cnt = 0;
	while (cin >> n) {
		cnt = 0;
		for (a = 0; a < 10 && a <= n; a++) {
			for (b = 0; b < 10 && b <= n; b++) {
				for (c = 0; c < 10 && c <= n; c++) {
					for (d = 0; d < 10 && d <= n; d++) {
						if (a + b + c + d == n) {
							cnt++;
							//break;
						}
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3056
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

int main()
{
	/*int n,k;
	cin >> n;
	vector<char>s(n);
	for (int j = 0; j < n; j++)  cin >> s[j];
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		if (s[i] != s[k-1]) {
			s[i] = '*';
		}
	}

	for (int l = 0; l < n; l++)
	{
		cout << s[l] ;
	}*/
	
	int n;
	cin >>n ;
	double sum=0;

	vector<double>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];

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

	sum = (a[0] + a[1])/2;
	
	for (int i = 2; i < n; i++) {
		sum = (sum + a[i])/2;
	}

	cout << sum<<endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main() {
  string s;
  cin>>s;
  ll n=s.size();
  ll ans=n*(n-1)/2+1;
  
  vector<ll> vec(26);
  rep(i,0,n){
    vec[s[i]-'a']++;
  }
  
  rep(i,0,26){
    ans-=vec[i]*(vec[i]-1)/2;
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 640
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n, w;
	cin >> n >> w;
	ll wi[n], vi[n], sum = 0;
	loop(i, n)	cin >> wi[i] >> vi[i] , sum += vi[i];
	vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, inf));
	loop(i, n + 1)	dp[i][0] = 0;
	FOR(i, 1, n)
	{
		FOR(j, 1, sum)
		{
			if (vi[i - 1] <= j)
			{
				dp[i][j] = min(dp[i - 1][j - vi[i - 1]] + wi[i - 1], dp[i - 1][j]);
			}
			else
			{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	// loop(i, n)
	// {
	// 	FOR(j, 0, sum)
	// 	{
	// 		if (dp[i][j] == inf)
	// 			cout << "INF ";
	// 		else
	// 			cout << dp[i][j] << " ";
	// 	}
	// 	cout << END;
	// }
	ll maxval = -inf;
	FOR(j, 0, sum)
	{
		if (dp[n][j] <= w)
			maxval = max(maxval, j);
	}
	cout << maxval << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}


Measured memory_bytes: 80256
input_num = input().split()
W,H,x,y,r = [int(n) for n in input_num]
# 0<=x<=(W-r),0<=y<=(H-r)
if (r<=x)&(x<=(W-r))&(r<=y)&(y<=(H-r)):
    print("Yes")
else:
    print("No")


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

using namespace std;

// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


#define debug(x) cout << #x << "==" << x << endl;

const int mod = 1e+9 + 7;

typedef long long ll;



int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  if( N == 1) {
    cout << 1 << "\n";
    return 0;
  }




  int li = 0, ri =0 ;
  int res = 0;
  int prev = a[li];
  while( li < N and ri < N and li <= ri ) {


    while( ri < N and a[li] == a[ri] ) {
      ri++;
    }

    if( ri >= N ) {
      res++;
      break;
    }

    bool up = (a[li] < a[ri]);

    int prev = a[li];


    while( ri < N and up and prev <= a[ri] ) {
      prev = a[ri];
      ri++;
    }

    while( ri < N and !up and prev >= a[ri] ) {
      prev = a[ri];
      ri++;
    }

    res++;
    li = ri;

  }

  cout << res;
  return 0;
}


Measured memory_bytes: 640