akhauriyash/Code-Regression huggingface dataset:
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});
/*
process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});
*/
process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////


function main() {
	var s = readLine();	
    s = s.split(" ");
	var N = parseInt(s[0]);
	var M = parseInt(s[1]);
	/*adjacency matrix*/
	var ADJ = []; 
    var vis = [];
	
	/*initalizing ADJ and vis array*/
	for (var i=0; i < N; i++){
		ADJ.push([]);
		vis.push(0);
	}
	
	/*reading the graph*/
	for (var i=0; i < M; i++){
		s = readLine().split(" ");
		var a = parseInt(s[0]); 
		var b = parseInt(s[1]); 
		a--; b--; /* now indexing from 0 to n-1 */
		ADJ[a].push(b);
		ADJ[b].push(a);
	}
	
	function dfs(nod, cant){
		if (cant == N) return 1;
		var ret=0;
		vis[nod] = 1;
		for (var i=0; i < ADJ[nod].length; i++){
			if (vis[ADJ[nod][i]] == 0){
				ret += dfs(ADJ[nod][i], cant+1);
			}
		}
		vis[nod] = 0;
		return ret;
	}
	
	console.log(dfs(0,1));
}

Measured memory_bytes: 9676
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>

using namespace std;
int main(){
  char s[11];
  int num[3],ans=1000;
  scanf("%s",s);

  for(int i=0;i<strlen(s)-2;i++){
    for(int j=0;j<3;j++){
      num[j]=s[i+j]-'0';
    }
    int temp=num[0];
    for(int j=1;j<3;j++){
      temp*=10;
      temp+=num[j];
    }
    if((int)fabs(temp-753)<ans) ans=(int)fabs(temp-753);
  }

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <algorithm>
#include <climits>

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)

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;

	bool operator >(const Node &a) const
	{
		return total_cost > a.total_cost;
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life });
		while (true)
		{
			if (pq.empty())
			{
				cout << "Help!" << endl;
				break;
			}
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				cout << current_node.total_cost << endl;
				break;
			}
			if (is_cooler[current_node.city_index])
			{
				REP(i, initial_life - current_node.current_life + 1)
				{
					int life = current_node.current_life + i;
					int cost = current_node.total_cost + i;
					int city_index = current_node.city_index;
					if (cost < d[city_index][life])
					{
						d[city_index][life] = cost;
						pq.push({ city_index, cost, life });
					}
				}
			}
			
			for (auto &road : roads[current_node.city_index])
			{
				int life = current_node.current_life - road.cost;
				if (life < 0)
				{
					continue;
				}
				int cost = current_node.total_cost + road.cost;
				if (cost < d[road.to][life])
				{
					d[road.to][life] = cost;
					pq.push({ road.to, cost, life });
				}
			}

		}
	}

	return 0;
}

Measured memory_bytes: 1468
s = input()
flg = True

if s != s[::-1]:
    flg = False
    
part1 = s[0:int((len(s)-1)/2)]
if part1 != part1[::-1]:
    flg = False
    
part2 = s[int((len(s)+3)/2 -1):len(s)]
if part2 != part2[::-1]:
    flg = False
    
if flg:
    print("Yes")
