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

using namespace std;

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define f(n) for(int i=0;i<n;++i)
#define f2(n) for(int j=0;j<n;++j)
#define f3(n) for(int k=0;k<n;++k)
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i) for(i=0;i<n;++i)
#define fa(x,y) for(auto x:y)

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template        
    

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if(a==2||b==2) cout<<"No";
    else cout<<"Yes";
    return 0;
}


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

void kihontensu(int bit,int &sum,int &cnt,int D,vector<int> &kihon,vector<int> &p,vector<int> &tensu){
    sum = 0;
    cnt = 0;
    rep(i,D){
//        cout << cnt << endl;
        if(bit & (1<<i)){
            sum += kihon.at(i);
            cnt += p.at(i);
        }else{
            rep(jj,p.at(i)-1){
                tensu.push_back(100*(i+1));
//                cout << tensu.at(tensu.size()-1);
            }
        }
    }
}

int main(){
    int D,G;
    cin >> D >> G;
    vector<int> p(D),c(D),kihon(D),tensu;
    rep(i,D){
        cin >> p.at(i) >> c.at(i);
        kihon.at(i) = p.at(i)*100*(i+1) + c.at(i);
 //       cout << kihon.at(i) << endl;
    }

    int sum,cnt,mn = 10000;
    for(int bit = 0; bit < (1<<D); bit++){
        kihontensu(bit,sum,cnt,D,kihon,p,tensu);
        for(int i=0; sum <G; i++){
            if( i>=tensu.size()){
                cnt = 10000;break;
            }
            sum += tensu.at(tensu.size()-1-i);
            cnt++;
//            cout << cnt <<endl;
        }
        mn = min(mn,cnt);
    }

    cout << mn << endl;
}   

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A, B, X;
    cin >> A >> B >> X;
    if(A % X == 0){
        cout << B / X - A / X + 1 << endl;
    }
    else{
        cout << B / X - A / X << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l1 = sc.nextInt();
		int l2 = sc.nextInt();
		int d = l2 - l1;
		int h = IntStream.rangeClosed(1, d).sum();
		System.out.println(h - l2);
	}
}

