akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,a[10010]={},b[11010]={};
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n)cin>>b[i];
	LL aa=0,bb=0,p=0,q=0;
	FOR(i,0,n){
		aa+=a[i];
		bb+=b[i];
		if(a[i]==b[i]){

		}else if(a[i]>b[i]){
			q+=a[i]-b[i];
		}else{
			p+=(b[i]-a[i]+1)/2;
		}
	}
	if(bb-aa>=p&&bb-aa>=q)cout<<"Yes";
	else cout<<"No";

    return 0;
}


Measured memory_bytes: 632
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int dp[1002], a[1002], n, w, r;
int main() {
	while (true) {
		cin >> n >> w; r++; if (n == 0)break;
		for (int i = 1; i <= n; i++)cin >> a[i];
		for (int i = 0; i <= n; i++) dp[i] = 999999999; dp[0] = 0;
		for (int i = 0; i < n; i++) {
			int s = 0;
			for (int j = i + 1; j <= n; j++) {
				s += a[j];
				if (j < n)dp[j] = min(dp[j], dp[i] + abs(s - w));
				if (j == n)dp[j] = min(dp[j], dp[i] + max(s - w, 0));
			}
		}
		cout << "Case " << r << ": " << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>

using namespace std;
int main(void) {
    int d, n;
    cin >> d >> n;
    
    if(n!=100) {
        if(d==0)
            cout << n;
        else if(d==1)
            cout << n*100;
        else
            cout << n*10000;
    } else {
        if(d==0)
            cout << 101;
        else if(d==1)
            cout << 10100;
        else
            cout << 1010000;
    }
    
    
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e5 + 7;
int n, a[N], dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    dp[i] = (int) 1e9;
    for (int j = i - 1; j >= i - 2 && j >= 1; j--) {
      dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    }
  }
  cout << dp[n] << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
#include <set>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

struct Edge {
    int src, dst, cost;
    Edge(int s, int d, int c = 1) : src(s), dst(d), cost(c) {}
    bool operator<(const Edge &e){ return cost < e.cost;}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

// O(|V||E|)
bool bellman_ford(int s, Graph &g, vector<long> &dist) {
    int n = g.size();
    dist.assign(n, INF);
    dist[s] = 0;

    for(int i = 0; i < n*2; ++i) {
        bool update = false;
        for(int v = 0; v < n; ++v) {
            for(Edge e : g[v]) {
                if(dist[e.src] != INF && dist[e.dst] > dist[e.src] + e.cost) {
                    dist[e.dst] = dist[e.src] + e.cost;
                    update = true;

                    if(i >= n && e.dst == n-1) {
                        // negative cycle
                        return true;
                    }
                }
            }
        }
        if(!update) break;
    }
    return false;
}

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

    long n, m, p; cin >> n >> m >> p;

    Graph g(n);
    REP(i,m) {
        long a,b,c; cin >> a >> b >> c;
        --a, --b; c -= p;
        g[a].emplace_back(a, b, -c);
    }

    vector<long> dist(n);
    if(bellman_ford(0, g, dist)) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << max(-dist[n-1],0L) << endl;
    }


    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  map<int,int> mp;
  int a;
  REP (i,n){
    cin>>a;
    mp[a]++;
  }
  int ans=0;
  for(auto p:mp){
    if(p.first<=p.second){
      ans += p.second-p.first;
    }else{
      ans += p.second;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<T>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	ios::sync_with_stdio(false);

	int n;
	string s;

	cin >> n >> s;

	REP(i, s.size()) {
		s[i] += n;
		if (s[i] > 'Z') {
			s[i] -= 26;
		}
	}

	cout << s;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    ll n,k,s;
    cin >> n >> k >> s;
    vector<int> v(n);
    rep(i,n){
        if(i < k) v[i] = s;
        else if(s < 1e9) v[i] = s + 1;
        else v[i] = s - 1;
    }
    rep(i,n){
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    ll n;
    cin >> n;
    if(n==1){cout << 0 <<endl;return 0;}
    ll ans = (n-1)*n;
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define NumberOfOnes __builtin_popcount
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twoll pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
int n,k;
int main(){FAST;xRand;
cin>>n>>k;
if((n+1)/2<k){
	cout<<-1<<endl;
	return 0;
}
for(int i=0;i<n;i++)
	if(i&1)
		cout<<i/2+(n+1)/2+k<<" "<<i/2+n+k<<" "<<i+n+n+k<<endl;
	else
		cout<<i/2+k<<" "<<i/2+n+n/2+k<<" "<<i+n+n+k<<endl;
}
/*

                   *           *
                  * *         * *
                 *   *       *   *
                *     *     *     *
                 *    *    *     *
                  *    *   *   *
                   *    * *   *
                     *      *
					   *  *


*/



Measured memory_bytes: 2304
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int N;

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


    cin >> N;

    cout << N * N * N << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,y;
  cin>>n>>y;
  for(int i=0;i<=n;++i)
    for(int j=0;j<=n-i;++j)
      for(int k=0;k<=n-i-j;++k)
        if(i+j+k==n&&i*10000+j*5000+k*1000==y){
          cout<<i<<' '<<j<<' '<<k<<'\n';
          return 0;
        }
  cout<<"-1 -1 -1\n";
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
temp = 0
pre = 1
mod = 998244353
c = 1

if D[0] != 0:
    print(0)
    a = 1

if a == 0:
    D = sorted(D)
    for i, d in enumerate(D):
        if i == 0:
            continue
        if d == 0:
            print(0)
            a = 1
            break
        if temp != d:
            if (d - temp) != 1:
                print(0)
                a = 1
                break
            ans *= pre ** c

            temp = d
            pre = c
            c = 1
        else:
            c += 1

        if i == N-1:
            ans *= pre ** c
    if a == 0:
        print(ans%mod)


 




        






Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=n/(a+b);
    ans*=a;
    cout<<ans+min(a,n%(a+b))<<endl;
}


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

int N, K;
const int MAX_N = 100;
int s[MAX_N + 1];
int ans = 0;

int main() {
  cin >> N >> K;

  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      s[a-1] = s[a-1] + 1;
    }
  }

  for (int k = 0; k < N; k++) {
    if (s[k] == 0) {
      ans++;
    }
  }

  printf("%d", ans);

  return 0;
}

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(b/a<c)
	{
		cout<<b/a<<endl;
		return 0;
	}
	else if(b/a>=c)
	{
		cout<<c<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

const int N= 2010;
int n;
long a[N],x,lab[N],id[N];
void input()
{
    cin>>n>>x;
    up(i,0,n-1) cin>>a[i];
}
bool bya(int i,int j)
{
	return a[i]< a[j];
}
int findset(int u)
{
	if (lab[u]<0) return u;
	else return lab[u]= findset(lab[u]);
}
void Union(int u,int v)
{
	lab[u]= v;
}
void solve()
{
	up(i,0,n-1) id[i]= i;
	sort(id+0,id+0+n,bya);

	long res= 1e15;
    up(dich,0,n-1)
    {
        up(i,0,n) lab[i]= -1;
        long mini_res= 0;
        up(i,0,n-1)
        {
        	int cur= id[i];
        	int u= cur;
            while (1)
			{
				u= findset(u); if (u==n or u> cur+dich ) break;
				mini_res+= a[cur]; Union(u,u+1);
			}
			if (cur+dich<n) continue;
			u= 0;
			while (1)
			{
				u= findset(u); if (u> (cur+dich)%n) break;
				mini_res+= a[cur]; Union(u,u+1);
			}
        }

        res= min(res,mini_res+ x* dich);
    }
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	#endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int a, b;
    cin >> a >> b;
    REP(i, 0, 1000) {
        int t = 1 + (a-1)*i;
        if(t >= b) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;

  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int s = S - x - y;
      if (0 <= s && s <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[25][25];
int main()
{
       int m,n,x,y;
       while(cin>>m>>n>>x>>y)
       {
           memset(a,0,sizeof(a));
           for(int i=1;i<=m;i++)
               for(int j=1;j<=n;j++)
               {
                   if(i<=x&&a[i][j]==0)
                       a[i][j]=1;
                   if(j<=y&&a[i][j]==0)
                       a[i][j]=1;
               }
           int ans=0;
           for(int i=1;i<=m;i++)
               for(int j=1;j<=n;j++)
                   if(a[i][j]==0)
                       ans++;
                   cout<<ans<<endl;
       }

        return 0;
}

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

int main(void)
{
	char s[100000];
	int i,cnt[2]={0};
	scanf("%s",s);
	for(i=0;s[i]!='\0';i++){
		cnt[s[i] - '0']++;
	}
	printf("%d\n",(int)fmin(cnt[0],cnt[1])*2);
	return 0;
}


Measured memory_bytes: 256
#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
using namespace std;
const int MOD=1000000007;
const ll MAX=9187201950435737471;
const int N=100005;
const ll NINF=1e14;

ll bit[2200000];
ll n;

void updt(ll i,ll x){
    i++;
    while(i<=n){
        bit[i]=max(bit[i],x);
        i+= i & -i;
    }
    return;
}

ll query(ll i){
    i++;
    ll res=0;
    while(i>0){
        res=max(res,bit[i]);
        i-= i & -i;
    }
    return res;
}

int main() {
    fastio

    cin>>n;
    vector<pair<ll,ll> >h(n);
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        ll s;
        cin>>s;
        h[i].fi=s-1;
        h[i].se=i;
    }
    sort(h.begin(),h.end());
    vector<ll>dp(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    for(auto it:h){
        dp[it.fi]=query(it.se-1)+a[it.se];
        updt(it.se,dp[it.fi]);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 8064
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    private int[] a;

    AtCoder(FastScanner sc) {
        a = IntStream.range(0, 3).map(i -> sc.nextInt()).toArray();
    }

    void solve(PrintWriter out) {
        if (a[0] + a[1] + a[2] <= 21) {
            out.println("win");
        } else {
            out.println("bust");
        }
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 28500
#include<iostream>
using namespace std;
int main()
{
	int H, W, i, k, j;
	while(1)
	{	
		cin >> H >> W;
		if ( H == 0 && W == 0 )break;
		else
		{
			for ( i = 0; i < H; i++)
				{
					if ( i % 2 == 1 )
						{
							for ( k = 0; k < W; k++)
							{
								j = k % 2;
								if ( j == 1 )cout << "#";
								else if ( j == 0 )cout << ".";
							}
							cout << endl;
						}
					else if ( i % 2 == 0 )	
						{
							for ( k = 0; k < W; k++)
							{
								j = k % 2;
								if ( j == 1 )cout << ".";
								else if ( j % 2 == 0 )cout << "#";
							}
							cout << endl;
						}
				}
		}
	cout << endl;
	}
return 0; 
}

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

signed main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif
  multiset<int> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    s.insert(x);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    if (!s.count(x)) {
      cout << "NO\n";
      return 0;
    }
    s.erase(s.find(x));
  }
  cout << "YES\n";
}

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

int main() {
    int count[128] = {0};
    string s;
    while (getline(cin, s)) {
        for (int i=0; i<s.size(); i++) {
            if (s[i] >= 'A' && s[i] <= 'Z')
                s[i] = s[i] + 32;
            if (s[i] >= 'a' && s[i] <= 'z')
                count[s[i]]++;
        }
    }
    for (char c='a'; c<='z'; c++) {
        cout << c << " : " << count[c] << endl;
    }
}


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

int last[101];

int main(){
	int n,lcount=0;
	
	while(cin>>n){
		last[n]++;
		if(lcount<last[n]){
			lcount=last[n];
		}
	}
	
	for(int i=1;i<101;i++){
		if(last[i]==lcount){
			cout<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1160
/**
 *    Creator :  bizarre
 *    Date : 3/2020
 *    Problem Number : 390
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre     ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
/*
const int inf = 2e9, mod = 1e9 + 7,N=1e6+5;
long long fact[N], inv[N];

void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}
int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
                c++;
            }

        }
    }

}
*/

int main()
{

  int n,cntr=0,ans,anss;
  cin>>n;
  vector<long long>a,b,c;
  for(int i=0;i<n;i++)
  {
      long long x; cin>>x;
      a.push_back(x);
      c.push_back(x);
  }
  for(int i=0;i<n;i++)
  {
      long long x; cin>>x;
      b.push_back(x);
  }
  sort(c.begin(),c.end());
  do{
    if(a==c)
        ans=cntr;
    if(b==c)
        anss=cntr;
    cntr++;
  }while(next_permutation(c.begin(),c.end()));
  cout << abs(anss-ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int L; cin >> L; L--;
  vector<vector<int>> graph;

  int N = 2, num = 2;
  graph.push_back({1, 2, 0});
  graph.push_back({1, 2, 1});
  for(int i=1; pow(2,i+1)<=L+1; i++) {
    graph.push_back({i+1, i+2, 0});
    graph.push_back({i+1, i+2, pow(2,i)});
    N++; num+=2;
  }

  int len = L;
  L -= pow(2, (N-1))-1;
  int dig = 1;
  while (L!=0) {
    int pd = pow(2, dig);
    if (L%2!=0) {
      graph.push_back({dig, N, len/pd*pd});
      num++;
    }
    dig++; L/=2;
  }

  cout << N << " " << num << endl;
  for (auto x: graph) cout << x[0] << " " << x[1] << " " << x[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int main(){
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%.7f\n",sqrt(pow(x2-x1,2)+pow(y2-y1,2)));//7f浮動小数点数,pow=sqrt
}





Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin >> N;
  VEC<pair<LL, LL>> work(N);
  REP(i, 0, N) { cin >> work[i].second >> work[i].first; }
  sort(ALL(work));
  LL t = 0;
  REP(i, 0, N) {
    auto w = work[i];
    // DUMP(t, w);
    t += w.second;
    if (t > w.first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 3328
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
     int kaiten=N;
      int ans=0;
      bool flg=false;
      while(!flg){
       if (kaiten%360==0){
         flg=true;
       }
        kaiten+=N;
        ans++;
      }
      Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 27396
#include<bits/stdc++.h>
#define N 200010
#define RG register
using namespace std;
typedef long long LL;
LL ans;
char c[N];
int n,sum,bas[26];
int main(){
    scanf("%s",c+1);
    n=strlen(c+1);
    for (RG int i=1;i<=n;++i){
	ans+=sum-bas[c[i]-'a'];
	++sum;
	++bas[c[i]-'a'];
    }
    printf("%lld\n",ans+1);
    return 0;
}

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

int main(){
	int k = 0;
	int n;
	string a,b,c;
	cin >> n >> a >> b >> c;
	for(int i = 0;i < n;i++){
		if(a[i] == b[i] && b[i] == c[i] && a[i] == c[i]){
			k += 0;
		}
		else if((b[i] != c[i] && a[i] == b[i] && a[i] != c[i]) or (a[i] != b[i] && b[i] == c[i] && a[i] != c[i]) or (a[i] != b[i] && b[i] != c[i] && a[i] == c[i])){
			k += 1;
		}
		else{
			k += 2;
		}
	}
	cout << k;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl

int main() {
  int N, a = 0;
  ci(N);
  ve(int) p(N);
  rep(i, N) {
    ci(p.at(i));
  }
  rep(i, N) {
    if(p.at(i) != i + 1) {
      a++;
    }
  }
  if(a <= 2) {
    co("YES");
  }
  else {
    co("NO");
  }
}  

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
string s,t,u;
int a,b;
int main(){
	cin>>s>>t>>a>>b>>u;
	if(u==s)
		a--;
	else
		b--;
	cout<<a<<' '<<b;
	return 0;
}

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

int main() {
  long long N;
  cin >> N;

  long long ans = 0;
  for ( long long i = 1; i <= N; i++ ) {
    long long a = i;
    long long d = i;
    long long n = N/i;
    ans += n * (2*a + (n-1)*d) / 2;
  }

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


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

#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define FOR_(i, a, b, x) for (int i = a; (x > 0) ? i < b : i > b; i += x)
#define FOR_1(e) FOR_(i, 0, e, 1)
#define FOR_2(i, e) FOR_(i, 0, e, 1)
#define FOR_3(i, a, e) FOR_(i, a, e, 1)
#define FOR_4(i, a, e, b) FOR_(i, a, e, b)
#define G5(a, b, c, d, e, ...) e
#define FOR_5(...) G5(__VA_ARGS__, FOR_4, FOR_3, FOR_2, FOR_1)
#define FOR(...)       \
    FOR_5(__VA_ARGS__) \
    (__VA_ARGS__)
#define IN(a, b) for (auto &a : b)

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<string, int> m;
    FOR(n)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl
         << "WA x " << m["WA"] << endl
         << "TLE x " << m["TLE"] << endl
         << "RE x " << m["RE"];
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <math.h>
int sosu(int n){
    int i=3,x,bl=1;
    double sn = sqrt(n);
    if (n == 2) {
        return bl;
    }
    if (n<2 || n%2==0) {
        bl=0;
        return bl;
    }
    while (i <= sn) {
        if (n%i == 0) {
            bl=0;
            return bl;
        }
        i+=2;
    }
    
    return bl;
}

int main(int argc, const char * argv[]) {
    
    int n,i,count=0;
    while (1) {
        scanf("%d",&n);
        if (n==0) {
            break;
        }
        
        for (i=n+1; i<=2*n; i++) {
            count+=sosu(i);
        }
        
        printf("%d\n",count);
        count=0;
        
    }
    return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int t[100010],x[100010],y[100010];
int main()
{
    int n,sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    for(int i=1;i<=n;i++)
    {
        sum=x[i]+y[i]-x[i-1]-y[i-1];
        if((t[i]-t[i-1])<sum)
        {
            printf("No\n");
            return 0;
        }
        if((sum-(t[i]-t[i-1]))%2)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1280
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let a = nextIntArray()
    let m = 1000
    let s = 0
    let last = 0
    for(let i = a.length; i>=1; i--){
        if(a[i] > a[i-1]){
            last = i
            break
        }
    }

    for(let i = 0; i < last; i++){
        // buy
        if(m > a[i] && a[i] < a[i+1]){
            let cnt = Math.floor(m / a[i])
            m -= cnt * a[i]
            s += cnt
        //sell
        } else if (s > 0 && a[i] > a[i+1]){
            m += s * a[i]
            s = 0
        }
    }
    m += s * a[last]
    console.log(m)
}
Main()


Measured memory_bytes: 29640
#include <iostream>
#define NMAX 100005
using namespace std;
int n,a[NMAX],i,d[NMAX],k,j;
int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        d[i]=1e9;
    }
    d[1]=0;
    for(i=2;i<=n;i++)
    {
        for(j=i-1;j>=max(1,i-k);j--)
            d[i]=min(d[i],d[j]+abs(a[i]-a[j]));
    }
    cout<<d[n];
    return 0;
}


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

int main() {
	int t;
	cin>>t;
	while(t--) {
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		if(d>c && b<a)
			cout<<-1<<"\n";
		else if(a<=b) {
			cout<<b<<"\n";
		}
		else {

			
			
			
				ll rem = a - b;
				//time = b;
				ll pp = (rem)%(c-d);
				ll pro = 0;
				if(pp != 0) {
					pro = (rem/(c-d)) + 1;
				}
				else {
					pro = rem/(c-d);
				}
				ll ans = b + pro*c;
				cout<<ans<<"\n";
			

		}
	}
	return 0;
}*/

/*#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double a1 = (h/6)*(3.14159265358979323846264338);
	double a2 = (m/30)*(3.14159265358979323846264338);
	//cout<<a1*(180/3.14159265358979323846264338)<<" "<<a2*(180/3.14159265358979323846264338)<<" ";
	double diff;
	if(abs(a2 - a1) > 3.14159265358979323846264338)
		diff = 2*3.14159265358979323846264338 - abs(a2 - a1);
	else
		diff = abs(a2-a1);
	//cout<<(180/3.14159265358979323846264338)*diff<<" ";
	//cout<<setprecision(20)<<diff<<" ";
	//double prod = cos(diff);

	//double ans = pow(a,2) + pow(b,2) − 2*a*b*prod;
	cout<<setprecision(20)<<sqrt(a*a + b*b - 2*a*b*cos(diff));
	return 0;
}*


/*
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ll t;
	cin>>t;
	while(t--) {
		ll n;
		cin>>n;
		n = 2*n;
		//cout<<M_PI<<" ";

		double ans = 1/(tan(3.141592653589/n));
		
		cout<<setprecision(20)<<ans<<"\n";
	}
	return 0;
}*/

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

const int INF = 1000000000;
vector<vector<pair<int, int>>> adj;
vector<int> d;
vector<int> p;
void dijkstra(int s) {
    int n = adj.size();
    d.assign(n, INF);
    p.assign(n, -1);
    vector<bool> vis(n+1,false);

    d[s] = 0;
    using pii = pair<int, int>;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push({0, s});
    while (!q.empty()) {
        int v = q.top().second;
        int d_v = q.top().first;
        vis[v] = true;
        q.pop();
        if (d_v != d[v])
            continue;

        for (auto edge : adj[v]) {
            int to = edge.first;
            int len = edge.second;

            if (d[v] + len < d[to] && !vis[to]) {
                d[to] = d[v] + len;
                p[to] = v;
                q.push({d[to], to});
            }
        }
    }
    int check = 0;
    for(int i=2; i<n; i++) {
    	if(d[i] == INF) {
    		cout<<"No";
    		check = 1;
    		break;
    	}
    }
    
    if(check == 0) {
    	cout<<"Yes"<<"\n";
    	for(int i=2; i<n; i++) {
    		cout<<p[i]<<"\n";
    	}
    }
	
}

int main() {
	int n,m;
	cin>>n>>m;
	adj.resize(n+1);
	for(int i=0; i<m; i++) {
		int u,v;
		cin>>u>>v;
		adj[u].push_back(make_pair(v,1));
		adj[v].push_back(make_pair(u,1));
	}
	dijkstra(1);
	return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;

  int n,m;
  n=s.size(), m=t.size();
  vector<vector<int>> dp(n+1,vector<int>(m+1));

  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      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 ans = "";
  int i = n, j = m;
  while(i>0 && j>0){
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else {
      ans = s[i-1] + ans;
      i--;
      j--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mod 1000000007


int main() {
flash;

string s; cin>>s;
string a="", b="";
int flag=0;

int q; cin>>q;
while(q--){
    
    int t,f; cin>>t;
    string c;
    
    if( t==1 ){
        //reverse(s.begin(),s.end());
        flag = (flag+1)%2;
    }
    else if( t==2 ){
        
        cin>>f>>c;
        string s1;
        
        if( flag==0 ){
            if(f==1){ a = c + a; }
            else if(f==2){ b = b + c; }
        }
        else{
            if(f==2){ a = c + a; }
            else if(f==1){ b = b + c; }
        }
    }
    //cout<<s<<endl;
}

if( flag==0 ){ s = a+s+b; }
else{
    
    reverse(a.begin(),a.end()) ;
    reverse(s.begin(),s.end()) ;
    reverse(b.begin(),b.end()) ;
    
    s = b+s+a;
}


cout<<s;

	return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N; cin>>N;
	vector<ll>A(N);
	rep(i,N)cin>>A[i];
	sort(all(A));
	vector<ll> B;
	B.push_back(A[N-1]);
	rep(i,N-1){
		B.push_back(A[i]);
		B.push_back(A[i]);
	}
	sort(all(B), greater<ll>());
	ll ans = 0;
	for(ll i = 0; i<N-1; ++i){ans += B[i];}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
#define x first
#define y second
set <pair <int, int> > s[10];
map <pair <int, int>, int> m;
ll h, w;
int n;
pair <int, int> p;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(h);
    read(w);
    read(n);
    FOR(i, 1, n){
        read(p.x);
        read(p.y);
        pair <int, int> q;
        FOR(cx, -1, 1){
            q.x=p.x+cx;
            if(q.x<2||q.x>=h) continue;
            FOR(cy, -1, 1){
                q.y=p.y+cy;
                if(q.y<2||q.y>=w) continue;
                if(m.find(q)==m.end()) m[q]=0;
                int d=m[q];
                s[d].erase(q);
                d++;
                s[d].insert(q);
                m[q]=d;
            }
        }
    }
    ll ans=(h-2)*(w-2);
    DFOR(i, 9, 1) ans-=s[i].size();
    writeln(ans);
    FOR(i, 1, 9) writeln(s[i].size());
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list()

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    l.append(str(input()))

for i in range(n):
    if l[i] == "AC":
        ac += 1
    elif l[i] == "WA":
        wa += 1
    elif l[i] == "TLE":
        tle += 1
    elif l[i] == "RE":
        re += 1

print ("AC x ",ac)
print ("WA x ",wa)
print ("TLE x ",tle)
print ("RE x ",re)


Measured memory_bytes: 16180
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    vi v(N, 0);
    REP(i, N-1) {
        int a;
        cin >> a;
        v[a-1] ++;
    }

    for (int n: v) {
        cout << n << endl;
    }


    return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    if ((a < c && c < b) || (a > c && c > b)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N, M;
  cin >> N >> M;

  vector<P> lst;
  for (int i = 0; i < M; i++) {
    P tmp;
    cin >> tmp.second >> tmp.first;
    lst.emplace_back(tmp);
  }
  sort(lst.begin(), lst.end());

  ll ans = 1;
  ll cur = lst[0].first;
  for (int i = 1; i < M; i++) {
    if(lst[i].second >= cur){
      ans++;
      cur = lst[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int> w(n);
	rep(i,n) cin>>w[i];
	int min=2e8,v,s1,s2;
	for(int t=0;t<n;t++){
		s1=0,s2=0;
		for(int i=0;i<n;i++){
			if(i<=t) s1+=w[i];
			else s2+=w[i];
		}
		if(s1<s2) v=s2-s1;
		else v=s1-s2;
		if(min>v) min=v;
	}
	cout<<min<<endl;

	return 0;
}

Measured memory_bytes: 256