akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/rope>
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
//
//template<class T> using Tree = tree<T, null_type, less<T>, rb_t_tag,t_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;

// watch this
//using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

const int mxN = 55;

vector<int> g[mxN];
int sz[mxN];
long long m[mxN];
long long sum[mxN];

long long X, D;

void dfs(int u) {
	sz[u] = 1;
	sum[u] = m[u];
	for (auto v : g[u])
		dfs(v), sum[u] += sum[v], sz[u] += sz[v];
}

bool cmp(int a, int b) {
	if (sum[a] * sz[b] != sum[b] * sz[a])
		return sum[a] * sz[b] < sum[b] * sz[a];
	return sz[a] > sz[b];
}

long long dp[2][mxN * mxN * mxN];

int main(int argc, char** argv) {
	//#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//#endif

	int N, p;
	cin >> N >> X >> D;
	vector<int> a(N);
	for (int i = 1; i <= N; i++) {
		cin >> m[i];
		if (i > 1)
			cin >> p, g[p].push_back(i);
		a[i - 1] = i;
	}
	dfs(1);
	sort(begin(a), end(a), cmp);
	vector<pair<int, int> > can;
	for (auto u : a) {
		long long mx = min((u == 1 ? X : D), X / sum[u]);
		if (mx) {
			can.push_back( { u, min(mx, (long long) N) });
		}
	}
	dp[0][0] = 0;
	for (int j = 1; j <= N * N * N; j++)
		dp[0][j] = X + 1;
	for (int i = 0; i < (int) can.size(); i++) {
		int d = i & 1;
		int o = !d;
		for (int j = 0; j <= N * N * N; j++)
			dp[o][j] = X + 1;
		for (int j = 0; j <= N * N * i; j++) {
			if (dp[d][j] > X)
				continue;
			for (int k = 0; k <= can[i].second; k++) {
				dp[o][j + k * sz[can[i].first]] = min(
						dp[o][j + k * sz[can[i].first]],
						dp[d][j] + k * sum[can[i].first]);
			}
		}
	}
	long long res = 0;
	for (int tot = 0; tot <= N * N * N; tot++) {
		if (dp[((int) can.size()) & 1][tot] > X)
			continue;
		long long cur = tot;
		long long curX = X - dp[((int) can.size()) & 1][tot];
		for (auto u : a) {
			long long mx = min((u == 1 ? X : D), X / sum[u]);
			if (mx <= N)
				continue;
			mx -= N;
			mx = min(mx, curX / sum[u]);
			curX -= mx * sum[u];
			cur += mx * sz[u];
		}
		res = max(res, cur);
	}
	cout << res << '\n';
	return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n,m;
vector<int> g[222222];
bool vis[222222];

bool dfs(int v,int dist){
  if(v==n-1)return true;
  if(dist==2)return false;
  vis[v]=true;
  for(int nv : g[v]){
    if(!vis[nv]&&dfs(nv,dist+1))return true;
  }
  return false;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].push_back(b); g[b].push_back(a);
  }
  if(dfs(0,0))cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 12656
h,n = map(int, input().split())
ls = [list(map(int, input().split())) for i in range(n)]
INF = 1001001001001
dp = [[INF]*(h+1) for _ in range(n+1)]

for i in range(n+1):
    dp[i][0] = 0


for i in range(1,n+1):
    for j in range(h+1):
        dp[i][j] = min(dp[i-1][j], dp[i][max(j-ls[i-1][0], 0)]+ls[i-1][1])

print(dp[-1][-1])





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

struct line{
	ll a,b;
	ll get(ll x){
		return a*x+b;
	}
};
struct CHT{
	deque<line>que;
	bool check(line a,line b,line c){
		ll A[]{a.a,b.a,c.a},B[]{a.b,b.b,c.b};
		return (B[1]-B[2])*(A[1]-A[0])<=(B[0]-B[1])*(A[2]-A[1]);
	}
	void add(line l){
		while(que.size()>1&&check(que[que.size()-2],que.back(),l))que.pop_back();
		que.push_back(l);
	}
	double get(double x){
		if(que.empty())return INFINITY;
		while(que.size()>1&&que[0].get(x)>=que[1].get(x))que.pop_front();
		return que[0].get(x);
	}
};

ll h[300000];
ll a[300000],b[300000];
ll dp[300000];