else:
    print("No")

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> AB(N, vector<ll>(2));
    for (ll i = 0; i < N; i++) cin >> AB.at(i).at(0) >> AB.at(i).at(1);
    sort(AB.begin(), AB.end());
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ll a = AB.at(i).at(0);
        ll b = AB.at(i).at(1);
        if (M <= b) {
            ans += a * M;
            break;
        } else {
            ans += a * b;
            M -= b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	ll X, K, D;
	cin>>X>>K>>D;
	X = abs(X);
	ll Q = X/D;
	ll R = X%D;
	if (Q>=K) {
		cout<<X-K*D<<endl;
	}
	else if ((K-Q)&1) {
		cout<<abs(R-D)<<endl;
	}
	else {
		cout<<X-Q*D<<endl;
	}

	return 0;
}


Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    N = int(input())
    D = list(map(int, sys.stdin.readline().rstrip().split()))
    D.sort()
    print(max(0, D[N//2]-D[N//2-1]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14004
import java.util.ArrayList;
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  ArrayList<Integer> list = new ArrayList<>();
	  while (true) {
		  int i = sc.nextInt();
		  if (i == 0) { break; }
		  list.add(i);
	  }
	  for (int i = 0; i < list.size(); i++) {
		  System.out.println("Case " + (i + 1) + ": " + list.get(i));
	  }
  }
}


Measured memory_bytes: 43616
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int main() {
	int k,s,i,j,count=0;
	cin >> k>>s;
	for(i=0;i<=k;i++){
		for(j=0;j<=k;j++){
			if(s-i-j>=0 && s-i-j<=k){
				count +=1;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int c[3][3];
    for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      std::cin >> c[i][j];
    }
  }
    int a[3],b[3];
    for(a[0] = 0;a[0] <= 100;a[0]++){
      for(a[1] = 0;a[1] <= 100;a[1]++){
        for(a[2] = 0;a[2] <= 100;a[2]++){
          b[0] = c[0][0] - a[0];
          b[1] = c[1][1] - a[1];
          b[2] = c[2][2] - a[2];
          if(c[0][1] == a[0] + b[1] && 
            c[0][2] == a[0] + b[2] &&
            c[1][0] == a[1] + b[0] &&
            c[1][2] == a[1] + b[2] &&
            c[2][0] == a[2] + b[0] &&
            c[2][1] == a[2] + b[1]){
            cout <<"Yes"<<endl;
            return 0;
          }
        }
      }
    }
  cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ans = 0

flag = n + 1
for i in a:
  if i == flag + 1:
    ans = ans + b[i-1] + c[i-2]
    flag = i
  else:
    ans = ans + b[i-1]
    flag = i
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int i, j, k, n, A[100];

int GCD(int x, int y){
	if(y == 0) return x;
	return GCD(y, x % y);
}

int main(){
	int x, y;
	scanf("%ld %ld",&x,&y);
	printf("%ld\n", GCD(x, y));
	return 0;
}

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

int main(){
  int n;cin>>n;
  string s="No";
  while(n>0)
  {
    
    if(n%4==0||n%7==0)
      s="Yes";
    n-=4;
  }
    while(n>0)
  {
   
    if(n%4==0||n%7==0)
      s="Yes";
    n-=7;
  }
  cout<<s;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int ans;
int gcdl(int a,int b)
{
	if(b==0)return a;
	return gcdl(b,a%b);
}
int main()
{
	int n,i,k,j,xx,x;
	cin>>n;
	for(i=1;i<=n;i++)
	for(j=i;j<=n;j++)
	for(k=j;k<=n;k++)
	{
		
		if(i==j&&k==j)
		{
			ans+=i;
			continue;
		}
		x=gcdl(i,j);
		xx=gcdl(x,k);
        if(i==j||j==k||i==k)
		{
			ans+=3*xx;
		}
		else
		ans+=6*xx;
		//cout<<i<<j<<k<<" "<<ans<<endl;
	}
	cout<<ans;
} 

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a.at(i);
  int ans = 0;
  int flag = 1;
  int now = 0, pre = 1;
  set<int> light; 
  while(flag){
    ans++;
    now = a.at(pre-1);
    if(now==2)break;
    if(light.count(now)){
      ans = -1;
      flag = 0;
      break;
    }else{
      light.insert(now);
      pre = now;
    }
  }
  cout<<ans<<endl; 
}

Measured memory_bytes: 5376
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=5005;

int n,k;
char s[N];

struct aa
{
	int p,l;
}t[N*5];

bool cmp(aa &a,aa &b) 
{
	for (int i=0;i<a.l&&i<b.l;i++)
	if (s[a.p+i]!=s[b.p+i]) return s[a.p+i]<s[b.p+i];
	if (a.l!=b.l) return a.l<b.l;
	return a.p<b.p;
}

bool operator !=(const aa &x,const aa &y) 
{
	if (x.l!=y.l) return true;
	for (int i=0;i<x.l;i++) if (s[x.p+i]!=s[y.p+i]) return true;
	return false;
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%d",&k);
	
	int num=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=k;j++) if (i+j-1<=n) t[++num]=(aa){i,j};
	sort(t+1,t+num+1,cmp);
	
	//for (int i=1;i<=num;i++) printf("%d %d\n",t[i].p,t[i].l);
	
	for (int i=1;i<=num;i++) 
	if (t[i]!=t[i-1]) 
	{
		k--;
		if (!k)
		{
			aa g=t[i];
			for (int i=0;i<g.l;i++) printf("%c",s[i+g.p]);
			return 0;
		}
	}
	
	
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  cout << (n/2) * ((n+1)/2) << endl;
}



Measured memory_bytes: 256
/**
 * C - gacha
 * https://atcoder.jp/contests/abc164/tasks/abc164_c
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    // くじ引きを N 回行い、i 回目には種類が文字列 Siで表される景品を手に入れました。
    // 何種類の景品を手に入れましたか？
    int N;
    cin >> N;
    
    map<string, bool> mp;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        mp[S] = true;
    }

    cout << mp.size() << endl;
}
 

Measured memory_bytes: 19084
/* ***********************************************
Author        :devil
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
#define inf 0x3f3f3f3f
#define LL long long
#define rep(a,b) for(int i=a;i<=b;i++)
#define dec(a,b) for(int i=a;i>=b;i--)
#define ou(a) printf("%d\n",a)
#define pb push_back
#define mkp make_pair
template<class T>inline void rd(T &x){char c=getchar();x=0;while(!isdigit(c))c=getchar();while(isdigit(c)){x=x*10+c-'0';c=getchar();}}
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
using namespace std;
const int mod=1e9+7;
const int N=2e3+10;
int n,x,a[N],mi[N][N];
LL ans;
int main()
{
    rd(n),rd(x);
    rep(1,n) rd(a[i]);
    for(int i=1;i<=n;i++)
    {
        mi[i][i]=a[i];
        ans+=a[i];
        for(int j=i+1;j<=n;j++) mi[i][j]=min(a[j],mi[i][j-1]);
    }
    for(int l=1;l<n;l++)
    {
        LL now=(LL)l*x;
        for(int i=1;i<=n;i++)
        {
            if(i>l) now+=mi[i-l][i];
            else now+=min(mi[1][i],mi[i+n-l][n]);
        }
        ans=min(ans,now);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	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;
	}

	// for prime MOD
	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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
vll ht;
vll bg;


ll ans(ll N, ll X) {
	//cout << N << X << endl;

	if (N == 0) {
		if (X == 0) { return 0; }
		if (X == 1) { return 1; }
	}

	
	if (X <= 1) { return 0; }
	if (X <= 1 + ht[N-1]) { return ans(N - 1, X - 1); }

	
	if (X <= ht[N - 1] + 2 + ht[N - 1]) { return bg[N - 1] +1+ ans(N - 1, X - ht[N - 1] - 2); }
	return bg[N];

}

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

	cout << 50 << endl;
	ll x = K / 50;
	ll y = K % 50;

	vll a(50, 50-y-1);
	rep(i, y)a[i] = 50;
	rep(i, 50)a[i] += x;

	rep(i, 50)cout << a[i] << " ";
	cout << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    int t;
    cin>>t;
    int ac=0,tle=0,wa=0,re=0;
    while(t--)
    {
        string s;
        cin>>s;
        if(s=="AC")
            ac++;
        if(s=="TLE")
            tle++;
        if(s=="WA")
            wa++;
        if(s=="RE")
            re++;
    }
    cout<<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 10960
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, k = wi()
v = wi()
v = deque(v)
pq = []
po = 0
cnt = 0
qwerty = min(n + 1, k + 1)
for i in range(qwerty):
    if i != 0:
        heappush(pq, v[i - 1])
    for j in range(qwerty - i):
        if j != 0:
            heappush(pq, v[-j])
        while k - i - j - cnt > 0:
            if pq != []:
                po = 0
                po = heappop(pq)
                if po < 0:
                    cnt += 1
                    tmpli.append(po)
                else:
                    heappush(pq, po)
                    cnt = 0
                    break
            else:
                break
        cnt = 0
        ans = max(ans, sum(pq))
        for bb in tmpli:
            heappush(pq, bb)
        tmpli = []
    pq = []
    for g in range(i + 1):
        if g != 0:
            heappush(pq, v[g - 1])

print(ans)

Measured memory_bytes: 78424
n, m, l = gets.split(" ").map(&:to_i)

mA = Array.new(n){Array.new(m){0}}
mB = Array.new(m){Array.new(l){0}}
for i in 0..n-1 do
  mA[i] = gets.split(" ").map(&:to_i)
end
for i in 0..m-1 do
  mB[i] = gets.split(" ").map(&:to_i)
end

for i in 0..n-1 do
  for j in 0..l-1 do
    sum = 0;
    for k in 0..m-1 do
      sum += mA[i][k] * mB[k][j]
    end
    printf "%d", sum
    printf " " if j < l-1
  end
  printf "\n"
end

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;

int main()
{
    long long n;
    cin>>n;
    long long h[n+1],dp[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin>>h[i];
    }
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for (int i = 3; i <= n; ++i)
    {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
package main

import "fmt"

func abs(x int) (y int){
  if x < 0{
    y = -x
  }else{
    y = x
  }
  return
}

func main(){
  var x, a, b int
  fmt.Scan(&x, &a, &b)
  if abs(x-a) < abs(x-b){
    fmt.Println("A")
  }else{
    fmt.Println("B")
  }
}


Measured memory_bytes: 512
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll N,M;cin>>N>>M;
    map<ll,ll> A;
    for(int i=0;i<N;i++){
        int x;cin>>x;
        A[x]++;
    }
    map<ll,ll> B;
    for(int i=0;i<M;i++){
        int y,z;cin>>y>>z;
        B[z] += y;
    }

/*    cout << endl;
    for(auto j=A.begin();j!=A.end();++j){
        cout << j->first << " " << j->second << endl;
    }
    cout << endl;
    for(auto j=B.begin();j!=B.end();++j){
        cout << j->first << " " << j->second << endl;
    }
*/
    auto i = A.begin();
    for(auto j=B.rbegin();j!=B.rend();++j){
        while(j->second!=0){
            if(i->first>=j->first) break;
            if(j->second>=i->second){
                B[j->first] -= i->second;
                A[j->first] += i->second;
                A.erase(A.begin());
                i = A.begin();
            }else{
                A[i->first] -= j->second;
                A[j->first] += j->second;
                B[j->first] = 0;
            }
        }
/*        cout << endl;
        for(auto j=A.begin();j!=A.end();++j){
            cout << j->first << " " << j->second << endl;
        }       
        cout << endl;
        for(auto j=B.begin();j!=B.end();++j){
            cout << j->first << " " << j->second << endl;
        }
        cout << endl;*/     
    }

    ll ans = 0;
    for(auto j=A.begin();j!=A.end();++j){
        ans += j->first * j->second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
typedef long long ll;

ll n, a;
ll x[55];
ll dp[55][55][55 * 55];
ll solve(ll sum, ll card, ll i);

int main()
{
	scanf("%lld %lld", &n, &a);
	for (ll i = 0; i < n; i++) {
		scanf("%lld", &x[i]);
	}

	for (ll i = 0; i < 55; i++) {
		for (ll j = 0; j < 55; j++) {
			for (ll k = 0; k < 55 * 55; k++) {
				dp[i][j][k] = -1;
			}
		}
	}

	printf("%lld\n", solve(0, 0, 0));

	return 0;
}

ll solve(ll sum, ll card, ll i)
{
	if (dp[i][card][sum] != -1) {
		return dp[i][card][sum];
	}

	if (i >= n && sum == card * a && card > 0) {
		return dp[i][card][sum] = 1;
	} else if (i >= n) {
		return dp[i][card][sum] = 0;
	}

	return dp[i][card][sum] = solve(sum + x[i], card + 1, i + 1) + 
		solve(sum, card, i + 1);
}


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

#define fr(i,a) for( i=0;i<a;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end());
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back

typedef long  ll;


int main()
{
    ll j,l,r,f=LONG_MAX, s = LONG_MAX ,i;
    cin>>l>>r;
    if((l-1)/2019!=r/2019){
        cout<<0<<endl;
    }
    else {
          l%=2019;
          r%=2019;
          ll ans=2018;
    for(i=l;i<=r;i++){
            for(j = i+1;j<=r;j++){
                ans = min(ans,(i*j)%2019);
            }
        }
    cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    x = int(input())

    for i in range(x, 100004):
        if is_prime(i):
            print(i)
            exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl;
#define coYES cout << "YES" << endl;
#define coyes cout << "yes" << endl;
#define coNo cout << "No" << endl;
#define coNO cout << "NO" << endl;
#define cono cout << "no" << endl;
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    ll x,sum=0;
    cin >> x;
    ll c500=x/500;
    ll left=x%500;
    left/=5;
    cout << c500*1000+left*5 << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int lb=-1,ub=10,mid; char res; string ask;
    while(ub-lb>1){
        mid=(ub+lb)>>1;
        cout << "? " << (int)pow(10,mid) << endl;
        cin >> res;
        (res=='Y'?lb:ub)=mid;
    }
    int digit=ub;
    lb=0,ub=11;
    while(ub-lb>1){
        mid=(ub+lb)>>1;
        cout << "? " << (int)pow(10,mid)-1 << endl;
        cin >> res;
        (res=='Y'?ub:lb)=mid;
    }
    if (digit==10&&ub!=10) digit=ub;
    vector<int> ans(digit);
    rep(i,digit){
        lb=(i?-1:0),ub=10;
        while(ub-lb>1){
            mid=(ub+lb)>>1;
            string ask="? ";
            rep(j,i) ask+=(char)(ans[j]+'0');
            ask+=(char)(mid+'0');
            if (i==digit-1) ask+='0';
            cout << ask << endl;
            cin >> res;
            ((i<digit-1&&res=='Y')||(i==digit-1&&res!='Y')?lb:ub)=mid;
        }
        ans[i]=(i<digit-1?lb:ub);
    }
    string ret="! ";
    rep(i,digit) ret+=(char)(ans[i]+'0');
    cout << ret << endl;
}

Measured memory_bytes: 596
N, A, B = list(map(int, input().split()))
ans = ""
# if N == A + B:
#     ans = A   #ans = len(A)とする必要ない
# elif N < (A + B) and N >= A:
#     ans = A
# elif N < (A + B) and N < A:
#     ans = N
x = N // (A + B)
ans1 = A * x
y = N - (A + B) * x
if y >= A:
    ans = A + ans1
elif y < A:
    ans = y + ans1
print(ans)
"""
y < (A + B)を条件に含める必要はない。yは余り部分だから必ずA+Bより小さい

"""

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  ll a[5];
  for(int i = 0; i < 5; i++) cin>>a[i];
  sort(a,a+5);
  ll k;
  if(n%a[0]!=0) k = n/a[0]+1;
  else k = n/a[0];
  cout<<k+4<<endl;
  return 0;
}


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

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (b == 1) {
        cout << 0 << endl;
    }
    else {
        cout << a-b << endl;
    }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;

}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);

}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);

  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right ==NIL) y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 1000;