Measured memory_bytes: 26832
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll a; ll b; ll c;
    cin >> a >> b >> c;
    ll k; cin >> k;
    while(a - b >= 0){
        b *= 2;
        k--;
        if (k < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    while(b - c >= 0){
        c *= 2;
        k--;
        if (k < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

const int MAX = 3010 ;
long long arr[MAX] ;
long long dp[MAX][MAX][2] ;
int n ;

long long solve(int l , int r , int turn)
{
    if(l > r || r < l)
        return 0 ;
    long long &ret = dp[l][r][turn] ;
    if(ret != -1)
        return ret ;
    if(turn == 0)
    {
        long long choice1 = solve(l+1 , r , 1) + arr[l] ;
        long long choice2 = solve(l , r-1 , 1) + arr[r] ;
        ret = max(choice1 , choice2);
        return ret ;
    }
    else if(turn == 1)
    {
        long long choice1 = solve(l+1 , r , 0) - arr[l] ;
        long long choice2 = solve(l , r-1 , 0) - arr[r] ;
        ret = min(choice1 , choice2);
        return ret ;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp , -1 , sizeof(dp));
    cin>>n ;
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    return cout<<solve(0 , n-1 , 0)<<"\n" , 0 ;
}


Measured memory_bytes: 141952
import heapq

N,M =map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i]*=-1

heapq.heapify(A)
for i in range(M):
    a=heapq.heappop(A)
    heapq.heappush(A,int(a/2))

print(sum(A)*-1)

Measured memory_bytes: 72428
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if ((x in a)and(y in a))\
    or((x in b)and(y in b))\
    or((x in c)and(y in c)):
    print('Yes')
else:
    print('No')

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

int main() {
  double a,b = 0;
  cin >> a >> b ;
  if(fmod((a+b)/2.0,1) == 0){
    cout <<   (a+b)/2.0 - fmod((a+b)/2.0,1) << endl;
  }else{
    cout <<   (a+b)/2.0 - fmod((a+b)/2.0,1) +1 << endl;
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    s: String,
    _t: String,
    a: i32,
    b: i32,
    u: String,
  }
  let mut a = a;
  let mut b = b;
  if u == s {
    a -= 1;
  } else {
    b -= 1;
  }

  puts!("{} {}\n", a, b);
}


Measured memory_bytes: 4352
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

x, y = MI()
ans = 0

if abs(x) == abs(y):
    ans = int(x * y < 0)

elif abs(x) < abs(y):
    ans = abs(abs(y) - abs(x)) + int(x < 0) + int(y < 0)

else:
    ans = abs(abs(y) - abs(x)) + int(x * y <= 0) + int(x > 0 and y > 0) * 2
    if x < 0 and y == 0:
        ans -= 1

print(ans)

Measured memory_bytes: 61908
p = 1000000007
s = input()
n = len(s)
e,a,b,c = 1,0,0,0
for i in range(n):
  if s[i] == "A":
    a = (e+a)%p
  elif s[i] == "B":
    b = (a+b)%p
  elif s[i] == "C":
    c = (b+c)%p
  else:
    e,a,b,c = (3*e)%p,(e+3*a)%p,(a+3*b)%p,(b+3*c)%p
print(c) 

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){
	int m, f, r;
	
	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		
		if(m + f >= 80) cout << "A" << endl;
		else if(m + f >= 65) cout << "B" << endl;
		else if(m + f >= 50) cout << "C" << endl;
		else if(m == -1 || f == -1) cout << "F" << endl;
		else if(m + f >= 30) {
			if(r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else if(m + f <= 30) cout << "F" << endl;
	}
	
	return 0;
}

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

using lli = long long int;

using namespace std;

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

    std::vector<lli> h(N);
    std::for_each(h.begin(), h.end(), [](auto &x) { cin >> x; });

    std::vector<lli> dp(N);
    dp[0] = 0;
    dp[1] = std::abs(h[0] - h[1]);

    for (lli i = 0; i < N - 2; ++i) {
        dp[i + 2] = std::min(dp[i + 1] + std::abs(h[i + 1] - h[i + 2]), dp[i] + std::abs(h[i] - h[i + 2]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)cin>>a[i];
    long long int med=0;
    for(long long int i=0;i<n;i++)med+=a[i];
    med/=n;
    long long int ans=0,val=0;
    for(long long int i=0;i<n;i++)val+=(med-a[i])*(med-a[i]);
    med++;
    for(long long int i=0;i<n;i++)ans+=(med-a[i])*(med-a[i]);
    cout<<min(ans,val)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

int digitsum(int N){
  if(N<=0) return 0;
  int digit=1+floor(log10(N)),res=0;
  for(int i=digit-1;i>=0;i--){
    int mono=N/pow(10,i);
    res+=mono;
    N-=mono*pow(10,i);
  }
  return res;
}
 
int main(void){
    int N;
    cin >> N;
    if(N%digitsum(N)==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	ll cnt=0;

	for(ll i=0;i<n;i++){
		if(a[i]%4==0){
			cnt+=2;
		}else if(a[i]%2==0){
			cnt++;
		}
	}

	if(n%2==1){
		if(cnt>=n-1){
			cout<<"Yes"<<endl;
			return 0;
		}
	}else{
		if(cnt>=n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 1024
question = int(input())
point = []
for i in range(question):
    point.append(int(input()))
    
point.sort()
point_max = sum(point)
i = 0
hantei = 0
while point_max % 10 == 0 and point_max != 0:
    if point[i] % 10 != 0:
        point_max -= (point[i])
        i += 1
    else:
        if i <= len(point) - 2:
            i += 1
        else:
            hantei += 1
            point_max = -1
            point[i] = -1

if hantei == 0:
    print(point_max)
else:
    print(0)

Measured memory_bytes: 3064
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int m, nin, nax;
int p[202];

bool input(){
  cin>>m>>nin>>nax;
  REP(i, m)cin>>p[i];
  return m;
}

void solve(){
  int s=0, b=0;
  FOR(i, nin-1, nax) {
    if(p[i]-p[i+1]>=s){
      b=i+1;
      s=p[i]-p[i+1];
    }
  }
  cout<<b<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 2988
#include <stdio.h>

int main(void)
{
	int n,K,i,j,k,p,t,total,min;
	int N[1000];
	total = 0;
	scanf("%d %d",&n,&K);
	for(i = 1;i <= n;i++){
		scanf("%d",&p);
		N[i - 1] = p;
	}
	for(i = 1;i <= K;i++){
		min = 1200;
		for(j = 1;j <= n;j++){
			if (min > N[j - 1]) min = N[j - 1];
		}
		for(k = 1;k <= n;k++){
			if (N[k-1] == min) {N[k-1] = 1200;break;}
		}
		total += min;
	}
	printf("%d\n",total);
	return 0;
}

Measured memory_bytes: 1740
import java.util.Scanner;

class Main{
    public static void main(String[] arr)

    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        if (a.length() == 2)
            System.out.printf(a);
        else {
            String re = new StringBuffer(a).reverse().toString();
            System.out.printf(re);
        }
    
    }
}

Measured memory_bytes: 21844
import collections

h, w = map(int, input().split())

ss = [input() for _ in range(h)]
start = [0,0]
goal = [w-1,h-1]
wall_count = 0
for s in ss:
    wall_count += s.count("#")

dx = [1,-1,0,0]
dy = [0,0,1,-1]

stack = collections.deque([start])
visited = [[-1 for _ in range(h)] for _ in range(w)]
visited[start[0]][start[1]] = 1

while len(stack) > 0:
    pos = stack.pop()
    if pos == goal:
        break
    
    for x,y in zip(dx, dy):
        next_pos = [pos[0]+x, pos[1]+y]
        
        if next_pos[0]<0 or (w-1)<next_pos[0] or next_pos[1]<0 or (h-1)<next_pos[1]:
            continue
        if ss[next_pos[1]][next_pos[0]] == "#":
            continue
        if visited[next_pos[0]][next_pos[1]] != -1:
            continue
        stack.appendleft(next_pos)
        visited[next_pos[0]][next_pos[1]] = visited[pos[0]][pos[1]] + 1

if visited[w-1][h-1] == -1:
    print("-1")
else:
    score = (h*w) - wall_count - visited[w-1][h-1]
    print(score)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i <= n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
  int k;
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#define INT long long
#define MOD 1000000007
using namespace std;

INT n, m, q, S[1<<18], T[1<<18], baseN, baseM;
string s, t;
int getN(int s, int e)
{
    int ret = 0;
    while( s <= e )
    {
        if( s%2==1 ) ret += S[s++], ret%=3;
        if( e%2==0 ) ret += S[e--], ret%=3;
        s>>=1, e>>=1;
    }
    return ret;
}
int getM(int s, int e)
{
    int ret = 0;
    while( s <= e )
    {
        if( s%2==1 ) ret += T[s++], ret%=3;
        if( e%2==0 ) ret += T[e--], ret%=3;
        s>>=1, e>>=1;
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>s>>t>>q;
    n = s.size(), m = t.size();
    for(baseN = 1 ; baseN < n ; baseN<<=1);
    for(baseM = 1 ; baseM < m ; baseM<<=1);
    for(int i = 0 ; i < n ; i++ ) S[baseN+i] = s[i]=='B'?2:1;
    for(int i = 0 ; i < m ; i++ ) T[baseM+i] = t[i]=='B'?2:1;
    for(int i = baseN-1 ; i > 0 ; i-- ) S[i] = S[i*2] + S[i*2+1], S[i]%=3;
    for(int i = baseM-1 ; i > 0 ; i-- ) T[i] = T[i*2] + T[i*2+1], T[i]%=3;
    while( q-- )
    {
        int a, b, c, d;
        cin>>a>>b>>c>>d; a--, b--, c--, d--;
        if( getN(a+baseN, b+baseN) == getM(c+baseM, d+baseM) ) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}



Measured memory_bytes: 4816
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		m[x]++
	}
	ans := 0
	for _, v := range m {
		if v%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
typedef long long ll;
ll n, a, b, c, d, ans;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld %lld %lld %lld %lld",&a ,&b ,&c ,&d ,&n);
	ans = n*4*a;
	ans = min(ans, n*2*b);
	ans = min(ans, n*c);
	ans = min(ans, (n/2)*d + (n%2)*c );
	ans = min(ans, (n/2)*d + (n%2)*2*b );
	ans = min(ans, (n/2)*d + (n%2)*4*a );
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	lint N, C;
	lint ans = 0;
	cin >> N >> C;

	vector<pair<lint, lint>> data(N);
	vector<lint> up_com(N + 1);
	vector<lint> down_com(N + 1);
	vector<lint> up_dis(N + 1);
	vector<lint> down_dis(N + 1);
	vector<lint> up_max(N + 1);
	vector<lint> down_max(N + 1);
	vector<lint> up_back_max(N + 1);
	vector<lint> down_back_max(N + 1);

	up_com[0] = down_com[0] = up_dis[0] = down_dis[0] = up_max[0] = down_max[0] = 0;
	for (int i = 0; i < N; i++)
	{
		lint tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		data[i] = make_pair(tmp1, tmp2);
	}

	for (int i = 0; i < N; i++)
	{
		up_com[i + 1] = up_com[i] + data[i].second;
		down_com[i + 1] = down_com[i] + data[N - 1 - i].second;
		up_dis[i + 1] = data[i].first;
		down_dis[i + 1] = C - data[N - 1 - i].first;
	}

	for (int i = 0; i < N; i++)
	{
		up_max[i + 1] = max(up_max[i], up_com[i + 1] - up_dis[i + 1]);
		up_back_max[i + 1] = max(up_back_max[i], up_com[i + 1] - up_dis[i + 1] * 2);
		down_max[i + 1] = max(down_max[i], down_com[i + 1] - down_dis[i + 1]);
		down_back_max[i + 1] = max(down_back_max[i], down_com[i + 1] - down_dis[i + 1] * 2);
	}

	for (int i = 0; i <= N; i++)
	{
		ans = max(ans, up_max[i] + down_back_max[N - i]);
		ans = max(ans, down_max[N - i] + up_back_max[i]);
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 8192
N, X = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
d = Array.new(N)
(0..(N - 1)).each do |i|
	d[i] = (x[i] - X).abs
end
if N == 1 then
	p d[0]
	exit(0)
end
ans = d[0].gcd(d[1])
(2..(N - 1)).each do |i|
	ans = ans.gcd(d[i])
end
p ans

Measured memory_bytes: 9220
/* ex 9_2
   person_A */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node  **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}


int main(void){
    //最初のノードの指す先
    node *first = NULL;
    char cubes[SIZE],top;
    int i,count=0,strlength;
    //赤色のキューブ'0'と青色のキューブ'1'を表す文字列の入力
    scanf("%s",cubes);
    strlength=strlen(cubes);

    //下の方からキューブをスタックに入れていく
    for(i=0;i<strlength;i++){
        //机の上にキューブがなければ、一つを置くだけ
        if(first==NULL){
            push(&first,cubes[i]);
        }
        else{
            top=pop(&first);
            //先頭と異なる色であれば、カウントする
            if(top!=cubes[i]){
                count+=2;
            }
            //先頭と同じ色であれば、二つを机の上に置き戻す
            else{
                push(&first,top);
                push(&first,cubes[i]);
            }
        }
    }
    
    //結果の出力
    printf("%d\n",count);

    return 0;
}


Measured memory_bytes: 4932
# モンスターの体力は H
# アライグマは N 種類の必殺技を使うことができ
# i番目の必殺技を使うとモンスターの体力を Ai 減らすことができます。
# モンスターの体力を0以下にすれば、アライグマ勝ち
# アライグマが同じ必殺技を 2 度以上使うことなくモンスターに勝つことができるなら Yes を、
# できないなら No を出力してください。

H, N = map(int, input().split())
data = list(map(int, input().split()))
sum = sum(data)

if H - sum > 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 20288
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  ll l,r;cin>>l>>r;
  
  ll ans=2020;
  ll smaller=min(r-l,(ll)2019);
  
  for (ll i=l;i<=l+smaller-1;i++) {
    for (ll j=i+1;j<=l+smaller;j++) {
      ans = min(ans,(i*j)%2019);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <limits>
#include <utility>
#include <string>
#include <numeric>


int main(int argc, char *argv[]){
    constexpr int MAX_N = 1000;

    static int A[MAX_N][MAX_N-1];
    static int S[MAX_N];
    static int D[MAX_N];

    int N;
    std::cin >> N;

    int i,j;
    for(i=0; i<N; ++i){
        for(j=0; j<N-1; ++j){
            std::cin >> A[i][j];
            --A[i][j];
        }
    }

    int days = 0, daysTmp;
    int enemy, enemyOfEnemy;
    int matches;
    const int maxMatches = (N*(N - 1))/2;
    bool isMatch;
    while(matches < maxMatches){
        isMatch = false;
        for(i=0; i<N; ++i){
            if(S[i] > N-2){
                continue;
            }
            enemy = A[i][S[i]];
            enemyOfEnemy = A[enemy][S[enemy]];
            if(i == enemyOfEnemy){
                ++S[i];
                ++S[enemy];
                isMatch = true;
                ++matches;
                daysTmp = std::max(D[i],D[enemy]);
                ++daysTmp;
                D[i] = daysTmp;
                D[enemy] = daysTmp;
                if(days < daysTmp){
                    ++days;
                }
            }
        }
        if(!isMatch){
            days = -1;
            break;
        }
    }
    
    std::cout << days << std::endl;
    return 0;
}


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

const int N = (int)1e6+7;
const int INF = (int)1e9+17;
const int mod = 998244353;

typedef long long ll;


int n, m;
int a[N];
int b[N];
int c[N];



bool check() {
    if (set<int>(c, c+n).size() < n) {
        return true;
    }
    map<int,int> pos;
    for(int i = 0; i < n; ++i) {
        pos[a[i]] = i;
    }
    int times = 0;
    for(int i = 0; i < n; ++i) {
        if (a[i] != c[i]) {
            ++times;
            int ps = pos[c[i]];
            pos[a[i]] = ps;
            swap(a[i], a[ps]);
        }
    }
    return times <= n - 2;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<pair<int,int>> p;
    for(int i = 0; i < n; ++i) {
        cin >> b[i];
        p.emplace_back(b[i], a[i]);
    }

    sort(p.begin(), p.end());
    copy(a, a+n, c);
    sort(c, c+n);
    sort(b, b+n);
    for(int i = 0; i < n; ++i) {
        if (c[i] > b[i]) {
            cout << "No" << endl;
            return 0;
        }
        a[i] = p[i].second;
    }
    for(int i = 0; i < n; ++i) {
        if (c[i] == a[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (check()) {
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 1; i < n; ++i) {
        swap(c[i], c[i-1]);
        if (c[i] <= b[i] && c[i - 1] <= b[i - 1]) {
            cout << "Yes" << endl;
            return 0;
        }
        swap(c[i], c[i-1]);
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 14324
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
int main()
{
	ll a,b,n,k,ans = 0;
	bool z = true;
	cin >> a >>b;
	int i=2;
	while(z){
	if(a >= b && a % b == 0){
		cout << -1;
		return 0;
	}
	else if((a*i) % b != 0)
	{
		cout << a*i;
		z = false;
	}
	else
		i++;
	}

	return 0;
}

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

int main() {

  int x,y;
  cin >> x >> y;
  vector<int>A(13);
  A = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  
   if(A.at(x)==A.at(y)){
    cout  << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    int n;
    cin>>n;
    if(n>=30){cout<<"Yes";}
    else{cout<<"No";}
    return 0;
    
}


Measured memory_bytes: 3616
N , M   = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(N) ]
lst.sort()
#残り必要本数
temp = M
#必要なお金
money = 0
for ab in lst:
	# 残り必要本数の方が多ければ
	if ab[1] < temp:
		temp -= ab[1]
		money += (ab[0] * ab[1])
	else: 
		money += (temp * ab[0])
		break

print(money)

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

const int INF=1e9;

int main(){
  int n;
  cin>>n;
  int dp[100000];
  dp[0]=0;
  for(int i=1;i<=100000;i++){
    if(i<6){
      dp[i]=i;
      continue;
    }
    dp[i]=INF;

    int p=6;
    while(p<=i){
      dp[i]=min(dp[i],dp[i-p]+1);
      p*=6;
    }
    p=9;
    while(p<=i){
      dp[i]=min(dp[i],dp[i-p]+1);
      p*=9;
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main() {
ll n;
cin>>n;
ll ca=0;
ll f=0;
ll a[n]={};
ll b[100005]={};
ll c[100005]={};
ll d[100005]={};
ll e[100005]={};
for(ll i=0; i<n; i++){
cin>>a[i];}
for(ll i=0; i<n; i=i+2){
b[a[i]]++;
d[a[i]]++;}
for(ll i=1; i<n; i=i+2){
c[a[i]]++;
e[a[i]]++;}
sort(d,d+100005);
sort(e,e+100005);
ll bm=d[100004];
ll cm=e[100004];
ll bi,ci;
ll bmm,cmm;
for(ll i=0; i<100005; i++){
if(b[i]==bm){
bi=i;}}
for(ll i=0; i<100005; i++){
if(c[i]==cm){
ci=i;}}
if(bi!=ci){
cout<<n-bm-cm<<endl;
}
else{
bmm=d[100003];
cmm=e[100003];
cout<<n-max(bm+cmm,bmm+cm)<<endl;}}


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


int main() {
    int k,a,b;
    cin>>k>>a>>b;
    rep(i,b+1) {
        if(k*i>=a and k*i<=b) {
            cout << "OK" <<endl;
            return 0;
        }
    }
    cout << "NG" <<endl;
}

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

int f(int n)
{
	if (n % 2)
	{
		return(3 * n + 1);
	}
	else
	{
		return(n / 2);
	}
}

int main()
{
	uint32_t s, aprev, n, ind;
	vector<int> a;
	bool b = true;

	cin >> s;
	n = 1;
	a.push_back(s);
	aprev = s;

	while (b)
	{	
		// cout << aprev << '\n';
		n++;
		aprev = f(aprev);
		a.push_back(aprev);

		ind = 1;
		for (auto itr = a.begin(); itr != a.end(); ++itr, ind++) {
			if ((aprev == *itr) && (ind != a.size()))
			{
				b = false;
				break;
			}
		}
	}

	cout << n; 
}


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

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i = 0;
    while(a > 0 && c > 0){
        if(i % 2 == 0){
            c -= b;
        } else {
            a -= d;
        }
        i++;
    }
    if(a <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

#define LL long long

LL N, K;
LL result_1, result_2;

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

  cin >> N >> K;

  cout << min(N % K, K - (N % K)) << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string s;
  cin>>s;
  int a=stoi(s.substr(0,2));
  int b=stoi(s.substr(2,2));
  int ym=0,my=0;
  if(1<=b && b<=12){
    ym=1;
  }
  if(1<=a && a<=12){
    my=2;
  }
  int x=ym+my;
  switch(x){
    case 0:
      cout<<"NA";
      break;
    case 1:
      cout<<"YYMM";
      break;
    case 2:
      cout<<"MMYY";
      break;
    case 3:
      cout<<"AMBIGUOUS";
      break;
  }
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    q = int(input())
    power10 = [1]
    for i in range(7):
        power10.append(10*power10[-1])

    for _ in range(q):
        N = int(input())
        if N//10 == 0:
            print(0)
            continue

        visited = {N}
        cnt = 0
        while True:
            cnt += 1
            next_number = -1
            for i in range(1,len(str(N))):
                next_number = max(next_number,(N//power10[i])*(N%power10[i]))
            if next_number in visited:
                cnt = -1
                break
            if next_number//10 == 0:
                break
            else:
                visited.add(next_number)
                N = next_number

        print(cnt)        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5616
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll calcGcd(ll x, ll y) {
    if (!y) {
        return x;
    }
    return calcGcd(y, x % y);
}

bool isPairwise(int N, const vector<ll>& A) {
    vector<bool> S(1000001, false);
    for (auto& a : A) {
        if (S[a] && a != 1) {
            return false;
        }
        S[a] = true;
    }
    for (ll now = 2; now <= 1000000LL; ++now) {
        ll tmp = now;
        bool exists = false;
        while (tmp <= 1000000LL) {
            if (S[tmp]) {
                if (exists) {
                    return false;
                } else {
                    exists = true;
                }
            }
            tmp += now;
        }
    }
    return true;
}

bool isSetwise(int N, const vector<ll>& A) {
    ll gcd = A.front();
    for (auto& a : A) {
        gcd = calcGcd(gcd, a);
    }
    return gcd == 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    if (isPairwise(N, A)) {
        cout << "pairwise coprime" << endl;
    } else if (isSetwise(N, A)) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }
    return 0;
}

Measured memory_bytes: 11240
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    vector<vector<int>> A(2, vector<int>(N));

    for (auto& Ai: A){
        for (auto& Aij: Ai){
            cin >> Aij;
        }
    }


    int max = 0;

    for (int j=0; j<N; ++j){
        int count = 0;

        for (int s=0; s<=j; s++){
            count += A[0][s];
        }

        for (int s=j; s<N; s++){
            count += A[1][s];
        }

        if (count > max)
            max = count;
    }

    cout << max << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
long long min(long long x, long long y) { return x < y ? x : y; }
int main() {
	long long n, a[5], m;
	scanf("%lld", &n);
	for (int i = 0; i < 5; i++) {
		scanf("%lld", &a[i]);
	}
	m = a[0];
	for (int i = 0; i < 5; i++) {
		if (m > a[i]) {
			m = a[i];
		}
	}
	if (n % m == 0)
		printf("%lld\n", (n / m) + 4);
	else
		printf("%lld\n", (n / m) + 5);
	return 0;
}

Measured memory_bytes: 128
import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    answer = sum(A)
    setA = set(A)
    numNumberList = [0] * 100001

    for Ai in A:
        numNumberList[Ai] = numNumberList[Ai] + 1    

    for i in range(Q):
        B, C = list(map(int, sys.stdin.readline().split()))
        answer = answer + (int(C) - int(B)) * numNumberList[B]

        numNumberList[C] = numNumberList[C] + numNumberList[B]
        numNumberList[B] = 0

        print(answer)

if __name__ == "__main__":
    main()

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

const int N = 2e3 + 10, MOD = 1e9 + 7;
int a[N], b[N], ps[N][N], n, m;

int sum(int a, int b){
	int c = a + b;
	if(c >= MOD)
		c -= MOD;
	return c;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	
	ps[0][0] = (a[0] == b[0]);	
	for (int j = 1; j < m; j++)
		ps[0][j] = sum(ps[0][j - 1], (a[0] == b[j]));
	for (int i = 1; i < n; i++)
		ps[i][0] = sum(ps[i - 1][0], (a[i] == b[0]));
		
	for (int i = 1; i < n; i++){
		for (int j = 1; j < m; j++){
			if(j > 0)
				ps[i][j] = ps[i][j - 1];
			if(i > 0)
				ps[i][j] = sum(ps[i][j], ps[i - 1][j]);
			if(i > 0 && j > 0)
				ps[i][j] = sum(ps[i][j], MOD - ps[i - 1][j - 1]);
			if(a[i] == b[j])
				ps[i][j] = sum(ps[i][j], sum(ps[i - 1][j - 1], 1));
		}
	}
	
	cout << sum(ps[n - 1][m - 1], 1);
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){	
	lint n,k,ans=0;
	cin>>n>>k;
	vector<int>h(n);
	rep(i,n)cin>>h.at(i);
	rep(i,n)if(k<=h.at(i))ans++;
	cout<<ans<<endl;
}


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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  long N,K,Q;
  cin>>N>>K>>Q;

  if(K>Q){
    for(int i=0;i<N;i++){
      cout<<"Yes"<<endl;
    }
    return 0;
  }

  vector<long> A(N);

  for(int i=0;i<Q;i++){
    long X;
    cin>>X;
    A.at(X-1)++;
  }

  //for(int i=0;i<N;i++){
  //  cout<<A.at(i)<<endl;
  //}

  for(int i=0;i<N;i++){
    if(A.at(i)>=Q-K+1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }

}

Measured memory_bytes: 1280
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
# a <= b <= c

for b in range(1,N-1):
  for c in range(b+1,N):
    # search min(c) with a + b > c <=> a > c - b
    idx = bisect.bisect_left(L,L[c]-L[b]+1)
    #print(L[b],L[c],idx)
    ans += max(b-idx,0) if idx >= 0 else 0 
    #print(idx, ans)
#print(L)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, M;
    cin >> N >> M;
    bool pass[N][N] = {};

    REP(i,M){
        int a,b;
        cin >> a >> b;
        pass[a-1][b-1] = true;
        pass[b-1][a-1] = true;
    }
    vector<int> v;
    REP(i,N){
        v.pb(i);
    }
    int ans = 0;
    do{
        bool flag = true;
        REP(i,N-1){
            if(v[0] != 0){
                flag = false;
                break;
            }
            if(!pass[v[i]][v[i+1]]){
                flag = false;
                break;
            }
        }
        if(flag){ans ++;}
    }while(next_permutation(All(v)));
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
							for(int j=0;j<n;j++){   \
								cout<<a[i][j]<<" "; \
							}                       \
							cout<<endl;             \
						}
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define len(s) (ll)(s.size())
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
	fast_io()
 

	ll te;
	//cin>>t;
	te=1;
	while(te--){
		string s,t;
		cin>>s>>t;
		ll m=len(s),n=len(t);
		ll dp[m+1][n+1];
		s="?"+s;
		t="?"+t;
		mset(dp,0);
		fori(i,1,m){
			fori(j,1,n){
				if(s[i]==t[j]){
					dp[i][j]=1+dp[i-1][j-1];
				}
				else{
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		int i=m,j=n;
		string a="";
		while(i>0&&j>0){
			if(s[i]==t[j]){
				a+=s[i];
				i--;
				j--;
			}
			else if(dp[i][j]==dp[i-1][j]){
				i--;
			}
			else{
				j--;
			}
		}
		reverse(all(a));
		cout<<a;
	}
	return 0;
}



Measured memory_bytes: 70656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    ll N,A,B,ans;
    cin>>N>>A>>B;
    if(A+2>=B||N+1<=A){
        cout<<N+1<<endl;
        return 0;
    }
    else{
        N=N-A+1;
        ans=A+(B-A)*(N/2);
        if(N%2==1)ans++;
    }
    cout<<ans<<endl;
}






Measured memory_bytes: 256
s=0
N=int(input())
L=list(map(int,input().split()))
for i in range(1,N-1):
  if L[i-1]>L[i] and L[i]>L[i+1]:
    s+=1
  if L[i-1]<L[i] and L[i]<L[i+1]:
    s+=1
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 305;
int n, m;
char mp[3*N][3*N];
int suml[3*N][3*N], sumr[3*N][3*N];
ll solve(int x, int y) {
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int num = 0;
        if (mp[x-i][y] == '#') num++;
        if (mp[x+i][y] == '#') num++;
        if (mp[x][y-i] == '#') num++;
        if (mp[x][y+i] == '#') num++;
        if (num == 3) ans++;
        else if (num == 4) ans += 4;
    }
    for (int i = 2; x-i >= N+1 && y-i >= N+1; i++) {
        if (mp[x-i][y] == '.' || mp[x][y-i] == '.') continue;
        int sx = x+1, sy = y+i-1;
        int ex = x+i-1, ey = y+1;
        ans += suml[ex][ey] - suml[sx-1][sy+1];
    }
    for (int i = 2; x-i >= N+1 && y+i <= N+m; i++) {
        if (mp[x-i][y] == '.' || mp[x][y+i] == '.') continue;
        int sx = x+1, sy = y-i+1;
        int ex = x+i-1, ey = y-1;
        ans += sumr[ex][ey] - sumr[sx-1][sy-1];
    }
    for (int i = 2; x+i <= N+n && y+i <= N+m; i++) {
        if (mp[x+i][y] == '.' || mp[x][y+i] == '.') continue;
        int sx = x-i+1, sy = y-1;
        int ex = x-1, ey = y-i+1;
        ans += suml[ex][ey] - suml[sx-1][sy+1];
    }
    for (int i = 2; x+i <= N+n && y-i >= N+1; i++) {
        if (mp[x+i][y] == '.' || mp[x][y-i] == '.') continue;
        int sx = x-i+1, sy = y+1;
        int ex = x-1, ey = y+i-1;
        ans += sumr[ex][ey] - sumr[sx-1][sy-1];
    }
    return ans;
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = N+1; i <= N+n; i++) scanf("%s", mp[i]+1+N);
    for (int i = 1; i <= 2*N+n; i++)
        for (int j = 1; j <= 2*N+m; j++)
            suml[i][j] = sumr[i][j] = (mp[i][j] == '#');
    for (int i = 1; i <= 2*N+n; i++)
        for (int j = 1; j <= 2*N+m; j++) {
            sumr[i][j] += sumr[i-1][j-1];
            suml[i][j] += suml[i-1][j+1];
        }
    ll ans = 0;
    for (int i = N+1; i <= N+n; i++)
        for (int j = N+1; j <= N+m; j++)
            ans += solve(i, j);
    cout << ans << endl;
}
/*
6 6
...#..
..#...
.#...#
......
...#..
......
*/


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a;
  cin>>a;
  cout<<(a-a%3)/3;
}

Measured memory_bytes: 256
d,n=map(int, input().split())
if d == 0:
  if n < 100:
    print(n)
  else:
    print(101)
if d == 1:
  if n < 100:
    print(n*100)
  else:
    print(10100)
if d == 2:
  if n < 100:
    print(n*10000)
  else:
    print(1010000)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003;

int n, m;
int a[N], b[N];
char s[N];

int main()
{
    n = gi();
    LL ans = 0;
    for (int i = 1; i <= n; i+=1) 
        if (i % 3 && i % 5) ans += i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char s[200001];
    cin >> s;
 	
  	int len = strlen(s);
    int a_idx, z_idx;
 
    for(int i = 0; i < len; ++i){
 
        if(s[i] == 'A'){
            a_idx = i;
            break;
        }
    }
 
    for(int i = 0; i < len; ++i){
 
        if(s[i] == 'Z'){
            z_idx = i;
        }
    }
 
    cout << z_idx - a_idx + 1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> one(63, 0);
  vector<ll> zero(63, 0);
  rep(i, n) {
    ll a;
    cin >> a;

    for (int j = 0; j < 63; j++) {
      if ((a >> j) & 1) {
        one[j]++;
      } else {
        zero[j]++;
      }
    }
  }
/*
  rep(i, 60) {
    cerr << one[i] << " ";
  }
  cerr << endl;
  rep(i, 60) {
    cerr << zero[i] << " ";
  }
  cerr << endl;
*/
  ll ans = 0;
  for (ll i = 0; i < one.size(); i++) {
    ll base = ll(pow(ll(2), i)) % mod;
    ll x = (one[i] * zero[i]) % mod;
    ans += (x * base) % mod;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long long i,j,a,b,c,d;
	while(scanf("%lld %lld",&a,&b)!=EOF)
	{
		i=a,j=b;
		while(i)
		{
			if(i<j)
				c=i,i=j,j=c;
			else
				i=i%j;
		}
		c=j;
		d=a*b/c;
		printf("%lld %lld\n",c,d);
	}
    return 0;
}

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

int n;
vector<ll> a(n+1,1);
ll dfs(int n,ll x,ll num){
    ll ans = 0;
    //printf("%d %lld %lld \n",n,x,num);
    if(n==1) return min(x-1,ll(3));
    if(num/2+1==x) return a[n-1] + 1;
    if(x==1) return 0;
    else if(x == num) return a[n];

    if(num/2+1<x){
        ans += a[n-1] + 1;
        x -= (num/2+1);
        num = num/2-1;
        ans += dfs(n-1,x,num);
    }else{
        num = num/2-1;
        --x;
        ans += dfs(n-1,x,num);
    }

    return ans;
}
int main(){
    ll x;
    cin >> n >> x;
    rep(i,n) a[i+1] = a[i]*2 + 1;
    ll num = 4;
    rep(i,n) num*=2;
    num-=3;
    //cout << num << endl;
    cout << dfs(n,x,num) << endl;
    
}

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

bool f(int i){
  bool y=false;
  int s=i,t=0,k=10000;
  for(int j=0;j<5;j++){
    t += (i%10)*k;
    i /= 10;
    k /= 10;
  }
  if(s == t) y = true;
  
  return y;
}

int main(){
  int a,b,ans=0;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(f(i)) ans++;
  }
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int u = stoi(S.substr(0, 2)), d = stoi(S.substr(2, 2));
  if (u >= 1 && u <= 12 && d >= 1 && d <= 12)
    cout << "AMBIGUOUS" << endl;
  else if (u >= 1 && u <= 12)
    cout << "MMYY" << endl;
  else if (d >= 1 && d <= 12)
    cout << "YYMM" << endl;
  else
    cout << "NA" << endl;
}

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

int main(){
    int r,d,x;cin>>r>>d>>x;
    for(int i=0;i<10;i++){
        x*=r;x-=d;cout<<x<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	
	ll d = c - a - b;
	if (d > 0 && d * d > 4 * a * b) cout << "Yes" << '\n';
	else cout << "No" << '\n';
	
	return 0;
}

Measured memory_bytes: 256