akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

const int INF = 1e+8;
// 入力
int HP, w, h;
// a[y][x] := (x,y)のグリッドの状態(文字'A' - 'Z')
vector<string> a;
// D[c] := 文字 c に対応する受けるダメージ数
int D[256] = {0};

// f[c] := 文字 c ('U','D','L','R') に対応する向き 0..3 を返す.
int f[256] = {0};
// 4近傍
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
// dp[k][bits] := k 回目の移動で現在の使ったポーションの状態 bits のときの最大の残り HP
int dp[1001][1<<12];

int main(){
	f['U'] = 0; f['D'] = 1; f['L'] = 2; f['R'] = 3;
	int hp;
	
	while( cin >> hp >> HP, hp || HP ){
		cin >> h >> w;
		a = vector<string>(h);
		for(int y=0 ; y < h ; y++ ){
			cin >> a[y];
		}
		int T, S, P;
		cin >> T;
		for(int i=0 ; i < T ; i++ ){
			char c;
			int d;
			cin >> c >> d;
			D[c] = d;
		}
		cin >> S;
		// path[k] := k 回目の移動する方向
		vector<int> path;
		for(int i=0 ; i < S ; i++ ){
			char dir;
			int n;
			cin >> dir >> n;
			for(int j=0 ; j < n ; j++ ){
				path.push_back( f[dir] );
			}
		}
		cin >> P;
		vector<int> p(P);
		for(int i=0 ; i < P ; i++ ){
			cin >> p[i];
		}
		// 各ステップで何ダメージ受けるか計算
		vector<int> damege;
		int x=0, y=0;
		damege.push_back(0);
		for(int i=0 ; i < path.size() ; i++ ){
			x += dx[path[i]];
			y += dy[path[i]];
			damege.push_back( D[a[y][x]] );
		}
		
		// dp の初期化
		int N = path.size() + 1;
		for(int i=0 ; i < N ; i++ ){
			for(int j=0 ; j < (1<<P) ; j++ ){
				dp[i][j] = 0;
			}
		}
		dp[0][0] = hp;
		
		for(int i=0 ; i < N ; i++ ){
			for(int j = 0 ; j < (1<<P) ; j++ ){
				if( i > 0 ){ // i 回目の移動で受けたダメージを計算
					dp[i][j] = max(dp[i][j], dp[i-1][j] - damege[i]);
				}
				// HP が 0 以下のときは終了
				if( dp[i][j] <= 0 ) continue;
				
				for(int k=0 ; k < P ; k++ ){
					if( j & (1<<k) ) continue;
					
					// p[k] のポーションを使う
					int next = j | (1<<k);
					dp[i][next] = min(HP, max(dp[i][next], dp[i][j] + p[k]));
				}
			}
		}
		int ans = 0;
		for(int i=0 ; i < (1<<P) ; i++ ){
			ans = max(ans, dp[N-1][i]);
		}
		cout << (ans? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 17272
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
static const ll max_n = 200010;
static const ll mod = 1000000007;
// static const ll max_dist = 10000000;
// vector<vector<ll>> distance_table(max_n, vector<ll>(max_n, max_dist));
// vector<ll> distance_list(max_n);
vector<ll> combination_table(max_n, 0);
vector<ll> value_num(max_n, 0);
vector<ll> combination_minus1_table(max_n, 0);
vector<ll> balls(max_n);

ll N, K;

ll this_num(ll this_k){
    ll m1 = this_k * N % mod;
    ll m2 = ((this_k - 1) * this_k / 2) % mod;
    m2 = (m2 * 2) %mod;
    return (m1 - m2 + 1) % mod;
}


int main(){
    // int u, v;
    // bool updated = alse;
    scanf("%lld %lld", &N, &K);

    ll ans = 0;
    for(ll i=K;i<=N+1;i++){
        ll this_sum = this_num(i);
        // printf("i=%lld, sum = %lld\n", i, this_sum);
        ans += this_sum;
        ans %= mod;
    }

    printf("%lld\n", ans);

    return 0;

}

Measured memory_bytes: 8968
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int x1 = Integer.parseInt(sc.next());
    int y1 = Integer.parseInt(sc.next());
    int x2 = Integer.parseInt(sc.next());
    int y2 = Integer.parseInt(sc.next());
    
    int sx = x2-x1;
    int sy = y2-y1;
    
    int x3 = x2-sy;
    int y3 = y2+sx;
    int x4 = x1-sy;
    int y4 = y1+sx;
    
    System.out.println(x3+" "+y3+" "+x4+" "+y4);
  }
}

Measured memory_bytes: 22100
N,T=map(int,input().split())
A=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append((a,b))
A=sorted(A)
dp=[[0]*(T) for j in range(N)]
#print(A)

for i in range(N):
  for j in range(T):
    if j>=A[i][0]:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-A[i][0]]+A[i][1])
    else:
      dp[i][j]=dp[i-1][j]
