akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        ll ans = INF;
        ll curr = 0, sum = 0;
        for(i = 0; i < n; i++){
            ll val = v[i];
            if(i % 2 == 0){
                if(sum + val > 0){
                    sum += val;
                }
                else{
                    curr += (-sum - val + 1);
                    sum = 1;
                }
            }
            else{
                if(sum + val < 0){
                    sum += val;
                }
                else{
                    curr += (sum + val + 1);
                    sum = -1;
                }
            }
        }
        ans = curr;
        curr = 0;
        sum = 0;
        for(i = 0; i < n; i++){
            ll val = v[i];
            if(i % 2 == 1){
                if(sum + val > 0){
                    sum += val;
                }
                else{
                    curr += (-sum - val + 1);
                    sum = 1;
                }
            }
            else{
                if(sum + val < 0){
                    sum += val;
                }
                else{
                    curr += (sum + val + 1);
                    sum = -1;
                }
            }
        }
        ans = min(ans, curr);
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3960
import Control.Monad

main :: IO ()
main = do
  [p, q] <- map read . words <$> getLine :: IO [Int]
  strs <- replicateM p getLine
  putStrLn $ concat $ replicate (q+2) "#"
  forM_ [0..p-1] $ \i -> do
    let str = "#" ++ (strs !! i) ++ "#"
    putStrLn str
  putStrLn $ concat $ replicate (q+2) "#"


Measured memory_bytes: 1404
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

ll a, b, c;
int main(void) {
	cin >> a >> b >> c;
	if (a + b == c || b + c == a || a + c == b)ct("Yes");
	else ct("No");
	return 0;
}

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

//g++ -std=c++11

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

vector <ll> v(25821);

