akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 1e8;
    rep(i, n-1) {
        if (s[i] != s[i+1]) {
            ans = min(ans, max(i+1, n-(i+1)));
        }
    }
    cout << (ans == 1e8 ? n : ans) << endl;
}


Measured memory_bytes: 512
<?php
/**
 * ABC132
 * D - Blue and Red Balls
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

$mod = 1000000007;

fscanf(STDIN, "%d %d", $n, $k);

init_combination($n);

for ($i = 1; $i <= $k; $i++) {
    echo combination($n - $k + 1, $i) * combination($k - 1, $i - 1) % $mod, PHP_EOL;
}

function init_combination($n) {
    global $fac, $finv, $inv, $mod;
    $fac[0] = $fac[1] = 1;
    $finv[0] = $finv[1] = 1;
    $inv[1] = 1;
    for ($i = 2; $i < $n; $i++){
        $fac[$i] = $fac[$i - 1] * $i % $mod;
        $inv[$i] = $mod - $inv[$mod % $i] * (intdiv($mod, $i)) % $mod;
        $finv[$i] = $finv[$i - 1] * $inv[$i] % $mod;
    }
}

function combination($n, $r) {
    global $fac, $finv, $inv, $mod;
    if ($n < $r) return 0;
    if ($n < 0 || $r < 0) return 0;
    return $fac[$n] * ($finv[$r] * $finv[$n - $r] % $mod) % $mod;
}


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

const int SZ = (1 << 19) + 5, INF = 1e9, RInf = 1e9 + 3e8 + 5e7 + 7e3;

int h, w;
int seg[SZ], lz[SZ];

void prop(int idx, int L, int R)
{
	if (L > R) return;
	if (lz[idx] != RInf)
	{
		seg[idx] = lz[idx];
		if (L < R)
		{
			int M = L + R >> 1;
			lz[2 * idx] = lz[idx];
			lz[2 * idx + 1] = lz[idx] + (M + 1 - L);
		}
		lz[idx] = RInf;
	}
}

void upd(int idx, int L, int R, int l, int r, int v)
{
	prop(idx, L, R); v += max(l, L) - l;
	l = max(l, L); r = min(r, R); 
	if (l <= r)
	{
		if (L == l && R == r) {lz[idx] = v; prop(idx, L, R);}
		else
		{
			int M = L + R >> 1;
			upd(2 * idx, L, M, l, r, v);
			upd(2 * idx + 1, M + 1, R, l, r, v);
			seg[idx] = min(seg[2 * idx], seg[2 * idx + 1]);
		}
	}
}

int qry(int idx, int L, int R, int l, int r)
{
	l = max(l, L); r = min(r, R); 
	if (l <= r)
	{
		prop(idx, L, R);
		if (L == l && R == r) {return seg[idx];}
		else
		{
			int M = L + R >> 1;
			return min(qry(2 * idx, L, M, l, r), qry(2 * idx + 1, M + 1, R, l, r));
		}
	}
	return INF - 1;
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;
	for (int i = 0; i < SZ; i++) {lz[i] = RInf;}
	for (int i = 1; i <= h; i++)
	{
		int a, b; cin >> a >> b;
		upd(1, 1, w, a, b, qry(1, 1, w, a - 1, a - 1) + 1);
		if (qry(1, 1, w, 1, w) + i < INF) cout << qry(1, 1, w, 1, w) + i << "\n";
		else cout << "-1\n";
	}
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

typedef vector<ll> arr;
typedef vector<arr> mat;

ll L, A, B, M;

mat eye(ll n){
	mat I(n, arr(n, 0));
	REP(i, n) I[i][i] = 1;
	return I;
}

mat mul(const mat &A, const mat &B){
	mat C(A.size(), arr(B[0].size(), 0));
	REP(i, C.size()){
		REP(j, C[0].size()){
			REP(k, A[0].size()){
				C[i][j] += A[i][k]*B[k][j];
				C[i][j] %= M;
			}
		}
	}
	return C;
}

mat matpow(const mat &A, ll k){
	mat res = eye(A.size());
	mat tmp = A;
	REP(i, 64){ // 64より大きい値にするとバグるので注意．long long が64バイトで表現されていることに依存する．65とかでも一見まともに動くがバグってる．
		if(k>>i&1) res = mul(res, tmp);
		tmp = mul(tmp, tmp);
	}
	return res;
}

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
        }
        a = a*a;
        n >>= 1;
    }
    return res;
}

ll powLLmod(ll a, ll n, ll mod){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
            res %= mod;
        }
        a = a*a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

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

    cin >> L >> A >> B >> M;

    vector<ll> cum(19, 0);
    vector<ll> digits(18);
    REP(i, 19){
    	ll ma = powLL(10, i) - 1;
    	if(A > ma) cum[i] = 0;
    	else{
    		cum[i] = (ma - A)/B;
    		cum[i]++;
    	}

    }
    REP(i, 18){
    	digits[i] = cum[i+1] - cum[i];
    }

    mat res(3, arr(3, 0));
    res[0][0] = 1;
    res[1][1] = 1;
    res[2][2] = 1;

    //cout << digits << endl;

    ll times = 0;
    REP(i, 18){
    	mat X(3, arr(3, 0));
    	X[0][0] = powLLmod(10, i+1, M);
    	X[0][1] = 1;
    	X[1][1] = 1;
    	X[1][2] = B%M;
    	X[2][2] = 1;

    	ll kake = min(digits[i], L - times);
    	times += kake; 

    	mat Y = matpow(X, kake);
    	res = mul(Y, res);
    }

    cout << ((res[0][1]%M)*(A%M)%M + res[0][2]%M)%M << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int floor(int a, int b) { return (a + b - 1) / b; };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  str s;
  cin >> s;
  if (s.substr(0,4)=="YAKI") cout << "Yes" << en;
  else cout << "No" << en;
}

Measured memory_bytes: 3616
#include<stdio.h>

#define g -3
#define w -2
#define b -1


int temp[101];
int time;
int d[101];
int f[101];
int N;
int A[101][101];



void DFS();

void DFSvisit(int u){
  int v;

  temp[u]=g;
  time++;
  d[u]=time;

  for(v=1;v<=N;v++){
    if(A[u][v]==0){
      continue;
    }
    if( temp[v]==w ){
      DFSvisit(v);
    }
  }  
  

  temp[u] = b;
  f[u] = ++time;

}


void DFS(){
  int i;
  for(i=1;i<=N;i++){
    temp[i] = w;
  }
  time=0;

  for(i=1;i<=N;i++){
    if(temp[i]==w){
      DFSvisit(i);
    }
  }
}




main (){

  int i,j,k,v,u;

  for(i=1;i<101;i++){
    for(j=1;j<101;j++){
      A[i][j] = 0;
    }
  }

  scanf("%d",&N);

  for(i=1;i<=N;i++){ 
    scanf("%d %d",&v,&k); 
    for(j=1;j<=k;j++){
      scanf("%d",&u);
      A[v][u] = 1;
    }
  }

  DFS();
   for(i=1;i<=N;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  return 0;
}
 

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <set>
#include <tuple>

using namespace std;
typedef vector<int>VI;
typedef long long LL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)

#define PB push_back
#define ST first
#define ND second
#define INF 1000000000


#define MAXSIZE 310

int odleglosci [MAXSIZE][MAXSIZE];
int drogi[MAXSIZE][MAXSIZE];
int n;
LL suma;
bool istnieje = true;

int main(){
    SCAN_INT(n);

    FOR(i,1,n)
        FOR(j,1,n){
            SCAN_INT(odleglosci[i][j]);
            drogi[i][j]=1;
        }

    FOR(k,1,n)
        FOR(i,1,n)
            FOR(j,1,n){
                if(odleglosci[i][k]+odleglosci[k][j]<odleglosci[i][j])
                    istnieje=false;
                else if(odleglosci[i][j]==odleglosci[i][k]+odleglosci[k][j]&&k!=j&&k!=i)
                    drogi[i][j]=0;

            }

    FOR(i,1,n)
        FOR(j,1,n)
            suma+=(drogi[i][j]==1)?odleglosci[i][j]:0;


    if(istnieje)
        printf("%lli",suma/2);
    else
        PRINT_INT(-1);

}


Measured memory_bytes: 1024
#include<stdio.h>

using namespace std;

int main() {
	char c, c1 = '0', c2 = '0';
	int count = 0;
	for (int i = 0; i < 4; i++) {
		scanf("%c", &c);
		if (c == c1) {
			count++;
		}
		else if (c == c2) {
			count++;
		}
		else if (c1 != '0') {
			c2 = c;
		}
		else {
			c1 = c;
		}
	}

	if (count == 2) {
		printf("%s", "Yes");
	}
	else {
		printf("%s", "No");
	}


}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <algorithm>
#include <vector>

#define MAX_N (100000)
#define MAX_M (100000)

using namespace std;

long ans[MAX_M] = {};
vector<vector<pair<long, long>>> prefectures;

int main(int argc, char *argv[]) {
  int N, M;
  scanf("%d %d", &N, &M);
  for (int p = 0; p < N; p++) {
    prefectures.push_back(vector<pair<long, long>>());
  }
  for (int c = 0; c < M; c++) {
    int p, y;
    scanf("%d %d", &p, &y);
    prefectures[p - 1].push_back(pair<long, long>(y, c));
  }
  for (long i = 0; i < N; i++) {
    sort(prefectures[i].begin(), prefectures[i].end());
    for (long j = 0; j < prefectures[i].size(); j++) {
      ans[prefectures[i][j].second] = 1000000 * (i + 1) + (j + 1);
    }
  }

  for (long i = 0; i < M; i++)
    printf("%012ld\n", ans[i]);
  
  return 0;
}


Measured memory_bytes: 8176
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int N,B,S=0;cin>>N;long int A[N+1];
  for(long int i=0;i<=N;i++)cin>>A[i];
  for(long int i=0;i<N;i++){
    cin>>B;
    if(A[i]<B){
      if(A[i]+A[i+1]<B){S+=A[i]+A[i+1];A[i+1]=0;}
      else{S+=B;A[i+1]+=A[i]-B;}
    }
    else S+=B;
  }
  cout<<S<<endl;
}

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

using namespace std;

const int N = 16;
const int N2 = 4;
const int LIMIT = 100;

typedef struct {
	int M[N];
	int space;
	int MD; 
} Puzzle;

const int dx[4] = {0,-1,0,1};
const int dy[4] = {1,0,-1,0};
const char dir[4] = {'r','u','l','d'};

int MDT[N][N];//曼哈顿距离 

Puzzle state;

int limit;//深度限制

int path[LIMIT];

int getAllMD(Puzzle pz){
	int sum = 0;
	for (int i=0;i<N;i++) {
		if (pz.M[i] == 0) continue; //空格不考虑
		sum += MDT[i][pz.M[i]-1]; 
	}
	return sum;
}

bool dfs(int depth,int prev) { //深度优先搜索 
    if (state.MD == 0) return true; //已经得到解
	
	if (depth + state.MD > limit) return false; //剪枝
	
	int sx = state.space / N2;
	int sy = state.space % N2;
	
	Puzzle tmp;
	
	for (int r=0;r<4;r++) {
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N2 || ty >= N2) continue;
		if (max(prev,r) - min(prev,r) == 2) continue; //避免把空格再移到上一步的位置
		tmp = state;
		
		state.MD -= MDT[tx * N2 + ty][state.M[tx*N2+ty] - 1]; //删除原状态的曼哈顿距离 
		state.MD += MDT[state.space][state.M[tx*N2+ty]-1]; //添加新状态的曼哈顿距离 
		swap(state.M[tx*N2 + ty],state.M[state.space]);
		state.space = tx*N2 + ty;
		if (dfs(depth + 1,r)) {
			path[depth] = r; return true;
		}
		state = tmp; //回溯 
	} 
	return false;
}

//迭代加深 
string iterative_deepening(Puzzle in) {
	in.MD = getAllMD(in);
	
	for (limit = in.MD;limit<= LIMIT;limit++) {
		state = in;
		if (dfs(0,-100)) {
			string ans = "";
			for (int i=0;i<limit;i++) {
				ans += dir[path[i]];
			}
			return ans;
		}
	}
	
	return "unsolvable";
}

int main() {
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			//d(i,j)=|X1-X2|+|Y1-Y2|.，这里竖轴为x，横轴为y 
			MDT[i][j] = abs(i / N2 - j /N2) + abs(i % N2 - j % N2); //计算i到j的曼哈顿距离 
		}
	}
	
	Puzzle in;
	for (int i=0;i<N;i++) {
		cin >> in.M[i];
		if (in.M[i] == 0) {
			in.space = i;
		}
	} 
	string ans = iterative_deepening(in);
	cout << ans.size() << endl;
	return 0;
} 


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  string res;
  rep(i,n) {
    res += s[i];
    res += t[i];
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int V = scanner.nextInt();
		int E = scanner.nextInt();
		int r = scanner.nextInt();
		int[] d = new int[V];
		Arrays.fill(d, Integer.MAX_VALUE);
		d[r] = 0;
		List<Edge> list = new ArrayList<Edge>();
		for (int i = 0; i < E; i++) {
			int s = scanner.nextInt();
			int t = scanner.nextInt();
			int l = scanner.nextInt();
			list.add(new Edge(s, t, l));
		}

		for (int i = 0; i < V; i++) {
			for (int j = 0; j < E; j++) {
				Edge edge = list.get(j);
				if (d[edge.from] != Integer.MAX_VALUE
						&& d[edge.to] > d[edge.from] + edge.cost) {
					d[edge.to] = d[edge.from] + edge.cost;
					if (i == V - 1) {
						System.out.println("NEGATIVE CYCLE");
						return;
					}
				}
			}
		}
		for(int i = 0;i<V;i++){
			if(d[i]==Integer.MAX_VALUE)
				System.out.println("INF");
			else
				System.out.println(d[i]);
		}
	}

	class Edge {
		int from, to, cost;
		
		@Override
		public String toString() {
			return "Edge [from=" + from + ", to=" + to + ", cost=" + cost + "]";
		}

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

	}
}

Measured memory_bytes: 29408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}

ll a[105];
ll dp[105][100005];

ll solve(ll n,ll k)
{
	if(k<0)
	{
		return 0;
	}
	if(n==0)
	{
		if(k<=a[0])
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	if(dp[n][k]!=-1)
	{
		return dp[n][k];
	}
	ll p,q,r;
	p=solve(n-1,k)%mod;
	q=solve(n,k-1)%mod;
	r=solve(n-1,k-1-a[n])%mod;
	dp[n][k]=(p+q-r+mod)%mod;
	return dp[n][k];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,K,i,j;
    cin>>N>>K;
    for(i=0;i<N;i++)
    {
    	cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    for(i=0;i<=K;i++)
    {
    	if(i<=a[0])
    	{
    		dp[0][i]=1;
    	}
    	else
    	{
    		dp[0][i]=0;
    	}
    }
    cout<<solve(N-1,K)<<"\n";
	return 0;
}

Measured memory_bytes: 93460
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long 
#define mod 1000000007

int main()
{
	string s;
	cin>>s;
	int l1=(int)s.size();
	l1--;
	for(int i=l1-1;i>=0;i--)
	{
		if((i+1)%2==0)
		{
			int q=(i+1)/2;
			if(s.substr(0,q)==s.substr(q,q))
			{
				cout<<i+1<<endl;
				return 0;
			}
		}
	}
}

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

ll ceil(ll a, ll b) {
    if (b < 0) {
        a *= -1;
        b *= -1;
    }
    if (a >= 0) {
        return (a + b - 1) / b;
    } else {
        return a / b;
    }
}

ll floor(ll a, ll b) {
    if (b < 0) {
        a *= -1;
        b *= -1;
    }
    if (a < 0) {
        return (a - b + 1) / b;
    } else {
        return a / b;
    }
}

int main() {
    int K;
    cin >> K;
    vector<ll> A(K);
    for (int i = 0; i < K; i++) {
        cin >> A[i];
    }

    vector<ll> M(K + 1), m(K + 1);
    M[K] = 2;
    m[K] = 2;
    for (int i = K - 1; i >= 0; i--) {
        if (m[i + 1] / A[i] == M[i + 1] / A[i] && m[i + 1] % A[i] != 0 && M[i + 1] % A[i] != 0) {
            cout << -1 << endl;
            return 0;
        }
        m[i] = ceil(m[i + 1], A[i]) * A[i];
        M[i] = floor(M[i + 1], A[i]) * A[i] + A[i] - 1;
    }
    cout << m[0] << " " << M[0] << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>

using namespace std;


int main(){
	int n,checkTableMin[10],checkTableMax[10],max,min,tmp;
	char buf[9];


	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",buf);
		min = max = 0;
		for(int k=0; k < 10; k++){
			checkTableMin[k] = 0;
			checkTableMax[k] = 0;
		}
		for(int k=0; buf[k] != '\0';k++){
			checkTableMin[buf[k]-'0']++;
			checkTableMax[buf[k]-'0']++;
		}

		tmp = 10000000;
		for(int k=0; k < 10; k++){
			while(checkTableMin[k] > 0){
				min += tmp*k;
				checkTableMin[k]--;
				tmp /= 10;
			}
		}
		tmp = 10000000;
		for(int k = 9; k>= 0; k--){
			while(checkTableMax[k] > 0){
				max += tmp*k;
				checkTableMax[k]--;
				tmp /= 10;
			}
		}

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

	}

    return 0;
}

Measured memory_bytes: 2704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;

int main()
{
    int n,a,b,c,i;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    for(i = 0;i < n;++i){
        cin >> l.at(i);
    }
    int beki = 1;
    for(i = 0;i < n;++i){
        beki *= 4;
    }
    int bit;
    int ans = abs(l.at(0)-a)+abs(l.at(1)-b)+abs(l.at(2)-c);
    vector<int> bunkai(n);
    int temp;
    for(bit = 0;bit < beki;++bit){
        int anstemp = 0;
        vector<long long> bo(3,0);
        temp = bit;
        for(i = 0;i < n;++i){
            bunkai.at(i) = temp%4;
            temp -= bunkai.at(i);
            temp /= 4;
        }
        for(i = 0;i < n;++i){
            if(bunkai.at(i) == 1){
                if(bo.at(0) != 0){
                    anstemp += 10;
                }
                bo.at(0) += l.at(i);
            }else if(bunkai.at(i) == 2){
                if(bo.at(1) != 0){
                    anstemp += 10;
                }
                bo.at(1) += l.at(i);
            }else if(bunkai.at(i) == 3){
                if(bo.at(2) != 0){
                    anstemp += 10;
                }
                bo.at(2) += l.at(i);
            }else if(bunkai.at(i) == 0){
                continue;
            }
        }
        if(bo.at(0)*bo.at(1)*bo.at(2) == 0){
            continue;
        }else{
            anstemp += abs(bo.at(0)-a)+abs(bo.at(1)-b)+abs(bo.at(2)-c);
        }
        if(anstemp < ans){
            ans = anstemp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

int len[2005], n;

int compare(const void * a, const void * b) { 
    return ( *(int*)a - *(int*)b ); 
}

int upper_bound(int x) {
	int lo = 0, hi = n-1, mid, ans = 0;
	while (lo <= hi) {
		mid = (lo+hi)/2;
		if (len[mid] >= x)
			hi = mid-1;
		else {
			ans = mid;
			lo = mid+1;
		}
	}
	return ans;
}

int lower_bound(int x) {
	int lo = 0, hi = n-1, mid, ans = n-1;
	while (lo <= hi) {
		mid = (lo+hi)/2;
		if (len[mid] <= x)
			lo = mid+1;
		else {
			ans = mid;
			hi = mid-1;
		}
	}
	return ans;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &len[i]);
	qsort(len, n, sizeof(int), compare);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int tmp = len[i]+len[j];
			int ub = upper_bound(tmp);
			tmp = len[j]-len[i];
			int lb = lower_bound(tmp);
			ans += ub-lb+1;
			if (lb <= j)
				ans--;
			if (lb <= i)
				ans--;
		}
	}
	printf("%lld\n", ans/3);
	return 0;
}

Measured memory_bytes: 128
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 12

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	cout << fixed;
	cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	vector<int> ps;
	for (int i = 0; i < n; i++)
	{
		int p;
		cin >> p;
		ps.push_back(p);
	}
	
	vector<int> qs;
	for (int i = 0; i < n; i++)
	{
		int q;
		cin >> q;
		qs.push_back(q);
	}
	
	vector<int> order;
	for (int i = 0; i < n; i++)
	{
		order.push_back(i + 1);
	}
	
	int p_order, q_order;
	int counter = 0;
	do
	{
		if (order == ps)
		{
			p_order = counter;
		}
		
		if (order == qs)
		{
			q_order = counter;
		}
		
		counter++;
	}
	while (next_permutation(order.begin(), order.end()));
	
	cout << abs(p_order - q_order) << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3628
S=input()
if S[0]!='A':
    print('WA')
elif S[1].isupper():
    print('WA')
else:
    count=0
    flag=0
    for i in range(2,len(S)-1):
        if S[i]=='C':
            count+=1
        else:
            if S[i].isupper():
                flag=1
    if count==1 and flag==0 and S[len(S)-1].islower():
        print('AC')
    else:
        print('WA')

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

int main(void){
    string S;
    cin >> S;
    if(S[0] != 'A'){
        cout << "WA\n";
        return 0;
    }
    if(S[1] == 'C' || !('a' <= S[1] && S[1] <= 'z')) {
        cout << "WA\n";
        return 0;
    }

    int j = 0;
    for(int i = 2; i <= S.length() - 2; i++){
        if(S[i] == 'C') j++;
        else if(!('a' <= S[i] && S[i] <= 'z')){
            cout << "WA\n";
            return 0;
        }

        if(j > 1) {
            cout << "WA\n";
            return 0;
        }
    }

    if(S[S.length() - 1] == 'C' || j != 1 || !('a' <= S[S.length() - 1] && S[S.length() - 1] <= 'z')) {
        cout << "WA\n";
        return 0;
    }
    cout << "AC\n";

    return 0;
}


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

long long int a[114514] = {};
long long int b[114514] = {};
long long int aa[114514] = {};
long long int bb[114514] = {};

int main() {

    long long int n;
    cin >> n;

    vector< pair< long long int, long long int > > v, vv;
    vector< pair< pair< long long int, long long int >, long long int > > s;
    vector< long long int > vl, vr;
    multiset< long long int > al, ar, bl, br;
    long long int ans = 0;

    for ( long long int i = 0; i < n; i++ ) {
        long long int l, r;
        cin >> l >> r;
        v.push_back( make_pair( l, r ) );
        vv.push_back( make_pair( -r, -l ) );
//        ans = max( ans, r - l + 1 );
        s.push_back( make_pair( make_pair( l, 0 ), i ) );
        s.push_back( make_pair( make_pair( r, 1 ), i ) );
        vl.push_back( l );
        vr.push_back( r );
        bl.insert( l );
        br.insert( r );
    }
/*
    sort( v.begin(), v.end() );
    long long int m = v[0].second;
    for ( long long int i = 0; i < n; i++ ) {
        m = min( m, v[i].second );
        a[i] = max( m - v[i].first + 1, 0LL );
    }
    m = v[n-1].second;
    for ( long long int i = n - 1; i >= 0; i-- ) {
        m = min( m, v[i].second );
        b[i] = max( m - v[n-1].first + 1, 0LL );
    }

    for ( long long int i = 0; i < n - 1; i++ ) {
        ans = max( ans, a[i] + b[i+1] );
    }

    sort( vv.begin(), vv.end() );
    m = vv[0].second;
    for ( long long int i = 0; i < n; i++ ) {
        m = min( m, vv[i].second );
        aa[i] = max( m - vv[i].first + 1, 0LL );
    }
    m = vv[n-1].second;
    for ( long long int i = n - 1; i >= 0; i-- ) {
        m = min( m, vv[i].second );
        bb[i] = max( m - vv[n-1].first + 1, 0LL );
    }

    for ( long long int i = 0; i < n - 1; i++ ) {
        ans = max( ans, aa[i] + bb[i+1] );
    }
*/
    sort( s.begin(), s.end() );
    for ( long long int i = 0; i < s.size(); i++ ) {
        long long int k = s[i].second;
        long long int p = s[i].first.first;
//        cout << " " << p << " " << k << endl;
        if ( s[i].first.second == 0 ) {
            bl.erase( bl.find( vl[k] ) );
            br.erase( br.find( vr[k] ) );
            al.insert( vl[k] );
            ar.insert( vr[k] );
        } else {
            al.erase( al.find( vl[k] ) );
            ar.erase( ar.find( vr[k] ) );
            bl.insert( vl[k] );
            br.insert( vr[k] );
        }
        if ( al.size() > 0 && bl.size() > 0 ) {
//            cout << "  * " << *(--al.end()) << " - " << *ar.begin() << "   :  " << *(--bl.end()) << " - " << *br.begin() << endl;
            ans = max( ans, max( *ar.begin() - *(--al.end()) + 1, 0LL ) + max( *br.begin() - *(--bl.end()) + 1, 0LL ) );
        }
    }

    for ( long long int i = 0; i < n; i++ ) {
        bl.erase( bl.find( vl[i] ) );
        br.erase( br.find( vr[i] ) );
        ans = max( ans, max( vr[i] - vl[i] + 1, 0LL ) + max( *br.begin() - *(--bl.end()) + 1, 0LL ) );
        bl.insert( vl[i] );
        br.insert( vr[i] );
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 20364
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	vector<int> r(n+1,0);
	vector<int> g(n+1,0);
	vector<int> b(n+1,0);
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='R')
		{
			r[i]=r[i+1]+1;
			g[i]=g[i+1];
			b[i]=b[i+1];
		}
		if(s[i]=='G')
		{
			r[i]=r[i+1];
			g[i]=g[i+1]+1;
			b[i]=b[i+1];
		}
		if(s[i]=='B')
		{
			r[i]=r[i+1];
			g[i]=g[i+1];
			b[i]=b[i+1]+1;
		}

	}

	long long ans=0;

	for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	{
		if(s[i]==s[j])continue;

		int tmp=0;
		if(s[i]=='R' or s[j]=='R')
		{
			if(s[i]=='G' or s[j]=='G')
				tmp=2; // B
			else
				tmp=1; // G
		}
		else
			tmp=0; // R

		char c[3]={'R','G','B'};

		int add=0;
		if(tmp==0)
			add=r[j];
		else if(tmp==1)
			add=g[j];
		else
			add=b[j];
		if(j+(j-i)<n and s[j+(j-i)]==c[tmp])
			add--;
		ans+=(add);


	}


	cout << ans << endl;


}


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

