akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")  
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++) 
#define REP(i,k,n) for (int (i) = (k); (i) <= (n); (i)++) 
#define REPR(i,k,n) for (int (i) = (k); (i) >= (n); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	/*---- continue Coding ;----*/

	string s;
	cin >> s;
	ll int sum = 0; 
	for(ll int i=0; i<s.length(); i++){
		char ch = s[i];
		int num = ch - 48;
		sum = sum + num;
	}
	if(sum%9 == 0){
		cout << "Yes" << "\n";
	}else{
		cout << "No" << "\n";
	}

	/*---- break ;----*/

	cerr<<"Execution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
	return 0;
}

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

const int N = 2e5 + 100;
vector<int> edges[N][2];
int used[N][2];
int cntComponents;

map<pair<int, int>, int> mp;

void dfs(int id, int v) {
    used[v][id] = cntComponents;
    for (auto u : edges[v][id])
        if (!used[u][id])
            dfs(id, u);
}

void solve() {
    int n, k, l;
    cin >> n >> k >> l;
    for (int i = 0; i < k; i++) {
        int v, u;
        cin >> v >> u;
        edges[v][0].push_back(u);
        edges[u][0].push_back(v);
    }
    for (int i = 0; i < l; i++) {
        int v, u;
        cin >> v >> u;
        edges[v][1].push_back(u);
        edges[u][1].push_back(v);
    }
    for (int id = 0; id < 2; id++) {
        cntComponents = 1;
        for (int v = 1; v <= n; v++) {
            if (!used[v][id]) {
                dfs(id, v);
                cntComponents++;
            }
        }
    }
    for (int v = 1; v <= n; v++) {
        mp[{used[v][0], used[v][1]}]++;
    }
    for (int v = 1; v <= n; v++)
        cout << mp[{used[v][0], used[v][1]}] << ' ';
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<string,int,int>> t;
    int N;
    cin>>N;
    string S;
    int P;
    for(int i=0;i<N;i++){
        cin>>S>>P;
        t.pb(make_tuple(S,100-P,i+1));
    }
    sort(ALL(t));
    int sub;
    for(int i=0;i<N;i++){
        cout<<get<2>(t[i])<<endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  vi32 v(5);
  rep(i, 5) cin >> v[i];
  int ans = 0;
  rep(i, 5) ans += ((v[i] + 9) / 10) * 10;
  int mn = 10;
  rep(i, 5) if(v[i] % 10 != 0) amin(mn, v[i] % 10);
  cout << ans - 10 + mn << endl;
  return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
Largest = A[0] + K - A[N-1]
for i in range(1, N):
    if A[i] - A[i-1] > Largest:
        Largest = A[i] - A[i-1]
print(K-Largest)

Measured memory_bytes: 26444
#include <iostream>
#include <cmath>
using namespace std;
int count=0;

void merge(int *A,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	int L[n1+1];
	int R[n2+1];
	for(int i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=1000000000;
	R[n2]=1000000000;
	int i=0;
	int j=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			count++;
			A[k]=L[i];
			i++;
		}else{
			count++;
			A[k]=R[j];
			j++;
		}
	}
}

void mergeSort(int *A,int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(){
	int n;
	cin>>n;
	int S[n];
	for(int i=0;i<n;i++){
		cin>>S[i];
	}
	mergeSort(S,0,n);

	for(int i=0;i<n;i++){
		if(i==n-1){
			cout<<S[i];
		}else{
		  cout<<S[i]<<' ';
		}
	}
	cout<<endl<<count<<endl;
}


Measured memory_bytes: 6868
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

bool isOK(ll a[], int N, int index){
	bool ok = true;
	ll sum = a[index];
	rep(i,N){
		if(i == index)continue;
		if(a[i]<=sum*2){
			sum += a[i];
		}else{
			ok = false;
			break;
		}
	}
    if(ok) return true;
    else return false;
}

int binary_search(ll a[], int nax){
    int ng = -1;
    int ok =nax;
    while(abs(ok-ng) > 1){
        int mid = (ok + ng)/2;
        if(isOK(a, nax, mid))ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
	int N; cin>>N;
	ll input[110010];
	rep(i,N)cin>>input[i];
	sort(input, input+N);
	int border = binary_search(input, N);
	cout<<N-border<<endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(a+b>=10) cout<<"error\n";
	else cout<<a+b<<'\n';
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 2e4 + 10;

struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
 int n, m;
 cin >> n >> m;
 int s[n + 1], c[m + 1];
 for (int i = 0; i < m; i++){
  cin >> s[i] >> c[i];
 }
 int ans = -1;
 for (int i = 0; i <= 1000; i++){
  string curr = to_string(i);
  int plen = (int)curr.length();
  if (plen != n) continue;
  bool ok = true;
  for (int j = 0; j < m; j++){
    ok &= curr[s[j] - 1] == c[j] + '0';
  }
  if (ok){
    ans = i;
    break;
  }
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int l[1003], r[1003];
map <int, bool> vis;
int ans;

int main() {
	vis.clear();
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];
	for(int i = 1; i <= n; i++) {
		for(int j = l[i]; j <= r[i]; j++) {
			if(!vis[j]) {
				vis[j] = 1;
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#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 ALL(a) a.begin(), a.end()

ll dp1[4][5050];
ll dp2[4][5050 * 5050];

int main() {
  int n;
  cin >> n;
  int a[3], b[3];
  REP(i, 3) cin >> a[i];
  REP(i, 3) cin >> b[i];
  REP(i, 4) for (int j = 0; j <= n; ++j) dp1[i][j] = j;
  REP(i, 3) for (int j = 0; j <= n; ++j) {
    if (j < a[i]) {
      dp1[i + 1][j] = dp1[i][j];
    } else {
      dp1[i + 1][j] = max(dp1[i][j], dp1[i + 1][j - a[i]] + b[i]);
    }
  }
  int m = dp1[3][n];
  REP(i, 4) for (int j = 0; j <= m; ++j) dp2[i][j] = j;
  REP(i, 3) for (int j = 0; j <= m; ++j) {
    if (j < b[i]) {
      dp2[i + 1][j] = dp2[i][j];
    } else {
      dp2[i + 1][j] = max(dp2[i][j], dp2[i + 1][j - b[i]] + a[i]);
    }
  }
  cout << dp2[3][m] << endl;
  return 0;
}

Measured memory_bytes: 788864
package main

import (
  "fmt"
  "strings"
)

func main() {
  var input string
  fmt.Scan(&input)
  s := strings.Split(input, "")
  if s[2] == s[3] && s[4] == s[5] {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 640
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)
#define REPV(i,a,b) for(int i = a; i>= b; --i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
#define INF 100000
#define ff first
#define ss second
const int M=1e9+7;


void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int pos_w = 0, pos_r = 0, p = 1, r = 0, w = 0;
	REP(i,0,n)
	{
		if(s[i] == 'R')
		{
			pos_r = i;
			++r;
		}
		else
		{
			if(p)
			{
				pos_w = i;
				p ^= 1;
			}
			++w;
		}
	}
	if(!w)
	{
		cout<<"0\n";
		return;
	}
	else if(pos_r < pos_w)
	{
		cout<<"0\n";
		return;
	}
	else
	{
		int ans = 0;
		int i = 0, j = n - 1;
		while(1)
		{
			while(i < j && s[i] != 'W')
			++i;
			if(i == j)
			break;
			while(i < j && s[j] != 'R')
			--j;
			if(i == j)
			break;
			swap(s[i], s[j]);
			++ans;
		}
		cout<<ans<<"\n";
	}
}


int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}


Measured memory_bytes: 3732
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int n,a;
  cin>>n>>a;
  cout<<n*n-a<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ', ' ');
            int b1 = int.Parse(input[0]);
            int b2 = int.Parse(input[1]);
            int b3 = int.Parse(input[2]);
            if ((b1 == 1 && b2 == 1) || (b3 == 1))
            {
                Console.WriteLine("Open");
            }
            else
            {
                Console.WriteLine("Close");
            }
            Console.ReadLine();
        }
    }



Measured memory_bytes: 9016
#include <stdio.h>
int n;
int main() {
	scanf("%d", &n);
	n = n % 10;
	if (n == 3)printf("bon\n");
	if (n == 0 || n == 1 || n == 6 || n == 8) {
		printf("pon\n");
	}
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
		printf("hon\n");
	}
}

Measured memory_bytes: 1660
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans = sc.nextInt();
		if(ans == 3 | ans == 5 | ans == 7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vint a(N);
    map<int, int> cnt;
    set<int> s;
    rep(i, N)
    {
        cin >> a[i];
        cnt[a[i]]++;
        s.insert(a[i]);
    }
    bool ok = false;
    switch (s.size())
    {
    case 1:
        ok = a[0] == 0;
        break;
    case 2:
        ok = N % 3 == 0 and cnt[0] == N / 3;
        break;
    case 3:
        int x = *s.begin(), y = *(++s.begin()), z = *(++++s.begin());
        ok = (x xor y xor z) == 0 and N % 3 == 0 and cnt[x] == N / 3 and cnt[y] == N / 3 and cnt[z] == N / 3;
        break;
    }
    ok ? cout << "Yes" : cout << "No";

    return 0;
}

Measured memory_bytes: 7808
#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--)
                        
#define pb push_back    
#define PII pair<int,int>
                        
#define VS vector<string>
#define VI vector<int>  
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {        
    int n=0, l=0, r=0;  
    int sum = 0;        
    cin >> n;           
    REP(i,n) {          
        cin >> l >> r;  
        sum += r - l + 1;
    }                   
    cout << sum << endl;                                                                             
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] h=new int[n+1];
		for(int i=0;i<n;i++){
			int a=int.Parse(Console.ReadLine());
			h[a]=h[a-1]+1;
		}
		Console.WriteLine("{0}",n-h.Max());
	}
}

Measured memory_bytes: 17884
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;



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

  cin>>n; int c[n]; V(int)g[n];
  rep(i,n-1){
    cin>>x>>y;
    g[--x].eb(--y); g[y].eb(x);
  }
  rep(i,n)cin>>c[i];
  sort(c,c+n); reverse(c,c+n);
  queue<int>q; q.push(0);
  bool see[n]={}; see[0]=1;
  int an[n]; Int ans=0; an[0]=c[0]; int id=1;
  while(!q.empty()){
    int p=q.front(); q.pop();
    for(int e:g[p]){
      if(!see[e]){
        ans+=c[id]; an[e]=c[id]; id++;
        q.push(e); see[e]=1;
      }
    }
  }
  pri1(ans);
  pri2(an,n);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll lg=31;
const ll N=1e5+5;
const ll INF=3e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define f first
#define s second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repp(i, a, b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define pb push_back
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	FASTIO;
	int n;
	cin >> n;
	vector<vector<int>> v;
	for (int i = 0; i < n; i++) {
	    int a, b;
	    cin >> a >> b;
	    vector<int> v1;
	    v1.push_back(a);
	    v1.push_back(b);
	    v.push_back(v1);
	}
	bool flag = false;
	for (int i = 0; i < n - 2; i++) {
	    if (v[i][0] != v[i][1]) {
	        continue;
	    }
	    bool poss = true;
	    for (int j = i + 1; j <= i + 2; j++) {
	        if (v[j][0] != v[j][1]) {
	            poss = false;
	            break;
	        }
	    }
	    if (poss) {
	        flag = true;
	        cout << "Yes" << endl;
	        break;
	    }
	}
	if (!flag) {
	    cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#define ll long long
#define pi acos(-1.0)
#define Go "\n"
#define Afor(i,a,b) for( i=a;i<b;i++)
#define GCD __gcd
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll i,j,sum=0;
   string s;
   cin>>s;
   ll len=s.size();
   for(i=0,j=1;i<len;i++)
   {
       if(s[i]=='W')
       {
           sum=sum+(i+1)-j;
           j++;
       }
   }
   cout<<sum<<"\n";


}


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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int N;
	ll a[10000], b[10000];
	ll da=0, db=0;
	scanf("%d", &N);
	REP(i, N) {
		scanf("%lld", &a[i]);
	}
	REP(i, N) {
		scanf("%lld", &b[i]);
	}
	REP(i, N) {
		if (a[i] > b[i]) {
			db += a[i] - b[i];
		}
		else if (a[i] < b[i]) {
			if ((b[i] - a[i]) % 2 == 0) {
				da += (b[i] - a[i]) / 2;
			}
			else {
				da += ((b[i] - 1) - a[i]) / 2;
			}
		}
	}

	if (da>=db) {
		PRINTS("Yes");
	}
	else {
		PRINTS("No");
	}
}

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

int compute(string num){
  if ( num[0] == num[1] && num[1] == num[2] && num[2] == num[3] ) return -1;

  int cnt = 0;
  string L, S;
  while(1){
    if ( num == "6174" ) break;
    L = S = num;
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    sort(S.begin(), S.end());
    int x = atoi(L.c_str()) - atoi(S.c_str());
    num[0] = '0' + x/1000; x %= 1000;
    num[1] = '0' + x/100; x %= 100;
    num[2] = '0' + x/10; x %= 10;
    num[3] = '0' + x;
    cnt++;
  }
  return cnt;
}

main(){
  string num;
  while(1){
    cin >> num;
    if ( num == "0000" ) break;
    int a = compute(num);
    if ( a< 0 ) cout << "NA" << endl;
    else cout << a << endl;
  }
}




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


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=0; i<n; ++i){
		ll x;
		cin>>x;
		ans = __gcd(ans,x);
	}
	cout<<ans<<'\n';
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n;
	ll ans = 1;

	cin >> n;

	REP(i, n) {
		ans = ans * 2;

		if (ans > n) {
			cout << ans / 2 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a[5];
  rep(i,0,5) cin>>a[i];
  rep(i,0,5) if(a[i]==0){cout<<i+1<<endl;return;}
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3516
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,a[100005],x,ans,sa[100005];
int main(void){
    scanf("%lld%lld",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%lld",a+i);
        sa[i]=a[i];
        ans+=a[i];
    }
    for(int i=1;i<n;i++){
        ll r=x*i;
        for(int j=0;j<n;j++){
            sa[j]=min(sa[j],a[(j+n-i)%n]);
            r+=sa[j];
        }
        ans=min(ans,r);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string s;
  int cnt;
  while(cin >> s&&s!="0") {
      cnt=0;
      for(int i=0; i<s.size(); i++) {
          cnt+=s[i]-'0';
      }
      cout << cnt << endl;
  }
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll x; cin >> x;
  if (x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
  return 0;
}


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

int main(int argc, char** argv){
  const long long MOD = 2019;
  long long L, R;
  cin >> L >> R;
  long long sub = R-L;
  
  if(sub >= MOD){
    cout << 0 << endl;
    return 0;
  }

  long long remL = L%MOD;
  long long minRem = 2019;
  for(long long cnt0=L; cnt0 < R; cnt0++){
//    cout << (remL+cnt0)%MOD << (remL+cnt0+1)%MOD << endl;
    for(long long cnt1=cnt0+1; cnt1 <= R; cnt1++){
      minRem = min(minRem, ((cnt0%MOD)*(cnt1%MOD))%MOD);
//          if(minRem == 1) {cout << cnt0 << ", " << cnt1 << endl; break;}

    }
  }
  printf("%lld\n", minRem);
  return 0;
}


Measured memory_bytes: 256
class Point
  include Comparable

  attr_reader :x, :y, :z

  def initialize(x, y, z)
    @x, @y, @z = x, y, z
  end

  def <=>(other)
    return @x <=> other.x unless @x == other.x
    return @y <=> other.y unless @y == other.y
    @z <=> other.z
  end

  def +(other)
    Point.new(@x + other.x, @y + other.y, @z + other.z)
  end

  def -(other)
    Point.new(@x - other.x, @y - other.y, @z - other.z)
  end

  def rotate(direction)
    case direction
      when :x
        @y, @z = -@z, @y
      when :y
        @x, @z = -@z, @x
      when :z
        @x, @y = -@y, @x
    end
  end
end

class Edge
  include Comparable

  attr_accessor :initial, :terminal

  def initialize(initial, terminal)
    @initial, @terminal = initial, terminal
  end

  def <=>(other)
    return @initial <=> other.initial unless @initial == other.initial
    @terminal <=> other.terminal
  end
end

class Key
  attr_reader :edge

  def initialize(list)
    @edge = Array.new
    @point = Hash.new
    make_path(list)
  end

  def make_path(list)
    x, y, z = [0, 0, 0]
    until list.empty?
      px, py, pz = x, y, z
      case command = list.shift
        when /([+-])([xyz])/
          eval("#{$2} #{$1}= 1")
          @edge << Edge.new(Point.new(px, py, pz), Point.new(x, y, z))
          @edge << Edge.new(Point.new(x, y, z), Point.new(px, py, pz))
        else
          @point[command] = [x, y, z] unless @point[command]
          x, y, z = @point[command]
      end
    end
  end

  def rotate(direction)
    @edge.each do |e|
      e.initial.rotate(direction)
      e.terminal.rotate(direction)
    end
  end

  def move(difference)
    @edge.each do |e|
      e.initial += difference
      e.terminal += difference
    end
  end

  def same?(other)
    @edge.sort!
    4.times do
      4.times do
        4.times do
          other.edge.sort!
          other.move(@edge.first.initial - other.edge.first.initial)
          return true if @edge == other.edge
          other.rotate(:x)
        end
        other.rotate(:y)
      end
      other.rotate(:z)
    end
    false
  end
end

key = Array.new
loop do
  list = gets.split(" ")
  next if list.empty?                   # 空行対策
  n = list.shift.to_i
  list += gets.split(" ") until list.size == n
  break if n.zero?
  key << Key.new(list)
  puts (key.shift.same?(key.shift) ? "SAME" : "DIFFERENT") if key.size == 2
end

Measured memory_bytes: 6184
import java.util.HashMap
fun main(args: Array<String>) {
    val S = readLine()!!
    val T = readLine()!!
    val SL = S.length
    val TL = T.length
    val M = hashMapOf<Char, MutableList<Int>>()
    S.forEachIndexed{ index, char ->
        val e = M[char]
        if (e == null) M.put(char, mutableListOf(index, index + SL)) else e.addAll(listOf(index, index + SL))
    }
    for ((k, v) in M) v.sort()
    var sn = 0L
    var tn = 0
    while (tn < TL) {
        val e = M[T[tn]]
        if (e == null) {
            println(-1)
            return //exit
        }
        val n = (sn % SL).toInt()
        val b = e.binarySearch(n)
        val p = if (b < 0) e[b.inv()] else e[b]
        sn += (p - n + 1)
        tn += 1
    }
    println(sn)
}


Measured memory_bytes: 46228
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, b) = readListOfInt() 
    var cnt = 0
    for(i in a..b) {
        val s = i.toString().toList()
        if(s == s.reversed()) {
            cnt++
        }
    }
    println(cnt)
    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
    }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 41288
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vvi c(3, vi(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    
    rep(i, 3) {
        rep(j, 2) {
            if (c[i][j] - c[(i+1)%3][j] != c[i][j+1] - c[(i+1)%3][j+1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    rep(j, 3) {
        rep(i, 2) {
            if (c[i][j] - c[i][(j+1)%3] != c[i+1][j] - c[i+1][(j+1)%3]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
x=0
for i in range(N//2):
  x=A[2*i]-A[2*i+1]+x

x=x+A[N-1]
z=x
ans=[]
for i in range(N-1):
  ans.append(str(x))
  x=2*A[i]-x
ans.append(str(x))
print(" ".join(ans))


Measured memory_bytes: 17352
n = int(input())
d = sorted([int(i) for i in input().split()])

if d[int(n/2)] != d[int(n/2) - 1]:
  print(d[int(n/2)] - d[int(n/2) - 1])
elif d[int(n/2)] == d[int(n/2) - 1]:
  print(0)


Measured memory_bytes: 14428
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

const int INF = 1001001001;

int main(){
    int n,m;	cin >> n >> m;
    vector<pair<int, int> >key;
    rep(i, m){
        int a,b;    cin >> a >> b;
        int s = 0;
        rep(j, b){
            int c;  cin >> c;
            --c;
            s |= 1 << c;
        }
        key.emplace_back(s, a);
    }
    vector<int>dp(1 << n, INF);
    dp[0] = 0;
    rep(s, 1 << n){
        rep(i, m){
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] = min(dp[t], cost);
        }
    }
    int ans = dp.back();
    if(ans == INF)  ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 256
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))

p.sort()

candidates = {}
for i in range(-1, 102):

    if i in p:
        continue

    if not (abs(X-i) in candidates.keys()):
        candidates[abs(X-i)] = [i]
    else:
        candidates[abs(X-i)].append(i)

smallest = min(candidates.keys())

minNum = min(candidates[smallest])

print(minNum)


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll N, K; cin >> N >> K;
    if (N > 2 * K) {
        N = N % K + K;
    }
    ll best = abs(N - K);
    while (N > K) N -= K;
    best = min(best, abs(N - K));
    N = abs(N - K);
    best = min(best, abs(N - K));
    print(best);
}

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  int a;
  map<int, int> A;
  for (int i{}; i < N; ++i) {
    scanf("%d", &a);
    ++A[a];
  }
  int count{};
  for (auto&kv : A) {
    count += kv.second % 2;
  }

  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n + 1);
    for (auto& x : xs) std::cin >> x;

    std::vector<lint> ls(n + 1), rs(n + 1);
    ls[n] = rs[n] = xs[n];

    for (int i = n - 1; i >= 0; --i) {
        ls[i] = (ls[i + 1] + 1) / 2;
        rs[i] = rs[i + 1];
        ls[i] += xs[i], rs[i] += xs[i];
    }

    if (ls[0] > 1) {
        std::cout << -1 << "\n";
        return;
    }

    lint sum = 1, d = 1;
    for (int i = 1; i <= n; ++i) {
        d = std::min(d * 2, rs[i]);
        sum += d;
        d -= xs[i];
    }

    std::cout << sum << "\n";
}

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

    solve();

    return 0;
}


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

int main(void){
    int n,h,w;
    cin >> n >> h >> w;
    int a[n],b[n];
    for(int i = 0;i < n;i++)cin >> a[i] >> b[i];
    int sum = 0;
    for(int i = 0;i < n;i++){
        if(a[i] >= h && b[i] >= w)sum++;
    }
    cout << sum;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n)cin >> a[i];

    ll res=0;
    ll sum=0;
    int r=0;
    REP(l,n){
        while((sum^a[r])==(sum+a[r]) && r<n){
            sum+=a[r];
            r++;
        }
        res+=r-l;
        sum^=a[l];
    }
    cout << res << endl;
}


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

using namespace std;

typedef long long ll;

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

	int q;
	cin >> q;
	while (q--) {
		int k;
		cin >> k;

		ll ans = 0;
		ll cm = 0, cc = 0;
		int left = 0, right = 0;
		ll plus = 0;
		for (; left < n; left++) {
			while (right < n && right - left < k) {
				if (s[right] == 'M')cm++;
				if (s[right] == 'C')plus += cm, cc++;
				right++;
			}

			if (s[left] == 'D')ans += plus;

			if (s[left] == 'M')plus -= cc, cm--;
			if (s[left] == 'C')cc--;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1412
import math

line = input().rstrip().split(" ")
N = int(line[0]) #焼きたいたこ焼き
X = int(line[1]) #一度に焼けるたこ焼き
T = int(line[2]) #一度にかかる時間

count = math.ceil(N / X)

print(int(count) * T)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define Max(a,b) ((a)>(b)?(a):(b)) 
#define Min(a,b) ((a)<(b)?(a):(b)) 

//FILE *fp,*fp2;
//fp=fopen("input.txt","r");
//fp2=fopen("output.txt","w");

int main()
{
    string s;
	cin>>s;
	int x=s.length();
	int m=0;
	for (int i=0;i<x;i++)
	{
	    if (s[i]=='9')
		{
		    m=1;
			break;
		}
	}
	if (m==1)
	    cout<<"Yes"<<endl;
	else
	    cout<<"No"<<endl;\
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
int Q;
vector<string> q;


void input(){
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> S >> Q;  
}

int solve(){
  bool rev=false;
  string front="",back="";
  for (int i = 0; i < Q; i++)
  {
    int I;
    cin >> I;
    if(I==1) {rev ^= 1; continue;}
    if(I==2) {
      int F;
      string C;
      cin >> F >> C;
      F--;
      if(rev==F) front += C;
      if(rev!=F) back += C;
    }
    
  }
  if(rev) {
    swap(front,back);
    reverse(ALL(S));
    }
  reverse(ALL(front));
  string ans;
  ans = front + S + back;
  cout << ans << endl;
  return 0;
}

int main()
{
  input();
  solve();
  // test();
  return 0;
}


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

typedef long long ll;

ll power(ll x, ll y, ll M)
{
    ll res = 1;
    x = x%M;
    while (y)
    {
        if (y&1) res = ((res%M)*(x%M))%M;

        y>>=1;
        x = ((x%M)*(x%M))%M;
    }
    return res;
}

int main(){

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

    string s;
    cin >> s;

    int n = s.length();    

    if(n<=3) cout << 0 << "\n";

    else{
        
        ll count=0;

        int arr[2019]={};

        ll x;
        ll y=0;
        string p;
        for(int i=0; i<n; i++){

            p=s[i];
            int d = stoi(p);
            x = (power(10,n-i-1,2019)*(d))%2019;
            y = ((y%2019)+(x%2019))%2019;

            // cout << y%2019 << " ";

            if(y%2019==0) count++;
            if(arr[y%2019]!=0) count+=arr[y%2019];
            arr[y%2019]++;
        }

        cout << count << "\n";

    }

    return 0;
}


Measured memory_bytes: 3796
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#include <functional>

#define SIZE 300005
#define INF 1000000000
#define FD(d) fixed << setprecision(d)
#define MOD 1000000007
#define ll long long

using namespace std;

typedef pair<ll, ll> P;




bool func(int n, vector<int> &d)
{
	int x;

	for (int i = 0; i < 5; i++) {
		int v = n;
		for (int j = 0; j < i; j++) {
			v = v / 10;
		}
		if (v == 0 && n!=0) break;
		x = v % 10;
		for (int j = 0; j < d.size(); j++) {
			if (x == d[j]) {
				return (false);
				break;
			}
		}
	}
	
	
	return (true);
}

int main()
{
	int n, k;
	

	cin >> n >> k;
	vector<int> d(k);

	for (int i = 0; i < k; i++) {
		cin >> d[i];
	}
		
		while (1) {
			if (!func(n, d)) { 
				n++; 
			}
			else {
				break;
			}
		}
	

	cout << n << endl;
	return (0);
}


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

//0024
int main(){
	double v;
	
	while(cin >> v){
		double t=v/9.8;		//g=9.8
		double h=4.9*t*t;	// (1/2) * g * t^2
				
		//5*f-5 > h;
		double f = (h+5)/5;
		cout << ceil(f) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
c = [0] * 3
for i in range(3):
    c[i] = list(map(int, input().split()))

if (c[0][0] + c[1][1] + c[2][2]) == (c[0][1] + c[1][2] + c[2][0]) and (
        c[0][2] + c[2][1] + c[1][0]) == (c[0][0] + c[1][1] + c[2][2]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

template<class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o<<"{";
    bool f = false;
    for (const T &a: v)
        o<<(f?", ":"")<<a,
        f = true;
    o<<"}";
    return o;
}

class UnionFind
{
public:
    vector<int> parent;
    vector<int> rank;
    
    UnionFind(int n): parent(n), rank(n)
    {
        for(int i=0;i<n;i++)
            parent[i] = i,
            rank[i] = 0;
    }

    int root(int x)
    {
        return parent[x]==x ? x : parent[x] = root(parent[x]);
    }

    bool same(int x, int y)
    {
        return root(x)==root(y);
    }

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (rank[x] < rank[y])
                parent[x] = y;
            else
                parent[y] = x;
            if (rank[x]==rank[y])
                rank[x]++;
        }
    }
};

int main()
{
    int N;
    cin>>N;
    vector<long long> a(N+1);
    for (int i=1; i<=N; i++)
        cin>>a[i];

    while (N<30)
        a.push_back(0),
        N++;

    UnionFind UF(N+1);
    for (int i=21; i<=N; i++)
        for (int j=i+i; j<=N; j+=i)
            UF.unite(i, j);

    vector<vector<int>> G;
    vector<vector<vector<bool>>> F;
    for (int i=21; i<=N; i++)
    if (UF.root(i) == i)
    {
        vector<int> g;
        for (int j=21; j<=N; j++)
            if (UF.root(j) == i)
                g.push_back(j);
        G.push_back(g);

        F.push_back(vector<vector<bool>>());
        int n = (int)g.size();
        for (int b=0; b<1<<n; b++)
        {
            vector<bool> f;
            for (int j=0; j<n; j++)
                f.push_back((b>>j&1) != 0);
            bool ok = true;
            for (int j=0; j<n; j++)
                for (int k=0; k<n; k++)
                    if (g[k]%g[j]==0 && !f[j] && f[k])
                        ok = false;
            if (ok)
                F.back().push_back(f);
        }
    }
    //for (auto g: G)
    //    cout<<g<<endl;
    //for (auto f: F)
    //    cout<<f<<endl;

    long long oo = 1000000000000LL;
    long long ans = 0LL;

    for (int b=0; b<1<<20; b++)
    {
        vector<bool> f(N+1, true);

        for (int i=1; i<=20; i++)
        if (b>>(i-1)&1)
            for (int j=i; j<=N; j+=i)
                f[j] = false;
        if (!f[1])
            continue;

        long long tans = 0;
        for (int i=1; i<=20; i++)
            if (f[i])
                tans += a[i];

        for (int i=0; i<(int)G.size(); i++)
        {
            long long t = -oo;
            for (vector<bool> &ff: F[i])
            {
                long long s = 0;
                for (int j=0; j<(int)G[i].size(); j++)
                    if (ff[j] && f[G[i][j]])
                        s += a[G[i][j]];
                t = max(t, s);
            }
            tans += t;
        }
        ans = max(ans, tans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import bisect
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

class Accumulation:
    def __init__(self,X,accumfunc,init_val=0):
        self.X = X
        self.accumfunc = accumfunc

        N = len(X)
        v1 = [0] * (N+1)
        v1[0] = init_val

        for i in range(N):
            v1[i+1] = accumfunc(v1[i],X[i])

        self.v1 = v1
    
    # 0-index
    def query(self,l,r):
        return self.v1[r+1] - self.v1[l]
    
    def get_array(self):
        return self.v1

INF=10**20
def main():
    N=ii()
    A=list(mi())
    B = []
    for a in A:
        B.append(a*2)

    def add(x,y): return x+y

    acc = Accumulation(A,add)
    accB = Accumulation(B,add)

    vA = acc.get_array()
    vB = accB.get_array()

    ans = INF
    for j in range(N):
        i1 = bisect.bisect_left(vB,vA[j+1]) - 1 

        Q,P=0,INF
        for di in [-1,0,1]:
            if not 0<= i1+di < N: continue
            q,p = acc.query(i1+di+1,j), acc.query(0,i1+di)
            if abs(p-q) < abs(P-Q):
                Q,P = q,p

        S,R = 0,INF
        i2 = bisect.bisect_left(vB,vA[N]+vA[j+1]) - 1
        for di in [-1,0,1]:
            if not 0<= i2+di < N: continue
            s,r = acc.query(i2+di+1,N-1), acc.query(j+1,i2+di)
            if abs(s-r) < abs(S-R):
                S,R=s,r



        ans = min(ans,abs(max(P,Q,R,S) - min(P,Q,R,S)))


    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 105896