int main() {

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);

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

    int a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k-a>0){
        ans += a;
        k-=a;
    } else if(k>0){
        ans += min(k,a);
        cout << ans << endl;
        return 0;
    }
    if(k-b>0){
        ans+= 0;
        k-=b;
    } else if(k>0){
        ans += 0;
        cout << ans << endl;
        return 0;
    }
    if(k-c>0){
        ans+=(-1*c);
        k-=c;
    } else if(k>0){
        ans -= min(k,c);
        cout << ans << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {
	ll n,k;
	ll h[100001];
	ll total=1000000000;

	cin>>n>>k;
	rep(i,n){
		cin>>h[i];
	}
	sort(h, h + n, greater<ll>());

		rep(i,n-k+1){
			total=min(total,h[i]-h[i+k-1]);
		}
		cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vl depth(101010,-1);
vl par(101010,-1);
vl state(101010,-1);
vpl num(101010,P(-inf,inf));
vvl G(101010);
vvl d(101010);

void dfs(ll u, ll p){
	par[u] = p;
	for(auto v : G[u]){
		if(v == p) continue;
		depth[v] = depth[u] + 1;
		d[depth[v]].push_back(v);
		dfs(v,u);
	}
}

bool check(ll u, ll v, P p){
	if(state[v] != -1 && state[u] == state[v]) return false;
	state[v] = 1 - state[u];
	chmax(num[v].first, p.first);
	chmin(num[v].second, p.second);
	return num[v].first <= num[v].second;
}

int main(){
	ll n; cin >> n;
	rep(i,n-1){
		ll a,b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll k; cin >> k;
	while(k--){
		ll v,p; cin >> v >> p; v--;
		num[v] = P(p,p);
		state[v] = p & 1;
	}
	depth[0] = 0;
	d[0].push_back(0);
	dfs(0,-1);
	for(ll i=n; i>=1; i--){
		for(auto u : d[i]){
			if(state[u] == -1) continue;
			P pp = P(num[u].first - 1, num[u].second + 1);
			if(!check(u,par[u],pp)){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	vl ans(n,-linf);
	ans[0] = num[0].second;
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll u = q.front(); q.pop();
		for(auto v : G[u]){
			if(ans[v] != -linf) continue;
			if(num[v].first <= ans[u]-1 && ans[u]-1 <= num[v].second){
				ans[v] = ans[u] - 1;
			}else{
				ans[v] = ans[u] + 1;
			}
			q.push(v);
		}
	}
	rep(i,n) cout << ans[i] << "\n";
}

Measured memory_bytes: 22912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const ll INF = 1e+13;

map<int, int> prime_divisor(int n){
    map<int, int> res;
    for(int i = 2; i * i <= n; ++i){
        if(n % i == 0){
            int tmp = 0;
            while(n % i == 0){
                n /= i;
                ++tmp;
            }
            res[i] = tmp;
        }
    }
    if(n != 1)  res[n] = 1;
    return res;
}

ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

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

struct Combination{
    int n;
    vector<ll> fact;
    vector<ll> ifact;

    Combination(int n_){
        n = n_;
        fact = vector<ll>(n + 1);
        ifact = vector<ll>(n + 1);

        fact[0] = 1;
        for(int i = 1; i <= n; ++i){
            fact[i] = (ll)fact[i - 1] * i % mod;
        }

        ifact[n] = mod_pow(fact[n], mod - 2);
        for(int i = n; i > 0; --i){
            ifact[i - 1] = ifact[i] * i % mod;
        }
    }

    ll get_combination(int n, int r){
        if(n < 0 || r < 0 || n < r)     return 0;

        return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
    }
};

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

    int n, m;
    cin >> n >> m;
    map<int, int> p_divisor = prime_divisor(m);
    Combination c(200005);
    ll res = 1;
    for(auto it = p_divisor.begin(); it != p_divisor.end(); ++it){
        cerr << it->first << " " << it->second << endl;
        res = res * c.get_combination(it->second + n - 1, n - 1) % mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 3328
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

main = getLine >>= putStrLn . map toUpper

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int in, sum = 0;
	for(int i = 0; i < 5; i++){
		cin >> in;
		in = max(40, in);
		sum += in;
	}
	cout << sum/5 << endl;
	return 0;
}


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

long long n,k,sum;

int main(){
	n = 100;
	cin>>k;
	for(int i = 1;i <= 3760;i ++){
		n = n + n / 100;
		sum++;
		if(n >= k){
			break;
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
using namespace std;
//#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1000050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		char S;
		cin>>S;
		if(S=='Y'){
			cout<<"Four"<<endl;
			return 0;
		}
	}
	cout<<"Three"<<endl;
	return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

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

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

    sort(ara, ara + n, greater<int>());

    ll ans = ara[0];
    int count = 2;
    int p = 1;
    while (count < n)
    {
        ans += ara[p];
        count++;

        if (count < n)
        {
            ans += ara[p];
            count++;
            p++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (s == u)cout << a - 1 << " " <<b << endl;
	if (t == u)cout << a << " " << b - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;

	int last = 0;
	int max = 0;

	cin >> last;
	max = last;
	int temp = last;
	for (int i = 1; i < n - 1; i++)
	{
		cin >> temp;
		max += min(last, temp);

		last = temp;
	}

	max += temp;
	cout << max;

}


Measured memory_bytes: 256
def main():
    num = int(input())
    nums = list(map(int, input().split()))
    
    flag = True
    i = 0
    swap_num = 0
    while flag:
        flag = False
        for j in range(num-1, i, -1):
            if nums[j] < nums[j - 1]:
                temp = nums[j-1]
                nums[j-1] = nums[j]
                nums[j] = temp
                flag = True
                swap_num += 1
                
        i += 1
    print(" ".join([str(n) for n in nums]))
    print(swap_num)
                

if __name__ == '__main__':
    main()
    


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

int main()
{
int c=0,d=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==45)
        {
            c++;
        }
        if(s[i]==43)
        {
            d++;
        }
    }
    cout<<d-c<<endl;
}


Measured memory_bytes: 256
#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;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

const int MAX_UF = 110000;
struct PotentialUnionFind{
    typedef ll TYPE;
    const TYPE SUM_UNITY = 0;
    TYPE par[MAX_UF],rank[MAX_UF];
    TYPE diff_weight[MAX_UF];
    int N;
    PotentialUnionFind(int n = 0):N(n){ for(int i = 0; i < n;i++){ par[i] = i; rank[i] = 0; diff_weight[i] = SUM_UNITY; } }
    void init(){ for(int i = 0; i < N;i++){ par[i] = i; rank[i] = 0; diff_weight[i] = SUM_UNITY; } }
    void init(int n){ for(int i = 0; i < n; i++){ par[i] = i; rank[i] = 0; diff_weight[i] = SUM_UNITY; } }
    
    TYPE root(TYPE x){
        if(par[x] == x) return x;
        else {
            TYPE r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    TYPE weight(TYPE x){ root(x); return diff_weight[x]; }
    bool same(TYPE x,TYPE y){
        return root(x) == root(y);
    }
    bool merge(TYPE x,TYPE y,TYPE w){
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) {swap(x, y); w = -w; }
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x; diff_weight[y] = w;
        return true;
    }
    
    TYPE diff(TYPE x,TYPE y){ return weight(y) - weight(x); }
};

void solve(){
    int N,M; cin >> N >> M;
    PotentialUnionFind PUF(N);
    for(int i = 0; i < M; i++){
        int l,r,d; cin >> l >> r >> d; l--; r--;
        if(PUF.same(l,r)){
            ll diff = PUF.diff(l,r);
            if(diff != d) {
                cout << "No" << endl; return;
            }
        }else{
            PUF.merge(l,r,d);
        }
    }
    cout << "Yes" << endl;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n,a[maxn];
ll f[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
unordered_map<int,int>pos;
f[0]=1;
for(int i=1;i<=n;i++){
  f[i]=f[i-1];
  if(i>1&&a[i]!=a[i-1]&&pos.find(a[i])!=pos.end()){
    f[i]+=f[pos[a[i]]];
    f[i]%=mod;
  }
  pos[a[i]]=i;
}
cout<<f[n]<<endl;
  return 0;
}

Measured memory_bytes: 10824
#include <iostream>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int a[101][101];
	int n;
	while(cin >> n && n)
	{
		memset(a,0,sizeof(a));
		rep(i,n)
		{
			rep(j,n)
			{
				cin >> a[i][j];
			}
		}

		int sum_n = 0;
		rep(i,n)
		{
			int sum = 0;
			int sum_2 = 0;
			rep(j,n)
			{
				sum += a[i][j]; 
				sum_2 += a[j][i];
			}
			a[i][n] = sum;
			a[n][i] = sum_2;

			sum_n += a[i][n];
		}

		a[n][n] = sum_n;

		rep(i,n+1)
		{
			rep(j,n+1)
			{
				cout.width(5);
				cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main() {
	string n;
	cin >> n;
	int x = n.length();
	vector<string> given(x);
	for (int i = 0; i < x; i++) {
		given.at(i) = n.at(i);
	}
	vector<string> start_0(x);
	vector<string> start_1(x);
	int flip = 0;
	for (int i = 0; i < x; i++) {
		if (flip == 0) {
			start_0.at(i) = "0";
			start_1.at(i) = "1";
			flip++;
		}
		else {
			start_0.at(i) = "1";
			start_1.at(i) = "0";
			flip--;
		}
	}
	int ans_0 = 0;
	int ans_1 = 0;
	for (int i = 0; i < x; i++) {
		if (start_0.at(i) != given.at(i)) {
			ans_0++;
		}
		else {}
		if (start_1.at(i) != given.at(i)) {
			ans_1++;
		}
		else {}
	}
	int ans = min(ans_0, ans_1);
	cout << ans << endl;
}

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

int k, l = 1, d, f[11][10];

int main(){
	scanf("%d", &k);
	++k;
	for(d = 0; d <= 9; d++){
		if(k == 1){
			putchar('0' + d);
			break;
		}
		f[1][d] = 1;
		--k;
	}
	while(d == 10){
		l++;
		for(d = 0; d <= 9; d++){
			f[l][d] = f[l - 1][d];
			if(d < 9) f[l][d] += f[l - 1][d + 1];
			if(d){
				f[l][d] += f[l - 1][d - 1];
				if(f[l][d] < k) k -= f[l][d];
				else{
					putchar('0' + d);
					break;
				}
			}
		}
	}
	for(--l; l; l--){
		--d;
		for(int i = 0; i < 3; i++){
			if(d == -1){
				d = 0;
				continue;
			}
			if(f[l][d] >= k){
				putchar('0' + d);
				break;
			}
			k -= f[l][d++];
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265359
#define INF 1000000000

int main() {
    int N, K; cin >> N >> K;
    int h[N];
    rep(i, N) {
        cin >> h[i];
    }
    int ans = 0;
    rep(i, N) {
        if (h[i] >= K) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);

string s;
int k,n;

ll dp[102][2][4];

ll f(int idx,bool c,int num){
    if(idx==n){
        if(num==k){
            //cout<<num<<"\n";
            return 1;
        }
        return 0;
    }
    if(num==k){
        return 1;
    }
    int d=9;
    ll &ret=dp[idx][c][num];
    if(ret!=-1){
        return ret;
    }
    ret=0;
    if(c){
        d=s[idx]-'0';
    }
    for(int i=0;i<=d;i++){
        bool new_c=(c && i==s[idx]-'0');
        ret+=(i>0)?f(idx+1,new_c,num+1):f(idx+1,new_c,num);
    }
    return ret;
}

void solve(int T){
    memset(dp,-1,sizeof dp);
    cin>>s>>k;
    n=s.size();
    cout<<f(0,1,0);
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





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

using namespace std;

int main(){
	double r;
	cin >> r;
	double s,l;
	s=r*r*M_PI;
	l=2*r*M_PI;
	printf("%f %f\n",s,l);
	return 0;
}

Measured memory_bytes: 3292
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll L,R;
	while(cin>>L>>R) {
		ll M = min(R, L+2100);
		ll ans = INF;
		RANGE(i, L, M+1) RANGE(j, L, M+1) if(i<j) {
			ll lans = ((ll)i*j)%2019;
//			DD(i);DD(j);DD(lans);
			minUpdate(ans, lans);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n,m; cin>>n>>m;
    vector<int> a(n+1,0),dp(n+2,0);
    for(int i=0;i<m;i++){
        int t; cin>>t;
        a[t]=1;
    }
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        if(a[i]) dp[i]=0;
        else dp[i]=(dp[i+1]+dp[i+2])%1000000007;
    }
    cout<<dp[0]<<endl;
}

Measured memory_bytes: 1024
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[101010],s[101010];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=n;i>=1;i--)
	{
		for(j=i;j>=1;j--)
		{
//			printf("%d %d\n",j,a[j]);
			if(a[j]==j)
			{
				s[i]=j;
				for(k=j;k<i;k++)
					a[k]=a[k+1];
				break;
			}
		}
		if(j==0)
		{
			puts("-1");
			return 0; 
		}
	}
	for(i=1;i<=n;i++)
		printf("%d\n",s[i]);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 256
<?php
/*
    http://code-festival-2016-quala.contest.atcoder.jp/tasks/codefestival_2016_qualA_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%s", $s);

echo substr($s, 0, 4);
echo " ";
echo substr($s, 4, 8);
echo PHP_EOL;

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<vector<int>>x(N,vector<int>(3));
  for(int i=0;i<N;i++)for(int j=0;j<3;j++)cin>>x[i][j];

  vector<vector<int>>dp(N+1,vector<int>(3,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k)continue;
        dp[i+1][j]=max(dp[i+1][j],dp[i][k]+x[i][j]);
      }
    }
  }

  cout<<max({dp[N][0],dp[N][1],dp[N][2]})<<endl;
  return 0;
}


Measured memory_bytes: 11136
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<set>
using std::set;

int main()
{
  int n, k;
  cin >> n >> k;
  
  set<int> s;
  for (int i = 0; i < k; i ++)
  {
    int d;
    cin >> d;
    
    for (int j = 0; j < d; j ++)
    {
      int tmp;
      cin >> tmp;
      s.insert(tmp);
    }
  }

  cout << n - s.size() << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ld double
#define F first
#define S second
#define sz size
#define pb push_back

using namespace std;

const int MAXN = 1e6 + 5;
const int inf = 1e9 + 7;
const ll INF = 1e18;

int n, m, ct[35];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++) {
            int a;
            cin >> a;
            ct[a]++;
        }
    }
    int res = 0;
    for (int i = 1; i <= m; i++) {
        if (ct[i] == n) {
            res++;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str,num;
        int a,b,i,j,x,y;
        str = scan.nextLine();
        a = Integer.valueOf(str);
        x = 0;
        y = 0;
        for(i=0;i<a;i++){
            str = scan.nextLine();
            String[] words = str.split(" ", 0);
            if(words[0].equals(words[1])){
                x += 1;
                y += 1;
            }else {
                if(words[0].length()>words[1].length()){
                    b = words[1].length();
                }else{
                    b = words[0].length();
                }
                for (j = 0; j < b; j++) {
                    if(words[0].charAt(j)>words[1].charAt(j)){
                        x += 3;
                        break;
                    }else if(words[0].charAt(j)<words[1].charAt(j)){
                        y += 3;
                        break;
                    }
                }
                if(j == b){
                    if(words[0].length()>words[1].length()){
                        x += 3;
                    }else{
                        y += 3;
                    }
                }
            }
        }
        System.out.println(x+" "+y);
        scan.close();

    }

}



Measured memory_bytes: 31520
#include<stdio.h>

int main(void){
	int task[128];
	
	for(int i = 0; i < 3; i++){
		scanf("%d", &task[i]);
	}
	
	int max;
	int min;
	
	max = task[0];
	if(task[1] > max) max = task[1];
	if(task[2] > max) max = task[2];
	
	min = task[0];
	if(task[1] < min) min = task[1];
	if(task[2] < min) min = task[2];
	
	int cost = max - min;
	printf("%d\n", cost);
	
	return 0;	
}
	

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;

void solve()
{
    db a, b, n;
    cin >> a >> b >> n;
    db x = min(b - 1, n);
    cout << floor(a * x / b) << "\n";


}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 3800
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            par: (0..n).collect(),
            rank: vec![0; n],
        }
    }
    fn root(&mut self, mut n: usize) -> usize {
        while n != self.par[n] {
            n = self.par[n];
        }
        n
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x == y {
            return;
        }

        if self.rank[x] < self.rank[y] {
            self.par[x] = y;
        } else {
            self.par[y] = x;
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        p: [usize1; n],
        xy: [(usize1, usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for (x, y) in xy.into_iter() {
        uf.unite(x, y);
    }

    let mut ans = 0;
    for (i, j) in p.into_iter().enumerate() {
        if uf.same(i, j) {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 10492
//in the name of allah
#include<iostream>
#include<algorithm>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
typedef pair<int , int> ii;
typedef long long ll;

const int maxn = 1e5+10;
int d[maxn];

int main(){
	int n , m , cnt=0;
	scanf("%d%d" , &n , &m);
	while(m --){
		int a , b;
		scanf("%d%d" , &a , &b);
		cnt -= d[a];
		cnt -= d[b];
		d[a] = 1-d[a];
		d[b] = 1-d[b];
		cnt += d[a];
		cnt += d[b];
	}
	puts(cnt == 0 ? "YES" : "NO");
}


Measured memory_bytes: 640
#include<stdio.h>

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

  int a[n+2];
  for(int i = 1;i <= n;i ++){
    scanf("%d",&a[i]);
  }
  a[0] = 0;
  a[n+1] = 0;
  int ans = 0;
  for(int i = 0;i <= n;i ++){
    ans += abs(a[i] - a[i+1]);
  }

  for(int i = 1;i <= n;i ++){
    printf("%d\n",ans - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]));
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<ll> a(n), b(n), c(n);

  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  for (int i = 0; i < n; ++i) {
    ll acnt = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll ccnt = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += acnt * ccnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
N = int(input())
A = list(map(int, input().split()))
allpoint = abs(A[0])
for i in range(N):
    if i < N-1:
        allpoint += abs(A[i]-A[i+1])
    else:
        allpoint += abs(A[i])

for i in range(N):
    if i == 0:
        print(allpoint+abs(A[i+1])-abs(A[i])-abs(A[i]-A[i+1]))
    elif i == N-1:
        print(allpoint+abs(A[i-1])-abs(A[i]-A[i-1])-abs(A[i]))
    else:
        print(allpoint+abs(A[i+1]-A[i-1])-abs(A[i]-A[i-1])-abs(A[i]-A[i+1]))


Measured memory_bytes: 14044
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n, color[MAX];
vector<int> G[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push( r );
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top();
    S.pop();
    REP(i, G[u].size()) {
      int v = G[u][i];
      if ( color[v] == NIL ) {
        color[v] = c;
        S.push( v );
      }
    }
  }
}

void assignColor() {
  int id = 1;
  REP(i, n) color[i] = NIL;
  REP(u, n) {
    if ( color[u] == NIL ) dfs(u, id++);
  }
}

int main() {
  int s, t, m, q;

  cin >> n >> m;

  REP(i, m) {
    cin >> s >> t;
    G[s].push_back( t );
    G[t].push_back( s );
  }

  assignColor();

  cin >> q;
  REP(i, q) {
    cin >> s >> t;
    if ( color[s] == color[t] ) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

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

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

long long MOD = 10000000000 + 7;

template<typename T>
T gcd(T a, T b) {
  if(a < b) swap(a,b);
    
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<ll> v(N), a(N), b(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
    a[i] = v[i];
    b[i] = v[i];
  }


  for(int i = 0; i < N; i++){
    if(i == 0){
      continue;
    } else { 
      a[i] = gcd(a[i], a[i-1]);
    }
  }

  for(int i = N -1; i >= 0; i--){
    if(i == N-1){
      continue;
    } else { 
      b[i] = gcd(b[i], b[i+1]);
    }
  }

  ll max_val = 0;
  for(int i = 0; i < N; i++){
    if(i==0){
      max_val = max(max_val, b[i+1]);
    } else if(i == N-1){
      max_val = max(max_val, a[i-1]);
    } else { 
      max_val = max(max_val, gcd(a[i-1], b[i+1]));
    }
  }
  cout << max_val << endl;
}


Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
int n,RT1,RT2,ff,S;
int tot=1,head[200005],nx[800005],to[800005];
int ru[200005],bj[400005],tt[100005];
int read()
{
    char ch=getchar();int x=0,ff=1;
    while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return ff*x;
}
void write(int z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
   	putchar(z%10+'0');
}
void jia(int aa,int bb)
{
   	tot++;
   	nx[tot]=head[aa];
   	to[tot]=bb;
   	head[aa]=tot;
   	return;
}
void oula(int rt)
{
   	for(int i=head[rt];i;i=head[rt])
   	{
   		head[rt]=nx[i];
   		if(!bj[i/2])
   		{
   			int yy=to[i];
   			bj[i/2]=yy;
   			oula(yy);
   		}
   	}
   	return;
}
int main()
{
	n=read();
   	for(int i=1;i<=n;++i)
   	{
   		int x=read();
   		if(x==-1) {RT1=i;continue;}
   		jia(i,x);jia(x,i);
   		ru[i]^=1;ru[x]^=1;
   	}
   	ru[RT1]^=1;
   	for(int i=1;i<=n;++i)
   	{
   		int x=read();
   		if(x==-1) {RT2=i+n;continue;}
   		jia(i+n,x+n);jia(x+n,i+n);
   		ru[i+n]^=1;ru[x+n]^=1;
   	}
   	ru[RT2]^=1;
   	for(int i=1;i<=n;++i) if(ru[i]!=ru[i+n]) ff=1;
   	if(ff) {puts("IMPOSSIBLE");return 0;}
   	puts("POSSIBLE");
   	S=n*2+1;
   	for(int i=1;i<=n;++i)
   	if(ru[i]) jia(i,i+n),tt[i]=tot/2,jia(i+n,i);
   	jia(S,RT1);jia(RT1,S);
   	jia(RT2,S);jia(S,RT2);
   	oula(S);
   	for(int i=1;i<=n;++i) 
   	if(ru[i]) 
   	{
   		if(bj[tt[i]]>n) write(1),putchar(' ');
   		else write(-1),putchar(' ');
   	}
   	else write(0),putchar(' ');
   	return 0;
}

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

struct UnionFind {
    vector<int> p;
    UnionFind(int n): p(n, -1) {}
    int root(int u) {
        if (p[u] < 0) return u;
        return p[u] = root(p[u]);
    }
    void merge(int u, int v) {
        u = root(u), v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        if (root(u) == root(v)) return true;
        return false;
    }
};
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<set<int>> ng(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.merge(a, b);
        ng[a].insert(b);
        ng[b].insert(a);
    }
    for (int i = 0; i < k; i++) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        if (!uf.same(c, d)) continue;
        ng[c].insert(d);
        ng[d].insert(c);
    }
    for (int i = 0; i < n; i++) {
        int out = uf.size(i) - ng[i].size() - 1;
        cout << out;
        if (i < n - 1) cout << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 26928
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define mod 1000000007 
#define rep(i,j,l) for(int i=j;i<=l;i++)
#define dec(i,j,l) for(int i=j;i>=l;i--)
#define inp(a,n) rep(i,0,n-1)cin>>a[i] 
#define out(a,n) rep(i,0,n-1)cin>>a[i]
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


int main()
{  ios_base::sync_with_stdio(0); 
   cin.tie(NULL);
   string s,t;
   cin>>s>>t;
   int m=s.length();
   int n=t.length();
   int dp[m+1][n+1];
   rep(i,0,m)
   dp[i][0]=0;
   rep(i,0,n)
   dp[0][i]=0;
   rep(i,1,m)
     rep(j,1,n)
     {   if(s[i-1]==t[j-1]) 
          dp[i][j]=dp[i-1][j-1]+1;
         else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 
     }
     string S="";   
     int i=m;
     int j=n;
     while(dp[i][j]!=0) 
     {
         if(s[i-1]==t[j-1]) 
          { S+=s[i-1];   
            i--;
            j--;
          }
         else if(dp[i-1][j]<dp[i][j-1]) 
           j--;
         else i--;  
     }     
     dec(i,S.length()-1,0)
     cout<<S[i];
   return 0;            
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> p(n), idx(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
        idx[p[i]] = i;
    }
    multiset<ll> pos;
    pos.insert(-1);
    pos.insert(-1);
    pos.insert(n);
    pos.insert(n);
    ll ans = 0;
    rrep(i, n) {
        ll m = idx[i];
        pos.insert(m);
        auto it = pos.lower_bound(m);
        auto cit = it;
        cit--;
        ll lin = *cit;
        cit--;
        ll lout = *cit;
        cit = it; cit++;
        ll rin = *cit;
        cit++;
        ll rout = *cit;
        ll cnt = 0;
        cnt += (rin - m) * (lin - lout);
        cnt += (m - lin) * (rout - rin);
        ans += cnt * (i + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}


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

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;  // check the limits, dummy

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
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;
}

template <class T>
void print(const vector<T> v) {
  cout << "[ ";
  F0R(i, v.size()) { cout << v[i] << ' '; }
  cout << "]" << '\n';
}

int mod(int i, int j) {
  return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int K, A, B;
  cin >> K >> A >> B;
  FOR(i, A, B + 1) {
    // cout << i << endl;
    if (i % K == 0) {
      cout << "OK" << endl;
      return;
    }
  }
  cout << "NG" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

int main() {
	ll t;
	//cin>>t;
	t=1;
	while(t--){
	setprecision(20);
    
    ll n;
    cin>>n;
    
    
    ll ans=1;
    ll a[n];
    bool f=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            f=1;
        }
    }
    sort(a,a+n);
    ll maxi=1e18;
    if(f)
    {
        cout<<0;
        return 0;
    }
    
    for(int i=0;i<n;i++)
    {
        if(ans>maxi/a[i])
        {
            cout<<-1;
            return 0;
        }
        ans=ans*a[i];
    }
    cout<<ans;
    
	}   
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    string s;
    cin >> s;
    map<char,ll> m;
    rep(i,0,s.size()){
        if(m.count(s[i]) == 0){
            m[s[i]] = 1;
        }
        else{
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<cstring>
#include<stack>
#include<cstdlib>
#include<cmath>
using namespace std;

int main()
{
	int n, h, w, a, b;
	int cnt = 0;
	cin >> n >> h >> w;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a >= h && b >= w)
			cnt++;
	}
	cout << cnt << endl;
}

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

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

ll R,D,X;


int main(){
  cin >> R >> D >> X;
  for (ll i=1;i<=10;i++){
    X=X*R-D;
    if (D<0)D=0;
    cout << X << endl;
  }
}


Measured memory_bytes: 888
row_length = int(input())
point = {}
for i in range(row_length):
    point[i] = list(map(int, input().split()))
from math import ceil
def feasible_point(t, x, y):
    if t % 2 == 0:  # tが偶数の時
        k = t / 2
        # (x,y)がk * kの間にある偶数点ならばokを返す・・・これが間違っていた
        # x + y <= 6の点なら何でもよかった
        if ((x+y)%2 == 0)&(x+y <= t):
            return True
        else:
            return False
    else:
        k = ceil(t / 2)
        # (x,y)がk * kの間にある奇数点ならばokを返す
        if ((x+y)%2 == 1)&(x+y<= t):
            return True
        else:
            return False

check_list = []
for j in range(len(point)):
    check_list.append(feasible_point(point[j][0], point[j][1], point[j][2]))

if all(check_list):
    # 各点同士の両立可能性を調べる
    check_list_2 = []
    for l in range(len(point)-1):
        t_gap = point[l+1][0] - point[l][0]
        xy_gap = point[l+1][1] + point[l+1][2] - point[l][1] - point[l][2]
        if abs(xy_gap) <= abs(t_gap):
            check_list_2.append(True)
        else:
            check_list_2.append(False)
    if all(check_list_2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 73048