akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define mp make_pair
#define all(a) a.begin(),a.end()

using  namespace std; 


vector < pair <ll,ll> > ans;
vector <ll> pos,neg;
ll diff;

vector <ll> a;

void calc(){
    diff = pos[0];
     for(int i = 0; i < pos.size() - 1; i++){
        if(diff < pos[i+1]){
            ans.push_back(mp(diff,pos[i+1]));
            diff = diff - pos[i+1];
        }else{
            ans.push_back(mp(pos[i+1],diff));
            diff = pos[i+1] - diff;
        }
    }
}

void negcalc(){
    for(int i =0  ; i < pos.size() ; i++)
    {
        ans.pb(mp(neg[0],pos[i]));
        neg[0] = neg[0] - pos[i];
    }
    ll x;
    for(int i = 0; i < neg.size() ; i++){
        ans.pb(mp(a[a.size()-1],neg[i]));
        a[a.size() - 1] -= neg[i];
    }
}
 
int main() {

    ll n;
    cin>>n;
    
    a.resize(n);

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

    

    sort(all(a));

    for(int i = 0 ; i <= n-2 ; i++){
        if(a[i] > 0){
            pos.pb(a[i]);
        }else{
            neg.pb(a[i]);
        }
    }


    if(neg.size() > 0){
        negcalc();
        cout<<a[n-1]<<endl;
    } else if(neg.size() == 0){
        calc();
        if(diff > a[n-1]){
            cout<<diff - a[n-1]<<endl;
            ans.push_back(mp(diff,a[n-1]));
        }else{
            cout<<a[n-1] - diff << endl;
            ans.push_back(mp(a[n-1],diff));
        }
    }
  




    for(int i = 0 ;  i < ans.size() ;i++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }





    return 0; 

}

Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int res = 700;
    rep(i, 3) if (s[i] == 'o') res += 100;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[100005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> a;
	cin >> b;
	cin >> c;
	
		d = a - b + 1;
	
		e = a - c + 1;
	


	cout << d*e << endl;
	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    void run() {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if (a * b % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
}




Measured memory_bytes: 101708
#include <iostream>
#include <vector>
#include <stdio.h>

int max( int p, int q ) {
	if( p > q ) return p;
	return q;
}

int pow(int x,int n) {
    if( x == 0 ) return 0;
    if( n == 0 ) return 1;
    if( n == 1 ) return x;
    if( n & 1 ) {
        int y = pow( x, (n-1)/2 );
        return x * y * y;
    } else {
        int y = pow( x, n / 2 );
        return y * y;
    }
}



int main( void ) {
	using namespace std;

	while( 1 ) {
		//n個のm面ダイス
		int n, m, k;
		cin >> n >> m >> k;
		if( n == 0 && m == 0 && k == 0 ) break;
		
		/*
			DPテーブルの作成
			dp[  ][ j ] = 合計がjになるパターンの個数
		*/
		vector< vector< int > > dp( 2, vector< int >( max( n * m + 1, 1 ), 0 ) ); 

		//初期化
		dp[ 0 ][ 0 ] = 1;

		//DP本体
		for( int i = 0; i < n; i++ ) {
			for( int j = 0; j < dp[0].size(); j++ ) {
				dp[ ( i + 1 ) % 2 ][ j ] = 0;
			}
			for( int j = 0; j < dp[0].size(); j++ ) {
				for( int k = 1; k <= m; k++ ) {
					if( k + j >= dp[0].size() ) break;
					dp[ ( i + 1 ) % 2 ][ k + j ] += dp[ i % 2 ][ j ];
				}
			}
		}
		int sum = 0;
		for( int i = 0; i < dp[0].size(); i++ ) {
			sum += max( 1, i - k ) * dp[ n % 2 ][ i ];
		}
		double e;
		e = ( double )( sum ) / pow( m, n );

		printf("%.8lf\n", e);
	}

	return 0;

}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
vector<ll> cost[52][52];

int main() {
    //cout.precision(10);
    ll beki[60];
    beki[0] = 1;
    for(int i = 1; i <= 55; i++){
        beki[i] = beki[i - 1] * 2;
    }
    for(ll i = 0; i <= 50; i++){
        for(ll j = 0; j <= i; j++){
            //cout << j << endl;
            if(i == j){
                cost[i][j].push_back(0);
                continue;
            }
            for(ll k = 1; k <= i; k++){
                ll newi = (i % k);
                if(i == newi){
                    //cout << i << " " << k << endl;
                }
                for(int l = 0; l < cost[newi][j].size(); l++){
                    //cout << i << " " << j << " " << k << " " << l << endl;
                    cost[i][j].push_back(cost[newi][j][l] + beki[k]);
                }
            }
        }
    }
    for(int i = 0; i <= 50; i++){
        for(int j = 0; j <= 50; j++){
            sort(cost[i][j].begin(), cost[i][j].end());
            cost[i][j].erase(unique(cost[i][j].begin(), cost[i][j].end()), cost[i][j].end());
        }
    }
    for(int i = 0; i < cost[5][0].size(); i++){
        //cout << cost[5][0][i] << endl;
    }
    //cout << endl;
    ll ans = 0;
    int n;
    cin >> n;
    int a[52], b[52];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++){
        if(cost[a[i]][b[i]].empty()){
            cout << -1 << endl;
            return 0;
        }
    }
    while(true){
        ll maxi = 0;
        for(int i = 1; i <= n; i++){
            maxi = max(maxi, cost[a[i]][b[i]][0]);
        }
        if(maxi == 0){
            cout << ans << endl;
            return 0;
        }
        ll now = 1;
        while(now * 2 <= maxi){
            now = now * 2;
        }
        //cout << now << endl;
        ans += now;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < cost[a[i]][b[i]].size(); j++){
                    //cost[a[i]][b[i]][j] -= now;
                    cost[a[i]][b[i]][j] = cost[a[i]][b[i]][j] & ~now;
            }
            sort(cost[a[i]][b[i]].begin(), cost[a[i]][b[i]].end());
            cost[a[i]][b[i]].erase(unique(cost[a[i]][b[i]].begin(), cost[a[i]][b[i]].end()), cost[a[i]][b[i]].end());
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

struct Card {
  char suit, value;
};


void swap(struct Card *A , int a, int b )
	  	
{
  struct Card temp ;	

  temp = A[a] ;    
  A[a] = A[b] ;	
  A[b] = temp ;
  
}

void bubble(struct Card *A, int N){

  int i,j;

  for(i=0; i<N; i++){
    for(j=N-1;j>=i;j--){
      if(A[j].value<A[j-1].value){

	swap(A,j,j-1);
      }
    }
  }
}

void selection(struct Card *A,int N){

  int i,j;

  for(i=0;i<N;i++){
    int minj=i;
    for(j=i;j<N;j++){
      if(A[j].value<A[minj].value) minj=j;
    }
    swap(A,i,minj);
  }
  
}



int isStable(struct Card *c1,struct Card *c2, int N){

  int i,j;

  for(i=0;i<N;i++){
    if(c1[i].suit!=c2[i].suit) return -1;
  }
  if(c1[i].suit==c2[i].suit)  return 1;
}

int main(){

  int i,j;

  struct Card c1[100],c2[100];
  int N;
  

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf(" %c%c",&c1[i].suit,&c1[i].value);
  }

  for(i=0;i<N;i++){
    c2[i]=c1[i];
  }

  bubble(c1,N);
  selection(c2,N);

  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%c%c", c1[i].suit, c1[i].value);
  }
  printf("\n");

  if(isStable(c1,c2,N)==1){
    printf("Stable");
  }
  else if(isStable(c1,c2,N)!=1){
    printf("Stable");
  }

  printf("\n");

  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%c%c", c2[i].suit, c2[i].value);
  }
  printf("\n");

  if(isStable(c1,c2,N)==1){
    printf("Stable");
  }
  else if(isStable(c1,c2,N)!=1){
    printf("Not stable");
  }

  printf("\n");

  return 0;
}

  

    
  





