akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

const int N = 2e5 + 5, MOD = 998244353, INF = 1e9 + 5;

int add(int x, int y) { return (((x + MOD) % MOD) + ((y + MOD) % MOD)) % MOD; }

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n, m;
    cin >> n >> m;
    vii segments;
    while (m--) {
        int l, r;
        cin >> l >> r;
        segments.eb(l, r);
    }
    vi dp(n + 2, 0), delta(n + 2, 0);
    dp[1] = 1;
    for (int i = 1; i <= n; i++) {
        delta[i] = add(delta[i], delta[i - 1]);
        dp[i] = add(dp[i], delta[i]);
        for (const auto &[l, r]: segments) {
            if (i + l > n) continue;
            int x = min(i + l, n), y = min(i + r, n);
            delta[x] = add(delta[x], dp[i]);
            delta[y + 1] = add(delta[y + 1], -dp[i]);
        }
    }
    cout << dp[n];
}


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

int main(){
  int n;
  cin >> n;
  vector<long long> h;
  for(int i=0;i<n;i++){
    long long H;
    cin >> H;
    h.push_back(H);
  }
  int flag = 1;
  int ce = h[0]-1;
  for(int i=0;i<n-1;i++){
    if (h[i+1]-1<ce){
      if(h[i+1]<ce){
        flag=0;
      }else{
        ce = h[i+1];
      }
    }else{
      ce = h[i+1]-1;
    }
    
  }
  if (flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int n, m;

signed main () {
	scanf("%d %d", &n, &m);
	vector < pair < int, int > > ans;
	if (n % 2) {
		for (int a = 1, b = n; a < b; a++, b--) 
			ans.push_back(make_pair(a, b));
	} 
	else {
		for (int a = 1, b = n / 2; a < b; a++, b--) 
            ans.push_back(make_pair(a, b));
		for (int a = n / 2 + 1, b = n - 1; a < b; a++, b--) 
			ans.push_back(make_pair(a, b));
	}
	for (int i = 0; i < m; ++i)
		printf("%d %d\n", ans[i].first, ans[i].second);
}


Measured memory_bytes: 4312
/*  ---------------  Copyrighted With ciphereck -----------------*/

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

/* ----------------------------- START of Template ---------------*/
#pragma GCC optimize ("-ffloat-store")  // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop") // to pop argument of function as soon as it returns
#define ll long long
#define pb push_back
#define fs first
#define se second
#define rd(x) scanf("%lld", &x)
#define all(v) v.begin(),v.end()
#define pr(i, j) pair< i , j >
#define mp(i, j) map< i , j >
#define rep(i, a, b) for(ll i=a; i<b; ++i)
#define repe(i, a, b) for(ll i=a; i<=b; ++i)
#define jrep(i, a, b, c) for(ll i=a; i<b; i+=c)
#define jrepe(i, a, b, c) for(ll i=a;i<=b; i+=c)
#define inp(i, n, a) for(ll i=0;i<n;i++) cin>>a[i];
ll dx[4]={-1, 0, 0, +1};
ll dy[4]={0, -1, +1, 0};
const ll LINF = 1e18;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll strtoll(string s) { stringstream str(s); ll number=0; str>>number; return number; }

string lltostr(ll n){ stringstream ss; ss<<n; return ss.str(); }


ll llsqrt(ll x){ if(x==0 || x==1) return x; ll start=1, end=x/2, ans; while(start<=end) { ll mid=(start+end)/2; if(mid*mid==x) return mid;
        else if(mid <= x/mid) ans=mid,start=mid+1; else end=mid-1; }  return ans; }

vector<ll> spf;
void sieve(ll size) { spf.resize(size+1); for(ll i=1;i<=size; ++i) spf[i]=i; for(ll i=4;i<=size; i+=2) spf[i]=2;
    for(ll i=3;i*i<=size; ++i) { if(spf[i]==i) { for(ll j=i*i; j<=size; j+=i) if(spf[j]==j) spf[j]=i; } } }

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}


ll modInverse(ll a, ll m) { return power(a, m-2, m); }

void fastscan(ll &number){ bool negative = false; register ll c; number = 0; c = getchar(); if (c=='-') { negative = true; c = getchar(); }
    for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; if (negative)  number *= -1;   }


/* ----------------------          End Of Template --------------------------------*/



int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
   clock_t tStart = clock();

  /*---------------------------------------------------------------------------------------------------*/

   ll a,b;
   cin>>a>>b;
   ll n=b-a-1;
   cout<<n*(n+1)/2-a;

  /*---------------------------------------------------------------------------------------------------*/

   // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


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

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=c))
        printf("Yes");
    else
        printf("No");
    return 0;
}

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

