akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ans;
void func(int arr[][2],int index,int n,int k,vector<int>temp)
{
    if(index==3){
        // cout<<"Array\n";
        // for(auto x:temp)
        //     cout<<x;
        //     cout<<"\n";
        vector<pair<int,int>>p{{1,2},{0,2},{0,1}};
        for(int i=0;i<3;i++){
            int l=p[i].first,r=p[i].second;
            // cout<<l<<" "<<r<<"\n";
            // cout<<temp[l]<<" "<<temp[r]<<" "<<temp[i]<<"\n";
            if((temp[l]^temp[r])!=temp[i]){
                return ;
            }
        }
        map<int,int>m;
        for(int i=0;i<k;i++){
            m[arr[i][0]]=arr[i][1];
        }
        for(int i=3;i<n;i++){
            if(m[temp[i%3]]){
                temp.push_back(temp[i%3]);
                m[temp[i%3]]--;
            }
            else
                return ;
        }
        // cout<<"Reached\n";
        if(temp[n-1]==(temp[0]^temp[n-2])){
            ans=1;
        }
        return ;
    }
    for(int i=0;i<k;i++){
        if(arr[i][1]){
            arr[i][1]--;
            temp.push_back(arr[i][0]);
            func(arr,index+1,n,k,temp);
            temp.pop_back();
            arr[i][1]++;
        }
    }
}
main()
{
    int n;
    cin>>n;
    int a[n];
    int k=0;
    map<int,int>m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        m[x]++;
    }
    if(m.size()>3){
        cout<<"No\n";
        return 0;
    }
    int arr[3][2],i=0;
    for(auto x:m){
        arr[i][0]=x.first;
        arr[i++][1]=x.second;
    }
    func(arr,0,n,i,{});
    if(ans)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//?????????WA????????????
//????????????????????£??????

int W,H,f[21][21],ans[1000],cnt=0,sx,sy;
string s,t;

void find(int x,int y){
	if(x>=W || x<0 || y>=H || y<0)return;
	if(f[x][y]==0)return;
	f[x][y]=0;
	ans[cnt]++;
	find(x+1,y);
	find(x-1,y);
	find(x,y+1);
	find(x,y-1);
}

int main(void){
	while(1){
		cin>>W>>H;
		if(W==0 && H==0)break;
		ans[cnt]=0;
		rep(i,H){
			cin>>s;
			rep(j,W){
				t = s[j];
				if(t==".")f[j][i]=1;
				if(t=="#")f[j][i]=0;
				if(t=="@"){
					f[j][i]=1;
					sx=j;
					sy=i;
				}
			}
		}
		find(sx,sy);
		cnt++;
	}
	rep(i,cnt)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, d, x;
    cin >> n >> d >> x;
    int a, sum = 0;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> a;
        v[i] = a;
        if (d % a == 0) {
            sum += (d / a);
        }else{
            sum += (1 + d / a);
        }
        
        
    }
    sum += x;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    ll ap[N], an[N];
    ll s = 0;
    REP(i, N) {
        ll A; cin >> A;
        s += A;
        ap[i] = s;
        an[i] = s;
    }

    debug(vector<ll>(ap, ap+N))

    ll ans_p = 0;
    bool p = false;
    ll c = 0;
    REP(i, N) {
        p ^= 1;
        ap[i] += c;
        if (p) {
            if (ap[i] > 0) continue;
            ll abs_r = -ap[i] + 1;
            c += abs_r;
            ans_p += abs_r;
        } else {
            if (ap[i] < 0) continue;
            ll abs_r = ap[i] + 1;
            c -= abs_r;
            ans_p += abs_r;
        }
        debug(i, p, c);
    }

    debug(vector<ll>(ap, ap+N))

    debug(ans_p)

    debug(vector<ll>(an, an+N))

    ll ans_n = 0;
    c = 0;
    p = true;
    REP(i, N) {
        p ^= 1;
        an[i] += c;
        if (p) {
            if (an[i] > 0) continue;
            ll abs_r = -an[i] + 1;
            c += abs_r;
            ans_n += abs_r;
        } else {
            if (an[i] < 0) continue;
            ll abs_r = an[i] + 1;
            c -= abs_r;
            ans_n += abs_r;
        }
        debug(i, p, c);
    }

    debug(vector<ll>(an, an+N))

    debug(ans_n)

    cout << min(ans_p, ans_n) << endl;
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,sum,a[200100];
long long ans;
int main(){
	char x;
	while(cin>>x)
		a[++n]=(x=='B'?1:0);
	for (register int i=n;i;--i){
		sum+=a[i];
		if (a[i]) ans+=n-i+1-sum;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
com = list(input())
ans = []
for c in com:
    if c == '0':
        ans.append("0")
    elif c == '1':
        ans.append("1")
    elif c == 'B':
        if len(ans) == 0:
            pass
        else:
            ans.pop()
a = "".join(ans)
print(a)

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

using namespace std;

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

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

    vector<int> a;
    REP(i, n){
        int ai;
        cin >> ai;
        a.push_back(ai);
    }
    sort(a.begin(), a.end());
    cout << a[n-1]-a[0] << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int,input().split()))
    
    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()