Measured memory_bytes: 2104
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }
                                   
 
  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=2e18+18;
  const int N=2e5+25;
  const int M=2e4;
  const double p2=pi/2.000000;
  
 int ct[100][100];
 void fft()
 { 
   int n,m; cin>>n>>m;
   vector<string> s(n);
   tr(i,s) cin>>i;

   if(s[0][0]=='#') ct[0][0]=1;

   for(int i=1;i<m;++i){
     ct[0][i]=ct[0][i-1];
     if(s[0][i]=='#'&&s[0][i-1]!='#') ct[0][i]++;    
   }
                       
   for(int i=1;i<n;++i){
     ct[i][0]=ct[i-1][0];
     if(s[i][0]=='#'&&s[i-1][0]!='#') ct[i][0]++;
   }
            
   for(int i=1;i<n;++i){
     for(int j=1;j<m;++j){

        if(s[i][j]=='#'){
          if(s[i-1][j]=='#')
           ct[i][j]=ct[i-1][j];
          else
           ct[i][j]=ct[i-1][j]+1;
           
          if(s[i][j-1]=='#')
          ct[i][j]=min(ct[i][j],ct[i][j-1]);
          else
          ct[i][j]=min(ct[i][j],ct[i][j-1]+1);
        }
        else
        ct[i][j]=min(ct[i-1][j],ct[i][j-1]);
     }
   }

   cout<<ct[n-1][m-1];

 }