bool used[SIZE];

int main()
{
	fastInp;

	ll n, k;
	cin >> n >> k;
	vector<ll> perm(n), vec(n);
	for (int i = 0; i < n; i++) {
		cin >> perm[i];
		perm[i]--;
	}
	ll ans = INT64_MIN;
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
		ans = max(ans, vec[i]);
	}


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

		ll v = perm[i];
		vector<ll> c;
		c.push_back(i);

		while (v != i) {
			used[v] = 1;
			c.push_back(v);
			v = perm[v];
		}

		ll s = 0;
		for (int i = 0; i < c.size(); i++) {
			ll cur = c[i];
			s += vec[cur];
		}

		for (int t = 0; t < c.size(); t++) {
			ll snd = 0;
			ll v = c[t];
			for (int j = 0; j < min(ll(c.size()), k); j++) {
				ll curC = s * ((k - j) / ll(c.size()));
				if (((k - j) / ll(c.size())) != 0) ans = max(ans, snd + curC);
				if (j > 0) ans = max(ans, snd);
				snd += vec[v];
				v = perm[v];
				curC = s * ((k - j - 1) / ll(c.size()));
				ans = max(ans, snd + curC);
				ans = max(ans, snd);
			}

		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3852
#include<stdio.h>

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

Measured memory_bytes: 1708
function main(s){
    return s.split('').map((e,i,s)=> i<s.length-2 ? Math.abs(753-(s[i]+s[i+1]+s[i+2])|0) :1000).reduce((a,b) => a>b ? b : a);
}
console.log(main(require('fs').readFileSync('/dev/stdin','utf8')));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
  int N,K;

  cin >> N >> K;
  vector <ll> data(N);
  vector<ll> ave(N+1);
  ave.at(0)=0;
  rep(i,0,N) cin >> data[i];
  rep(i,0,N){
      ave.at(i+1) = ave.at(i)+data[i]+1;
  }
  
  ll maxim=0;
  rep(i,0,N+1-K){
      maxim = max(maxim,ave.at(i+K)-ave.at(i));
  }
  //cout << (double)(maxim)/2<< endl;
  cout << fixed << setprecision(10) << (double)(maxim)/2 << endl;
  
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n);
	map<int, int> mp;
	for (int i = 1; i <= arr[n - 1] + 10; i++)
		mp[i] = 1;
	for (int i = 0; i < n; i++)
	{
		if (i >= 1 && arr[i] == arr[i - 1])
			mp[arr[i]] = 0;

		for (int j = 2; arr[i]*j <= arr[n - 1]; j++)
		{
			mp[arr[i]*j] = 0;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		if (mp[arr[i]] == 1)
			c++;
	}
	cout << c;
	return 0;
}


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