int main() {
	// your code goes here
	long long int x,d,n,y,i,c=0;
	cin>>n>>d;
	for(i=0;i<n;i++)
	{
	    cin>>x>>y;
	    long long int s=0;
	    s=x*x+y*y;
	    if(s<=d*d)
	    c++;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,n,cnt = 0;
    cin>>a>>b>>c>>n;
    for(int i = 0;i <= a;i++)
    {
        for(int j = 0;j <= b;j++)
        {
            if(n - 500 * i - 100 * j >= 0 && n - 500 * i - 100 * j <= 50 * c)
                cnt++;
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
char s[10000];
int main(){
    int i, j, k;
    cin >> n;
    scanf("%s",s);
    if(n < 3200)cout << "red" << endl;
    else cout << s << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (n % k == 0) {
			System.out.println(0);
		} else {
			System.out.println(1);
		}
	}
}


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

int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}

int main()
{
	int p, q, n, res = 1;
	cin >> p >> q;
	n = q / GCD(p, q);
	for (int i = 2; i < sqrt(n) + 2; i++) {
		if (n % i == 0) {
			res *= i;
			while (n % i == 0) {
				n /= i;
			}
		}
	}
	res *= n;
	if (res == 1) res = 2;
	cout << res << endl;
	return 0;
}

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

int K;

void solve()
{
	if(K%2 == 0 || K%10 == 5) cout << -1 << '\n';
	else{
		int cur = 1, x = 7;
		set<int> seen;
		while(true){
			if(x % K == 0){
				cout << cur << '\n';
				return;
			}
			(x = 10*x+7)%=K;
			cur++;
			if(seen.count(x)){
			    cout << -1 << '\n';
			    return;
			}
			seen.insert(x);
		}
	}
}


int main()
{
	cin >> K;
	solve();
	return 0;
}

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

int main(){
	string str;
	cin>>str;
	string cc="CODEFESTIVAL2016";
	int res=0;
	for(int i=0;i<16;i++){
		if(str[i]!=cc[i])res++;
	}
	cout<<res<<endl;
	return 0;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int r,g;
    cin >> r >> g;
    cout << 2*g - r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a;
	int b;
	
	cin >> a >> b;
	if(a >= 13) cout << b;
	else if(a >= 6 && a <= 12) cout << b/2;
	else cout << 0;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mod=1e9+7;
int fact(int n,long long int result){

    for(int i=2;i<=n;i++){
        result=result*i;
        result%=mod;
    }
    return result;
}
int main(){
    int n,m;
    cin>>n>>m;
    if(n<m){
        int temp=n;
        n=m;
        m=temp;
    }
    int result=1;
    if(n-m>1){
        cout<<"0"<<endl;
    }
    else{
        if(n==m)
            result=result*2;
        result=fact(n,result);
        result=fact(m,result);
        cout<<result<<endl;
    }
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K;

int main(){
	getint(N), getint(K);
	return puts(K <= (N + 1 >> 1) ? "YES" : "NO"), 0;
}

Measured memory_bytes: 256
from itertools import permutations

def testcase_ends():
    a, b, c, d = map(int, input().split())
    if (a, b, c, d) == (0, 0, 0, 0):
        return True

    operators = '+-*'
    expressions = [
        '((({0} {1} {2}) {3} {4}) {5} {6})',
        '(({0} {1} ({2} {3} {4})) {5} {6})',
        '(({0} {1} {2}) {3} ({4} {5} {6}))',
        '({0} {1} ({2} {3} ({4} {5} {6})))',
        '({0} {1} (({2} {3} {4}) {5} {6}))',
    ]

    for s in operators:
        for t in operators:
            for u in operators:
                for x in expressions:
                    for p in permutations([a, b, c, d]):
                        a, b, c, d = p
                        f = x.format(a, s, b, t, c, u, d)

                        if eval(f) == 10:
                            print(f)
                            return False

    print(0)
    return False

while not testcase_ends():
    pass



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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int l, cnt= 0;
    string s;
    cin>> l >>s;

    for (int i= 0; i<l-2; i++)
    {
        if(s[i]=='A' && s[i+1]== s[i] +1 && s[i+2]== s[i] +2  )
            cnt++;
    }

    cout << cnt;
    nl;


    return 0;
}




Measured memory_bytes: 3616
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn as_u64(line: String) -> u64 {
    line.parse().unwrap()
}

fn sum(n: u64) -> u64 {
    n * (n - 1) / 2
}

fn main() {
    let n = as_u64(read_line());
    println!("{}", sum(n));
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

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

char mp[30][30];
ll H, W;

ll flg[30][30];
ll solve(ll x, ll y){
    if(mp[y][x] == '#')return -1;
    rep(i, 30)rep(j, 30)flg[i][j] = INF;
    queue<P>Q;
    Q.push(P(x, y));
    flg[y][x] = 0;
    ll ret = 0;
    while(!Q.empty()){
        x = Q.front().first;
        y = Q.front().second;
        Q.pop();
        chmax(ret, flg[y][x]);
        rep(i, 4){
            ll nx = x + dx[i];
            ll ny = y + dy[i];
            if(mp[ny][nx] == '#')continue;
            if(flg[ny][nx] < INF)continue;
            flg[ny][nx] = flg[y][x] + 1;
            Q.push(P(nx, ny));
        }
    }
    return ret;
}


int main(){
    
    rep(y, 30)rep(x, 30)mp[y][x] = '#';
    cin >> H >> W;
    rep1(y, H)rep1(x, W){
        cin >> mp[y][x];
    }
    ll ans = 0;
    rep1(y, H)rep1(x, W){
        chmax(ans, solve(x, y));
    }
    cout << ans << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
int N;
long long A[200000];

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

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll f(int x) {
	ll b = 0, c = 1, d = 1;
	for (int i = 0; i < x - 1; i++) {
		d = (b + c) % 1000000007;
		b = c;
		c = d;
	}
	return d;
}
int main() {
	int n, m;
	cin >> n >> m;
	if (m == 0) {
		cout << f(n + 1);
		return 0;
	}
	vector<int> a(m);
	for (int i = 0; i < m; i++)
		cin >> a[i];
	ll ans = f(a[0]);
	for (int i = 1; i < m; i++) {
		if (a[i] - a[i - 1] == 1) {
			cout << 0;
			return 0;
		}
		else {
			ans = (ans * f(a[i] - a[i - 1] - 1)) % 1000000007;
		}
	}
	ans = (ans * f(n - a[m - 1])) % 1000000007;
	cout << ans;
}

Measured memory_bytes: 640
/* ****Ragnar7 -SHINIGAMI- _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		string a,b;
		ll n,m;
		cin>>a>>b;
		n=a.size();
		m=b.size();
		ll dp[n+5][m+5];
		memset(dp,0,sizeof(dp));
		for(ll i=1;i<=n;i++)
		{
			for(ll j=1;j<=m;j++)
			{
				if(a[i-1]==b[j-1])
					dp[i][j]=1+dp[i-1][j-1];
				else
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
		// cout<<dp[n][m];
		ll x = n,y=m;
		string ans="";
		while(x>=1 and y>=1)
		{
			if(a[x-1]==b[y-1])
			{
				ans+=a[x-1];
				x--;
				y--;
			}
			else if(dp[x-1][y]==dp[x][y])
				x--;
			else
				y--;

		}
		reverse(ans.begin(), ans.end());
		cout<<ans;
		
	}

	
	time
	return 0;
}

Measured memory_bytes: 74164
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,m,c;
  cin>>n>>m>>c;
  int b[25];
  for(int i=0;i<m;i++)cin>>b[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int a;
    int sum=c;
    for(int i=0;i<m;i++){
      cin>>a;
      
      sum=sum+(a*b[i]);
    }
    if(sum>0)ans++;
  }
  cout<<ans<<endl;
}

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

/*
  AOJ :: 0110
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0110
  Wrong Answer.
 */

char in[3][130];

bool iseq(){
    int tmp[130];
    int na = strlen(in[0]), nb = strlen(in[1]), nc = strlen(in[2]);
    int i;

    memset(tmp, 0, sizeof(tmp));
    for(i=0; i<na; i++) tmp[i] += in[0][na-i-1] - '0';
    for(i=0; i<nb; i++) tmp[i] += in[1][nb-i-1] - '0';
    for(i=1; i<130; i++){
        tmp[i] += tmp[i-1] / 10;
        tmp[i-1] %= 10;
    }

    for(i=0; i<nc; i++){
        if( tmp[i] != in[2][nc-i-1] - '0' ) return false;
    }
    for(; i<130; i++) if( tmp[i] != 0 ) return false;
    return true;
}

bool ischeck(int n, int p, int num){
    int i;
    bool res = false;

    if( n == 3 ){ // end
        return iseq();
    }

    if( in[n][p] == '\0' ){ // next str
        return ischeck(n+1, 0, num);
    }

    if( in[n][p] == 'X' ){
        if( p == 0 && num == 0 && strlen(in[n]) > 1 ) return false;
        in[n][p] = num + '0';
        res = ischeck(n, p+1, num);
        in[n][p] = 'X';
    }
    else{
        res = ischeck(n, p+1, num);
    }
    return res;
}

int main(){
    int num;

    while( ~scanf(" %[^+]+%[^=]=%s ", in[0], in[1], in[2]) ){
        for(num=0; num<=9; num++){
            if( ischeck(0, 0, num) ) break;
        }
        if( num > 9 ){
            puts("NA");
        }
        else{
            printf("%d\n",num);
        }
    }

    return 0;
}

Measured memory_bytes: 0
import itertools

def main():
    N = int(input())
    BIT = list(itertools.product([True,False], repeat=N))
    P = [[(0,0)]]
    for i in range(1,N+1):
        A =  int(input())
        L = []
        for _ in range(A):
            x,y = map(int,input().split())
            L.append((x,y))
        P.append(L)

    ans = 0

    for b in BIT:
        cnt = 0
        flag = True
        HU = [-1]*(N+1)
        for i in range(1,N+1):
            if b[i-1]:
                cnt += 1
                for hu in P[i]:
                    if b[hu[0]-1] != (hu[1]==1):
                        flag = False
                        break
        if flag:
            ans = max(ans,cnt) 


    print(ans)


if __name__ == '__main__':
    main()

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

int main(){
  string s; cin >> s;
  string ret="Yes";
  if(s=="AAA"||s=="BBB") ret="No";
  cout << ret;

}

Measured memory_bytes: 256
const lines=readlines()
const N,M=map(x->parse(Int,x),split(shift!(lines)))
const G=[Int[] for _=1:N]
const dp=zeros(N)
const x=zeros(N)
function main()
	for s=lines
		x,y=map(x->parse(Int,x),split(s))
		push!(G[x],y)
	end
	x[1]=1
	for i=1:N
		for v=G[i]
			x[v]+=x[i]/length(G[i])
		end
	end
	for i=N-1:-1:1
		for v=G[i]
			dp[i]+=dp[v]
		end
		L=length(G[i])
		dp[i]/=L
		dp[i]+=1
	end
	ans=dp[1]
	for i=1:N-1
		if length(G[i])==1
			continue
		end
		sum=m=0
		for v=G[i]
			sum+=dp[v]
			m=max(m,dp[v])
		end
		ans=min(ans,dp[1]+((sum-m)/(length(G[i])-1)+1-dp[i])*x[i])
	end
	println(ans)
end
main()

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

using namespace std;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(NULL);
    
    int n,i,j;
    cin >> n;
    long long int arr[n] , dp[n][n];
    for(i=0;i<n;i++){
    cin >> arr[i];
    dp[i][i] = arr[i];
    }
    
    for(i=1;i<n;i++){
        int x =0;
        for(j=i;j<n;j++,x++){
            dp[x][j] = max(arr[x] - dp[x+1][j] , arr[j] - dp[x][j-1]);
        }
    }
    cout << dp[0][n-1];
    return 0;
}

Measured memory_bytes: 70144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    map<ll, ll> mp;
    vector<ll> v, tar;
    mp[0] += 1;
    rep(i, n){
        ll x;   cin >> x;
        mp[x] += 1;
    }
    ll res=-1;
    tar.push_back(0);
    tar.push_back(24);
    for(auto x: mp){
        if(!(x.first%12) && 1<x.second) res = 0;
        else if(2<x.second) res = 0;
        else if(2==x.second){
            tar.push_back(x.first);
            tar.push_back(24-x.first);
        }else if(0<x.first) v.push_back(x.first);
            
    }
    
    if(res<0){
        ll sv=v.size();
        rep(i, 1<<sv){ 
            vector<ll> tmp = tar;
            rep(j, sv){
                if(i&1<<j) tmp.push_back(v[j]);
                else tmp.push_back(24-v[j]);
            }
            sort(ALL(tmp));
            ll uiw=LINF;
            rep(i, tmp.size()-1) uiw = min(uiw, tmp[i+1]-tmp[i]);
            res = max(res, uiw);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	
	int n;
	int k;
	
	cin >> n;
	cin >> k;
	vector<long long>v(n, 1e12),m(n,0);
	v[0] = 0;
	for (int i = 0; i < n; i++)
		cin >> m[i];
	v[1] = abs(m[1] - m[0]);
	for (int i = 2; i < n; i++)
	{
		
		for(int j=1;j<=k&&i-j>-1;j++)
			v[i] = min(v[i], abs(m[i] - m[i - j]) + v[i - j]);
		
	}
	cout << v[n - 1] << endl;
	return 0;
}

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> data(h, vector<char>(w));
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> data.at(i).at(j);
        }
    }
    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < 1<<h; i++){
        for (int j = 0; j < 1<<w; j++){
            tmp = 0;
            for(int k = 0; k<h; k++){
                for(int l = 0; l<w; l++){
                    if(i>>k&1) continue;
                    if(j>>l&1) continue;
                    if(data.at(k).at(l) == '#') tmp++;
                }
            }
            if(tmp == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int INF=1<<21;
const int maxn=100+10;
int n;
vector<int> g[maxn];
int vis[maxn];
int d[maxn];
void bfs(int s)
{
    queue<int> que;
    que.push(s);
    vis[s]=1;
    d[s]=0;
    while(!que.empty())
    {
        int u=que.front();que.pop();
        for(int i=0;i<g[u].size();i++)
        {
            int v=g[u][i];
            if(!vis[v])
            {
                que.push(v);
                vis[v]=1;
                d[v]=min(d[v],d[u]+1);

            }
        }
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int no,cnt,dd;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&no,&cnt);
        for(int j=0;j<cnt;j++)
        {
            scanf("%d",&dd);
            g[no-1].push_back(dd-1);
        }
    }
    for(int i=0;i<n;i++) d[i]=INF;
    bfs(0);
    for(int i=0;i<n;i++)
    {
        printf("%d %d\n",i+1,d[i]==INF?-1:d[i]);
    }

    return 0;
}

Measured memory_bytes: 3220
d = {}
n = int(input())

for i in range(n):
  x = input()
  if x in d:
    d[x] += 1
  else:
    d[x] = 1

mx = 0
ans = []

for itm in d.items():
  if itm[1] == mx:
    ans.append(itm[0])
  elif itm[1] > mx:
    ans = [itm[0]]
    mx = itm[1]
  else:
    continue

ans.sort()

for x in ans:
  print(x)

Measured memory_bytes: 32096