int main(){
	int n;ll C;cin>>n>>C;
	rep(i,n)scanf("%lld",&h[i]);
	CHT cht;
	dp[0]=0;
	cht.add({-2*h[0],h[0]*h[0]+C});
	for(int i=1;i<n;i++){
		dp[i]=cht.get(h[i])+h[i]*h[i];
		cht.add({-2*h[i],dp[i]+h[i]*h[i]+C});
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll n,m,x;cin>>n>>m;
    char a[n][m];ll p[n][m];
    for(ll i=0;i<n;i++)
     for(ll j=0;j<m;j++)
      cin>>a[i][j];
    memset(p,0,sizeof(p));
    for(ll i=0;i<n;i++)
    {
    	x=0;
    	for(ll j=0;j<m;j++)
    	{
    		if(a[i][j]=='.') {p[i][j]+=x;x++;}
    		else x=0;
		}
		 x=0;
		for(ll j=m-1;j>=0;j--)
		{
			if(a[i][j]=='.'){p[i][j]+=x;x++;
			}
			else x=0;
		}
    	
	}
	for(ll j=0;j<m;j++)
	{
		x=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i][j]=='.') {p[i][j]+=x;x++;
			}
			else x=0;
		}
		x=0;
		for(ll i=n-1;i>=0;i--) 
		{ 
		  if(a[i][j]=='.') {p[i][j]+=x;x++;
		  }
		  else x=0;
		}
	}
	
	ll ans=p[0][0];
	for(ll i=0;i<n;i++)
	 for(ll j=0;j<m;j++)
	  ans=max(ans,p[i][j]);ans++;
	  cout<<ans;
      
	
	
	
 return 0;
}

Measured memory_bytes: 35456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var A = new int[N];
            var B = new int[N];


            for (int i =0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                B[i] = A[i];

            }

            Array.Sort(B);

            for (int i = 0;i < N; i++)
            {
                if (A[i] == B[N - 1])
                {
                    Console.WriteLine(B[N - 2]);
                }
                else
                {
                    Console.WriteLine(B[N - 1]);
                }

            }

        }
    }
}


Measured memory_bytes: 17876
from collections import deque
number,m = map(int,input().split())

h = deque([])

for _ in range(m):
    l = list(map(int,input().split()))
    h.append(l)
count = 0

for i in range(m):
    if i != 0:
        h.append([a1,b1])
    a1,b1 = h.popleft()
    g = [[] for _ in range(number)]
    for a,b in h:

        g[a-1].append(b)
        g[b-1].append(a)

    q = deque([a1])
    pre = [0]*number
    pre[a1-1] = 1
    while q:
        now = q.popleft()

        for n in g[now-1]:

            if pre[n-1] == 0:
                q.append(n)
                pre[n-1] = 1
            else:
                continue
    
    if sum(pre) != number:
        count+=1

print(count)



Measured memory_bytes: 9384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] array = line2.split(" ");

		long[] ai = new long[array.length];
		for (int i = 0; i < ai.length; i++) {
			ai[i] = Integer.parseInt(array[i]);
		}

		Arrays.sort(ai);
		long A = ai[0];
		long B = ai[n - 1];

		long C = 0;
		for (int i = 0; i < ai.length; i++) {
			C += ai[i];

		}

		System.out.println(A + " " + B + " " + C);

	}

}

Measured memory_bytes: 31576
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define N 100012
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007

using namespace std;

ll n, x;