int main() {

  int N, K, i, A = 0;
  cin >> N >> K;
  for(i = 0;i < N; i++){
    int x;
    cin >> x;
    if(x < K - x){
      A = A + 2 * x;
    }
    else{
      A = A + 2 * (K - x);
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
#define F first
#define S second
#define RE register
#define random(x) (rand()%x)
#define LOG(a,b) (log(a)/log(b))
#define N 200005
#define mod 998244353
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3fll
int n,tot=0,a[N],hd[N],t[N<<1],nxt[N<<1],ans[N],dp[N];
inline void add(int u,int v){
	t[++tot]=v;
	nxt[tot]=hd[u];
	hd[u]=tot;
}
inline void dfs(int u,int fa,int len){
	int v,l=0,r=len,mid,tdp;
	while(l<=r){
		mid=l+r>>1;
		if(a[u]>dp[mid]) l=mid+1;
		else r=mid-1;
	}
	//printf("%d:%d %d\n",u,l,r);
	if(l>len) ++len;
	tdp=dp[l];
	dp[l]=a[u];
	ans[u]=len;
	for(int i=hd[u];i;i=nxt[i]){
		v=t[i];
		if(v==fa) continue;
		dfs(v,u,len);
	}
	dp[l]=tdp;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;++i){
		printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 23448
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int n, m, x;
vector<int> c;
vector<vector<int>> a;
ll res = inf;

void dfs(string f) {
	if (sz(f) == n) {
		ll sum[15] = {};
		ll yen = 0;
		rep(i, n) {
			if (f[i] == '0') continue;
			rep(j, m) {
				sum[j] += a[i][j];
			}
			yen += c[i];
		}
		bool ok = true;
		rep(j, m) {
			if (sum[j] < x) {
				ok = false;
			}
		}
		if (ok) {
			chmin(res, yen);
		}
		
		return;
	}

	dfs(f + "0");
	dfs(f + "1");
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> n >> m >> x;

	c.resize(n);
	a.resize(n, vector<int>(m));

	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}

	dfs("");

	if (res != inf) out(res);
	else out(-1);

	return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();
		long ans=0;
		if(a+b<2*c){
			ans+=(a+b)*Math.min(x,y);
		}else{
			ans+=2*c*Math.min(x,y);
		}
		if(x>y){
			ans+=(x-y)*Math.min(2*c,a);
		}else{
			ans+=(y-x)*Math.min(2*c,b);
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 21844
from sys import stdin
from itertools import accumulate
readline = stdin.readline

N, W = map(int, input().split())
vs = [[] for _ in range(4)]
w, v = map(int, input().split())
w1 = w
vs[0].append(v)
for _ in range(N - 1):
    w, v = map(int, input().split())
    vs[w - w1].append(v)

for i in range(4):
    vs[i].sort(reverse=True)
    vs[i] = [0] + list(accumulate(vs[i]))

result = 0
for i in range(len(vs[0])):
    a = W - w1 * i
    if a < 0:
        break
    for j in range(len(vs[1])):
        b = a - (w1 + 1) * j
        if b < 0:
            break
        for k in range(len(vs[2])):
            c = b - (w1 + 2) * k
            if c < 0:
                break
            t = vs[0][i] + vs[1][j] + vs[2][k]
            for l in range(len(vs[3])):
                d = c - (w1 + 3) * l
                if d < 0:
                    break
                result = max(result, t + vs[3][l])
print(result)


Measured memory_bytes: 9272
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
a.append(10**10)
c.append(10**10)
a = [-1] + a
c = [-1] + c
ans = 0
for i in range(len(b)):
    al = 0
    ar = n+1
    while True:
        am = (al+ar)//2
        if a[am] < b[i]:
            al = am
        else:
            ar = am
        an = al
        if al+1 == ar:
            break
    cl = 0
    cr = n+1
    while True:
        cm = (cl+cr)//2
        if c[cm] <= b[i]:
            cl = cm
        else:
            cr = cm
        cn = n - (cr-1)
        if cl+1 == cr:
            break
    ans += an*cn
print(ans)


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

#define ff              first
#define ss              second
#define endl            "\n"
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi              acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	int tt = 1;
	// cin >> tt;
	while (tt--)
	{
		string s, t;
		cin >> s >> t;
		int n = s.length(), m = t.length();
		int dp[n + 1][m + 1];
		int choice[n + 1][m + 1];
		memset(dp, 0, sizeof(dp));
		memset(choice, 0, sizeof(choice));
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				dp[i][j] = dp[i - 1][j];
				choice[i][j] = 1;
				if (dp[i][j - 1] > dp[i][j])
				{
					dp[i][j] = dp[i][j - 1];
					choice[i][j] = 2;
				}
				if (s[i - 1] == t[j - 1])
				{
					if (dp[i - 1][j - 1] + 1 > dp[i][j])
					{
						dp[i][j] = dp[i - 1][j - 1] + 1;
						choice[i][j] = 3;
					}
				}
			}
		}
		string ans = "";
		int row = n, col = m;
		while (row && col)
		{
			if (choice[row][col] == 1)
			{
				row--;
			}
			else if (choice[row][col] == 2)
			{
				col--;
			}
			else
			{
				ans += s[row - 1];
				row--;
				col--;
			}
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
	return 0;
}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    ll n;
    std::cin >> n;
    VEC(ll,a,5);
    sort(all(a));
    std::cout << 4+(n+a[0]-1)/a[0] << std::endl;
}

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

int main()
{
    string s; cin >> s;
    if(s[0] == s[1]) cout << "Bad" << endl;
    else if(s[1] == s[2]) cout << "Bad" << endl;
    else if(s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

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

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,a,b,c;
	cin>>n>>a>>b>>c;

	vector<string> s;
	string si;
	for(int i=0;i<n;i++)
	{
		cin>>si;
		s.push_back(si);
	}

	if(a+b+c==0)
		cout<<"No \n";
	else if(a+b+c==1)
	{
		bool ctr=1;
		string res;
		
		for(int i=0;i<n;i++)
		{
			if(s[i]=="AB"&&(a==0&&b==0))
			{
				ctr=0;
				break;
			}
			else if(s[i]=="AB"){
				if(a==1)
				{
					a=0;
					b=1;
					res.push_back('B');
				}
				else{
					a=1;
					b=0;
					res.push_back('A');
				}
			}

			if(s[i]=="AC"&&(a==0&&c==0))
			{
				ctr=0;
				break;
			}
			else if(s[i]=="AC"){
				if(a==1)
				{
					a=0;
					c=1;
					res.push_back('C');
				}
				else{
					a=1;
					c=0;
					res.push_back('A');
				}
			}

			if(s[i]=="BC"&&(c==0&&b==0))
			{
				ctr=0;
				break;
			}
			else if(s[i]=="BC"){
				if(b==1)
				{
					b=0;
					c=1;
					res.push_back('C');
				}
				else{
					c=0;
					b=1;
					res.push_back('B');
				}
			}
		}
		if(ctr)
		{
			cout<<"Yes \n";
			for(auto it:res)
				cout<<it<<"\n";
		}
		else cout<<"No \n";
	}
	else{
		bool ct=1;
		if(s[0]=="AB"&&(a==0&&b==0))
			ct=0;
		if(s[0]=="AC"&&(a==0&&c==0))
			ct=0;
		if(s[0]=="BC"&&(b==0&&c==0))
			ct=0;
			
		if(ct==0)
		{
			cout<<"No \n";
		}
		else{
		
		cout<<"Yes \n";
		string res;
		for(int i=0;i<n;i++)
		{
			string sin=s[i];

			if(sin=="AB")
			{
				if(a<b)
				{
					a++;
					b--;
					res.push_back('A');
				}
				else if(b<a){
					b++;
					a--;
					res.push_back('B');
				}
				else{
					if(s[i+1]==sin)
					{
						res.push_back('B');
						res.push_back('A');
						i++;
					}
					else if(s[i+1]=="BC")
					{
						b++;
						a--;
						res.push_back('B');
					}
					else{
						a++;
						b--;
						res.push_back('A');
					}
				}
			}
			if(sin=="AC")
			{
	
				if(a<c)
				{
					a++;
					c--;
					res.push_back('A');
				}
				else if(c<a){
					c++;
					a--;
					res.push_back('C');
				}
				else{
					if(s[i+1]==sin)
					{
						res.push_back('C');
						res.push_back('A');
						i++;
					}
					else if(s[i+1]=="BC")
					{
						c++;
						a--;
						res.push_back('C');
					}
					else{
						a++;
						c--;
						res.push_back('A');
					}
				}
			}

			if(sin=="BC")
			{
				if(c<b)
				{
					c++;
					b--;
					res.push_back('C');
				}
				else if(b<c){
					b++;
					c--;
					res.push_back('B');
				}
				else{
					if(s[i+1]==sin)
					{
						res.push_back('C');
						res.push_back('B');
						i++;
					}
					else if(s[i+1]=="AC")
					{
						c++;
						b--;
						res.push_back('C');
					}
					else{
						b++;
						c--;
						res.push_back('B');
					}
				}				
			}			
		}

		for(auto it:res)
			cout<<it<<"\n";
		}
	}

	return 0;
}

Measured memory_bytes: 7420
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define rep(i,st,end)   for(int i=st;i<end;i++)
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void s_g_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	s_g_c();
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int max = 0;
	int height = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] <= max)
		{
			height += (max - a[i]);
		}
		else
			max = a[i];
	}
	cout << height << endl;
	return 0;
}

Measured memory_bytes: 5212