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

const int INF = 99999999;
const int N = 1000000;

int dp[N+1], odd_dp[N+1];

int main(void) {
  vector<int> pollock, odd_pollock;
  for (int n = 1; n*(n+1)*(n+2)/6 <= N; n++) {
    int t = n*(n+1)*(n+2)/6;
    pollock.push_back(t);
    if (t%2) odd_pollock.push_back(t);
  }
  for (int i = 0; i <= N; i++) {
    dp[i] = INF;
    odd_dp[i] = INF;
  }
  for (int i = 0; i < pollock.size(); i++) {
    dp[pollock[i]] = 1;
  }
  for (int i = 0; i < odd_pollock.size(); i++) {
    odd_dp[odd_pollock[i]] = 1;
  }

  for (int i = 0; i < 5; i++) {
    for (int j = 1; j <= N; j++) {
      if (dp[j] != INF) {
        for (int k = 0; k < pollock.size(); k++) {
          if (j+pollock[k] > N) break;
          dp[j+pollock[k]] = min(dp[j]+1, dp[j+pollock[k]]);
        }
      }
      if (odd_dp[j] != INF) {
        for (int k = 0; k < odd_pollock.size(); k++) {
          if (j+odd_pollock[k] > N) break;
          odd_dp[j+odd_pollock[k]] = min(odd_dp[j]+1, odd_dp[j+odd_pollock[k]]);
        }
      }
    }
  }

  int n;
  while (cin >> n, n) {
    cout << dp[n] << " " << odd_dp[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>_;
    set<string> st;
    while(_--)
    {
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
}


Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	string s, t; int a, b; string u;
	cin >> s >> t >> a >> b >> u;
	if(s == u) a--;
	if(t == u) b--;
	printf("%d %d\n", a, b);
}


Measured memory_bytes: 256
#include<stdio.h>
//include<algorithm>
//using namespace std;

void trace(int a[], int n){
  int i;
  for( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
}

void insertionSort(int a[], int n){
  int j, i, v;
  for(int i = 1; i < n; i++){
    v = a[i];
    for(j = i - 1; j >= 0 && a[j] > v; j = j - 1){
      a[j+1] = a[j];
    }
    a[j+1] = v;
    trace(a, n);
  }
}

int main(){
  int n, i, j;
  int a[100];
  
  scanf("%d", &n);
  for( i = 0; i < n; i++) scanf("%d", &a[i]);
  
  trace(a, n);
  insertionSort(a, n);
  return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    if(A == 0 && B == 0){
        for(int i = 0; i < H; i++){
            vector<int> v(W, 0);
            for(int j = 0; j < W; j++) cout << v[i];
            cout << endl;
        }
    }
    else if(A == 0 && B != 0){
        for(int i = 0; i < H; i++){
            if(i < B){
                vector<int> v(W, 1);
                for(int j = 0; j < W; j++) cout << v[j];
                cout << endl;
            }
            else{
                vector<int> v(W, 0);
                for(int j = 0; j < W; j++) cout << v[j];
                cout << endl;
            }
        }
    }
    else if(A != 0 && B == 0){
        for(int i = 0; i < H; i++){
            vector<int> v(W, 0);
            for(int j = 0; j < W; j++){
                if(j < A) v[j] = 1;
                cout << v[j];
            }
            cout << endl;
        }
    }
    else{
        for(int i = 0; i < H; i++){
            vector<int> v(W, 0);
            for(int j = 0; j < W; j++){
                if(i < B && j < A) v[j] = 1;
                else if(i >= B && j >= A) v[j] = 1;
                cout << v[j];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void) {
int g[4][14];
int a,b,c,e,f; 
char d; 
scanf("%d",&a);
a*=2; 
for(b=0;b<a;b++){ 
scanf("%c %d",&d,&c); 
if(d=='S'){
  g[0][c]=3;} 
else if(d=='H'){
  g[1][c]=3;} 
else if(d=='C'){
  g[2][c]=3;} 
else if(d=='D'){
  g[3][c]=3;}}
  for(f=1;f<14;f++){
   if(g[0][f]!=3){
    printf("S %d\n",f);}}
  for(f=1;f<14;f++){
   if(g[1][f]!=3){
    printf("H %d\n",f);}}
  for(f=1;f<14;f++){
   if(g[2][f]!=3){
    printf("C %d\n",f);}}
  for(f=1;f<14;f++){
   if(g[3][f]!=3){
    printf("D %d\n",f);}}
return 0;
}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    IO
    ll n;
    cin>>n;
    ll a[n+1];
    ll has[n+5];
    for(ll i=1;i<=n;i++)
    has[i]=0;
    for(ll i=1;i<n;i++)
    {
        cin>>a[i];
        has[a[i]]++;
    }
    for(ll i=1;i<=n;i++)
    cout<<has[i]<<'\n';
    return 0;
}

Measured memory_bytes: 6716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+10, MOD=1e9+7;
int n,k;
ll sum;
int main()
{
	scanf("%d%d",&n,&k);
	for (ll i=k;i<=n+1;i++)
	{
		sum=(sum+((n+n-i+1)*i/2-(i-1)*i/2+1+MOD)%MOD)%MOD;
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 3820
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextLong()
  val a = sc.nextLong()
  val b = sc.nextLong()
  val c = sc.nextLong()
  val d = sc.nextLong()
  val e = sc.nextLong()

  var min = Math.min(a, b)
  min = Math.min(min, c)
  min = Math.min(min, d)
  min = Math.min(min, e)


  var tmp = n / min
  if (n % min != 0L) tmp++

  tmp--

  println(5 + tmp)
}


Measured memory_bytes: 36464
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 

// Function to return the count of deletions 
// of sub-strings "01" or "10" 
int substrDeletion(string str, int len) 
{ 

	// To store the count of 0s and 1s 
	int count0 = 0, count1 = 0; 

	for (int i = 0; i < len; i++) { 
		if (str[i] == '0') 
			count0++; 
		else
			count1++; 
	} 

	return min(count0, count1); 
} 

// Driver code 
int main() 
{ 
	string str ;
  cin >> str;
	int len = str.length(); 
	cout << 2*substrDeletion(str, len); 

	return 0; 
} 


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 100005
#define inf 10000000000001
#define ll long long
#define MOD 1000000007
using namespace std;


int main(){
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i =0;i<n;i++){
        cin>> arr[i];
    }
    ll dp[n+5][n+5], sum[n+5][n+5];
    // dp[i][j] = minimum sum combined in range (i, j)
    memset(sum,0, sizeof(0));
    for(ll i =0; i < n; i++){
        ll k = arr[i];
        for(ll j = i; j < n; j++){
            if(i==j) sum[i][j] = k;
            else {
                k += arr[j];
                sum[i][j] = k;
            }
           // cout << i<< " " << j << " " << sum[i][j] << "\n";
        }
     //   cout << endl;
    }
    for(ll i=n-1;i>=0;i--){ // left range
        for(ll j = i;j<n;j++){ // right range
            dp[i][j] = inf;
            if(i==j) dp[i][j] = 0; // no cost for combining single element
            else {
                dp[i][j] = inf;
                for(ll k = i; k<j; k++){
                    dp[i][j] = min(dp[i][j], dp[i][k]+ dp[k+1][j] + sum[i][j]);
                }
            }
        }
    }

    cout << dp[0][n-1] << endl;

}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>


signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int n = sz(s);
    vector<int> v;
    int found = s.find("dream");
    while(found != -1) {
        v.push_back(found);
        found = s.find("dream", found + 1);
    }
    found = s.find("erase");
    while(found != -1) {
        v.push_back(found);
        found = s.find("erase", found + 1);
    }
    sort(v.begin(), v.end());
    bool ans = true;
    v.push_back(n);
    if(v[0] != 0) ans = false;
    for(int i = 0; i < sz(v) - 1; i++) {
        if(v[i + 1] - v[i] == 5) continue;
        else if(v[i + 1] - v[i] != 7 && v[i + 1] - v[i] != 6) {
            ans = false;
        } else if(s.substr(v[i], 6) != "eraser" && s.substr(v[i], 7) != "dreamer") {
            ans = false;
        }
    }
    if(ans) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();

		String str[]=s.split(",", 3);
		System.out.println(str[0]+" "+str[1]+" "+str[2]);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s;
  int k;
  char ans='1';
  
  cin >> s >> k;

  for(int i=0; i<k; i++){
    if(s[i]!='1'){
      ans = s[i];
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

t = []
for i, p in enumerate(P):
    if (i + 1) == p:
        t.append(i)

ans = 0
checked = [False] * len(t)
for i in range(len(t)):
    if checked[i]:
        continue
    if i + 1 < len(t) and t[i] + 1 == t[i + 1]:
        checked[i] = True
        checked[i + 1] = True
    else:
        checked[i] = True
    ans += 1
print(ans)



Measured memory_bytes: 20636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int p;
  int c = 0;
  for(int i = 1; i <= n; i++){
    cin>>p;
    if(i != p){
      c++;
    }
  }
  if(c >= 3){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
}


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

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> articulationPoint(const Graph& g){
    int n = g.size(), idx;
    vector<int> low(n), ord(n), art;
    function<void(int)> dfs = [&](int v){
        low[v] = ord[v] = ++idx;
        for(auto &e : g[v]){
            int w = e.dst;
            if(ord[w] == 0){
                dfs(w);
                low[v] = min(low[v], low[w]);
                if((ord[v] == 1 && ord[w] != 2) ||
                   (ord[v] != 1 && low[w] >= ord[v])) art.push_back(v);
            } else low[v] = min(low[v], ord[w]);
        }
    };
    for(int u = 0; u < n; u++) if(ord[u] == 0){ idx = 0; dfs(u); }
    return art;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    while(cin >> n >> m){
        Graph g(n);
        rep(i,m){
            int a,b;
            cin >> a >> b;
            g[a].emplace_back(a,b,0);
            g[b].emplace_back(b,a,0);
        }
        vector<int> arts = articulationPoint(g);
        sort(all(arts));
        auto last = unique(all(arts));
        for(auto it = arts.begin(); it != last; ++it) cout << *it << '\n';
    }
}

Measured memory_bytes: 5844
//08-2 共通部分文字列
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#define LL long long
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define ROOP() while(true)

int main(){
	ROOP(){
		string A,B;
		cin >> A;
		if(cin.eof()) { break; }
		cin >> B;
		if(B.size() > A.size()){//Aのほうが長い
			string tmp = B;
			 B = A;
			 A = tmp;
		}
		string t = "";
		for(int i=0; i<B.size(); i++){
			t += ".";
		}
		A = t + A;

		int ans = 0;
		while(A.size()>0){
			int tmp = 0;
			for(int j=0; j<min(A.size(),B.size()); j++){
				if(A[j]==B[j]){
					tmp++;
					ans = max(ans,tmp);
				}
				else tmp = 0;
			}
			A.erase(A.begin());
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,i,count=0;
  cin>>N;
  int D1[N],D2[N];
  for(i=0;i<N;i++){
    cin>>D1[i]>>D2[i];
  }
  for(i=0;i<N;i++){
    if(D1[i]==D2[i]){
      count++;
    }else{
      count=0;
    }
    if(count==3){
      break;
    }
  }
  if(count==3){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
    
      

Measured memory_bytes: 3572
from itertools import product

n = int(input())

n_num = [[0] * 10 for _ in range(10)]

for i in range(n + 1):
    a, b = int(str(i)[0]), i % 10
    n_num[a][b] += 1

answer = sum(n_num[a][b] * n_num[b][a] for a, b in product(range(1, 10), repeat=2))
print(answer)


Measured memory_bytes: 9184
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   int H, W, M;
   cin >> H >> W >> M;
   vector<int> cntX(H);
   fill(cntX.begin(), cntX.end(), 0);
   vector<int> cntY(W);
   fill(cntY.begin(), cntY.end(), 0);
   vector<pair<int, int>> t(M);
   set<pair<int, int>> S;
   for (int i = 0; i < M; i++)
   {
      cin >> t[i].first >> t[i].second;
      cntX[t[i].first - 1]++;
      cntY[t[i].second - 1]++;
      t[i].first--;
      t[i].second--;
      S.insert(t[i]);
   }
   sort(t.begin(), t.end());
   int ansX = 0;
   int ansY = 0;
   vector<int> xi;
   for (int i = 0; i < H; i++)
   {
      ansX = max(ansX, cntX[i]);
   }
   for (int i = 0; i < H; i++)
   {
      if (ansX == cntX[i])
      {
         xi.emplace_back(i);
      }
   }

   for (int i = 0; i < W; i++)
   {
      ansY = max(ansY, cntY[i]);
   }
   vector<int> yi;
   for (int i = 0; i < W; i++)
   {
      if (ansY == cntY[i])
      {
         yi.emplace_back(i);
      }
   }
   for (int i : xi)
   {
      for (int j : yi)
      {
         if (S.find(make_pair(i, j)) == S.end())
         {
            cout << ansX + ansY << endl;
            return 0;
         }
      }
   }
   cout << ansX + ansY - 1 << endl;
   return 0;
}


Measured memory_bytes: 26220
/* ***********************************************
Author        :yang12138
Created Time  :2017年04月27日 星期四 00时05分36秒
File Name     :E.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=5e5+10;

int a[N];
ll suf[N],pre[N];

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	int n;
	scanf("%d%lld",&n,pre+0);

	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(a[i]<2*pre[i-1]) pre[i]=abs(pre[i-1]-a[i]);
		else pre[i]=pre[i-1];
	}

	suf[n+1]=1;
	for(int i=n;i>=1;i--){
		if(a[i]>=2*suf[i+1]) suf[i]=suf[i+1];
		else suf[i]=a[i]+suf[i+1];
	}

	int Q;
	scanf("%d",&Q);
	while(Q--){
		int q;
		scanf("%d",&q);
		if(pre[q-1]>=suf[q+1]) printf("YES\n");
		else printf("NO\n");
	}

    return 0;
}


Measured memory_bytes: 11648
public class Main {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int l =0;
		int [][] ar = new int[0][2];
		int [][] arc = new int[0][2];
		while (true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h == 0 && w == 0) {
				break;
			}

			l++;

			ar = new int[l][2];
			for (int i = 0; i < l - 1; i++) {
				ar[i] = arc[i];
			}
			ar[l - 1] = new int[] { h, w };

			arc = new int[l][2];
			for (int i = 0; i < l; i++) {
				arc[i] = ar[i];
			}
		}

		for (int i = 0; i < ar.length; i++) {
			int h = ar[i][0];
			int w = ar[i][1];

			String sYoko = "";
			for (int j = 0; j < w; j++) {
				sYoko = sYoko + "#";
			}
			for (int j = 0; j < h; j++) {
				System.out.println(sYoko);
			}
			System.out.println();
		}
	}
}

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

#define MOD 1000000007
typedef unsigned long long ull;

int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
      cout << r;
  } else {
      cout << (r + 100 * (10 - n));
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    int n;
    cin >> n;
    LL a[SIZE];
    for( int i = 0; i < n; ++i ) cin >> a[i];
    LL res[n];
    res[0] = 0;
    LL tmp = 0;
    for( int i = n - 1; i >= 0; --i ) {
        if( i % 2 == 0 ) res[0] += a[i];
        else res[0] -= a[i];

    }

    a[0] -= res[0] / 2;
    for( int i = 1; i < n; ++i ) {
        res[i] = a[i - 1] * 2;
        a[i] -= res[i] / 2;

    }

    cout << res[0];
    for( int i = 1; i < n; ++i ) cout << " " << res[i];
    cout << endl;

    return 0;
}



Measured memory_bytes: 2944
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M, R = in.next().toInt
  val r = new Array[Int](R)
  for (i <- 0 until R) {
    r(i) = in.next().toInt
  }

  val d = Array.ofDim[Long](N+1, N+1)  // d[a][b] は辺 e = (a, b) のコスト(存在しない場合はINF, ただし d[i][i] = 0 とする)
  val MAX = Integer.MAX_VALUE

  // 初期化
  for(i <- 0 to N; j <- 0 to N){
    if(i == j)
      d(i)(j) = 0
    else
      d(i)(j) = MAX
  }

  // input d
  for(_ <- 0 until M) {
    val a, b, c = in.next().toInt
    d(a)(b) = c
    d(b)(a) = c
  }

  // function
  def warshall_floyd() =
    for(k <- 1 to N; i <- 1 to N; j <- 1 to N){
      d(i)(j) = Math.min(d(i)(j), d(i)(k) + d(k)(j))
    }


  // main process
  warshall_floyd()

  var ans: Long = Integer.MAX_VALUE
  for(pl <- r.toList.permutations) {
    var tmp = 0L
    for(i <- 0 until pl.length - 1) {
      tmp += d(pl(i))(pl(i+1))
    }
    ans = Math.min(ans, tmp)
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



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

struct Card { char suit, value; };

void bubble(struct Card A[],int N){
  for(int i = 0; i < N; i++){
    for(int j = N - 1; j >= i + 1; j--){
      if(A[j].value < A[j - 1].value){
	Card t = A[j];
	A[j] = A[j - 1];
	A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    if (i > 0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
   for(int i = 0; i < N; i++){
     if(C1[i].suit != C2[i].suit)return false;
   }
   return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0; i < N; i++)C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }
  else {
    cout << "Not stable" << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
n=int(input())
X=input()
x=list(map(int,list(X)))
mod=998244353
pow_2=[0]*n
pow_2[n-1]=1
for i in range(1,n):
    pow_2[n-1-i]=(pow_2[n-i]*2)%mod
num=0
for i in range(n):
    if x[i]==1:
        num=(num+pow_2[i])%mod
#約数全列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
li=make_divisors(n)
lst=[]
for i in li:
    if i%2==1 and i>2:
        lst.append(i)
lst.sort(reverse=True)
sum=0
count=0
s=[]
t=[]
for u in lst:
    U=u
    u=n//u
    cnt=0
    for i in range(1,u+1):
        if x[u-i]==1:
            cnt=(cnt+pow_2[-i])%mod
    y=list(X[:u])
    for i in range(u):
        if y[i]=="0":
            y.append("1")
        else:
            y.append("0")
    y="".join(y)
    y*=(U+1)//2
    y=y[:n]
    if y<=X:
        cnt+=1
    for i in range(len(s)):
        if u%s[i]==0:
            cnt-=t[i]
    sum=(sum+(2*cnt*u)%mod)%mod
    s.append(u)
    t.append(cnt)
    count=(count+cnt)%mod
print((((num+1-count)*2*n)%mod+sum)%mod)

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int result = 1;

  for (int i = 0; i < N; i++) {
    if (result < K) {
      result *= 2;
    } else {
      result += K;
    }
  }
  
  cout << result << endl;
}



Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll a[200010];
    rep(i,0,N) cin >> a[i];
    ll val = 0;
    rep(i,0,N) val ^= a[i];
    ll ans[200010] = {};

    rep(i,0,N){
        ll v1 = (val^a[i]);
        ans[i] = v1;
    }
    printa(ans,N);

    

}

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

Measured memory_bytes: 6736
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define w(e) int e ; cin >> e ; while (e--)  
#define ll long long 
#define endl "\n"
#define mod  10000000007
#define pi 3.1415926535897932384626433
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)  
/*
*/
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n ; cin >> n;
    string s ; cin >> s ;
    if (s.length() > n)
    {
        for (int i=0 ;i< n ;i++)
        {
            cout << s[i] ;
        }
        cout << "..." << endl;
    }
    else 
        cout << s << endl;
	return  0;
}

Measured memory_bytes: 3592
import itertools
n=input()
ans=0

for i in range(3,len(n)+1):
    li=itertools.product([3,5,7],repeat=i)
    
    for j in li:
        t=''.join(map(str,j))
        
        if int(t)<=int(n):
            if t.count("3")>=1 and t.count("5")>=1 and t.count("7")>=1:
                ans+=1

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
const int MOD=1000000007;
string arr[27]={"z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
string ans;
int cnt;
void dfs(int k){
	if(k<=26){cnt--;ans=arr[k]+ans;return;}
	int re=k%26;
	if(re==0){
		ans="z"+ans;
		cnt--;
		dfs(k/26);
		return;
	}
	ans=arr[re]+ans;
	cnt--;
	dfs((k-re)/26+1);
	return;
}
int main() {
	
	int n;
	cin>>n;
	int arr[4];
	for(int i=0;i<4;i++)arr[i]=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC")arr[0]++;
		if(s=="WA")arr[1]++;
		if(s=="TLE")arr[2]++;
		if(s=="RE")arr[3]++;
	}
	for(int i=0;i<4;i++){
		if(i==0)cout<<"AC";
		if(i==1)cout<<"WA";
		if(i==2)cout<<"TLE";
		if(i==3)cout<<"RE";
		cout<<" x "<<arr[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3600
n = int(input())
y_l = []
b_l = []
for i in range(n):
    x, u = input().split()
    if u == 'JPY':
        y_l.append(float(x))
    else:
        b_l.append(float(x))

total = sum(y_l) + (sum(b_l) * 380000)
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto &ai : a) cin >> ai;
    int p = 1;
    int roop = -1;
    vector<int> used(n);
    for(int x=0; x<k; x++){
        used[p-1] = x;
        p = a[p-1];
        if(used[p-1] || p == 1){
            k = k - used[p-1];
            k %= x - used[p-1] + 1;
            while(k--){
                p = a[p-1];
            }
        }        
    }
    cout << p << endl;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x;i <= y; ++ i)
#define repd(i,x,y) for(register int i = x;i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
	char c;int sign = 1;x = 0;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}

const int mod = 1e9 + 7,N = 2e5 + 50;
int n,mx[N],f[N];
struct DATA { int v,x,l,r; }a[N];
const bool cmp(DATA a,DATA b) { return a.v < b.v || a.v == b.v && a.x < b.x; }
const bool cmp2(DATA a,DATA b) { return a.l < b.l || a.l == b.l && a.r < b.r; }

struct BIT_TREE
{
	int t[N];
	#define lowbit(x) (x & -x)

	inline void add(int x,int w)
	{
		for(register int i = x;i <= n + 1; i += lowbit(i))
			t[i] = (t[i] + w) % mod;
	}
	inline int find(int x)
	{
		int ans = 0;
		for(register int i = x; i ; i -= lowbit(i))
			ans = (ans + t[i]) % mod;
		return ans;
	}
}t;

int main()
{
	read(n);
	rep(i,1,n) read(a[i].x),read(a[i].v);
	sort(a + 1,a + 1 + n,cmp);
	rep(i,1,n) 
	{
		mx[i] = max(mx[i-1],a[i].x);
		int l = 1,r = i,mid;
		while(l <= r)
		{
			mid = l + r >> 1;
			if(mx[mid] >= a[i].x) a[i].l = mid,r = mid - 1;
			else l = mid + 1;
		}
	}
	mx[n + 1] = 1e9 + 7;
	repd(i,n,1) 
	{
		mx[i] = min(mx[i+1],a[i].x);
		int l = i,r = n,mid;
		while(l <= r)
		{
			mid = l + r >> 1;
			if(mx[mid] <= a[i].x) a[i].r = mid,l = mid + 1;
			else r = mid - 1;
		}
	}
	sort(a + 1,a + 1 + n,cmp2);
	f[0] = 1; t.add(n + 1,1);
	rep(i,1,n)
	{
		int z = t.find(n + 1 - (a[i].l - 1));
		t.add(n + 1 - a[i].r,z);
		f[a[i].r] = (f[a[i].r] + z) % mod;
	}

	//rep(i,1,n) printf("%d %d\n",a[i].l,a[i].r);

	cout << f[n] << endl;

	return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 2e3 + 6, MOD = 1e9 + 7;
int n, m, ans;
int Arr[MAX_N];
int Brr[MAX_N];
int d[MAX_N];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;

	return c;
}

int _sub (int a, int b) {
	int c = a - b;
	if (c < 0)
		c += MOD;

	return c;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> Arr[i];
	for (int j = 0; j < m; j++)
		cin >> Brr[j];

	ans = 1;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			if (Arr[i] == Brr[j])
				ans = _sum(ans, _sum(sum, 1));

			sum = _sum(sum, d[j]);
			if (Arr[i] == Brr[j])
				d[j] = _sum(sum, 1);
		}
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int l;
    cin >> l;

    double ans=l*l*l/27.0000000000000000;
    cout << std::setprecision(15) << ans <<endl;
}

Measured memory_bytes: 256
import sys

s = input()
t = input()
s_ = s
num = 1

for i in range(len(t)):
    if s.find(t[i]) == -1:
        print(-1)
        sys.exit()
    elif s_.find(t[i]) == -1:
        num += 1
        s_ = s[s.find(t[i]) + 1:]
    else:
        s_ = s_[s_.find(t[i]) + 1:]

print(num*len(s) - len(s_))


Measured memory_bytes: 3536
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	M := getInt()

	nNum := N * (N-1) / 2
	mNum := M * (M-1) / 2
	fmt.Println(nNum + mNum)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
//const ll p = 1e9 + 7;
//const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, p;
	string s;
	cin >> n >> p >> s;

	if (p == 2 || p == 5) {
		ll ans = 0;
		for (ll i = 0; i < n; i++) {
			if ((s[i] - '0') % p == 0) ans += i + 1;
		}
		cout << ans << endl;
	}
	else {
		vll remcnt(p, 0);
		remcnt[0]++;
		ll rem = 0, x = 1;
		for (ll i = n - 1; i >= 0; i--) {
			rem += (s[i] - '0') * x % p;
			rem %= p;
			remcnt[rem]++;
			x *= 10;
			x %= p;
		}
		ll ans = 0;
		for (ll i = 0; i < p; i++) {
			ans += remcnt[i] * (remcnt[i] - 1) / 2;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)

int main(){
    int n; cin >> n;
    int x[n],y[n];
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    double res = 0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            res+=(double)sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    ll re=1;
    for(int i=1;i<=n;i++){
        re*=i;
    }
    ll rr=re;
    re*=(n-1);
    int r = n*(n-1)/2;
    re/=r;
    cout << fixed << setprecision(10) << (double)re*res/rr << endl;
}


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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec p(N + 10);
  map<int, int> mp;
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
    mp[p[i]] = i;
  }

  int n = 30000;
  vec a(202020), b(202020);
  for (int i = 1; i <= N; i++) {
    a[i] = n * i;
    b[i] = n * (N - i) + mp[i];
  }

  for (int i = 1; i <= N; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  for (int i = 1; i <= N; i++) {
    cout << b[i] << " ";
  }
  cout << endl;

  return 0;
}


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

class Point {  
public:
  double x, y;
  
  void print() { cout << x << " " << y << endl; }
};

void koch(Point p1, Point p2, int i, int n) {
  if (i < n) {
  
    Point s, t, u;

    s.x = (2.0 / 3.0) * p1.x + (1.0 / 3.0) * p2.x;
    s.y = (2.0 / 3.0) * p1.y + (1.0 / 3.0) * p2.y;
    t.x = (1.0 / 3.0) * p1.x + (2.0 / 3.0) * p2.x;
    t.y = (1.0 / 3.0) * p1.y + (2.0 / 3.0) * p2.y;
    u.x = (1.0 / 2.0) * ((t.x - s.x) - sqrt(3) * (t.y - s.y)) + s.x;
    u.y = (1.0 / 2.0) * (sqrt(3) * (t.x - s.x) + (t.y - s.y)) + s.y;
    
    koch(p1, s, i+1, n);
    s.print();
    koch(s, u, i+1, n);
    u.print();
    koch(u, t, i+1, n);
    t.print();
    koch(t, p2, i+1, n);
  }       
}

int main() {
  int n;
  Point end1, end2;

  end1.x = 0.0;
  end1.y = 0.0;
  end2.x = 100.0;
  end2.y = 0.0;

  cin >> n;
  end1.print();
  koch(end1, end2, 0, n);
  end2.print();

  return 0;
}



Measured memory_bytes: 3292
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string S = Console.ReadLine();
		string A = "abcdefghijklmnopqrstuvwxyz";
		int[] n = new int[26];
		for(var i=0;i<S.Length;i++){
			n[i] = A.IndexOf(S.Substring(i,1))+1;
		}
		if(S.Length < 26){
			for(var j=0;j<=25;j++){
				if(S.IndexOf(A.Substring(j,1)) == -1){
					S += A.Substring(j,1);
					break;
				}
			}
		} else {
			int t = 0;
			for(var i=24;i>=0;i--){
				for(var j=i+1;j<26;j++){
					if(n[j] > n[i]){
						while(n[i] < 26){
							n[i] += 1;
							if(Array.IndexOf(n,n[i]) == i){
								break;
							}
						}
						for(var k=i+1;k<26;k++){
							n[k] = 0;
						}
						t = 1;
						break;
					}
				}
				if(t == 1){
					break;
				}
			}
			if(t == 0){
				S = "-1";
			} else {
				string S2 = "";
				for(var i=0;i<26;i++){
					if(n[i] > 0){
						S2 += A.Substring(n[i]-1,1);
					}
				}
				S = S2;
			}
		}
		Console.WriteLine(S);
	}
}

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

using namespace std;

int main(){
    int n;
    vector<int> inp;
    vector<int> org;
    cin>>n;

    for(int i=0;i<n;i++){
        int input;
        cin>>input;
        inp.push_back(input);
    }
    org=inp;

    sort(inp.begin(),inp.end());
    int count=0;
    for(int i=0;i<n;i++){
        if(org.at(i)!=inp.at(i)){
            count++;
        }
    }
    if(count<=2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define inf 1000000000
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef  double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
typedef pair<ld , ld> pdd;
typedef vector<pdd> vdd;
typedef vector<ld> vd;
const int MOD = 1e9 + 7; //998244353;

int dp[3005][3005];
int bt[3005][3005];
string s , t;

int solve(int a , int b){
    if(a == 0 || b == 0)return 0;
    if(dp[a][b] != -1)return dp[a][b];
    int x = solve(a-1,b) , y = solve(a , b-1) , z = solve(a-1 , b-1);
    if(s[a-1] == t[b-1])z++;
    if(x > y && x > z){
        bt[a][b] = 0;
        dp[a][b] = x;
    }
    else if(y > z){
        dp[a][b] = y;
        bt[a][b] = 1;
    }
    else {
        dp[a][b] = z;
        bt[a][b] = 2;
    }
    return dp[a][b];
}
int main() {
    boost;
    memset(dp , -1, sizeof dp);
    memset(bt , -1, sizeof bt);
    cin >> s >> t;
    solve(s.length() , t.length());
    int n = s.length() , m = t.length();
    string res = "";
    while(bt[n][m] != -1){
        if(bt[n][m] == 2 && s[n-1] == t[m-1])res += s[n-1];
        if(bt[n][m] == 0){
            n--;
        }
        else if(bt[n][m] == 1)m--;
        else {
            n--;
            m--;
        }
    }
    reverse(all(res));
    cout << res;
}


Measured memory_bytes: 74512
#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(){
    string s;
    int k;
    cin >> k;
    cin >> s;
    if (s.size()<=k) cout << s << endl;
    else {
        rep(i,k) cout << s[i];
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n,k,i,j;
	cin>>n;
	int sum=0;
	vector<int>v;
	for(i=0;i<n;i++)
	{
		cin>>k;
		v.push_back(k);
		sum+=k;
	}
	sum/=n;
	int a1=0,a2=0;
	for(i=0;i<n;i++)
	{
		a1+=(abs(v[i]-sum))*(abs(v[i]-sum));
		a2+=(abs(v[i]-sum-1))*(abs(v[i]-sum-1));
	}
	int ans=min(a1,a2);
	cout<<ans<<endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  long max1=0, max2=0;
  for(int i=0;i<n-1;i++){
    if(a.at(i) == a.at(i+1)){
      if(max1 == 0){
        max1 = a.at(i);
        i++;
      }
      else {
        max2 = a.at(i);
        break;
      }
    }
  }
  cout << max1*max2 << endl;
}


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


void solve(long long H, long long W, long long h, long long w){
  cout << (H - h) * (W - w) << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long h;
    scanf("%lld",&h);
    long long w;
    scanf("%lld",&w);
    solve(H, W, h, w);
    return 0;
}


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

const int PLAYER_MAX = 200;
const int VALUE_MAX = 100;

void fill(int t[], int N) {
	for (int i = 0; i < N; i++)t[i] = 0;
}

int main() {
	int N;
	int num[3][PLAYER_MAX] = { {0} };
	int point[PLAYER_MAX] = { 0 };
	int table[VALUE_MAX] = { 0 };

	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> num[j][i];
		}
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < N; j++) {
			table[num[i][j] - 1]++;
		}
		for (int j = 0; j < N; j++) {
			if (table[num[i][j] - 1] == 1) {
				point[j] += num[i][j];
			}
		}
		fill(table, VALUE_MAX);
	}

	for (int i = 0; i < N; i++) {
		cout << point[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include <iostream>

int main() {
    int year;
    char c;
    int month;
    int day;
    std :: string heisei = "Heisei";
    std :: string tbd = "TBD";

    std :: cin >> year >> c >> month >> c >> day;
    if(year == 2019) {
        if(month <= 4){
            std :: cout << heisei << '\n';
        } else std :: cout << tbd << '\n';
    } else if(year < 2019) std :: cout << heisei << '\n';
    else std :: cout << tbd << '\n';
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vll act;
/******* define variable end *******/
int solve() {
	cin >> n;
	act.resize(n, vl(3));
	REP(i, n){
		REP(j, 3){
			cin >> act[i][j];
		}
	}
	vll dp(n+1, vl(3, 0));
	REP(i, n){
		REP(j, 3){
			dp[i+1][j] = max(dp[i][(j+1)%3] + act[i][(j+1)%3], dp[i][(j+2)%3] + act[i][(j+2)%3]);
		}
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 14288
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

vector<int>prime;

void fun(int a,int b){


    for(int i=2;i<=max(a,b);i++){
        int in=0;
        while(a%i==0){
            prime.emplace_back(i);
            a/=i;
            in++;
        }
        int cnt=0;
        while(b%i==0){
            cnt++;
            if(in<cnt)prime.emplace_back(i);
            b/=i;
        }
    }
    return ;

}

int main(){

int a,b;
cin>>a>>b;

fun(a,b);

long long ans=1;
rep(i,prime.size()){
    ans*=prime[i];
}
cout<<ans<<endl;

return 0;

}
/*
2 3

6

123 456

18696

100000 99999

9999900000
*/


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    char h[] = {'a', 'i', 'u', 'e', 'o'};
    char c;
    cin >> c;

    bool ok = false;
    rep(i, 5) {
        if(c == h[i]) ok = true;
    }

    if(ok) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
int INF = 1e14;
int mod = 1e9 + 7;

int power(int x, unsigned int y)
{
    int temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2) % mod;
    if (y % 2 == 0)
        return (temp * temp) % mod;
    else
        return x * ((temp * temp) % mod) % mod;
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        int temp = 1 ^ 2 ^ 3 ^ 4 ^ 5;
        rep(i, 0, 5)
        {
            int x;
            cin >> x;
            temp ^= x;
        }
        cout << temp << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void){
	
	long long to=0;
	int max=-1000000,min=1000000,i,n;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		if(t>max)max=t;
		if(t<min)min=t;
		to+=t;
	}

	printf("%d %d %ld\n",min,max,to);

	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://code-festival-2017-qualc.contest.atcoder.jp/tasks/code_festival_2017_qualc_c>
問題文============================================================
 問題文
 英小文字のみからなる文字列 s があります。
 すぬけ君は、次の操作を繰り返し行うことができます。
 
 s の任意の位置 (先頭および末尾を含む) をひとつ選び、英小文字 x をひとつ挿入する。
 すぬけ君の目標は、s を回文にすることです。
 すぬけ君の目標が達成可能か判定し、達成可能ならば必要な操作回数の最小値を求めてください。
 
 注釈
 回文とは、前後を反転しても変わらない文字列のことです。
 例えば、a, aa, abba, abcba は回文ですが、ab, abab, abcda は回文ではありません。
 
 制約
 1≤|s|≤10^5
 s は英小文字のみからなる。
=================================================================

解説=============================================================

================================================================
*/
ll solve(){
    string s; cin >> s;
    ll ret = 0;
    
    ll l = 0, r = s.length()-1;
    while(l <= r){
      //  cout << s[l] << " " << s[r] << endl;
        if(s[l] == s[r]){
            l++; r--;
        }else{
            if(s[l] == 'x'){
                l++; ret++;
                continue;
            }
            if(s[r] == 'x'){
                r--; ret++;
                continue;
            }
            return -1;
        }
    }
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 512