signed main()
{ 
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 
   
   int t=1;                         
//   cin>>t;

  rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   fft();
   if(i<t)
   cout<<nl;
  }
  
 
 return 0; 
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1)%1000000007;
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    //頂点sからｔへたどり着けるか
    // 頂点数と辺数
    ll n,m;
    cin>>n>>m;
    graph g(n);
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        g[--a].push_back(--b);//無向辺
        g[b].push_back(a);//有向辺
    }
    ll s=0,t=n-1;
    // 頂点 s をスタートとした探索
    vector<ll>dist(n,-1);
    queue<ll>que;
    dist[s]=0,que.push(s);
    while(!que.empty()){
        ll v=que.front();
        que.pop();
        for(auto nv:g[v]){
            if(dist[nv]==-1){
                dist[nv]=dist[v]+1;
                que.push(nv);
            }
        }
    }
    /*
    for(ll v=0;v<n;v++){
        cout<<v+1<<": "<<dist[v]<<endl;
    }
    */

     // t に辿り着けるかどうか
    if(dist[t]!=-1&&dist[t]==2){
        cout<<"POSSIBLE"<<endl;
        //cout<<dist[t]<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
        //cout<<dist[t]<<endl;
    }


    

}

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

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

	// 同じ単語を使ってはいけない
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			if (v[i] == v[j]) {
				cout << "No" << endl;
				exit(0);
			}
		}
	}

	int count = 0;

	for (int j = 0; j < N - 1; j++) {
		if (v[j][v[j].size() - 1] == v[j+1][0]) {
			++count;
		}
	}

	if (count == N - 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

const int INF = 1001001001;
int d[100005];

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  vector<vector<int>> length(n);
  rep(i,n-1) {
    int u,v,w;
    cin >> u >> v >> w;
    --u; --v;
    to[u].push_back(v);
    to[v].push_back(u);
    length[u].push_back(w);
    length[v].push_back(w);
  }
  rep(i,n) d[i] = INF;
  queue<int> q;
  q.push(0);
  d[0] = 0;
  while (!q.empty()) {
    int c_v = q.front();
    // cout << c_v << endl;
    q.pop();
    for(int i=0;i<to[c_v].size();i++){
      int n_v = to[c_v][i];
      int l = length[c_v][i];
      if (d[n_v] != INF) continue;
      d[n_v] = (d[c_v]+l)%2;
      q.push(n_v);
    }
  }
  rep(i,n)cout << d[i] << endl;
  return 0;
}