#define lp(i,n) for(int i=0;i<n;i++)
int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  a+=b*5+c*10+d*50+e*100+f*500;
  if(a>=1000) cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}



Measured memory_bytes: 3092
/*--ILRS-- sr4saurabh  */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846
//--------------------------------------------



//--------------------------------------------





//============================================
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

	//THE WATER WAS DEEP, I DROWNED AND THEN CAME FLOATING UP,DEAD!!



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

       	 ll suff[n+1]; suff[n] = 0;
       	 for(int j = n-1; j >=0 ; j--)
       	 	suff[j] = (suff[j+1]  +  arr[j])%mod;

       	 ll ans =0;
       	 for(int i = 0; i < n-1 ; i++)
       	 	ans = (ans + (suff[i+1]*arr[i])%mod)%mod;

       	 cout<<ans;






return 0;
}

Measured memory_bytes: 6764
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


K = I()
ans = ''
for i in range(K):
    ans += 'ACL'
print(ans)


Measured memory_bytes: 61960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

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

    if (a == b && b == c && c == a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

int N,H,W;
char Screen[51][51];
string ans;
set<char> Set;
set<char>::iterator it;

void Check()
{
  while(1){
    int sum=0;
    for(it=Set.begin();it!=Set.end();it++){
      char t=*it;
      int a=H,b=0,c=W,d=0;
      for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  if(Screen[i][j]==t){
	    a=min(a,i);
	    b=max(b,i);
	    c=min(c,j);
	    d=max(d,j);
	  }
	}
      }
      if(a==H && b==0 && c==W && d==0)continue;
      bool flag=true;
      for(int i=a;i<=b;i++){
	for(int j=c;j<=d;j++){
	  if(Screen[i][j]!=t && Screen[i][j]!='#')flag=false;
	}
      }
      if(!flag)continue;
      sum++;
      for(int i=a;i<=b;i++)for(int j=c;j<=d;j++)Screen[i][j]='#';
    }
    if(sum==0)return;
  }
}

int main()
{
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>H>>W;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>Screen[i][j];
	if(Screen[i][j]!='.')Set.insert(Screen[i][j]);
      }
    }
    ans="SAFE";
    Check();
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(Screen[i][j]!='.' && Screen[i][j]!='#')ans="SUSPICIOUS";
      }
    }						    
    cout<<ans<<endl;
  }
  return 0;
}

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