#print(dp)
bma=[0]
t=0
for i in range(N-1,0,-1):
  t=max(t,A[i][1])
  bma=[t]+bma
#print(bma)
ans=0
for i in range(N):
  d=dp[i][-1]+bma[i]
  ans=max(d,ans)
print(ans)

Measured memory_bytes: 145648
import sys
sys.setrecursionlimit(10**6)

n = int(input())
edges = [[] for i in range(2*10**5)]
for i in range(n):
    xi, yi = map(int, input().split())
    xi -= 1
    yi = yi - 1 + 10**5
    edges[xi].append(yi)
    edges[yi].append(xi)

already = set([])
def dfs(x, y, node):
    if node in already:
        return x, y
    if node < 10**5:
        x += 1
    else:
        y += 1
    already.add(node)
    for next_node in edges[node]:
        x, y = dfs(x, y, next_node)
    return x, y

num = 0
for i in range(10**5):
    x, y = dfs(0, 0, i)
    num += x * y
print(num-n)

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

struct Node{//binary tree's node
    int key;
    Node *parent, *left, *right;
};

Node *root, *NUL;

void insert(int node){
    //Now Searching...
    Node *nowNode = root;//start with root
    Node *nowParent = NUL;//root node's parent node is NULL
    while(nowNode!=NUL){
        if(nowNode->key<node){
            nowParent = nowNode;
            nowNode = nowParent -> right;
        }else{
            nowParent = nowNode;
            nowNode = nowNode -> left;
        }
    }
    //Now Creating new Node
    Node *newNode = new Node();
    newNode->key = node;
    newNode->left = newNode->right = NUL;
    //Now Inserting
    if(nowParent==NUL){//empty tree's root node
        root = newNode;
    }else if(node<nowParent->key){
        nowParent->left = newNode;
    }else{
        nowParent->right = newNode;
    }
}

void preOrder(Node *nowNode){
    if(nowNode==NUL) return;
    cout<<" "<<nowNode->key;
    preOrder(nowNode->left);
    preOrder(nowNode->right);
}

void inOrder(Node *nowNode){
    if(nowNode==NUL) return;
    inOrder(nowNode->left);
    cout<<" "<<nowNode->key;
    inOrder(nowNode->right);
}

int main(){
    root = NUL;//initial root
    int ope;
    cin>>ope;
    for(int i=0; i<ope; i++){
        string op;
        cin>>op;
        if(op=="print"){
            inOrder(root);
            cout<<endl;
            preOrder(root);
            cout<<endl;
        }else{
            int toInsert;
            cin>>toInsert;
            insert(toInsert);
        }
    }
    return 0;
}



Measured memory_bytes: 26660
dataset = []
wayset = []

while True:
    n, x = input().split()    
    n = int(n)
    x = int(x)
    if n == x == 0:
        break
    dataset.append([n, x])