Measured memory_bytes: 11904
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
 
using namespace std;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

ll a, b, gcd, ans = 1;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> a >> b;
   gcd = __gcd (a, b);
   for (int i = 2; 1ll * i * i <= gcd; i ++) {
      if (gcd % i == 0) {
         ans ++;
         while (gcd % i == 0) gcd /= i;
      }                          
   }
   if (gcd > 1) ans ++;
   cout << ans;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

string s;
int n;

bool check(int m){
	REP(i, n - m){
		string tmp = s.substr(i, m);
		if (s.find(tmp, i + m) != string::npos){
			return true;
		}
	}
	return false;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
	cin >> n >> s;
	int lo = 1, hi = n / 2, mid, ans = 0;
	while (lo <= hi){
		mid = (lo + hi) / 2;
		if (check(mid)){
			lo = mid + 1;
			ans = max(ans, mid);
		}
		else hi = mid - 1;
	}
	cout << ans << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;	
}

Measured memory_bytes: 384
N = gets.to_i
h = gets.split.map(&:to_i)
dp = [0, (h[0] - h[1]).abs]
2.step(N-1) do |i|
  dp[0], dp[1] = dp[1], [dp[1] + (h[i-1] - h[i]).abs, dp[0] + (h[i-2] - h[i]).abs].min
end
puts dp[1]

Measured memory_bytes: 10500
MOD = 10**9 + 7
n = sorted([int(item) for item in input().split()])

def nPr(n, r):
    val = 1
    for i in range(r):
        val = val * (n-i) % MOD 
    return val

if n[1] - n[0] >= 2:
    print(0)
    exit()

ans = nPr(n[0], n[0]) * nPr(n[1], n[1])
if n[1] == n[0]:
    ans *= 2
ans %= MOD

print(ans)

Measured memory_bytes: 3064
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var k = o.a();
  var x = o.a();
  return k*500>=x?"Yes":"No";
}

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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	int ans;

	if (a == b) cnt++;
	if (b == c) cnt++;
	if (c == a) cnt++;

	if (cnt == 0) ans = 3;
	if (cnt == 1) ans = 2;
	if (cnt == 3) ans = 1;

	cout << ans << endl;

	return 0;
}

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

using namespace std;

const long long N = 2e5 + 3;
const long long M = 1e6 + 4;
const long long INF = 1e9 + 7;
const int SM = 1e3 + 4;

long long n, a[N], pos[N], l[N], r[N], ans = 0;