Measured memory_bytes: 21652
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[200007];
map<ll,ll> M;

int main(){
  ll N;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    M[A[i]]++;
  }
  sort(A,A+N);
  reverse(A,A+N);
  ll ANS=0;
  rep(i,N){
    rrep(k,31){
      ll j=1<<k;
      if(A[i]>j){
        break;
      }
      if(M.find(j-A[i])!=M.end()){
        if(((j-A[i]!=A[i] && M[j-A[i]]>0) && M[A[i]]>0  )|| (j-A[i]==A[i] &&  M[j-A[i]]>1)){
          M[A[i]]--;
          M[j-A[i]]--;
          ANS++;
          break;
        }
      }
    }
  }
  cout << ANS << endl;
}


Measured memory_bytes: 17692
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s,t = map(str,input().split())
ans = []

for i in range(n):
  ans.append(s[i])
  ans.append(t[i])

print("".join(ans))

Measured memory_bytes: 77136
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  ll N, K, H;
  cin >> N >> K;
  ll ans = 0;
  vector<int> vec(N);

  for (ll i = 0; i < N; i++){
    cin >> H;
    vec.at(i) = H;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  if(K > N) K = N;
  for (ll i = 0; i < K; i++) {
    vec.at(i) = 0;
  }

  ans = accumulate(vec.begin(), vec.end(), 0LL);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<vi> v;



int main()
{
	string s;
	while (getline(cin, s))
	{
		vi t;
		REP(i, s.size())
		{
			if (isdigit(s[i]))
			{
				if (i + 1 == s.size() || s[i + 1] == ',') t.push_back(s[i]-'0');
				else
				{
					t.push_back((s[i]-'0') * 10 + (s[i + 1]-'0'));
					i++;
				}
				
			}
		}
		v.push_back(t);
	}

	int dp[105][105] = {};
	dp[0][0] = v[0][0];
	FOR(i, 1, v.size() / 2 + 1)
	{
		dp[i][0] = v[i][0] + dp[i - 1][0];
		dp[i][v[i].size() - 1] = v[i][v[i].size() - 1] + dp[i - 1][v[i - 1].size() - 1];
		FOR(j, 1, v[i].size() - 1) dp[i][j] = v[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j]);
	}
	FOR(i, v.size() / 2 + 1, v.size())
	{
		REP(j, v[i].size())
		{
			dp[i][j] = v[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
		}
	}
	cout << dp[v.size() - 1][0] << endl;
	return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect 

const int N = 2e5 + 7, INF = 1e9 + 7;

vector <int> g[N], ng[N];
int ans[N], cnt1, cnt2;
short used[N];

void dfs(int v, int c) {
    if (used[v]) return;
    used[v] = c;
    (c == 1 ? ++cnt1 : ++cnt2);
    for (int u : g[v])
        dfs(u, 3 - c);
}

void solve() {
    int n; cin >> n;
    loop(i, n - 1) {
        int u, v; cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    dfs(1, 1);
    int cg = 1, c = 1;
    if (cnt2 <= n / 3 || cnt1 <= n / 3) {
        loop1(i, n) {
            if ((used[i] == 1 && cnt1 <= n / 3) || (used[i] == 2 && cnt2 <= n / 3)) {
                ans[i] = cg * 3; ++cg;
            }
            else {
                if (c > n) {
                    ans[i] = cg * 3; ++cg;
                }
                else {
                    ans[i] = c; ++c;
                    if (c % 3 == 0) ++c;
                }
            }
        }
    }
    else {
        int c1 = 0, c2 = 0;
        loop1(i, n) {
            if ((used[i] == 1 && cnt1 > cnt2) || (used[i] == 2 && cnt1 <= cnt2)) {
                if (c1 * 3 + 1 > n) {
                    ans[i] = cg * 3; ++cg;
                }
                else {
                    ans[i] = c1 * 3 + 1; ++c1;
                }
            }
            else {
                if (c2 * 3 + 2 > n) {
                    ans[i] = cg * 3; ++cg;
                }
                else {
                    ans[i] = c2 * 3 + 2; ++c2;
                }
            }
        }
    }
    loop1(i, n) cout << ans[i] << " ";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 20992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    string s; cin >> s;
    vector<int> cnt(s.size(), 0);
    if (s.front() == 'A' || s.front() == 'C' || s.front() == 'G' || s.front() == 'T') cnt[0]++;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cnt[i] = cnt[i - 1] + 1;
    }

    cout << *max_element(cnt.begin(), cnt.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      String n = sc.next();
      for (int i=0; i<3; i++) {
        if (n.charAt(i) == '1') System.out.print(9);
        if (n.charAt(i) == '9') System.out.print(1);
      }
    }
}

Measured memory_bytes: 20820
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
char s[2001];
int vis[2001];
int a,b;
bool ok=0;
int main()
{
	cin>>a>>b;
	cin>>s;
	for(int i=0;i<a;i++){
		if(s[i]>='0'&&s[i]<='9')continue;
		else {
			cout<<"No";ok=1;return 0;
		}
	}
	if(s[a]!='-'){
		cout<<"No";ok=1;return 0;
	}
	for(int i=a+1;i<a+b+1;i++){
		if(s[i]>='0'&&s[i]<='9')continue;
		else {
			cout<<"No";ok=1;return 0;
		}
	}
	if(ok==0)cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main(){
    int Ans=0;
    getline(cin,s);
    getline(cin,t);
    for(int i=0,I=s.size();i<I;i++)
        if(s[i]!=t[i])
            Ans++;
    cout<<Ans;
    return 0;
}

Measured memory_bytes: 3912
n = gets.chomp.to_i
h_arr = gets.chomp.split(" ").map(&:to_i)

flag = 0
h_arr.each_cons(2) do |a, b|
  if a - b >= 2
    puts "No"
    exit 0
  end
  if a < b
    flag = 0
  elsif a > b
    flag += 1
  end
  if flag == 2
    puts "No"
    exit 0
  end
end

puts "Yes"


Measured memory_bytes: 21876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define MOD 1000003
typedef pair<int,int> Pii;


int main(){
    while(true){
        int n,m;
        cin>>n>>m;
        if(n==0) return 0;
        if(n%2){
            cout<<0<<endl;
            continue;
        }
        vector<Pii> edge(0);
        rep(i,m){
            int a,b;
            cin>>a>>b;
            a--;b--;
            if(abs(a-b)%2==0) continue;
            edge.push_back(Pii(min(a,b),max(a,b)));
        }
        sort(edge.begin(), edge.end(), [](Pii a,Pii b){return a.second-a.first < b.second-b.first;});
        edge.push_back(Pii(0,n-1));
        vector<Pii> dp(n); //Pii（最長道路、行き方)
        rep(i,n-1) dp[i]=Pii(i+1,1);
        for(Pii P : edge){
            int a=P.first,b=P.second;
            long long cnt=1,left=a+1;
            while(left != b){
                cnt *= dp[left].second;
                cnt %= MOD;
                left = dp[left].first+1;
            }
            dp[a+1]=Pii(b-1,cnt);
            left=a;cnt=1;
            while(left != b+1){
                cnt *= dp[left].second;
                cnt %= MOD;
                left = dp[left].first+1;
            }
            dp[a]=Pii(b,(cnt+dp[a+1].second)%MOD);
        }
        cout<<dp[0].second<<endl;

    }

    return 0;
}


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

struct data1 {
    int t;
    int x;
    int y;

};
int main() {

    int N;
    cin >> N;
    vector<data1> input(N + 1);



    data1 tmp;
    tmp.t = 0;
    tmp.x = 0;
    tmp.y = 0;
    input.at(0) = tmp;

    int count = 1;

    while (count < N + 1) {

        data1 tmp;
        cin >> tmp.t >> tmp.x >> tmp.y;
        input.at(count) = tmp;
        count++;
    }

    count = 0;
    int flag = 0;
    while (count < N) {
        int delay_t = input.at(count + 1).t - input.at(count).t;
        int delay_x = abs(input.at(count + 1).x - input.at(count).x);
        int delay_y = abs(input.at(count + 1).y - input.at(count).y);
		
      
        //cout << delay_t << delay_x << delay_y << endl;
        if (delay_t < delay_x + delay_y) {
            flag = 1;
            break;
        }
        else if (delay_t == delay_x + delay_y) {

        }
        else if (delay_t > delay_x + delay_y) {
           // cout << "a" << endl;
            if (delay_t % 2 == (delay_x + delay_y) % 2) {
            }
            else {
                flag = 1;
                break;
            }
        }
        else if ((delay_x + delay_y) == 0) {
            if (delay_t % 2 == 1) {
                flag = 1;
                break;
            }
        }
      count++;
    }

    if (flag == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 1408
def bowling(game):
	game=map(int,game.split())
	score,thrw=0,1
	for flame in range(10):
		if game[thrw]==10:
			score+=sum(game[thrw:thrw+3])
			thrw+=1
		elif game[thrw]+game[thrw+1]==10:
			score+=10+game[thrw+2]
			thrw+=2
		else:
			score+=game[thrw]+game[thrw+1]
			thrw+=2
	return game[0],score
	
while 1:
	n=input()
	if n==0:break
	ls=[bowling(raw_input()) for i in range(n)]
	for k,s in sorted(sorted(ls),key=lambda x:x[1],reverse=True):
		print k,s

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

int main()
{
    int x, y;
    cin >> x >> y;
    string ans = "No";
    for (int i = 0; i <= x; i++)
    {
        int b = x - i;
        if (2 * i + 4 * b == y)
        {
            ans = "Yes";
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main(void) {
  string abcd;
  cin >> abcd;
  int a = abcd[0] - '0';
  int b = abcd[1] - '0';
  int c = abcd[2] - '0';
  int d = abcd[3] - '0';

  int i, j, k;
  bool flag = false;
  for(i = 0; i < 2; i++) {
    int x = a;
    if(i == 0) {
      x += b;
    }
    else {
      x -= b;
    }
    for(j = 0; j < 2; j++) {
      int y = x;
      if(j == 0) {
	y += c;
      }
      else {
	y -= c;
      }
      for(k = 0; k < 2; k++) {
	int z = y;
	if(k == 0) {
	  z += d;
	}
	else {
	  z -= d;
	}
	if(z == 7) {
	  flag = true;
	  break;
	}
      }
      if(flag) {
	break;
      }
    }
    if(flag) {
      break;
    }
  }
  char op1, op2, op3;
  op1 = '+' + i * 2;
  op2 = '+' + j * 2;
  op3 = '+' + k * 2;

  cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
}

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

int main(){
	int t;
	while(cin >> t && t){
		int n;
		cin >> n;
		int s = 0;
		for(int i = 0 ; i < n; i++){
			int a,b;
			cin >> a >> b;
			s += b-a;
		}
		if( s >= t ){
			cout << "OK" << endl;
		}else{
			cout << t - s << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll POW3(ll x,ll n,ll m){
  x%=m;
  if(n==0)return 1;
  if(n%2==0)return POW3(x*x,n/2,m)%m;
  return x*POW3(x,n-1,m)%m;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)//xのm進数でのx^nの位の値
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)//xのn進数での桁数
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)//x!のnで割り切れる回数
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)//xのnで割り切れる回数
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

ll SGS(ll x,ll y, ll m)//1+x+…+x^(y-1)をmで割った余り
{
  if(y==0)return 0;
  if(y%2==0){
    return (1+POW3(x,y/2,m))*SGS(x,y/2,m)%m;
  }
  return (1+x*SGS(x,y-1,m))%m;
}

ll SSGS(ll x,ll y,ll m)//Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
  if(y==0)return 0;
  if(y==1)return 1;
  if(y%2==0){
    return (SSGS(x,y/2,m)*(POW3(x,y/2,m)+1)%m+SGS(x,y/2,m)*y/2%m)%m;
  }
  return (SSGS(x,y-1,m)*x%m+y)%m;
}

int main()
{
  ll n,a[210000],b[210000],c=0;
  cin >> n;
  rep(i,n)cin >> a[i] >> b[i];
  vector<pair<ll,ll>>p(n);
  rep(i,n)p[i]=make_pair(b[i],a[i]);
  sort(all(p));
  rep(i,n){
    c+=p[i].second;
    if(c>p[i].first){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
} 

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

long long pow_mod(long long x, long long y){

    long long res = x;
    for(int i=1; i<y; i++){
        res *= x;
        res %= MOD;
    }
    return res;
}

int main()
{
    long long n;
    cin >> n;
    vector<int> v(n, 0);
    int max_n = 0;
    rep(i, n){
        int d;
        cin >> d;
        if(i == 0 && d != 0){
            cout << 0;
            return 0;
        }
        max_n = max(max_n, d);
        v[d]++;
    }

    if(v[0] != 1){
        cout << 0;
        return 0;
    }

    long long pre = v[1], now;
    long long ans = 1;
    for(int i=2; i<=max_n; i++){
        now = v[i];
        if(v[i] == 0){
            cout << 0;
            return 0;
        }
        ans *= pow_mod(pre, now);
        ans %= MOD;
        pre = now;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 640
class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[0]*(n)
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):
        return self.find(x)==self.find(y)
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

from collections import Counter

n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)

for i in range(k):
    x,y=map(int,input().split())
    uf1.union(x-1,y-1)

for i in range(l):
    x,y=map(int,input().split())
    uf2.union(x-1,y-1)

#for i in range(n):
#uf1.find(i)
#uf2.find(i)

ctr=Counter()
for i in range(n):
    r1 = uf1.find(i)
    r2 = uf2.find(i)
    ctr[(r1,r2)]+=1

ans=[]
for i in range(n):
    r1 = uf1.find(i)
    r2 = uf2.find(i)
    ans.append(ctr[(r1,r2)])
print(*ans)

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int p;
	p = b;
	b = a;
	a = p;

	p = c;
	c = a;
	a = p;

	cout << a << " " << b << " " << c << endl;

}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#n,a = [int(i) for i in read().split()]



p,q,m = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

ans = min(a)+min(b)

for _ in range(m):
    x,y,c = [int(i) for i in readline().split()]
    ans = min(ans,a[x-1]+b[y-1]-c)

print(ans)
    














Measured memory_bytes: 18616
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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


int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };

const ll MOD = 1000000007;
const ll INF = 1000000000;

int gcd(int a, int b){
    int mi = min(a, b);
    int mx = max(a, b);
    if (mi == 0) return mx;
    return gcd(mi ,mx % mi);
}

int main(void){
    int n;
    int a[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = gcd(a[0], a[1]);
    for (int i = 2; i < n; i++){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;

}



Measured memory_bytes: 640
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        a: [usize; n],
    }

    let mut ones = vec![0usize; 64];
    for &a in &a {
        for i in 0..64 {
            if (a>>i) & 1 == 1 {
                ones[i] += 1;
            }
        }
    }
    let x = dfs(0, 64, &ones, k, n);
    let mut ans = 0;
    for a in a {
        ans += x ^ a;
    }
    println!("{}", ans);
}

fn dfs(mut val: usize, bit: usize, ones: &[usize], k: usize, n: usize) -> usize {
    if bit == 0 {
        return val;
    }

    if ones[bit-1] <= n - ones[bit-1] {
        if val + (1<<(bit-1)) <= k {
            val += 1<<(bit-1);
        }
    }
    dfs(val, bit-1, ones, k, n)
}


Measured memory_bytes: 4004
#include<iostream>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >>C;
  bool visit[110];
  for(int i=0;i<110;i++) visit[i]=false;
  
  int i=1;
  while(true){
    int j=(i*(A%B))%B;
    if(j==C){
      cout << "YES" <<endl;
      return 0;
    }
    if(visit[j]){
      cout << "NO" <<endl;
      return 0;
    }else{
      visit[j]=true;
      i++;
    }
  }
  
}

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

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

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

int main() {

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

	int A, B;
	cin >> A >> B;

	if (6 <= A && A <= 12) B /= 2;
	else if (5 >= A) B = 0;

	cout << B << "\n";

	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
ud = False
ud_count = 0
sub_s = ""
for i in range(q):
    query = list(input().split())
    if int(query[0]) == 1:
        ud = not(ud)
        ud_count += 1
    else:
        if (int(query[1])==1 and ud==False) or (int(query[1])==2 and ud==True):
            sub_s += query[2]
        else:
            s += query[2]
s = sub_s[::-1] + s
if ud_count%2:
    print(s[::-1])
else:
    print(s)


Measured memory_bytes: 4280
# ABC118B - Foods Loved by Everyone
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    cnt = defaultdict(int)
    for _ in range(N):
        _, *A = map(int, input().split())
        for a in A:
            cnt[a] += 1
    ans = sum(i == N for i in cnt.values())
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int temp,a,b,c;

    scanf("%d",&a);

    scanf("%d",&b);

    scanf("%d",&c);

    temp=a;
    a=b;
    b=c;
    c=temp;


    printf("%d %d %d\n ",b,c,a);

    return 0;
}


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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var p = Console.ReadLine().Split().Select(double.Parse).ToArray();
            Console.WriteLine("{0:f5}", Math.Sqrt(Math.Pow(p[0] - p[2], 2) + Math.Pow(p[1] - p[3], 2)));
        }
    }
}

Measured memory_bytes: 14292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  int K; cin >> K;
  vector<bool> f(N,false);
  rep(i,K){
    int d; cin >> d;
    rep(j,d){
      int n; cin >> n;
      f[n-1] = true;
    }
  }
  int ans = 0;
  rep(i,N) if(f[i]==false) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
 
using namespace std;
 
typedef pair<int,int>P;
typedef pair<ll,ll>pll;
 
const int MAX_N = 40;
 
ll w[MAX_N];
ll v[MAX_N];
ll W;
int n;
pll ps[1<<(MAX_N/2)];
 
void solve()
{
    int n2 = n/2;
    rep(i,1<<n2){
        ll sw =0,sv=0;
        rep(j,n2){
            if(i&(1<<j)){
                sw += w[j];
                sv += v[j];
            }
        }
        ps[i] = pll(sw,sv);
    }
    sort(ps,ps+(1<<n2));
    int m=1;
    for(int i=1;i<(1<<n2);i++){
        if(ps[m-1].second < ps[i].second){
            ps[m++] = ps[i];
        }
    }
    ll res = 0;
    rep(i,1<<(n-n2)){
        ll sw=0,sv=0;
        rep(j,n-n2){
            if((i>>j)&1){
                sw += w[n2+j];
                sv += v[n2+j];
            }
        }
        if(sw <= W){
            ll tv = (lower_bound(ps,ps+m,pll(W-sw,INF))-1)->second;
            res = max(res,sv+tv);
        }
    }
    printf("%lld\n",res);
}
 
int main()
{
    cin >> n >> W;
    rep(i,n){
        cin >> v[i] >> w[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 19604
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 string toBin(int n){
    if(n == 1)return "1";
    else if(n == 0)return "0";

    return toBin(n/2)  + to_string(n%2);
}
int main(){
    ll n, k;
    cin >> n >> k;
    ll sum = 0;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    vector<ll> b;
    rep(i, n){
        ll sum = 0;
        for(ll j=i; j<n; ++j)sum+=a[j], b.push_back(sum);
    }
    ll ans = 0;
   for(ll i=40; i>=0; --i){
        ll cnt = 0;
        ll x = ans|(1LL<<i);
        rep(j, b.size()){
            if((x&b[j])==x)cnt++;
        }
        if(cnt>=k)ans=x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

signed main(){
  string s; cin>>s;
  if(s.back()=='1'||s[0]=='0'){
    cout<<-1<<en;
    RE;
  }
  int n=s.size();
  for(int i=1; i<n-1; i++){
    if(s[i]!=s[n-i-2]){
      cout<<-1<<en;
      RE;
    }
  }
  queue<int> one;
  for(int i=0; i<n; i++){
    if(s[i]=='1') one.push(i);
  }
  one.push(n-1);
  for(int i=0; i<n-1; i++){
    if(one.front()==i){
      one.pop();
    }
    cout<<i+1<<" "<<one.front()+1<<en;
  }
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

ll gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

int main() {
    cin >> A >> B >> C >> D;
    ll undac = (A - 1) / C;
    ll undad = (A - 1) / D;
    ll undacd = (A - 1) / lcm(C, D);
    ll undbc = B / C;
    ll undbd = B / D;
    ll undbcd = B / lcm(C, D);
    ll a = undac + undad - undacd;
    ll b = undbc + undbd - undbcd;
    cout << B - A + 1 - (b - a) << endl;
}

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

int main() {
  int s, w;
  cin >> s >> w;
  if (s > w) puts("safe");
  else cout << "unsafe" << endl;
  return 0;
}

Measured memory_bytes: 3624
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 + y1 - y2
y3 = -x1 + x2 + y2
x4 = x1 + y1 - y2
y4 = -x1 + x2 + y1

print(x3,y3,x4,y4)

Measured memory_bytes: 2940
n, m, c = map(int, input().split())
 
B = list(map(int, input().split()))
ans = 0
 
for i in range(n):
    A = list(map(int, input().split()))
    x = 0
 
    for j in range(m):
        x += A[j]* B[j]
    x += c
    if x > 0:
        ans += 1

print(ans)

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

  int main(){

    int n;
    cin>>n;
    int count = 0;
    bool holds = false;
    for(int i = 0; i< n; i++){
      int a,b;
      cin>>a>>b;
      if(a==b){
        count++;
      }
      if(a!=b){
        count = 0;
      }

      if(count == 3){
        holds = true;
      }

    }
    if(holds) cout<<"Yes";
    else cout<<"No";
    return 0;
  }


Measured memory_bytes: 3620
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto S = RD!(char[]);
	auto Q = RD;
	char[] str1, str2;
	bool dir = true;
	foreach (i; 0..Q)
	{
		auto T = RD;
		if (T == 1)
		{
			dir = !dir;
		}
		else
		{
			auto F = RD;
			auto C = RD!string;
			if ((dir && F == 1) || (!dir && F == 2))
				str1 ~= C;
			else
				str2 ~= C;
		}
	}
	if (dir)
	{
		str1.reverse();
		writeln(str1 ~ S ~ str2);
	}
	else
	{
		str2.reverse();
		S.reverse();
		writeln(str2 ~ S ~ str1);
	}

	stdout.flush;
	debug readln;
}

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
  int x;
  cin >> x;
  while(true){
    is_prime(x);
    if(is_prime(x)==true){
      cout << x << endl;
      return 0;
    }
    x++;
  }
  
  return 0;

}


Measured memory_bytes: 3640
X, K, D = map(int, input().split())

l_ast = (K*D-X) / (2*D)

def dist(l):
    return abs(X+2*l*D-K*D)

if l_ast > K:
    d = dist(K)
elif l_ast < 0:
    d = dist(0)
else:
    l_ = int(l_ast)
    if l_ast - l_ < 0.5:
        d = dist(l_)
    else:
        d = dist(l_+1)
print(d)


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

class Node{
public:
	Node *parent;
	Node *l;
	Node *r;
	long key;
	
	Node() : parent(NULL), l(NULL), r(NULL), key(0){
		return;
	}
	~Node(){
		if(l != NULL){ delete l; l = NULL; }
		if(r != NULL){ delete r; r = NULL; }
	}
};

void insert(Node **root_handle, long key){
	Node *y = NULL;
	Node *x = *root_handle;

	while(x != NULL){
		y = x;
		if(key < x->key){
			x = x->l;
		}
		else{
			x = x->r;
		}
	}

	Node *z = new Node;
	z->parent = y;
	z->key = key;

	if(y == NULL){
		*root_handle = z;
	}
	else if(z->key < y->key){
		y->l = z;
	}
	else{
		y->r = z;
	}
	return;
}

bool find(Node *n, long key){
	if(n->key == key){
		return true;
	}

	if(key < n->key){
		if(n->l != NULL){
			return find(n->l, key);
		}
		else{
			return false;
		}
	}
	else{
		if(n->r != NULL){
			return find(n->r, key);
		}
		else{
			return false;
		}
	}
	return false;
}

void print_inorder(Node *n){
	if(n->l != NULL){
		print_inorder(n->l);
	}
	std::cout << " " << n->key;

	if(n->r != NULL){
		print_inorder(n->r);
	}
	return;
}

void print_preorder(Node *n){
	std::cout << " " << n->key;
	if(n->l != NULL){
		print_preorder(n->l);
	}

	if(n->r != NULL){
		print_preorder(n->r);
	}
	return;
}

int main(int argc, char **argv){
	int m = 0;
	Node *root = NULL;
	char str[100];
	long key = 0;

#if INPUT_FROM_FILE
	FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	fscanf(fp, "%d", &m);
#else
	scanf("%d", &m);
#endif

	for(int i = 0; i < m; i++){
#if INPUT_FROM_FILE
		fscanf(fp, "%s", str);
#else
		scanf("%s", str);
#endif
		if(str[0] == 'i'){
#if INPUT_FROM_FILE
			fscanf(fp, "%d", &key);
#else
			scanf("%d", &key);
#endif
			insert(&root, key);
		}
		else if(str[0] == 'p'){
			print_inorder(root);
			std::cout << std::endl;
			print_preorder(root);
			std::cout << std::endl;
		}
		else{
#if INPUT_FROM_FILE
			fscanf(fp, "%d", &key);
#else
			scanf("%d", &key);
#endif
			bool ret = find(root, key);

			if(ret){
				std::cout << "yes" << std::endl;
			}
			else{
				std::cout << "no" << std::endl;
			}
		}
	}


#if INPUT_FROM_FILE
	fclose(fp); fp = NULL;
#endif
	if(root != NULL){ delete root; root = NULL; }
	return 0;
}


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


int main(void)
{
	long int a, b, c, d;
	long int i, j;
	long int first = 0, last = 0;
	long int work, work_c, work_d;
	long int sum = 0;
	long int bc0, ac0, bd0, ad0, bcd0, acd0;
	long int cd;
	
	scanf("%ld%ld%ld%ld", &a, &b, &c, &d);
	
	if(c < d) {
		work = c;
		c = d;
		d = work;
	}
	
	work_c = c;
	work_d = d;
	
	work = work_c % work_d;
	while(work != 0) {
		work_c = work_d;
		work_d = work;
		work = work_c % work_d;
	}
	
	bc0 = b / c;
	ac0 = (a - 1) / c;
	bd0 = b / d;
	ad0 = (a - 1) / d;
	bcd0 = b / (c * d / work_d);
	acd0 = (a - 1) / (c * d / work_d);
	
	printf("%ld\n", b - a + 1 - (bc0 - ac0) - (bd0 - ad0) + (bcd0 - acd0) );
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;

bool win(const char* str, char c)
{
	bool ret = false;
	ret |= str[0]==c && str[1]==c && str[2]==c;
	ret |= str[3]==c && str[4]==c && str[5]==c;
	ret |= str[6]==c && str[7]==c && str[8]==c;
	ret |= str[0]==c && str[3]==c && str[6]==c;
	ret |= str[1]==c && str[4]==c && str[7]==c;
	ret |= str[2]==c && str[5]==c && str[8]==c;
	ret |= str[0]==c && str[4]==c && str[8]==c;
	ret |= str[2]==c && str[4]==c && str[6]==c;
	return ret;
}

int main()
{
	char str[16];
	while(scanf("%s", str) != EOF){
		if(win(str, 'o'))
			puts("o");
		else if(win(str, 'x'))
			puts("x");
		else
			puts("d");
	}
}

Measured memory_bytes: 0
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  int N;
  in(N);
  vector<int> A(N);
  int all=1,bad=1;
  rep(i,N){
    in(A[i]);
    all*=3;
    if(A[i]%2==0)bad*=2;
  }
  out(all-bad);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin>>s;
    int ans=0;
    if(s.at(0)=='R'){
        ans++;
        if(s.at(1)=='R'){
            ans++;
            if(s.at(2)=='R'){
                ans++;
                cout<<ans<<endl;
            }else{
                cout<<ans<<endl;
            }
        }else{
            cout<<ans<<endl;
        }
    }else{
        if(s.at(1)=='R'){
            ans++;
            if(s.at(2)=='R'){
                ans++;
                cout<<ans<<endl;
            }else{
                cout<<ans<<endl;
            }
        }else{
            if(s.at(2)=='R'){
                ans++;
                cout<<ans<<endl;
            }else{
                cout<<ans<<endl;
            }
        }
    }
}


Measured memory_bytes: 3624