for x in dataset:
    ways = 0
    for i in range(x[0]):
        for j in range(x[0]):
            for k in range(x[0]):
                if k > j and j > i:
                    if i + j + k + 3 == x[1]:
                        ways += 1
    wayset.append(ways)

for x in wayset:
    print(x)

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

using namespace std;

typedef long long ll;

int n, m, A[100010];

ll X[100010];

void add(int x, int y, int v, int s)
{
	X[x] += v, X[y + 2] += v + s * (y - x);
	X[x + 1] -= v - s, X[y + 1] -= v + s * (y - x + 1);
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &A[i]);
	for(int i = 1; i < n; i++) {
		int a = A[i + 1], s = A[i] <= a ? a - A[i] : a - A[i] + m;
		if(a - s < 1) {
			add(a + 1, a - s + m, s, 0);
			add(a - s + m + 1, m, s, -1);
			add(1, a, a, -1);
		} else {
			add(a + 1, m, s, 0);
			add(1, a - s, s, 0);
			add(a - s + 1, a, s, -1);
		}
		/*if(a + s <= m && a - s >= 1) {
			add(a, a + s - 1, 1, 1);
			add(a + s, m, s, 0);
			add(1, a - s, s, 0);
			add(a - s + 1, a - 1, s, -1);
		} else if(a + s > m && a - s >= 1) {
			add(a, m, 1, 1);
			add(1, a + s - m - 1, m + 1 - a + 1, 1);
			add(a + s - m, a - s, s, 0);
			add(a - s + 1, a - 1, s, -1);
		} else {
			add(a, a + s - 1, 1, 1);
			add(a + s, a - s + m, s, 0);
			add(a - s + m + 1, m, s, -1);
			add(1, a - 1, a - 1, 1);
		}*/
	}
	ll mn = 1e18;
	for(int i = 1; i <= m; i++) X[i] += X[i - 1];
	for(int i = 1; i <= m; i++) mn = min(mn, X[i] += X[i - 1]);
	return printf("%lld\n", mn), 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>ar[i];
    int c=0;
    for(int i=0,j=1; i<n; i++)
    {
        if(ar[i]==j)
        {
            j++;
        }
        else
            c++;
    }
    if(c==n)
        cout<<-1<<endl;
    else
        cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;

ll m;