int main() {
	//freopen("ex.in", "r", stdin);
	//freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	
	for(long long i = 1;i <= n;i++){
		cin >> a[i];
	}
	
	stack<long long> st;
	
	for(long long i = 1;i <= n;i++){
		l[i] = 1;
		while(!st.empty() && a[st.top()] > a[i]){
			st.pop();
		}
		if(!st.empty()){
			l[i] = st.top() + 1;
		}
		st.push(i);
	}
	
	while(!st.empty()){
		st.pop();
	}
	
	for(long long i = n;i >= 1;i--){
		r[i] = n;
		while(!st.empty() && a[st.top()] > a[i]){
			st.pop();
		}
		if(!st.empty()){
			r[i] = st.top() - 1;
		}
		st.push(i);
	}	
	
	for(long long i = 1;i <= n;i++){
		//cout << l[i] << " " << r[i] << "\n";
		ans += (r[i] - i + 1) * (i - l[i] + 1) * a[i];
	}
	
	cout << ans;

	return 0;
}






Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
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;}

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i,n) {
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i,m) {
        int a = q.top();q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    rep(i,n) {
        int a = q.top();q.pop();
        ans += a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const double PI=acos(-1);


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

    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> ans(h,vector<int>(w));
    int cnt=1;
    int row=1;
    rep(i,h) {
        bool flag=0;
        rep(j,w) {
            if (s[i][j]=='#') {
                if (!flag) flag=1;
                else ++cnt;
            }
            rep(k,row) ans[i-k][j]=cnt;
        }
        if (flag) {
            ++cnt;
            row=1;
        } else if (i<h-1) {
            ++row;
        } else {
            rep(j,w) {
                rep(k,row) ans[i-k][j]=ans[i-row][j];
            } 
        }
    }
    rep(i,h) {
        rep(j,w) cout << ans[i][j] << ' ';
        cout << endl;
    }
     
    return 0;   
}

Measured memory_bytes: 3876
N = int(input())
L = []

for i in range(N):
    L.append([int(i) for i in input().split()])
from itertools import permutations
def get_len(L1,L2):
    return ((L1[0]-L2[0])**2 +(L1[1]-L2[1])**2 )**0.5
ans =0
for i in list(permutations(L)):
    for l in range(len(i)-1):
        ans +=get_len(i[l],i[l+1])
print(ans/len(list(permutations(L))))    

Measured memory_bytes: 8120
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

A, B = map(int, input().split())
t = A + B
m = A - B
k = A * B

print(max(t, m, k))






# def main():
# if __name__ == '__main__':
#     main()


Measured memory_bytes: 3568
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#import numpy as np
from itertools import combinations

def main():
	n=II()
	d=LI()
	d.sort()
	t=[0]*25
	t[0]=1
	t[24]=1

	for i in range(n):
		if i%2==0:
			t[d[i]]+=1
		else:
			t[24-d[i]]+=1

	if max(t)>=2:
		print(0)
		exit(0)

	ans=12
	cnt=0
	for i in range(1,25):
		if t[i]==0:
			cnt+=1
		else:
			ans=min(ans,cnt+1)
			cnt=0

	print(ans)


if __name__ == "__main__":
	main()


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

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  for(int i=0;i<n;i++){
    if(s.at(i) == '#') count++;
  }
  int ans = count;
  for(int i=n-1;i>=0;i--){
    if(s.at(i) == '.') count++; else count--;
    ans = min(ans,count);
  }
  cout << ans << endl;
}

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

using namespace std;
int main()
{
    int i,a,b,n,c=0;
    cin>>n;
    cin>>a>>b;
    for(i=a;i<=b;i++){
    if(i%n==0)
    {
      c++;
    }
    }
    if(c>=1)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;



   return 0;
}


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

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

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

  cout << gcd(a, b) << endl;
}



Measured memory_bytes: 3100
allCards :: [String]
allCards = map unwords $ sequence [["S" , "H" , "C" , "D"] , [show x | x <- [1..13] :: [Int]]]

solve :: [String] -> [String]
solve xs = filter (\x -> notElem x xs) allCards

main :: IO ()
main  = getLine
    >>  getContents
    >>= return . lines
    >>= return . solve
    >>= mapM_ putStrLn

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> next;
    ll d = INF;
    int p = 0;
    vector<int> pt;
};