int main(){
    ios_base::sync_with_stdio(0);
    cin >> n;
    x = 100;
    int i;
    for(i = 0; (x < n); ++i){
        x = x * 1.01;
    }
    cout << i << '\n';
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
int main(){
	while(true){
		int n,a=0,b=0;
		cin >> n;
		if(!n) break;
		rep(i,n){
			int p,q;
			cin >> p >> q;
			if(p>q) a+=(p+q);
			else if(p<q) b+=(p+q);
			else{
				a+=p;
				b+=p;
			}
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
from itertools import permutations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    P = tuple(map(int, readline().split()))
    Q = tuple(map(int, readline().split()))

    perms = list(permutations(range(1, N + 1)))
    print(abs(perms.index(P) - perms.index(Q)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;

int main() {
  int64_t N,A,B;
  cin>>N>>A>>B;
  int64_t ans=0;
  if(A%2==B%2){ans=(B-A)/2;}
  else{
    int64_t win=A-1+1+(B-A-1)/2;
    int64_t lose=N-B+1+(B-A-1)/2;
    ans=min(win,lose);
  // ans=min(A-1,N-B)+1+(B-A-1)/2;
    }
  cout<<ans<<endl;
  return 0;}

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


int main(){
	string s;cin>>s;
	int K;cin>>K;
	set<string> p;
	for(char x = 'a';x<='z';x++){
		for(int i=0;i<s.size();i++) if(s[i] == x){
			for(int j=1;j<=5;j++) p.insert(s.substr(i,j));
		}
		if(p.size() >= K) break;
	}
	int idx = 1;
	for(auto x: p){
		if(idx == K){
			cout<<x<<endl;
			return 0;
		}
		idx += 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int count(vector<int> circ) {
    int mi = 101010;
    REP(i, circ.size()) {
        REP(j, circ.size()) {
            if(i != j) {
                int d1 = abs(circ[i] - circ[j]);
                int d2 = 24 - d1;
                int d = min(d1, d2);
                mi = min(mi, d);
            }
        }
    }
    // print(circ);
    // cout << mi << endl;
    return mi;
}

int main() {
    int N;
    cin >> N;
    // Nがかなり小さい
    vector<ll> D(N);
    vector<ll> F(N);
    map<int, int> cnt;
    REP(i, N) {
        cin >> D[i];
        cnt[D[i]]++;
    }
    // https://www.hamayanhamayan.com/entry/2017/11/27/224728
    // D_iごとにカウントするる
    //おなじD_iに三人以上いる場合は0
    //一人だけの場合は左右の二通り
    // 2^11とおりを試せばよい
    if(cnt[0] > 0) {
        cout << 0 << endl;
        return 0;
    }
    REP(i, 13) {
        if(cnt[i] > 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    // D[i]が2のときはそれを全探査
    vector<int> v;
    vector<int> cricle;
    cricle.push_back(0);
    REP(i, 13) {
        if(i == 12) {
            if(cnt[i] > 0) {
                cricle.push_back(i);
            }
        } else if(cnt[i] == 1) {
            v.push_back(i);
        } else if(cnt[i] == 2) {
            cricle.push_back(i);
            cricle.push_back(24 - i);
        }
    }
    // print(cricle);
    // print(v);
    int ans = 0;
    if(v.size() == 0) {
        cout << count(cricle) << endl;
        return 0;
    }
    REP(msk, 1 << v.size()) {
        vector<int> tmp = cricle;
        REP(j, v.size()) {
            if(msk & (1 << j)) {
                tmp.push_back(v[j]);
            } else {
                tmp.push_back(24 - v[j]);
            }
        }
        ans = max(ans, count(tmp));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n > 0) {
            int i = 0;
            n = 1000 - n;
            if (n >= 500) {
                while (n >= 500) {
                    n -= 500;
                    i++;
                }
            }
            if (n >= 100) {
                while (n >= 100) {
                    n -= 100;
                    i++;
                }
            }
            if (n >= 50) {
                while (n >= 50) {
                    n -= 50;
                    i++;
                }
            }
            if (n >= 10) {
                while (n >= 10) {
                    n -= 10;
                    i++;
                }
            }
            if (n >= 5) {
                while (n >= 5) {
                    n -= 5;
                    i++;
                }
            }
            if (n >= 1) {
                while (n >= 1) {
                    n -= 1;
                    i++;
                }
            }
            System.out.println(i);
            n = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 26152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N;
    cin >> N;
    vector<vector<int>> memo(N);
    rep(i,N) memo[i].resize(N,-1);
    rep(i,N){
      int a; cin >> a;
      rep(j,a){
        int x, y;
        cin >> x >> y;
        x--;
        memo[i][x] = y;
      }
    }

    int ans = 0;
    for(int bit = 0; bit < (1<<N); bit++){
      int total = 0;
      vector<int> check(N,0);
      bool ok = 1;

      for(int i = 0; i < N; i++){
        if(bit & (1<<i)) check[i] = 1;
      }

      rep(i,N){
        if(check[i]==1){//iは正直者
          rep(j,N){
            if(memo[i][j]!=-1){
              if(memo[i][j]!=check[j]) ok = 0;
            } 
          }
          if(!ok) break;
        }
      }

      if(ok){
        rep(i,N) if(check[i]==1) total++;
        ans = max(ans,total);
      }
    }

    cout << ans << endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> way(n+1);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    way[a].push_back(b);
    way[b].push_back(a);
  }
  vector<int> ans(n+1,-1);
  queue<int> qu;
  
  ans[1]=0;
  qu.push(1);
  while(!qu.empty()){
    int x=qu.front();
    qu.pop();
   
    for(int i:way[x]){
      if(ans[i]!=-1) continue;
      
      ans[i]=x;
      qu.push(i);
    }
  }
  cout << "Yes" << endl;
  for(int i=2;i<=n;i++){
    cout << ans[i] << endl;
  }
  return 0;
}  


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

struct Node
{
  int key;
  struct Node *next;
  struct Node *prev;
};

struct Node *nil;

struct Node* listSearch(int key)
{
  struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key)
    {
      cur=cur->next;
    }
    
  return cur;
}

void input();
void print();
void deleteNode(struct Node *t);
void deletefirst();
void deletelast();
void deleteKey(int key);
void insert(int key);

int main(void)
{
  int i;
  int key,n;
  int size = 0;
  char com[20];
  int np=0,nd=0;
    
  scanf("%d",&n);
    
  input();
    
  for(i=0;i<n;i++)
    {
      scanf(" %s %d",com,&key);
      if(com[0]=='i')
	{
	  insert(key);
	  np++;
	  size++;
        }
      else if(com[0]=='d')
	{
	  if(strlen(com)>6)
	    {
	      if(com[6]=='F')
		{
		  deletefirst();
		}
	      else if(com[6]=='L')
		{
		  deletelast();
		}
            }
	  else
	    {
	      deleteKey(key);
	      nd++;
            }
	  size--;
        }
    }
    
  print();
    
  return 0;
    
}

void input()
{
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void print()
{
  struct Node *cur=nil->next;
    
  int i=0;
    
  while(1)
    {
      if(cur==nil)
	{
	  break;
	}
      if( i++>0 )
	{
	  putchar(' ');
	}
	
      printf("%d",cur->key);
	
      cur=cur->next;
    }
    
  putchar('\n');
}

void deleteNode(struct Node *t)
{
  if(t==nil)
    {return;
    }
    
  t->prev->next=t->next;
    
  t->next->prev=t->prev;
    
  free(t);
}

void deletefirst()
{
  deleteNode(nil->next);
}

void deletelast()
{
  deleteNode(nil->prev);
}

void deleteKey(int key)
{
  deleteNode(listSearch(key));
}

void insert(int key)
{
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));

  x->key=key;   
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}



Measured memory_bytes: 32952
#include<iostream>
#include<math.h>
using namespace std;

int keta(int x){
  int keta = 0;
  while(x != 0){
    x /= 10;
    keta++;
  }
  return keta;
}
int main(){
  int N;
  cin >> N;
  int n = N;
  int s = 0;
  int k = keta(N);
  while(k != 0){
    k--;
    s += N/pow(10, k);
    N = N % (int)pow(10, k);
  }
   if(n%s == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 998244353;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 4010
ll p2[N];

void xo(string &a, string &b){
	int n = min(a.size(), b.size());
	rep(i, n) a[i] = '0'+(a[i]^b[i]);
}

bool le(string &a, string &b){
	int n = min(a.size(), b.size());
	rep(i, n){
		if(a[i]<b[i]) return true;
		if(a[i]>b[i]) return false;
	}
	return true;
}

void ker(vector<string> &s){
	int n = s.size();
	rep(i, n-1){
		while(s[i].size()>0){
			if(s[i].size()<s[i+1].size()) s[i].swap(s[i+1]);
			xo(s[i], s[i+1]);
			int j = 0;
			while(j<s[i].size() &&s[i][j]=='0') j++;
			s[i].erase(0, j);
		}
	}
}

int main(){
	int n;
	string x;
	cin>>n>>x;
	int m = x.size();
	vector<string> s(n);
	rep(i, n) cin>>s[i];
	ker(s);
	string a(s[n-1]), b(m, '0');
	p2[0] = 1;
	rep(i, N-1) p2[i+1] = p2[i]*2%mod;
	ll res = 0;
	int m2 = a.size(), l = m-m2+1;
	rep(i, l){
		b.erase(0, 1); b += '0';
		if(x[i]=='1'){
			res += p2[l-i-1];
			if(b[0]=='0'){
				xo(b, a);
			}
		} else {
			if(b[0]=='1'){
				xo(b, a);
			}
		}
		res %= mod;
	}
	/*cerr<<"debug"<<endl;
	cerr<<a<<endl;
	cerr<<b<<endl;
	cerr<<x<<endl;*/
	string y = x.substr(m-m2);
	if(le(b, y)) res++;
	cout<<res%mod<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;


ll comb(ll m, ll n){
  ll a = 1;
  REP(i, n){
    a *= m-i;
    a /= i+1;
  }
  return a;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  ll v[n];
  REP(i, n) cin >> v[i];
  sort(v, v+n);
  ll sum = 0;
  bool f = true;
  REP(i, a){
    sum += v[n-i-1];
    if(i != 0 && v[n-i-1] != v[n-i]) f = false;
  }
  if(f){
    int t = 0;
    REP(i, n)if(v[i] == v[n-1])t++;
    ll ans = 0;
    FOR(i, a, b+1){
      (ans += comb(t, i));
    }
    cout << v[n-1] << endl << ans << endl;
  }
  else{
    int t = 0, u = 0;
    cout << fixed << setprecision(16) << (double)sum/(double)a << endl;
    REP(i, n){
      if(v[i] == v[n-a]){
        t++;
        if(i >= n-a) u++;
      }
    }
    cout << comb(t, u) << endl;
  }
	return 0;
}


Measured memory_bytes: 256
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]
AB_sorted = sorted(AB, key=lambda x: x[1])
task_sum = 0
ans = 'Yes'

for i in range(N):
  task_sum += AB_sorted[i][0]
  if task_sum > AB_sorted[i][1]:
    ans = 'No'
    break
print(ans) 

Measured memory_bytes: 48456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
namespace std {
  bool operator<(const P a, const P b) {
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
}
VP convexHull(VP ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  ch.resize(k-1);
  return ch;
}
int main(){
  int n;
  cin>>n;
  VP v;
  while(n--){
    double a,b;
    cin>>a>>b;
    v.push_back(P(a,b));
   }
  v=convexHull(v);
  cout<<v.size()<<endl;
  for(int i=0;i<v.size();i++){
    cout<<v[i].X<<' '<<v[i].Y<<endl;
  }
}


Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
string S;
unordered_map< int64, int64 > dp[14][9 * 14 + 1][4];
int length;
int64 weight;

int64 dfs(int idx, int num, int64 seki, int flag)
{
  if(num - (length - idx) * 9 > 0) return(0);
  if(idx == length) {
    if(seki != weight) return(seki < weight);
    return(flag == 1);
  }
  if(dp[idx][num][flag].find(seki) != dp[idx][num][flag].end()) return(dp[idx][num][flag][seki]);
  int64 ret = 0;
  for(int i = 0; i <= min(num, 9); i++) {
    int nextflag = flag;
    if(flag == 0) {
      if(i < S[idx] - '0')      nextflag = 1;
      else if(i > S[idx] - '0') nextflag = 2;
    }
    ret += dfs(idx + 1, num - i, seki * (i + 1), nextflag);
  }
  return(dp[idx][num][flag][seki] = ret);
}

int main()
{
  cin >> S;
  length = S.size();
  int sum = accumulate(S.begin(), S.end(), 0) - '0' * S.size();
  if(sum == 0) {
    cout << 0 << endl;
  } else {
    vector< int64 > poyo(sum, 0);
    poyo[0] = 1;
    for(int i = 0; i < length; i++) {
      for(int j = sum - 1; j >= 0; j--) {
        for(int k = j + 1; k <= min(sum - 1, j + 9); k++) {
          poyo[k] += poyo[j];
        }
      }
    }
    weight = 1;
    for(int i = 0; i < S.size(); i++) weight *= (S[i] - '0' + 1);
    cout << accumulate(poyo.begin(), poyo.end(), 0LL) + dfs(0, sum, 1, 0) << endl;
  }
}

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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s;
    int ans = 0;
    int n;
    cin >> n >> s;
    s += "F";
    s += "F";
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }
    cout << ans;
    return 0;
}

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

bool isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
 int x;
    cin>>x;
    while(1)
    {
        if(x==1)
        {
            cout<<"2"<<endl;
            break;
        }
        
        if(isPrime(x))
        {
            cout<<x<<endl;
            break;
        }
        x++;
    }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,m,tmp;
	long long sum=0;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>tmp;
		sum+=tmp;
	}
	if(sum>n)cout<<"-1";
	else cout<<n-sum;
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  long long h;
  scanf("%lld", &h);

  bitset<64> bs(h);

  int digit = -1;
  for (int i = 63; i >= 0; --i) {
    if (bs.test(i)) {
      digit = i;
      break;
    }
  }

  bitset<64> bso((long long)0);
  bso.set(digit + 1);

  long long val = bso.to_ullong() - 1;

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
    // Your code here!
 int n,m;
 cin>>n>>m;
 
 vector<vector<int>> vec(m);
 vector<int> p(m,0);
 int a,b;
 for(int i=0;i<m;i++){
     
     cin>>a;
     for(int j=0;j<a;++j){
         cin>>b;
         b--;
         vec[i].push_back(b);
     }
 }
 for(int i=0;i<m;i++){
     cin>>p[i];
 }
 
int count=0,ans=0;
for(int i=0;i<(1<<n);++i){
    count=0;
    for(int j=0;j<m;j++){
            int count1=0;
        for(int k=0;k<vec[j].size();k++){
           if((1<<vec[j][k]) & i)
                count1++;
        }
        {
                if(count1%2==p[j]){
                    count++;
                }
                    
        }
    }
    if(count==m)
    ans++;
}

cout<<ans;

}


Measured memory_bytes: 3152
import numpy as np

def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    mod = 10 ** 9 + 7
    a = b = 1
    for i in range(r):
        a = (a * (n - i)) % mod
        b = (b * (r - i)) % mod
    return (a * pow(b,mod-2,mod))%mod

X,Y = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    left = np.array([[1,2],[2,1]])
    right = np.array([X,Y])
    n = int(np.linalg.solve(left,right)[0])
    m = int(np.linalg.solve(left,right)[1])
    if n < 0 or m < 0 :
        print(0)
    else:
        print(nCr(n+m,n))

Measured memory_bytes: 15560
#include<bits/stdc++.h>
using namespace std;
int main()
  {
    string S;
    int cmt=0,i,j;
    cin>>S;
    for(i=0;i<4-1;i++)
      {
      for(j=i+1;j<4;j++)
        {
        if(S[i]==S[j])
          {
           cmt++;
          }
         }
      }
    if(cmt==2)
           cout<<"Yes"<<endl;
    else
           cout<<"No"<<endl;
    return 0;
           
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
////////////////////////////////////////////////////////////////////
using namespace std ;

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

  if(a > b){
    printf("safe");
  }else{
    printf("unsafe");
  }

  return 0;
}

Measured memory_bytes: 3776
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int MAX_K = 15;
double dp[2][MAX_K], ans[100010];

signed main() {
    dp[0][1] = ans[1] = 1.0;

    rep(i,0,100000) {
        int cur = i%2, nxt = cur^1;
        rep(j,0,MAX_K) {
            double P = pow(0.5, j);
            if(j+1 < MAX_K) dp[nxt][j+1] += P * dp[cur][j];
            dp[nxt][0] += (1 - P) * dp[cur][j];
        }
        fill(dp[cur], dp[cur] + MAX_K, 0.0);
        ans[i+2] = ans[i+1] + (1 - dp[nxt][0]);
    }
    
    while(1) {
        int N; scanf("%lld", &N);
        if(N == 0) break;
        printf("%.12f\n", ans[N]);
    }
    return 0;
}


Measured memory_bytes: 4132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;


int A, B, C, X, Y;

int main(){
	
	cin >> A >> B >> C >> X >> Y;

	int c = min(X, Y);
	int price = c * min(A + B, 2 * C);
	
	if (X > Y) {
		price += (X - Y)* min(A, 2 * C);
	}
	else {
		price += (Y - X)* min(B, 2 * C);
	}

	cout << price << endl;

	return 0;
}



Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a = I()
s = S()
if a >= 3200:
    print(s)
else:
    print("red")

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

using namespace std;
using ll = long long;

const int N = 200005;

int n;
ll k;

int a[N];

ll f(ll lim) {

	ll ans = 0;
	int neg_ptr = 0, pos_ptr = n;
	
	for(int i = 0; i < n; i++) {
		if(a[i] == 0) {
			if(lim >= 0) ans += n - 1;
		}
		else if(a[i] > 0) {
			while(pos_ptr - 1 >= 0 and 1LL * a[i] * a[pos_ptr - 1] > lim) {
				pos_ptr--;
			}
			while(pos_ptr < n and 1LL * a[i] * a[pos_ptr] <= lim)
				pos_ptr++;
			if(i < pos_ptr) ans += pos_ptr - 1;
			else ans += pos_ptr;
		}
		else { // a[i] < 0
			while(neg_ptr < n and 1LL * a[i] * a[neg_ptr] > lim) {
				neg_ptr++;
			}
			while(neg_ptr - 1 >= 0 and 1LL * a[i] * a[neg_ptr-1] <= lim) neg_ptr--;
			if(i >= neg_ptr) ans += n - neg_ptr - 1;
			else ans += n - neg_ptr;
		}
	}
	assert(ans % 2 == 0);
	return ans / 2;
}

int main() {
	scanf("%d %lld", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d", a + i);

	sort(a, a + n);

	ll lo = -1e18, hi = 1e18, ans = 0;

	while(lo <= hi) {
		ll mid = (lo + hi) / 2;
		if(f(mid) >= k) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	printf("%lld\n", ans);
	
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long dfs(long long h)
{
	if (h==1) return 1;
	return 2*dfs(h/2)+1;
}
int main()
{
	long long h;
	cin>>h;
	cout<<dfs(h);
	return 0;
}

Measured memory_bytes: 256
s1, s2 = input().split()
a1, a2 = [int(i) for i in input().split()]
s = input()

if s1 == s:
  print(a1 - 1, a2)
elif s2 == s:
  print(a1, a2 - 1)
else:
  print(a1, a2)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
const int N=1000009;
int n,dp[N][4];
const int mod=1000000007;
signed main(){
	n=read();
	dp[1][1]=dp[1][2]=1;
	dp[1][0]=8;
	for(int i=2;i<=n;++i) {
		for(int j=0;j<=9;++j) {
			for(int k=0;k<4;++k) {
				int t=k;
				if(j==0)t|=1;
				if(j==9)t|=2;
				(dp[i][t]+=dp[i-1][k])%=mod;
			}
		}
	}
	printf("%lld\n",dp[n][3]);
	return 0;
}


Measured memory_bytes: 34644
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);

    public static void main(String args[]){
        String S=sc.next();
        if(S.equals("RRR")) System.out.println(3);
        else if(S.equals("RSR")||S.equals("RSS")||S.equals("SSR")||S.equals("SRS")) System.out.println(1);
      	else if(S.equals("SSS")) System.out.println(0);
        else System.out.println(2);
    }
}


Measured memory_bytes: 35624
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
#define inf 1000000007

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

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

signed main(){
	int n,cnt=0;
	cin>>n;
	vector<int>s(n);
	for(int i=0;i<n;i++){
		cin>>s[i];
		cnt+=s[i];
	}
	sort(s);
	if(cnt%10!=0)cout<<cnt<<endl;
	else{
		for(int i=0;i<n;i++){
			if(s[i]%10!=0){
				cout<<cnt-s[i]<<endl;
				return 0;
			}
		}
		cout<<0<<endl;
	}
}


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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int N = 100 * r + 10 * g + b;
    if (N % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX_L 100000

int gcd(int m, int n) {
  int tmp;
  while (m % n != 0) {
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return n;
}

int main(void) {
  int N;
  int A[MAX_L];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  int L[MAX_L];
  L[0] = 0;
  for(int i = 1; i < N; i++) {
    L[i] = gcd(L[i-1], A[i-1]);
  }

  int R[MAX_L+1];
  R[N] = 0; 
  for(int i = N-1; i >= 0; i--) {
    R[i] = gcd(R[i+1], A[i]);
  }

  int ans = L[N-1];
  for(int i = 0; i < N-1; i++) {
    int tmp = gcd(L[i], R[i+1]);
    if(tmp > ans)
      ans = tmp;
  }

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


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int N=2e5+5; 
ll n,C,x[N],v[N],pv[N],sv[N];
priority_queue<ii> q,q2;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>C;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>v[i],pv[i]=pv[i-1]+v[i];
	ll val=0;
	for(int i=n;i>=1;i--)
	{
		val+=v[i],sv[i]=val;
		q.push(ii(val-(C-x[i]),n-i+1));
	}
	ll res=0,p=1,mx=0;
	for(int i=0;i<=n;i++)
	{
		ll c1=2ll*x[i];
		if(i==0)
			c1=0;
		//case 1
		while(!q.empty()&&(q.top().second>n-i||C-x[n-q.top().second+1]<=x[i]))
			q.pop();
		if(!q.empty())
			res=max(res,pv[i]-c1+max(0ll,q.top().first));	
		//case 2
		while(p<=n-i&&C-x[n-p+1]<=x[i])
			q2.push(ii(sv[n-p+1]-2ll*(C-x[n-p+1]),p)),p++;
		while(!q2.empty()&&(q2.top().second>n-i))
			q2.pop();			
		if(!q2.empty())
			res=max(res,pv[i]-x[i]+max(0ll,q2.top().first));
		res=max(res,pv[i]-x[i]);		
	//	cout<<i<<' '<<res<<'\n';
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 10224
A= []
for _ in range(3):
    a,b=map(int,input().split())
    A.append(a)
    A.append(b)
B = []
for i in range(1,5):
    B.append(A.count(i))
if B.count(1) == 2 and B.count(2) == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 1;
    
    for(int i=0;i<N-1;i++){
        if(S[i]!=S[i+1]){
            ans += 1;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

al = 0
bo = 0

for i in range(len(a)):
    if i % 2 == 1:
        bo += a[i]
    else:
        al += a[i]

print(al - bo)


Measured memory_bytes: 8992
import sys
from collections import deque

readline = sys.stdin.readline

S = list(readline().rstrip())
Q = int(readline())
a = deque([])
b = deque([])
s = 1

for _ in range(Q):
    query = readline().rstrip()
    if query == '1':
        s = -s
    else:
        _, F, C = map(str, query.split())
        if s == 1:
            if F == '1':
                a.appendleft(C)
            else:
                b.append(C)
        else:
            if F == '1':
                b.append(C)
            else:
                a.appendleft(C)

answer = list(a) + S + list(b)
answer = ''.join(answer)
if s == -1:
    answer = answer[::-1]
print(answer)


Measured memory_bytes: 10508
#include <stdio.h>

int
main(void)
{
	int a;
	int b;
	int x;
	int y;
	int r;
	
	scanf("%d %d %d %d %d", &a, &b, &x, &y, &r);
	
	if ((x - r >= 0 && x + r <= a) && (y - r >= 0 && y + r <= b))
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}



Measured memory_bytes: 2092
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    int dp[n+1];
    memset(dp, 1, sizeof(dp));
    for (int i = 0; i < n; i++) *upper_bound(dp, dp+n+1, -a[i]) = -a[i];
    cout << lower_bound(dp, dp+n+1, 1) - dp << endl;
}


Measured memory_bytes: 1024
X,Y,A,B,C = (int(x) for x in input().split())
red = list(map(int, input().strip().split()))
green = list(map(int, input().strip().split()))
clear = list(map(int, input().strip().split()))
red.sort(reverse=True)
green.sort(reverse=True)
# clear.sort(reverse=True)
apple = red[0:X] + green[0:Y] + clear
apple.sort(reverse=True)
print(sum(apple[0:X+Y]))

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

int main(){
  long long def,l,r,t,ans=2019;cin>>l>>r;
  def=(r-l)%2020;l%=2019;r=l+def;
  
  for(long long i=l;i<=r-1;i++){
    for(long long j=i+1;j<=r;j++){
      ans=min(ans,(i*j)%2019);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
m = raw_input()
n = int(m)
a = map(int,raw_input().split())
su=0
i=0
ma=-1000000
mi=1000000
while i<n:
	if ma<a[i]:
		ma=a[i]
	if mi>a[i]:
		mi=a[i]
	su += a[i]
	i+=1
print"%d %d %d"%(mi,ma,su)


Measured memory_bytes: 5404
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"

	"strconv"
)

func solve(in io.Reader, out io.Writer) error {
	sc := bufio.NewScanner(in)
	sc.Split(bufio.ScanWords)
	a, b, x := nextInt(sc), nextInt(sc), nextInt(sc)

	if a > x || a+b < x {
		fmt.Fprintln(out, "NO")
	} else {
		fmt.Fprintln(out, "YES")
	}

	return nil
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	err := solve(os.Stdin, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long,long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long,long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long,long>>> lvvii;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

long long mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n;
	cin>>n;
	ll xrs=0;
	ll a,b; cin>>a>>b;
	for (int i = 0; i < n-2; ++i)
	{
		ll x;
		cin>>x;
		xrs^=x;
	}
	ll sum=a+b;
	ll ands=(sum-xrs)/2;
	if((sum-xrs) < 0 || (sum-xrs)%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	ll a1,b1;
	a1=b1=ands;
	ll rem=sum - 2*ands;
	if(rem<0 || rem&ands)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	for(ll i=50;i>=0;i--)
	{
		if((1LL<<i)&rem)
		{
			if((a1 + (1LL<<i))<=a) a1+=(1LL<<i);
			else b1+=(1LL<<i);
		}
	} 
	if(a1>0 && (a1^b1)==xrs && a1<=a)
	{
		cout<<a-a1<<endl;
	}
	else cout<<"-1"<<endl;
	return 0;
}	

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwert=b; x<qwert; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

const int N=50;
int A[N], n;
vector<pair<int,int> > ans;

int main(){
	cin >> n;
	int i=0;
	fore(x,0,n)cin>>A[x];
	fore(x,0,n)if(abs(A[x])>abs(A[i]))i=x;
	fore(x,0,n)if(i!=x)ans.pb({i,x}), A[x]+=A[i];
	for(int x=A[i]>0?1:n-2; 0 <= x && x < n; x += A[i]>0?1:-1)
		ans.pb({A[i]>0?x-1:x+1,x});
	cout << SZ(ans) << "\n";
	for(auto p : ans)cout << p.fst+1 << " " << p.snd+1 << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100001
#define Gard -1

typedef struct{
  int parent;
  int leftch;
  int rightch;
}Tree;

int main(){
  Tree Root[N];
  int loop,freq,chnode,numnode,temp,count,change,list;
  int i,j;

  scanf("%d",&loop);
  for(i=0;i<loop;i++){
    Root[i].parent=Gard;
    Root[i].leftch=Gard;
    Root[i].rightch=Gard;
  }

  for(i=0;i<loop;i++){
    scanf("%d %d",&freq,&chnode);
    
    for(j=0;j<chnode;j++){
      scanf("%d",&numnode);

      if(j==0){
	Root[freq].leftch=numnode;
	Root[numnode].parent=freq;
	temp=numnode;
      }

      else{
	Root[temp].rightch=numnode;
	Root[numnode].parent=freq;
	temp=numnode;
      }
    }
  }


  for(i=0;i<loop;i++){
    printf("node %d: parent = %d, ",i,Root[i].parent);

    count=0;
    change=i;
    while(Root[change].parent>Gard){
      change=Root[change].parent;
      count++;
    }
   
    printf("depth = %d, ",count);
    
    if(Root[i].parent==Gard){
      printf("root, [");
    }

    else if(Root[i].leftch==Gard){
      printf("leaf, [");
    }

    else{
      printf("internal node, [");
    }

    list=Root[i].leftch;
    count=0;
    while(list>Gard){
      if(count!=0){
	printf(", %d",list);
      }

      else{
	printf("%d",list);
      }
      count++;
      list=Root[list].rightch;
    }
    printf("]\n");
  }

  return 0;
}



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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b; cin >> a >> b;
	cout << a + b/2 << endl;
} 

Measured memory_bytes: 256