int main()
{
    int N;
    int a[100];
    int sum[2];
    sum[0] = 0;
    sum[1] = 0;

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort (a, a + N);
    for (int i = 0; i < N; i++){
        if (i % 2 != 0){
            sum[0] += a[i];
        }
        else {
            sum[1] += a[i];
        }
    }
    if (sum[0] > sum[1]){
        cout << sum[0] - sum[1] << endl;
        return (0);
    }
    else if(sum[0] < sum[1]){
        cout << sum[1] - sum[0] << endl;
        return (0);
    }
    else {
        cout << 0 << endl;
        return (0);
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h[ohara], w, x, y, sum, k, q;

bool check(ll kai) {
  ll now[n + 10] = {}, ret = 0;
  rep(i, n) now[i] = h[i];
  rep(i, n) {
    ld hika1, hika2;
    hika1 = (ld)now[i] / (ld)b;
    hika2 = (ld)kai;
    if (hika1 < hika2) {
      now[i] = 0;
    } else {
      now[i] -= b * kai;
    }
  }
  ll hera = a - b;
  rep(i, n) {
    if (now[i] <= 0) continue;
    ll cost = (now[i] % hera == 0 ? now[i] / hera : now[i] / hera + 1);
    ret += cost;
  }
  if (ret <= kai)
    return true;
  else
    return false;
}

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

  cin >> n >> a >> b;
  rep(i, n) cin >> h[i];
  ll le = 0, ri = LINF, mid;
  while (ri - le > 1) {
    mid = (le + ri) / 2;
    if (check(mid))
      ri = mid;
    else
      le = mid;
  }
  rrep(i, max(0LL, le - 6), min(ri + 7, LINF)) {
    if (check(i)) {
      Cout(i);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a[1011000];
int b[1010100];
int sum[1010100];

struct Tr{
    int tr[400010];
    void clear(){for (int i=1;i<=400010;i++) tr[i] = 0;}
    void add(int x,int v){
	    for (int i=x;i<=400010;i+=(i&(-i))) tr[i] += v;
	}
	int ask(int x){
	    int Ans=0;
	    for (int i=x;i>=1;i-=(i&(-i))) Ans += tr[i];
	    return Ans;
	}
};

Tr tr; 
bool check(int x){
    for (int i=1;i<=n;i++)
      if (a[i]>=x) b[i]=1;else b[i]=-1;
//    if (x == 29) {cout<<"OK:"<<' ';for (int i=1;i<=n;i++) cout<<b[i]<<' ';cout<<endl;}
    for (int i=0;i<=n+1;i++) sum[i] = 0;
    for (int i=1;i<=n;i++) sum[i] = sum[i-1]+b[i];
//    for (int i=1;i<=n;i++) cout<<sum[i]<<' ';
//    cout<<endl;
    int ans=0;
	for (int i=1;i<=n;i++){
	    ans += tr.ask(sum[i]+1+n);
	    tr.add(sum[i]+1+n,1);
	    ans += sum[i] >= 0;
	}
	tr.clear();
//	cout<<ans<<endl;
	return ans>=(n*(n+1)/2+1)/2;
}

signed main(){
    scanf("%lld",&n);
    for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
    int l = 0,r = 2e9+100;
    while (l+1<r){
	    int mid = l+r>>1;
	    if (check(mid)) l = mid;else r = mid;
//	    cout<<l<<' '<<r<<endl;
	}
	printf("%lld",check(l)?l:r);
	return 0;
}

Measured memory_bytes: 8448
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define sz(x)                       (ll) x.size()
#define PB(x)                       push_back(x)
#define bs(a, x)                   binary_search(a , a + sizeof(a) / sizeof(a[0] , x)
#define ts(x)                       to_string(x)
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define bsv(a, x)                  binary_search(all(a), x)
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ld PI = 4 * atan((ld) 1);
ll dp[MAXN][3] , A[MAXN] , B[MAXN] , C[MAXN];
int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    for (ll i = 0 ; i < n ; i++)
        cin >> A[i] >> B[i] >> C[i];
    dp[0][0] = A[0];
    dp[0][1] = B[0];
    dp[0][2] = C[0];
    for (ll i = 1; i < n ; i++)
    {
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + A[i];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + B[i];
        dp[i][2] = max(dp[i - 1][0] , dp[i - 1][1]) + C[i];
    }
    cout << max(dp[n - 1][0] , max(dp[n - 1][1] , dp[n - 1][2])) << endl;
    return 0;
}



Measured memory_bytes: 7680
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
#C = [0] * len(A)
        
count = 0
#next = 0
for i in range(N):
    if B[i] <= A[i]:
        count += B[i]
    else:
        count += A[i]
        count += min(B[i]-A[i], A[i+1])
        A[i+1] = max(A[i+1]-(B[i]-A[i]), 0)
        #C[i+1] = B[i]-A[i]
        
    #print(count)
    #print(A)
    #print(B)
    #print(C)

print(count)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    deque<int> b;
    if (n%2 == 0) {
        rep(i,n) {
            if (i%2 == 0) b.push_back(a.at(i));
            else b.push_front(a.at(i));
        }
    }
    else {
        rep(i,n) {
            if (i%2 == 0) b.push_front(a.at(i));
            else b.push_back(a.at(i));
        }
    }
    while (!b.empty()) {
        cout << b.front();
        b.pop_front();
        if (!b.empty()) cout << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int 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=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll dp[21][50001];
ll c[21];
ll n,m;

int main() {

	cin>>n>>m;

	rep(i,m){
		cin>>c[i];
	}
	rep(i,21){
		rep(j,50001){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;

	rep(i,m){
		rep(j,n+1){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j>=c[i])dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-c[i]]+1);
		}
	}
	cout<<dp[m][n]<<endl;
	return 0;
}



Measured memory_bytes: 11320
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m, v, p := nextInt4()
	a := nextInts(n)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	sa := make([]int, n+1)
	for i := 1; i <= n; i++ {
		sa[i] = sa[i-1] + a[i-1]
	}

	possible := func(x int) bool {
		if x < p {
			return true
		}
		if a[x]+m < a[p-1] {
			return false
		}
		// 問題x, 上位p-1問, 問題x+1以降, 問題i:p<=i<x
		can := m + m*(p-1) + m*(n-x-1)
		if p-1 < x {
			can += (a[x]+m)*(x-p+1) - (sa[x] - sa[p-1])
		}
		return can >= m*v
	}

	ok, ng := 0, n
	for ok < ng-1 {
		mid := (ok + ng) / 2
		if possible(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	puts(ok + 1)
}


Measured memory_bytes: 5140
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  int a[2001]={0};
  int n,m;
  while(1){
    cin >> n >> m;
    if(n==0&&m==0) break;
    for(int i=1;i<=n;i++){
      cin >> a[i];
    }
    int koma=1;
    int b,flg=0;
    for(int i=1;i<=m;i++){
      cin >> b;
      if(flg==0){
	koma+=b;
	if(koma>=n){
	  printf("%d\n",i);
	  flg=1;
	}
	koma+=a[koma];
	if(koma>=n && flg==0){
	  printf("%d\n",i);
	  flg=1;
	}
      }
    }
  }
}

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

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

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

	priority_queue<int,vector<int>,greater<int> > que;
	REP(i,n){
		int v;
		scanf("%d",&v);
		que.push(v);
	}

	double compare = (double)que.top();
	que.pop();

	while(!que.empty()){
		compare = (compare + (double)que.top())/2.0;
		que.pop();
	}

	printf("%.8f",compare);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=3e5+10;
const int N=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,a[maxn];
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,3*n)scanf("%d",&a[i]);
    ll ret=0;
    int cnt=0;
    sort(a+1,a+3*n+1);
    for(i=3*n-1;;i-=2)
    {
        ret+=a[i];
        if(++cnt==n)break;
    }
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 1408
# coding:utf-8
k, n = map(int, input().split())
a = list(map(int, input().split()))
distance = []
for i in range(len(a)):
  if i == len(a) - 1:
    distance.append(k+a[0] - a[i])
  else:
  	distance.append(a[i+1] - a[i])
distance.sort()
print(sum(distance[:-1]))


Measured memory_bytes: 26060
// {{{ Template for Competitive Programming
// -std=c++14 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

using vint = vector<int>;
using pint = pair<int, int>;

#define int long long
#define FOR(i, a, b)  for (int(i) = (a); (i) < (b); ++(i))
#define CFOR(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
#define rep(i, n) FOR((i), 0, (n))
#define crep(i, n) CFOR((i), 0, (n))
#define rrep(i, n) RFOR((i), (n), 0)
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(ALL(x), 0)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline void debug(T a) { cout << "[ "; for (const auto e : a) { cout << e << ", "; } cout << "]" << endl; }

int ceil(int a, int b) { return (a + (b - 1)) / b; }

const int INF = 1'010'000'000'000'000'017LL;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// }}}

signed main() {
	int n;
	cin >> n;
	cout << pow(n, 3) << endl;
}



Measured memory_bytes: 256
while 1:
    zero=0
    number=1
    n=int(input())
    if n==0:break
    for i in range(1,n+1):
        number*=i
        while len(str(number))>7:number=int(str(number)[1:])
        while number%10==0:
            zero+=1
            number=int(number/10)
    print(zero)


Measured memory_bytes: 5588
#include<stdio.h>


 long long calc(long long a) {
	 if (a % 4 == 0)return a;
	 if (a % 4 == 1)return 1;
	 if (a % 4 == 2)return a + 1;
	 if (a % 4 == 3)return 0;
	 return 0;
}
int main() {

	long long a, b;

	scanf("%lld%lld", &a, &b);
	printf("%lld", calc(a-1) ^ calc(b));
	


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int dp[45][450][450];

int main(void){
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<tuple<int, int, int>> v;
  REP(i, n){
    int a, b, c;
    cin >> a >> b >> c;
    v.emplace_back(a, b, c);
  }
  REP(i, n+1) REP(j, 450) REP(k, 450) dp[i][j][k] = INF;
  dp[0][0][0] = 0;
  REP(i, n) REP(j, 400) REP(k, 400){
    int a, b, c;
    tie(a, b, c) = v[i];
    chmin(dp[i+1][j][k], dp[i][j][k]);
    chmin(dp[i+1][j+a][k+b], dp[i][j][k]+c);
  }
  int ans = INF;
  for(ll i = 1; i*ma <= 400 && i*mb <= 400; i++){
    chmin(ans, dp[n][i*ma][i*mb]);
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define all(x)              (x).begin(), (x).end()
#define inf                 1e18

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod = 998244353;

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

inline ll inv(ll a) { return bp(a, mod - 2); }

void solve() {
	ll n, s;
	cin >> n >> s;
	vector <ll> v(n);
	for (auto &i : v) cin >> i;

	vector <ll> pw(n + 1); pw[0] = 1;
	for (int i = 1; i <= n; ++i) pw[i] = (2 * pw[i - 1]) % mod;

	vector <ll> f(s + 100);

	ll res = 0; f[0] = pw[n];
	for (int i = 0; i < n; ++i) {
		vector <ll> dp(s + 100); dp = f;
		for (int sum = 0; sum + v[i] <= s; ++sum) {
			dp[sum + v[i]] += (f[sum] * inv(2));
			dp[sum + v[i]] %= mod;
		}
		swap(f, dp);
	}
	cout << f[s];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	ifstream cin("input.txt");
//	ofstream cout("output.txt");
	int q = 1; // cin >> q;
	while (q--) {
		solve();
	}
}

Measured memory_bytes: 3700
import numpy as np
n,m = map(int, input().split())
a = [False]*n
b = [0]*n
for i in range(m):
  p,s = map(str,input().split())
  p = int(p)-1
  if s == "AC":
    a[p] = True
  else:
    if a[p] == False:
      b[p]=b[p]+1
print(np.array(a).sum(),np.array(b)[np.array(a)].sum())

Measured memory_bytes: 21296
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i=0, a; i<n; i++) {
        cin >> a;
        if (a == cnt+1) cnt++;
    }
    cout << (cnt > 0 ? n - cnt : -1) << '\n';
    return 0;
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
money=[]

for i in range(2**n):
    ans=[0]*m
    res=0
    for j in range(n):
        if not (i & (1<<j)):
            continue
        s=l[j]
        c=s[0]
        for k in range(m):
            ans[k]+=s[k+1]
        res+=c
    for i in range(m):
        if ans[i]<x:
            break
    else:
        money.append(res)
if money:
  print(min(money))
else:
  print(-1)

Measured memory_bytes: 68816
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> g[100010];
int flag[100010];

int fin(int tmp,int dis){
    flag[tmp]=dis;
    for (int i=0;i<g[tmp].size();++i)
    if (!flag[g[tmp][i]])
        fin(g[tmp][i],dis+1);
}

int fin_u(int tmp,int dis){

    if (flag[tmp]== dis) return tmp;
   // printf("%d %d %d\n",tmp,flag[tmp],dis);

    for (int i=0;i<g[tmp].size();++i)
    if (flag[g[tmp][i]] == flag[tmp]-1 )
        return fin_u( g[tmp][i],dis );
}

int fin_len(int tmp){

    int now_len=0;
    for (int i=0;i<g[tmp].size();++i)
    if (flag[g[tmp][i]] ==flag[tmp]+1 ){
        int tmp_len=fin_len( g[tmp][i] )+1;
        if (tmp_len>now_len)
            now_len=tmp_len;
    }
    return now_len;

}

int main()
{
    int n,u,v;
    scanf("%d%d%d",&n,&u,&v);
    for (int i=1;i<n;++i){
        int t1,t2;scanf("%d%d",&t1,&t2);
        g[t1].push_back(t2);
        g[t2].push_back(t1);
    }
    for (int i=1;i<=n;++i) flag[i]=0;
    fin(v,1);



    int ans=0;
    int dis_u=flag[u];
    int tmp_u_dis=0,tmp_v_dis=0;
    if (dis_u%2){
        int tmp=(dis_u+1)/2;
        tmp_u_dis = tmp+1;
        tmp_v_dis = tmp-1;
        ans+=tmp_v_dis-1;
    }else{
        tmp_u_dis = dis_u/2+1;
        tmp_v_dis = dis_u/2;
        ans+=tmp_v_dis-1;
    }
        //for (int i=1;i<=n;++i) printf("%d ",flag[i]);printf("\n");

    v= fin_u(u,tmp_v_dis); u= fin_u(u,tmp_u_dis);

                //for (int i=1;i<=n;++i) printf("%d ",flag[i]);printf("\n");

    int len=fin_len(u);
    ans+=len;
    if (dis_u%2){
        ans+=1;
    }

    //for (int i=1;i<=n;++i) printf("%d ",flag[i]);printf("\n");

    //printf("%d %d %d %d %d %d\n",len,dis_u,u,v,tmp_u_dis,tmp_v_dis);

    printf("%d\n",ans);

}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a < b) {
    cout << 2 * b - 1 << endl;
  } else if (a == b) {
    cout << 2 * a << endl;
  } else {
    cout << 2 * a - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
k,s=map(int,input().split())
ans=0
for x in range(k+1):
  for y in range(x,k+1):
    z=s-(x+y)
    if z>k or z<y:
      continue
    if x==y and y==z:
      ans+=1
    elif x==y or y==z or x==z:
      ans+=3
    else:
      ans+=6
print(ans)


Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int X[n],Y[n];
    REP(i,n){
        cin >> X[i] >> Y[i];
    }
    auto g = [&](double x, double y) {
        double res = 0;
        REP(i,n){
            res = max(res, sqrt((X[i] - x) * (X[i] - x) + (Y[i] - y) * (Y[i] - y)));
        }
        return res;
    };
    auto f = [&](double x) {
        double l = 0.0, r = 1000.0;
        for(int i = 0; i < 100; i++){
            double ml = (2.0 * l + r) / 3.0, mr = (l + 2.0 * r) / 3.0;
            if(g(x, ml) < g(x, mr)) r = mr;
            else l = ml;
        }
        double y = (l + r) / 2;
        double res = 0;
        REP(i,n){
            res = max(res, sqrt((X[i] - x) * (X[i] - x) + (Y[i] - y) * (Y[i] - y)));
        }
        return res;
    };
    double l = 0.0, r = 1000.0;
    for(int i = 0; i < 100; i++){
        double ml = (2.0 * l + r) / 3.0, mr = (l + 2.0 * r) / 3.0;
        if(f(ml) < f(mr)) r = mr;
        else l = ml;
    }
    printf("%.10lf\n", f((l + r) / 2));
    return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = str(input()).split(' ')

p1 = [0]*(max([int(i) for i in lst])+1)
p2 = [0]*(max([int(i) for i in lst])+1)
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1)+sorted(p2)[-2] >= sorted(p1)[-2]+max(p2):
		pp2 = p2.index(sorted(p2)[-2])
	else:
		pp1 = p1.index(sorted(p1)[-2])

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1

print(cnt1 + cnt2)

Measured memory_bytes: 14612
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
    std::cin >> N;
    int64_t M = 0, A = 0, R = 0, C = 0, H = 0;
    for (int64_t i = 0; i < N; i++)
    {
        std::string s;
        std::cin >> s;
        if (s[0] == 'M') M++;
        if (s[0] == 'A') A++;
        if (s[0] == 'R') R++;
        if (s[0] == 'C') C++;
        if (s[0] == 'H') H++;
    }

    // 5C3 = 10
    int64_t ans = 0;
    ans += M * A * R;
    ans += M * A * C;
    ans += M * A * H;
    ans += M * R * C;
    ans += M * R * H;
    ans += M * C * H;
    ans += A * R * C;
    ans += A * R * H;
    ans += A * C * H;
    ans += R * C * H;

    std::cout << ans << std::endl;
}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forr(i,a,b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const ll MX = 600005;
const ll inf = 2e18;
#define ptr nodo*
#define tam 601000
const ll mod=1e9+7;
ll fact[tam];
ll pot(ll base,ll exp)
{
    ll res=1;
    base%=mod;
    while(exp)
    {
        if (exp&1)
            res*=base,res%=mod;
        base*=base,base%=mod;
        exp/=2;
        base%=mod;
    }
    return res%mod;
}
ll C(ll n,ll m)
{
    if (m>n)return 0;
    return (((fact[n]*pot(fact[m],mod-2))%mod)*pot(fact[n-m],mod-2))%mod;
}
int main () 
{
    //cout<<(22583772*(pot(5005,mod-2)))%mod<<endl;
    ios_base::sync_with_stdio(0); cin.tie(0);
    fact[0]=1;
    forr(i,1,tam)
    fact[i]=(fact[i-1]*i)%mod;
    ll n,k;
    cin>>n>>k;
    if (k>=n-1)
    {
        cout<<C(n+n-1,n)<<endl;
    }
    else
    {
        ll tot=0;
        forr(kp,0,k+1)
        {
            tot+=(C(n-1,kp)*C(n,kp))%mod;
            tot%=mod;
        }
        cout<<tot<<endl;
    }
}


Measured memory_bytes: 4992
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;


int main()
{
	ll i, j, k, l, m, flag, N, M,K;
	cin >> N;
	vector<ll>A(N);
	ll temp;
	ll cc;
	cc = 0;
	ll ans;
	for (i = 0; i<N; i++) {
		cin >> A[i];

	}
	cc = 0;
	ans = 0;
	sort(A.begin(), A.end());
	map<ll,int> T;
	i = 0;
	flag = 0;
	while (i < N) {
		temp = A[i];
		cc = 0;
		flag = 0;
		while (A[i]==temp) {
			i++;
			cc++;
			if (i >= N) {
				break;
			}
		}
		if (i >= N)
			break;
			T.insert(make_pair(A[i-1], cc));
		
	}
	T.insert(make_pair(A[i - 1], cc));
	ll pos;
	ll idx,idy;
	for (i = N - 1; i >= 1; i--) {
		temp = A[i];
		cc = 0;
		while (A[i] > 1) {
			A[i] /= 2;
			cc++;
		}
A[i]=temp;
		if (binary_search(A.begin(),A.begin()+i,(ll)pow(2,cc+1)-temp)) {
if((ll)pow(2,cc+1)-temp!=temp){
			if (T[(ll)pow(2, cc + 1) - temp] != 0&&T[temp]!=0) {
				ans++;
				T[(ll)pow(2, cc + 1) - temp]--;
T[temp]--;

}
}
else{
		if (T[temp]>=2) {
				ans++;
T[temp]-=2;

}
}
		}
		

	}
	output(ans);




	return 0;
}



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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  if(A.back()==B.at(0) && B.back()==C.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

return 0;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

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

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int cost[100010];
int main() {
    int N,K; cin >> N >> K;
    vector<int>h(N);
    rep(i,N) cin >> h[i];
    Fill(cost, INFint);

    cost[0]=0;
    for(int i=1; i<=K; i++){
        cost[i]=abs(h[i]-h[0]);
    }

    for(int i=K+1; i<N; i++){
        for(int j=1; j<=K; j++) {
            cost[i] = min(cost[i], abs(h[i]-h[i-j])+cost[i-j]);
        }
    }

    cout << cost[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main()
{
    while (true) {
        int a, b;
        char op;
        cin >> a >> op >> b;

        if (op == '?')
            break;

        if (op == '+') {
            cout << a + b << endl;
        } else if (op == '-') {
            cout << a - b << endl;
        } else if (op == '*') {
            cout << a * b << endl;
        } else {
            cout << a / b << endl;
        }
    }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h> 
#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 REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

long long p[1000] = {1};
long long a[1000] = {1};

int main() {
	string s; CI s;
	int res = 0;
	int ans = 99999999;

	REP(i, s.size() - 2) {
		string sstr = s.substr(i, 3);
		res = stoi(sstr);
		ans = min(ans, abs(res - 753));
	}

	CO ans EN;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int  dp[3000+1][3000+1];

string getLCS(string& s,string& t,int len){

    string lcs;
    int i=0,j=0;
    while(len>0){
        if(s[i]==t[j]){
            lcs.push_back(s[i]);
            i++;
            j++;
            len--;
        }
        else{
            if(dp[i][j+1]>dp[i+1][j]){
                j++;
            }
            else{
                i++;
            }
        }
    }
    return lcs;
}

int lenLCS(string& s,string &t,int i,int j){

    if(i>=s.length() || j>=t.length()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(s[i]==t[j]){
        return dp[i][j]= 1+lenLCS(s,t,i+1,j+1);
    }
    else{
        return dp[i][j]= max(lenLCS(s,t,i,j+1),lenLCS(s,t,i+1,j));
    }
}

string solve(string s,string t){
    memset(dp,-1,sizeof dp);
    int l=lenLCS(s,t,0,0);
    return getLCS(s,t,l);
}

int main(){

    string s,t;
    cin>>s>>t;
    cout<<solve(s,t)<<endl;
    return 0;
}

Measured memory_bytes: 39248
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    char s;
    cin>>s;
    s+=1;
    cout<< s<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define LIMIT 100
#define NIL -1

#define MAX(a,b) (a>b? a:b)

typedef struct{int parent, left, right; }Node;

Node T[LIMIT];
int depth[LIMIT],degree[LIMIT],height[LIMIT];

int getHeight(int x,int h){
	if(T[x].left==NIL && T[x].right==NIL)return h;
	else if(x==-1)return h-1;
	
	int ret=MAX(getHeight(T[x].left,h+1),getHeight(T[x].right,h+1));

	return ret;
}
int getDepth(int x, int d){
	if(T[x].parent==NIL)return d;

	return getDepth(T[x].parent,d+1);
}

void Print(int x){
	int i,c;
	int p=T[x].parent;
	int sibling=T[p].right;
	if(x==sibling)sibling=(T[p]).left;

	if(p==NIL)sibling=-1;
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",x,p,sibling,degree[x],depth[x], height[x]);
	if(T[x].parent == NIL)printf("root");
	else if(T[x].left == NIL&&T[x].right==NIL)printf("leaf");
	else printf("internal node");

	printf("\n");
}


int main(){
	int i,j,n,id,l,r;	scanf("%d",&n);
	for(i=0;i<n;i++)T[i].parent=T[i].left=T[i].right=NIL;

	for(i=0;i<n;i++){
		scanf("%d%d%d",&id,&l,&r);
		T[l].parent=T[r].parent=id;

		if(l!=-1){
			T[id].left=l;
			degree[id]++;
		}
		if(r!=-1){
			T[id].right=r;
			degree[id]++;
		}
	}

	for(i=0;i<n;i++){
		height[i]=getHeight(i,0);	
		depth[i]=getDepth(i,0);
		Print(i);
	}


	return 0;
}



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

int main()
{
	string s,t,t1;
	long long k;
	cin >> s;
	cin >> k;
	int l = s.length();
	t = s;
	t1 = s;
	long long ans1 = 0,ans2 = 0,ans3 = 0;
	for(int i = 1; i < l; i++){
		if(t[i] == t[i - 1]){
			ans1++;
			t[i] = '0';
		}
	}
	if(s[0] != s[l - 1])
		ans2 = ans1;
	else{
		if(s[0] == t[l - 1]){
			s[0] = '0';
			ans2++;
		}
		for(int i = 1; i < l; i++){
			if(s[i] == s[i - 1]){
				ans2++;
				s[i] = '0';
			}
		}
	}
	if(t1[0] == s[l - 1]){
		t1[0] = '0';
		ans3++;
	}
	for(int i = 1; i < l; i++){
		if(t1[i] == t1[i - 1]){
			ans3++;
			t1[i] = '0';
		}
	}
	long long sum = ans1 + (ans3 + ans2) * ((k - 1) / 2);
	if(k % 2 == 0)
		sum += ans2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
char a[105][105],s;
int dir[4][2]={0,1,0,-1,-1,0,1,0},n,m;
void dfs(int x,int y)
{
	for(int i=0;i<4;i++)
	{
		int tx=x+dir[i][0];
		int ty=y+dir[i][1];
		if(tx<0||tx>=n||ty<0||ty>=m)
		{
			continue;
		 } 
		 if(a[tx][ty]==s)
		 {
		 	a[tx][ty]='0';
		 	dfs(tx,ty);
		 }
	}
}
int main()
{
	while(cin>>n>>m)
	{
		if(n==0&&m==0)
		{
			return 0;
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(a[i][j]!='0')
				{
					s=a[i][j];
					a[i][j]='0';
					dfs(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(H + 1, 0));
    rep(j, H + 1) {
        dp[0][j] = (j + A[0] - 1) / A[0] * B[0];
    }
    rep(i, N - 1) {
        rep(j, H + 1) {
            ll x = j - A[i + 1];
            if (x < 0) x = 0;
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][x] + B[i + 1]);
        }
    }
    cout << dp[N - 1][H] << endl;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vl a(n);
    REP(i, n) cin >> a[i];
    ll p = 1000;
    ll q = 0;
    bool up = false;
    if (a[0] < a[1]) {
        q += p / a[0];
        p -= (p / a[0]) * a[0];
        up = true;
    }
    // cout << 0 << ">> " << p << "/" << q << endl;
    REP1(i, n - 1) {
        if (up) {
            if (a[i] > a[i + 1]) {
                p += q * a[i];
                q = 0;
                up = false;
            }
        } else {
            if (a[i] < a[i + 1]) {
                q += p / a[i];
                p -= (p / a[i]) * a[i];
                up = true;
            }
        }
        // cout << i << ">> " << p << "/" << q << endl;
    }
    if (a[n - 2] <= a[n - 1]) p += q * a[n - 1];
    else p += q * a[n - 2];
    cout << p << endl;
}


Measured memory_bytes: 3648
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
using namespace std;

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()


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

    vector<int> A(N);
    FOR(i,0,N) cin>>A[i];


    cout<<A[0];
    FOR(i,1,N) cout<<" "<<A[i];


    FOR(i,1,N){
        RFOR(j,i,0){
            if(A[j] < A[j-1]) swap(A[j],A[j-1]);
        }
        cout<<"\n"<<A[0];
        FOR(i,1,N) cout<<" "<<A[i];
        
    }
    cout<<endl;
 
}


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

const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    combination nck(n);
    mint ans;
    for (int i = 0; i <= k; i++) {
        mint pat(m * modpow(m - 1, n - i - 1));
        pat *= nck(n - 1, i);
        ans += pat;
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 6320