Vertex V[100005];
bool isC[100005];
int pN[100005];
int Ans[100005];
bool U[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, N - 1 + M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        isC[b] = true;
        V[a].next.push_back(b);
        V[b].pt.push_back(a);
        V[b].p++;
        pN[b]++;
    }

    int root = -1;
    REP(i, N)
    {
        if (!isC[i])
        {
            root = i;
            break;
        }
    }

    V[root].d = 0;
    Ans[root] = -1;
    queue<int> q;
    q.push(root);
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        if (U[t])
            continue;

        REP(i, V[t].next.size())
        {
            int n = V[t].next[i];
            V[n].p--;
            if(V[n].p>0)
            {
continue;
            }
            Ans[n]=t;
            q.push(n);
        }
    }

    REP(i, N)
    {
        cout << Ans[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	int t,i;
	cin>>t;
	int A[t];
	for(i=0;i<t;i++)
	{
		cin>>A[i];
	}
	int n = sizeof(A) / sizeof(A[0]); 
	int XOR = 0; 
	for (int i = 0; i < n; i++) 
		XOR ^= A[i]; 
	for (int i = 0; i < n; i++) 
		A[i] = XOR ^ A[i]; 
	for (int i = 0; i < n; i++) 
		cout << A[i] << " "; 
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,x,t;
    cin>>n>>x>>t;
    cout<<((ll)(ceil((double)(n)/x)))*t<<endl;
    
	return 0;
}

Measured memory_bytes: 3756
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static class Query implements Comparable<Query> {
		int from, to, cost;

		public Query(int from, int to, int cost) {
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public int compareTo(Query o) {
			return Integer.compare(cost, o.cost);
		}

	}

	int[] p;

	int get(int v) {
		return p[v] == v ? v : (p[v] = get(p[v]));
	}

	boolean unite(int a, int b) {
		a = get(a);
		b = get(b);

		if (a != b) {
			if (((a + b) & 1) == 1) {
				p[a] = b;
			} else {
				p[b] = a;
			}
		}

		return a != b;
	}

	void solve() throws IOException {
		int n = nextInt();
		int q = nextInt();

		PriorityQueue<Query> que = new PriorityQueue<>();

		for (int i = 0; i < q; i++) {
			int from = nextInt();
			int to = nextInt();
			int cost = nextInt();
			que.add(new Query(from, to, cost));
			que.add(new Query(to, (from + 1) % n, cost + 1));
		}

		p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}

		long ans = 0;

		while (!que.isEmpty()) {
			Query top = que.poll();

			// System.err.println(top.from + " " + top.to + " " + top.cost);

			if (unite(top.from, top.to)) {
				ans += top.cost;

				top.from = (top.from + 1) % n;
				top.to = (top.to + 1) % n;
				top.cost += 2;

				que.add(top);
			}
		}

		out.println(ans);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 61752
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const double PI=3.14159265358979323846;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double R;
    cin >> R;
    cout << fixed << setprecision(10) << 2 * PI * R << endl;
    return 0;
}

Measured memory_bytes: 3796
'''
問題：
    あなたは、電車とバスを乗り継いで旅行をする計画を立てました。
    電車は旅程に沿って通常のきっぷを買うと A円かかり、
    乗り放題きっぷを買うと B円かかります。
    バスは旅程に沿って通常のきっぷを買うと C円かかり、
    乗り放題きっぷを買うと D円かかります。

    電車およびバスについて
    通常の切符を買うか乗り放題きっぷを買うかをうまく選んだときの、
    運賃の合計の最小値を求めてください。
'''

'''
制約：
    1 ≤ A ≤ 1,000
    1 ≤ B ≤ 1,000
    1 ≤ C ≤ 1,000
    1 ≤ D ≤ 1,000
    入力値はすべて整数である。
'''

# 標準入力から A, B, C, D の値を取得する
a = int(input())
b = int(input())
c = int(input())
d = int(input())

# 乗り換えのパターンをリストに入れて、リストの最小値を出力する
travel_costs = [a + c, a + d, b + c, b + d]

print(min(travel_costs))


Measured memory_bytes: 9044
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int ans = 0;
    for(int i=0; i<n; ++i){
        for(int j=0; j<i; ++j){
            ans += a[i] * a[j];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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;
}

int main(){
    string s;cin >> s;
    vl v(4);
    rep(i,4){
        v[i]=s[i]-'0';
    }
    vector<string> o(3);
    rep(bit,8){
        ll tmp=v[0];
        rep(i,3){
            if(bit&(1<<i)){
                tmp+=v[i+1];
            }
            else{
                tmp-=v[i+1];
            }
        }
        if(tmp==7){
            rep(i,3){
                if(bit&(1<<i)){
                    o[i]='+';
                }
                else{
                    o[i]='-';
                }
            }
        }
    }
    rep(i,3){
        cout << v[i] <<o[i];
    }
    cout << v[3] <<"=7" <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

void swap(int *x,int *y) {
  int z;
  z=*x;*x=*y;*y=z;
}

int partition(int *A, int p, int r){//一番右を基準にする。　そこから左は　小さい、　右は大きい
  
  int j;
  int  x = A[r];//基準
  int i = p-1;//最初   右と左の区切り
  
  for (j = p;j<r;j++){//ｊ０スタートして、最後まで
    if (A[j] <= x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;//基準を返す
}



int main(){
  int A[MAX];
  int n;
  int i;
  int ii;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  ii= partition(A,0,n-1);//配列、オリジン、基準の要素数
 
  
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==ii)printf("[%d]",A[i]);//基準をカッコで囲む
    else printf("%d",A[i]);
  }
  printf("\n");
 
  return 0;
}



Measured memory_bytes: 2128
#include<stdio.h>

int main(void)
{
	int a = 100000, b, n, f1;
	scanf("%d",&n);
	for(f1 = 1; f1 <= n; f1++)
	{
		a *= 1.05;
		b = a % 1000;
		a = (a / 1000) *1000;
		if(b >= 1)
			a += 1000;
	}
	printf("%d\n",a);
	return 0;
}

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


int main() {
    ll n;

    std::cin >> n;
    unordered_map<string,ll> c;
    for (int i = 0; i < n; i++) {
        string s;
        std::cin >> s;
        sort(s.begin(),s.end());
        c[s]++;
    }
    ll result = 0;
    for (auto e : c) {
        if(e.second>=2){
            result += e.second*(e.second-1)/2;
        }
        // std::cout << e.second << std::endl;
        // result += COM(e.second,2);
    }
    std::cout << result << std::endl;
    
}
 

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

int f(int x) {
  int y = 0;
  while (x != 0) {
    y += x % 10;
    x /= 10;
  }
  
  return y;
}

int main() {
  int N;
  cin >> N;
  int ans = 1e9;
  for (int i = 1; i < N; i++) {
    int a = f(i) + f(N-i);
    ans = min(ans,a); 
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#!python3.4
# -*- coding: utf-8 -*-
# abc158/abc158_d
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = deque(i2s())
    Q = i2n()
    reverse = False
    for _ in range(Q):
        T, *args = i2s().split(' ')
        if T == '1':
            reverse = not reverse
            continue
        F, C = args
        toHead = F == '1'
        if toHead ^ reverse:
            # 先頭
            S.appendleft(C)
        else:
            # 末尾
            S.append(C)
    if not reverse:
        print(''.join(S))
    else:
        print(''.join(reversed(S)))
    return

main()


Measured memory_bytes: 8436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    string ans = "";
    while(n>0){
        n -= 1;
        ans += ('a' + n%26);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3632
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


def main():
    m = I()
    D = LI()
    if D[0] != 0:
        return 0
    cnt = Counter(D)
    ret = 1
    for i in range(max(D) + 1):
        val = cnt[i]
        if not val:
            return 0
        else:
            if i == 0:
                if val != 1:
                    return 0
            elif i == 1:
                pre = val
            else:
                ret = pow(pre, val, mod) * ret % mod
                pre = val
    return ret


print(main())



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

using namespace std;

const int N = 1024;

char s[N][N];
int d[N][N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int main() {
  memset(d, -1, sizeof d);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%s", s[i]);
  queue<pair<int, int>> que;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] != '#') continue;
      d[i][j] = 0;
      que.emplace(i, j);
    }
  }
  while (!que.empty()) {
    int x, y;
    tie(x, y) = que.front();
    que.pop();
    for (int i = 0; i < 4; ++i) {
      int xx = x + dx[i], yy = y + dy[i];
      if (min(xx, yy) < 0 || xx >= n || yy >= m) continue;
      if (d[xx][yy] != -1) continue;
      d[xx][yy] = d[x][y] + 1;
      que.emplace(xx, yy);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      ans = max(ans, d[i][j]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 13584
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Airplane
            var planes = ReadLine();

            Console.WriteLine(planes.OrderBy(x => x).Take(2).Sum());
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13396
#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 n, k;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];
    

    int ans;
    if ((n-1) % (k-1) == 0) ans = (n-1) / (k-1);
    else ans = (n-1) / (k-1) + 1;
    
    cout <<  ans << endl;
    

    return 0;
}

Measured memory_bytes: 3960
def f(x):
    a = 0
    # a >= 0, b <= 0
    while True:
        ap = a ** 5
        b = -a
        while True:
            s = ap - b ** 5
            if s > x:
                break
            if s == x:
                return a, b
            b -= 1
        a += 1
        if a ** 5 > x // 2:
            break
    # 0 <= b < a
    while True:
        ap = a ** 5
        for b in range(0, a):
            if ap - b ** 5 == x:
                return a, b
        a += 1


if __name__ == '__main__':
    x = int(input())
    print(' '.join(map(str, f(x))))


Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define int long long
#define REP(i,l,r) for(int i=l;i<r;i++)
using namespace std;
typedef pair<int,int> P;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
struct edge{
    int to,cost;
};
class dijkstra{
    int V;
    int d[100002];
    priority_queue<P,vector<P>,greater<P>>que;
    void update(int s,vector<edge> G[]){
        fill(d,d+V+1,100000000000ll);
        d[s]=0;
        que.push(make_pair(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            rep(i,G[v].size()){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
public:
    dijkstra(int v,int s,vector<edge> G[]){
        V=v;
        update(s,G);
    }
    int find(int e){
        return d[e];
;    }
};
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
    int get_Size(int a){
        return s[a];
    }
};
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(max(a,b)>c&&c>min(a,b))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# F
# input
from bisect import bisect
X = int(input())
K = int(input())
r_list = [0] + list(map(int, input().split()))

Q = int(input())
query_list = [list(map(int, input().split())) for _ in range(Q)]


MmRL_list = []

# M:max, m:min, R:min_a(M), L:max_a(m)
M = X
m = 0
R = X
L = 0

MmRL_list.append([M, m, R, L])

for i in range(K):
    M_ = M
    m_ = m
    R_ = R
    L_ = L
    lag = r_list[i+1] - r_list[i]
    # update
    if i % 2 == 0:
        if M_ - lag < 0:
            M = 0
            R = 0
        else:
            M = M_ - lag
            R = R_
        if m_ - lag < 0:
            m = 0
            L = L_ + lag - m_
        else:
            m = m_ - lag
            L = L_
    else:
        if M_ + lag > X:
            M = X
            R = R_ - (M_ + lag - X)
        else:
            M = M_ + lag
            R = R_
        if m_ + lag > X:
            m = X
            L = X
        else:
            m = m_ + lag
            L = L_
    MmRL_list.append([M, m, R, L])
        

# print(MmRL_list)
for q in range(Q):
    t, a = query_list[q]
    j = bisect(r_list, t) - 1
    # find status then
    M, m, R, L = MmRL_list[j]
    if a <= L:
        a_ = m
    elif a >= R:
        a_ = M
    else:
        a_ = m + (a - L)
    t_ = t - r_list[j]
    if j % 2 == 0:
        res = max(a_ - t_, 0)
    else:
        res = min(a_ + t_, X)
    print(res)


Measured memory_bytes: 47000
import numpy as np
 
N=int(input())
A=np.array(list(map(int,input().split())))
 
odd=np.count_nonzero(A%2!=0)
four=np.count_nonzero(A%4==0)
ans='No'

if odd==1 and four>=1:
  ans='Yes'
elif odd==2 and four>=2:
  ans='Yes'
else:
  if odd+four==N and odd-1<=four:
    ans='Yes'
  elif odd<=four:
    ans='Yes'
print(ans)

Measured memory_bytes: 38044