void printmat(M a) {
    loop (MSIZE, i) {
        loop (MSIZE, j) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

M matmul(M a, M b) {
    M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
    loop (MSIZE, i) loop (MSIZE, j) {
        loop (MSIZE, s) {
            ret[i][j] += a[i][s] * b[s][j] % m;
            ret[i][j] %= m;
        }
    }
    return ret;
}

int main() {
    ll l, a, b; cin >> l >> a >> b >> m;
    ll crr = a;

    ll x = 0, s = a % m;

    loop1 (18, d) {
        ll last = 1;
        loop (d, i) last *= 10;
        last--;
        last = min(last, a + b * (l - 1));
        if (last < crr) continue;
        ll c = (last - crr) / b + 1;
        crr += b * c;

        ll shift = 1;
        loop (d, i) shift = (shift * 10) % m;
        M base = {
            { shift, 0, 0 },
            { 1, 1, 0 },
            { 0, b % m, 1 }
        };
        M mat = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };

        while (c) {
            if (c % 2) mat = matmul(mat, base);
            base = matmul(base, base);
            c /= 2;
        }

        ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
        ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
        x = nx, s = ns;
    }

    cout << x << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool d = b-a == c-b;
    cout << (d?"YES":"NO") << '\n';
}


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

def check(dollars):
    for cakes in range(0, int(dollars / 4) + 1):
        for doughnuts in range(0, int(dollars / 7) + 1):
            sum = 4 * cakes + 7 * doughnuts
            # print("{}, {}, {}, {}".format(cakes, doughnuts, sum, sum == dollars))
            if sum == dollars:
                return "Yes"
    return "No"

dollars = int(input())
print(check(dollars))

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

int main()
{
	int n;
	cin >> n;
	auto a = vector<int>(n);
	auto b = a, c = a, d = a;
	for(auto i = 0; i < n; ++i){
		cin >> a[i] >> b[i];
	}
	for(auto i = 0; i < n; ++i){
		cin >> c[i] >> d[i];
	}
	auto g = vector<vector<int>>(n * 2);
	for(auto i = 0; i < n; ++i){
		for(auto j = 0; j < n; ++j){
			if(a[i] < c[j] && b[i] < d[j]){
				g[i].push_back(n + j);
				g[n + j].push_back(i);
			}
		}
	}
	auto m = vector<int>(n * 2, -1);
	auto bipartite = [&g, &m](auto bipartite, int a, vector<bool>& visited) -> bool {
		for(auto i = 0; i < (int)g[a].size(); ++i){
			int e = g[a][i];
			if(visited[e]) continue;
			if(m[e] == -1){
				m[a] = e;
				m[e] = a;
				return true;
			}else{
				visited[e] = true;
				if(bipartite(bipartite, m[e], visited)){
					m[a] = e;
					m[e] = a;
					return true;
				}
			}
		}
		return false;
	};
	int ans = 0;
	for(auto i = 0; i < n; ++i){
		auto v = vector<bool>(n * 2);
		if(bipartite(bipartite, i, v)) ++ans;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  string s;
  cin >> s;
  int n = s.size();

  vi last_r(n), last_l(n);
  rep (i, n) {
    if (s[i] == 'R') {
      last_r[i] = i;
    }
    else {
      last_r[i] = last_r[i - 1];
    }
  }

  rrep (i, n) {
    if (s[i] == 'L') {
      last_l[i] = i;
    }
    else {
      last_l[i] = last_l[i + 1];
    }
  }

  vi num(n);
  rep (i, n) {
    int cnt = 1000000;
    if (s[i] == 'L') {
      cnt -= last_r[i] - i;
      int now = last_r[i];
      if (cnt % 2 == 0) {
        num[now]++;
      }
      else {
        num[now + 1]++;
      }
    }
    else {
      cnt -= last_l[i] - i;
      int now = last_l[i];
      if (cnt % 2 == 0) {
        num[now]++;
      }
      else {
        num[now - 1]++;
      }
    }
    //DEBUG_VEC(num);
  }
  rep (i, n) {
    cout << num[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1792
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 10**9+7
for i in range(x[0], x[n-1]+1):
    res = []
    for j in range(n):
        res.append((i-x[j])**2)
    ans = min(sum(res), ans)
print(ans)

Measured memory_bytes: 3060
function main(arg) {
	arg = arg.split("\n")[0]
	arg = arg.split("")

	var near_n = -1
	var thresh = 753

	for (var i = 0;i < arg.length -2; i++) {
		var num = String(arg[i]) + String(arg[i+1]) + String(arg[i+2])
		num = Number(num)

		if (i === 0) {
			near_n = Math.abs(thresh - num)
			continue
		}

		var tmp = Math.abs(thresh - num)

		if (tmp < near_n) {
			near_n = tmp
		}
	}
	console.log(near_n)

	
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]


F = [[0]*c for _ in range(r)]

for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
  
for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3],0)

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)]

best = 0


for k in range(4):
  best = max(best, dp[0][c-1][k])
    
print(best)

Measured memory_bytes: 207612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        System.out.println((int)Math.pow(sc.nextInt(), 3));
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader(InputStream x) {
            br = new BufferedReader(new
                    InputStreamReader(x));

        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 20820
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define pause

#ifdef _DEBUG
#define puase system("pause");
#endif

int main() {
	int n, m;
	cin >> n;
	vector<int> v(n);
	map<int, int> mp;
	for (auto & x : v)
		cin >> x;
	for (auto & x : v) {
		mp[x]++;
		mp[x - 1]++;
		mp[x + 1]++;
	}

	int mx = 0;

	for (auto & p : mp) {
		mx = max(mx, p.second);
	}
	cout << mx << endl;
	pause return 0;
}
/*
7
3 1 4 1 5 9 2
*/

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

int	main() {
	string S;
	cin >>S;
	for (int i=0; i<S.size(); i++) {
		if (0==i%2) {
			if ('L'==S.at(i)) {
				cout <<"No" <<endl;
				return 0;
			}
		} else {
			if ('R'==S.at(i)) {
				cout <<"No" <<endl;
				return 0;
			}
		}
	}
	cout <<"Yes" <<endl;
	return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int n;
int h[100010];
int f[100010];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
		f[i]=1e9;
	}
	f[1]=0;
	f[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++)
	{
		f[i]=min(f[i-1]+abs(h[i-1]-h[i]),f[i-2]+abs(h[i-2]-h[i]));
	}
	printf("%d",f[n]);
	return 0;
}





Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sp = new String[2];
        try {
            int n = Integer.parseInt(br.readLine());
            for (int i = 0; i < n; i++) {
                sp = br.readLine().split(" ");
                if (sp[0].equals("insert")) {
                    list.addFirst(sp[1]);
                } else if (sp[0].equals("delete")) {
                    list.remove(sp[1]);
                } else if (sp[0].equals("deleteFirst")) {
                    list.removeFirst();
                } else if (sp[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            if (!list.isEmpty()) {
                ans.append(list.getFirst());
                list.removeFirst();
            }
            while (!list.isEmpty()) {
                ans.append(" ").append(list.getFirst());
                list.removeFirst();
            }
            System.out.println(ans.toString());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 230492
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i : irange(0, n, 2)) {
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long ans = 0;
    if (a >= k)
    {
        ans = k;
    }
    else if (a + b >= k)
    {
        ans = a;
    }
    else
    {
        k -= a + b;
        ans = a - k;
    }

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
//void ckmax(int &x,int y){
//	if (x<y)
//		x=y;
//}
//void ckmin(int &x,int y){
//	if (x>y)
//		x=y;
//}
const int N=200005;
const int INF=1e9;
int n,m;
int D[N];
vector <pii> e[N];
int tp[N],weight[N];
int inq[N],vis[N];
int main(){
	n=read(),m=read();
	For(i,1,n)
		D[i]=read();
	For(i,1,m){
		int x=read(),y=read();
		e[x].pb(mp(y,i));
		e[y].pb(mp(x,i));
		weight[i]=INF;
	}
	vi v(n);
	iota(v.begin(),v.end(),1);
	sort(v.begin(),v.end(),[&](int a,int b){
		return D[a]<D[b];
	});
	for (auto x : v){
		inq[x]=1;
		for (auto E : e[x]){
			int y=E.fi;
			if (!inq[y])
				continue;
			if (vis[y]){
				if (!vis[x]){
					vis[x]=1,tp[x]=tp[y]^1;
					weight[E.se]=D[x];
				}
			}
			else {
				if (D[y]!=D[x])
					return puts("-1"),0;
				vis[x]=vis[y]=1;
				tp[y]=tp[x]^1;
				weight[E.se]=D[x];
			}
		}
	}
	For(i,1,n)
		if (!vis[i])
			return puts("-1"),0;
	For(i,1,n)
		putchar(tp[i]?'W':'B');
	puts("");
	For(i,1,m)
		printf("%d\n",weight[i]);
	return 0;
}

Measured memory_bytes: 16368
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;

    int N = s.size(), ans = 0;
    for(int i=0; i<N; i++) {
        int x = i, y = N - 1 - i;
        if(x > y) break;
        ans += (s[x] != s[y]);
    }

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


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

int main()
{
    int a,c=0,n,b;
    
    cin >> n >> b;
    
    while(n--)
    {
        cin >> a;
        if(a>=b)c++;
    }
    cout << c << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int n,d,x;
   scanf("%d %d %d",&n,&d,&x);
   
   int choco[n];
   int i,j;
   int count=0;
   
   for(i=0;i<n;i++){
       scanf("%d",&choco[i]);
       for(j=0;j<d;j++){
           if(j*choco[i]<d){
               count++;
           }
       }   
       
   }
   
   printf("%d\n",count+x);
   
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n; cin >> n;
	cout << (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
s = gets.chomp

def mm?(i)
  1 <= i && i <= 12
end

s1 = s[0,2].to_i
s2 = s[2,2].to_i

if mm?(s1)
  if mm?(s2)
    puts 'AMBIGUOUS'
  else
    puts 'MMYY'
  end
else
  if mm?(s2)
    puts 'YYMM'
  else
    puts 'NA'
  end
end


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

int main()
{
	int n,m;
	int k,*a,t;
	int i,j;

	scanf("%d%d",&n,&m);
	a=(int*)malloc(m*sizeof(int));
	for(i=0;i<m;i++) a[i]=0;

	for(i=0;i<n;i++)
	{
		scanf("%d",&k);
		for(j=0;j<k;j++)
		{
			scanf("%d",&t);
			a[t-1]++;
		}
	}

	for(i=0,j=0;i<m;i++)
	{
		if(a[i]==n)
			j++;
	}
	printf("%d\n",j);
	free(a);
	return 0;
}

Measured memory_bytes: 128
import numpy as np

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))

# グループ内（初項）
a = 0
for i in range(n - 1):
    a += np.where(arr[i + 1:] < arr[i])[0].shape[0]

# グループ間（差）
d = 0
for i in range(n):
    d += np.where(arr < arr[i])[0].shape[0]

mod = 10**9 + 7

ans = (a + a + d * (k - 1)) * k // 2 % mod

print(ans)

Measured memory_bytes: 12488
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(N == 4){
			Console.WriteLine("2 3");
			return;
		}
		
		int MM = (N - 1) / 2;
		List<int> L = new List<int>();
		List<int> R = new List<int>();
		if(N % 2 == 1){
			int l = 1, r = (N + 1) / 2;
			while(r > l){
				L.Add(l);
				R.Add(r);
				l++;
				r--;
			}
			l = (N + 1) / 2 + 1; r = N;
			while(r > l){
				L.Add(l);
				R.Add(r);
				l++;
				r--;
			}
		} else {
			int l = 1, r = (N - 2) / 2;
			while(r > l){
				L.Add(l);
				R.Add(r);
				l++;
				r--;
			}
			l = (N - 2) / 2 + 1; r = N - 1;
			while(r > l){
				L.Add(l);
				R.Add(r);
				l++;
				r--;
			}
		}
		
		var sb = new StringBuilder();
		for(int i=0;i<M;i++){
			sb.AppendLine(String.Format("{0} {1}",L[i], R[i]));
		}
		Console.Write(sb.ToString());
		
		
		
		
	}
	int N,M;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, v[max], c[max];
    int ans=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &v[i]);
    }
    rep(i, n){
        scanf("%d", &c[i]);
    }
    
    rep(i, n){
        if (v[i]>=c[i]) {
            ans+=(v[i]-c[i]);
        }
    }
    
    printf("%d", ans);
    
    return 0;
}


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

int main(){
  int n,k,r,s,p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  
  int i,a=0;
  for(i=0;i<k;i++){
    if(t.at(i)=='r'){
      a += p;
    }else if(t.at(i)=='s'){
      a += r;
    }else{
      a += s;
    }
  }
  
  for(i=k;i<n;i++){
    if(t.at(i)!=t.at(i-k)){
      if(t.at(i)=='r'){
        a += p;
      }else if(t.at(i)=='s'){
        a += r;
      }else{
        a += s;
      }
    }else{
      t.at(i)='n';
    }
  }
  
  cout << a << endl;
}

Measured memory_bytes: 3744
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i64,
        l: i64,
    }
    let mut ans = 0;

    if l >= 0 {
        for i in 1..n {
            ans += l + i
        }
    } else if n.abs() > l.abs() {
        for i in 0..n {
            ans += l + i
        }
    } else {
        for i in 0..n-1 {
            ans += l + i
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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

vvi g;
vi a,b,ans;
map<pii,int> mp;
int ind(int x,int y){
    if(x > y)swap(x,y);
    if(x == -1)return -1;
    return mp[pii(x,y)];
}

void dfs(int v, int par){
    int used = -1;
    if(ind(v, par) >= 0)used = ans[ind(v, par)];
    int cnt = 1;
    //cout << v << " " << par << " " << used << endl;
    for(auto ne: g[v])if(ne != par){
        if(cnt == used)cnt++;
        int t = ind(v,ne);
        ans[t] = cnt;
        cnt++;
        dfs(ne,v);
    }
}
signed main(void) {
    int n;
    cin >> n;
    g = vvi(n);
    a = b = ans = vi(n-1,-1);
    rep(i,n-1){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        mp[pii(a[i],b[i])] = i;
    }
    int ma = 0;
    rep(i,n)ma = max(ma, (ll)g[i].size());
    cout << ma << endl;
    rep(i,n)if(g[i].size() == ma){
        dfs(i,-1);
        rep(j,n-1)cout << ans[j] << endl;
        return 0;
    }
}


Measured memory_bytes: 15104
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int R, C;
int sheet[101][101];

int main(void) {

    cin >> R >> C;

    for (int r = 0; r < R; ++r) {
        for (int c = 0; c < C; ++c) {
            cin >> sheet[r][c];
            sheet[r][C] += sheet[r][c];
            sheet[R][c] += sheet[r][c];
            printf("%d ", sheet[r][c]);
        }
        sheet[R][C] += sheet[r][C];
        printf("%d\n", sheet[r][C]);
    }

    for (int c = 0; c < C; ++c) {
        printf("%d ", sheet[R][c]);
    }
    printf("%d\n", sheet[R][C]);

    return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


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

    int s = N;
    int sum = 0;
    while(s > 0){
        sum += s % 10;
        s /= 10;
    }
    if(N % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	
	string s;
	cin>>s;
	ll ans = 0;

	for(i=0;i<s.length();i++)
	{
		if(s[i]=='R')
		{
			ll cnt= 0;
			while(s[i]=='R' && i<s.length())
			{
				cnt++;
				i++;
			}
			i--;
			ans = max(ans,cnt);
		}
	}
	cout<<ans<<endl;
	
	


	
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int dy[] = { 0, 0, 1, -1,1,1,-1,-1 };
int dx[] = { 1, -1, 0, 0,1,-1,1,-1 };
vector<int>to[10101010];
int n, q;
vector<int>ans;

void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p)continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main() {
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 255488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n)  for(int i=0;i<(n);++i)
#define ALL(x) (x).begin(),(x).end()
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main() {
  int N;
  cin >> N;
  int zorome;
  for (int i = 1; i < 10; i++) {
    zorome = i * 100 + i * 10 + i;
    if (zorome - N >= 0) {
      break;
    }
  }
  cout << zorome << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int res=0;
    int tmp=0;
    vector<int> c(N,-1);
    for (int i=0;i<M;i++){
        int si,ci;
        cin >> si >> ci;
        if (c[si-1]==-1){
            c[si-1]=ci;
        }else{
            if(c[si-1]!=ci){
                res=-1;
            }
        }
    }

    if (N>1){
        if (c[0]==-1) c[0]=1;
    }else{
        if (c[0]==-1) c[0]=0;
    }

    for (int i=0; i<N-1; i++){
        if(tmp==0 && c[i]==0){
            res=-1;
            break;
        }
        tmp=c[i];
    }

    if(res==-1){
        cout << res;
    }else{
        bool flag=false;
        for (int i=0;i<N;i++){
            if (c[i]==-1){
                c[i]=0;
            }
            if (i==N-1){
                flag=true;
            }
            if (c[i]==0){
                if(flag==true){
                    cout << c[i];
                }
            }else{
                flag=true;
                cout << c[i];
            }
        }
    }
    cout << endl;
}


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

int main(){
	stack<int> st;
	int n, a;

	while(cin >> n){
		if(n!=0){
			st.push( n );
		}else{
			a = st.top();
			cout << a << endl;
			st.pop();
		}
	}
}

Measured memory_bytes: 3004
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> dp(N+1, 1000000007);
  dp[0] = 0;
  std::vector<int> six{6, 6*6, 6*6*6, 6*6*6*6, 6*6*6*6*6, 6*6*6*6*6*6};
  std::vector<int> nine{9, 9*9, 9*9*9, 9*9*9*9, 9*9*9*9*9};
  for(int i=1;i<=N;i++){
    for(int j=1;j<=5;j++) dp[i] = min(dp[i], (i-j<0?1000000007:dp[i-j]+j));
    for(int j=0;j<=5;j++) dp[i] = min(dp[i], (i-six[j]<0?1000000007:dp[i-six[j]]+1));
    for(int j=0;j<=4;j++) dp[i] = min(dp[i], (i-nine[j]<0?1000000007:dp[i-nine[j]]+1));
  }
  std::cout << dp[N] << '\n';
  return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	sort.Ints(p)
	var ans int
	for i := 0; i < k; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}


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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    cout << fixed << setprecision(12);
    ld l;
    cin>>l;
    ld a = l/3;
    ld b= a, c = a;
    cout << a*b*c << "\n";
    return 0;
}



Measured memory_bytes: 256
import math as m

N = int(input())
CSF = []
for i in range(N - 1):
    CSF.append([int(i) for i in input().split()])


def next_stat_arrival(here, time):
    if here == N - 1:
        return time
    if time < CSF[here][1]:
        return CSF[here][1] + CSF[here][0]
    return m.ceil(time / CSF[here][2]) * CSF[here][2] + CSF[here][0]


for i_start in range(N):
    time = 0
    for jth_station in range(i_start, N - 1):
        time = next_stat_arrival(jth_station, time)
    print(time)


Measured memory_bytes: 3188
#include<stdio.h>

int main(void){
    int tmp=0;
    char tmp_c;
    while(1){
        scanf("%c", &tmp_c);
        if(tmp_c=='\n'){
            printf("%d\n", tmp);
            tmp = 0;
            scanf("%c", &tmp_c);
            if(tmp_c=='0') break;
        }
        tmp += tmp_c - '0';
    }
    return 0;
}


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

int main () {
  string O, E;
  cin >> O >> E;
  
  for (int i = 0; i < O.size(); i++) {
    cout << O[i];
    if (i != E.size()) {
        cout << E[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

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

    scanf("%d%d",&i,&j);
    while(1){
        k = i%j;
        i = j;
        j = k;
        if(j == 0) break;
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	string s;
	int n,q;
	cin >> n >> q;
	cin >> s;
	vector<int> rsum(n);
	cu(i,1,s.length()){
		rsum[i] = rsum[i-1];
		if(s[i] == 'C' && s[i-1]  == 'A'){
			++rsum[i];
		}
	}
	int x,y;
	while(q--){
		cin >> x >> y;
		--x;--y;
		cout << rsum[y] - rsum[x] << '\n';
	}
}


Measured memory_bytes: 1488
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr){ sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N;
    string S;
    cin >> N >> S;
    unique(S);
    cout << S.size();
    //
    return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
ll mod=998244353;
int main() {
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){cout<<"Yes";}
    else{cout<<"No";}
   
    
	return 0;
}

Measured memory_bytes: 256