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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;


int res(vector<int>&v,int k){
    vector<int>dp(v.size()+1,INT_MAX);
    dp[0]=0;
    dp[1]=abs(v[0]-v[1]);
    for(int i=2;i<v.size();i++){
       for(int j=1;j<=k;j++){
            if(i<j)
               break;
            dp[i] = min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
       }    
    }
    return dp[v.size()-1];
}
void solve(){
    int x,k;
    cin>>x>>k;
    vector<int>v(x);
    for(int i=0;i<x;i++){
        cin>>v[i];
    }
    cout<<res(v,k);
}

int main(){
    std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
  return 0;
}


Measured memory_bytes: 1024
n,m,k,*x=map(int,open(0).read().split())
s=sum(x[:n])
z=i=j=n
while~i:
	while j<n+m and s+x[j]<=k:s+=x[j];j+=1
	if s<=k:z=max(z,i+j)
	i-=1
	s-=x[i]
print(z-n)

Measured memory_bytes: 55288
#include<iostream>
using namespace std;
int n,m=0,a[40],b[40],c[41];
void solve(int l,int r){
  if(l>r)return;
  int x=a[m++];
  solve(l,c[x]-1);
  solve(c[x]+1,r);
  cout<<x<<(x==a[0]?"\n":" ");
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i],c[b[i]]=i;
  solve(0,n-1);
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int X, Y;
  cin >> X >> Y;

  rep(i,X+1){
    int a = 2 * i;
    int b = 4 * (X-i);

    if(a+b==Y){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3640
import scala.io.Source.stdin

object Main extends App {
  stdin.getLines.foreach { s =>
    val n = s.split(" ").map(_.toInt)
    if((1 to 10).filter( i => i!=n(0) && i!=n(1) && i!=n(2) ).count( _ <= 20-(n(0)+n(1)) ) >= 4)
      println("YES")
    else
      println("NO")
  }
}

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

int main() {
	int n,m;
	cin>>n>>m;
	if(n<m){
	    for(int i=0;i<m;i++)cout<<n;
	}
	else
	  for(int i=0;i<n;i++)cout<<m;
	  
	return 0;
}


Measured memory_bytes: 3552
H, W = map(int,input().split())
G = [input() for k in range(H)]
yoko = [[0 for k in range(W)] for k in range(H)]
tate = [[0 for k in range(W)] for k in range(H)]


for h in range(H):
    t = 0
    s = 0
    for w in range(W):
        if G[h][w] == ".":
            t += 1
        else:
            if t > 0:
                for k in range(s,w):
                    yoko[h][k] = t
            s = w+1
            t = 0
    if t > 0:
        for k in range(s,W):
            yoko[h][k] = t


for w in range(W):
    t = 0
    s = 0
    for h in range(H):
        if G[h][w] == ".":
            t += 1
        else:
            if t > 0:
                for k in range(s,h):
                    tate[k][w] = t
            s = h+1
            t = 0
    if t > 0:
        for k in range(s,H):
            tate[k][w] = t

ans = 0
for w in range(W):
    for h in range(H):
        ans = max(ans,tate[h][w]+yoko[h][w]-1)
print(ans)


Measured memory_bytes: 126424
P, Q, R = map(int, input().split())

ans = float('inf')
ans = min(ans, P + Q)
ans = min(ans, R + Q)
ans = min(ans, P + R)
ans = min(ans, Q + R)
ans = min(ans, Q + P)
ans = min(ans, Q + P)

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;

int gcd( int m, int n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int main(void){

int l1,l2;
int gc,lc;
char mz;
	while(cin >> l1 >> l2){
		gc = gcd(l1,l2);
		lc = lcm(l1,l2);
		cout << gc << " " << lc << endl;
	}	
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<map>
using namespace std;
int n, K, L;
int p1[200200], p2[200200];
map<pair<int, int>, int> sz;
int root(int* p, int x)
{
	return p[x] == x ? x : p[x] = root(p, p[x]);
}
int main()
{
	scanf("%d%d%d", &n, &K, &L);
	for (int i = 1; i <= n; i++) {
		p1[i] = p2[i] = i;
	}
	for (int i = 1; i <= K; i++)
	{
		int p, q;
		scanf("%d%d", &p, &q);
		p1[root(p1, p)] = root(p1, q);
	}
	for (int i = 1; i <= L; i++)
	{
		int p, q;
		scanf("%d%d", &p, &q);
		p2[root(p2, p)] = root(p2, q);
	}
	for (int i = 1; i <= n; i++)
	{
		auto key = make_pair(root(p1, i), root(p2, i));
		auto it = sz.find(key);
		if (it == sz.end()) sz[key] = 1;
		else it->second++;
	}
	for (int i = 1; i <= n; i++)
	{
		auto key = make_pair(root(p1, i), root(p2, i));
		printf("%d%c", sz[key], i == n ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 10752
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int n;
  cin>>n;
  int a;
  int o=0;
  int e=0;
  rep(i,n){
    cin>>a;
    if(a%2)o++;
    else e++;
  }
  cout<<(o?"first":"second")<<endl;
}


Measured memory_bytes: 888
MODE = "stdiro"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '147 105'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
def gcd(x,y)
  x,y=[x,y].sort
  while y>0
    r=x%y
    x=y
    y=r
  end
  return x
end
  
x,y = line[0].split(" ").map(&:to_i)

puts gcd(x,y)

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

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

   if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BComparison {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string a, b;
	    in >> a >> b;

	    if(a.length() < b.length()){
	        out << "LESS" << endl;
	        return;
	    }else if(a.length() > b.length()){
	        out << "GREATER" << endl;
	        return;
	    }else{
	        if(a > b) out << "GREATER" << endl;
	        else if(a < b) out << "LESS" << endl;
	        else out << "EQUAL" << endl;
	    }
	}
};


int main() {
	BComparison solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include<bits/stdc++.h>
#define N 200005
#define p 1000000007
using namespace std;

inline void rd(int &X){
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X;
}

int n,c[N],pre[N],v[N],f[N];

signed main(){
    rd(n);
    for(int i=1;i<=n;i++)
        rd(c[i]),pre[i]=v[c[i]],v[c[i]]=i;
    f[0]=1;
    for(int i=1;i<=n;i++){
        f[i]=f[i-1];
        if(pre[i] and pre[i]!=i-1) (f[i]+=f[pre[i]])%=p;
    }
    cout<<f[n];
}


Measured memory_bytes: 3328
n = int(input())
a_array = [int(x) for x in input().split()]
ans_array = [0 for x in range(n)]
for index in reversed(range(1, n + 1)):
    if index > n // 2:
        ans_array[index - 1] = a_array[index - 1]
    elif index - 1 != 0:
        tmp = sum([ans_array[x] for x in range(index * 2 - 1, n, index) if ans_array[x] != 0]) % 2
        if tmp == a_array[index - 1]:
            pass
        else:
            ans_array[index - 1] = 1

    else:
        tmp = sum([x for x in ans_array[1:] if x != 0]) % 2
        if tmp == a_array[index - 1]:
            pass
        else:
            # tmpが0だったら1、1だったら0になるように
            ans_array[index - 1] = 1
print(sum([x for x in ans_array if x != 0]))
for index, ans in enumerate(ans_array, 1):
    if ans != 0:
        print(index)


Measured memory_bytes: 9148
from collections import Counter

MOD = 2019
S = input()[::-1]
n = 0
x = 1
c = Counter()
ans = 0

for s in S:
    c[n] += 1
    n += int(s) * x
    n %= MOD
    ans += c[n]
    x = x * 10 % MOD
    
print(ans)

Measured memory_bytes: 9684
//======================================
//author @Amit Singh : global_const
//======================================

#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
template <class Key, class T, class Compare, class Alloc>
  bool operator== ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );
template <class Key, class T, class Compare, class Alloc>
  bool operator!= ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );
template <class Key, class T, class Compare, class Alloc>
  bool operator<  ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );	
template <class Key, class T, class Compare, class Alloc>
  bool operator<= ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );
template <class Key, class T, class Compare, class Alloc>
  bool operator>  ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );	
template <class Key, class T, class Compare, class Alloc>
  bool operator>= ( const map<Key,T,Compare,Alloc>& lhs,const map<Key,T,Compare,Alloc>& rhs );
#define yeah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define loop(i,n) for(int i=0;i<n;++i)
#define pii pair<int,int>
#define mp make_pair
signed main()
{ yeah;
  double a,b;
  cin>>a>>b;
  printf("%.f\n",floor(a*b));
}

Measured memory_bytes: 3764
while 1:
        n,r = map(int, raw_input().split())
        if n == 0 and r == 0: break
        lib = range(n, 0, -1)
        #print lib
        for i in xrange(r):
                temp = []
                p,c = map(int, raw_input().split())
                for j in xrange(c):
                        temp.append(lib.pop(p-1))
                lib = temp + lib
                #print lib
        print lib[0]

Measured memory_bytes: 4224
#include"bits/stdc++.h"
#define ll long long
#define inf 1e9
using namespace  std;

int main(){

	ll n;
	cin>>n;

	ll h[n];

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

	

	vector<ll> dp(n,inf);

	dp[0]=0;

	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<=i+2;j++){
			if(j<n){
				dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
			}
		}
	}

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

	return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n, d;
	cin >> n >> d;
	int ans = 0;
	for(int i = 0;i < n;i++){
		int a, b;
		cin >> a >> b;
		if(a*a + b*b <= d*d){
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
int n, m, x, y, z;
vector<pair<int, int> > a[2020];
vector<int> b[2020];
vector<int> c[2020];
int d[2020], w[4020];
int st[2020], ed[2020];
bool v[2020];
bool dfs(int x, int y, int t, vector<int> &b) {
	if (x == t) {
		return true;
	}
	for (auto i: a[x]) {
		if (i.X != y) {
			b.push_back(i.Y);
			if (dfs(i.X, x, t, b)) {
				return true;
			}
			b.pop_back();
		}
	}
	return false;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &x, &y);
		a[x].push_back({y, 2 * i});
		a[y].push_back({x, 2 * i + 1});
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &st[i], &ed[i]);
		dfs(st[i], 0, ed[i], b[i]);
		for (int j: b[i]) {
			c[j / 2].push_back(i);
			d[j / 2]++;
		}
	}
	for (int i = 1; i < n; i++) {
		z += min(d[i], 2);
	}
	while (true) {
		int p = 0, q = -1; // p = choose edge, q = choose path
		for (int i = 1; i < n; i++) {
			if (d[i] == 1 && w[i * 2] != w[i * 2 + 1]) {
				p = i;
				break;
			}
		}
		if (p == 0) {
			for (int i = 1; i < n; i++) {
				if (d[i] >= 2) {
					p = i;
					break;
				}
			}
		}
		if (p == 0) {
			break;
		}
		for (int i: c[p]) {
			if (!v[i]) {
				q = i;
				break;
			}
		}
		v[q] = true;
		for (int i: b[q]) {
			if (i / 2 == p) {
				if (w[i]) {
					swap(st[q], ed[q]);
					for (int &j: b[q]) {
						j ^= 1;
					}
				}
				for (int &j: b[q]) {
					d[j / 2]--;
					w[j] = 1;
				}
				break;
			}
		}
	}
	printf("%d\n", z);
	for (int i = 0; i < m; i++) {
		printf("%d %d\n", st[i], ed[i]);
	}
	return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>
using namespace std;

void convert(string& n) {
    for (int i = 0; i < n.size(); i++) {
        switch (n[i]) {
            case '1': case '2': case '3':
                break;
            case '4':
                n[i] = '5'; 
                break;
            case '5': case '6': case '7':
                n[i] = n[i] + 2;
                break;
        }
    }
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        ostringstream ss;
        ss << oct << n;
        string ns = ss.str();
        convert(ns);
        cout << ns << endl;
    }
    return 0;
}

Measured memory_bytes: 936
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    if(s.equals("AAA")||s.equals("BBB")){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 23636
#include<stdio.h>
int main(void)
{
  int a[10],b[10],i,m1,m2,j,c;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<10;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<10;i++){
   for(j=9;j>i;j--){
     if(a[j-1]>a[j]){
       c=a[j];
       a[j]=a[j-1];
       a[j-1]=c;
     }
     if(b[j-1]>b[j]){
       c=b[j];
       b[j]=b[j-1];
       b[j-1]=c;
     }
  }
  }

  printf("%d %d\n",a[9]+a[8]+a[7],b[9]+b[8]+b[7]);
  return 0;
}
 

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

int main(){
  int N,HP;
  cin >> N;
  int d[N];
  for(int i = 0;i < N;i++){
    cin >> d[i];
  }
  for(int s = 0;s < N;s++){
    for(int t = s + 1;t < N;t++){
      HP += (d[s] * d[t]);
    }
  }
  cout << HP << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define N 100000

struct P{
  char name[100];
  int num;
};

int head, tail, n, c=0, q;
struct P Q[N];
void enqueue(){

  Q[head].num=(Q[head].num)-q;
  Q[tail] = Q[head];

  if(tail > n+1){tail = 0;}
  else tail++;
}

void dequeue(){
  printf("%s %d\n",Q[head].name, Q[head].num+c);
}

int main(){
  int i;

  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].num);
  }
  head = 1;
  tail = n+1;
  i = 1;

  while(head != tail){
    if(Q[head].num > q){
      enqueue();
      c+=q;
    }
    else{
      dequeue();
      c+=Q[head].num;
    }
    if(head>n+1){head = 0;}
    else head++;
  }
  return 0;
}


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

int main(void){
    int N, Abuf;
    multiset<int> Aset;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        multiset<int>::iterator AbufinAset = Aset.lower_bound(Abuf);
        if(AbufinAset != Aset.begin())Aset.erase(--AbufinAset);
        Aset.insert(Abuf);
    }

    cout << Aset.size() << endl;

    return 0;
}

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

int map[101][101];
int w,h; 
int color;
int xg,yg;

bool dfs(int y,int x) {
  if ( map[y][x] != color ) return 0;
  map[y][x] = 10;
  bool f=0;
  if ( y-1 >= 1 ) f|=dfs( y-1 , x );
  
  if ( y+1 <= h ) f|=dfs( y+1 , x );
  if ( x-1 >= 1 ) f|=dfs( y , x-1 );
  if ( x+1 <= w ) f|=dfs( y , x+1 );
  
  if ( y==yg && x==xg ) return 1; 
  return f;

}

int main() {
  while ( cin >> w >> h ,w+h ) {
    for(int i=1; i<=h; i++) {
      for(int j=1; j<=w; j++) map[i][j]=0;
    }
    int xs,ys; cin >> xs >> ys;
    cin >> xg >> yg;
    int n; cin >> n;
    while ( n > 0 ) {
      n--;
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if ( d == 1 ) {

	for ( int i = y; i < y+4; i++ ) {
	  for ( int j = x; j < x+2; j++ ) map[i][j] = c;
	}
      
      } else if ( d == 0 ) {
	for ( int i = y; i < y+2; i++ ) {
	  for ( int j = x; j < x+4; j++ ) map[i][j] = c;
	}
      }
      
    }
    color = map[ys][xs];
    if ( dfs(ys,xs) ) cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

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

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if (s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main(void) {
  char s[4];
  char a, b;
  scanf("%s", s);
  a = s[0];
  if(s[1] == a) {
    if (s[2] == s[3] && s[2] != a) {
      printf("Yes\n");
      return 0;
    }
    else {
      printf("No\n");
      return 0;
    }
  }
  else {
    b = s[1];
    if(s[2] == a) {
      if(s[3] == b) {
        printf("Yes\n");
        return 0;
      }
      else {
        printf("No\n");
        return 0;
      }
    }
    else if(s[2] == b) {
      if(s[3] == a) {
        printf("Yes\n");
        return 0;
      }
    }
    else {
      printf("No\n");
      return 0;
    }
  }
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc = new Scanner(System.in);
		List<Integer> list = new ArrayList<Integer>();
		int a, i=0, judge;
		while ((judge=sc.nextInt())>0){
			for (int j=1; j<judge+1; j++){
				list.add(a = sc.nextInt());
				i++;
			}
			Collections.sort(list);
			Collections.reverse(list);
			int sum = 0;
			for (int k=1; k<i-1; k++){
				sum = sum+list.get(k);
			}
			System.out.println((sum/(i-2)));
			i=0;
			list.clear();
		}
			
	}
	
}

Measured memory_bytes: 29044
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t 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 { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];

    ll ans =0;
    rep(i,n){
        ans+=a[i]-1;
    }

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

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int a,b,c,d[15],e[15][15],tot[15],ans = 0x7fffffff;
bool flag;
bool check(int c) 
{
    for(int i=1;i<=b;i++) 
	{
        if(tot[i]<c) 
		{
            return false;
        }
    }
    return true;
}

void dfs(int kkk,int temp) 
{
    if(temp>=ans) 
	{
        return;
    }
    if(kkk>a) 
	{
        if(check(c)) 
		{
            flag=true;
            ans=min(ans,temp);
        }
        return;
    }
    dfs(kkk+1,temp);
    for(int i=1;i<=b;i++) 
	{
        tot[i]+=e[kkk][i];
    }
    dfs(kkk+1,temp+d[kkk]);
    for (int i=1;i<=b;i++) 
	{
        tot[i]-=e[kkk][i];
    }
}

int main() 
{
    cin>>a>>b>>c;
    for(int i=1;i<=a;i++) 
	{
        cin>>d[i];
        for(int j=1;j<=b;j++) 
		{
            cin>>e[i][j];
        }
    }
    dfs(1,0);
    if (flag) 
	{
        cout<<ans;
    } 
	else 
	{
        cout<<-1;
    }
    return 0;
}

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


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


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;

int n;
ll h[MAXN];

void solve() {
  ll maxCnt = 0;
  ll cnt = 0;
  for (int i=0;i<n-1;i++) {
    if (h[i] >= h[i+1]) {
      cnt++;
    } else {
      maxCnt = max(maxCnt, cnt);
      cnt = 0;
    }
  }

  cout << max(maxCnt, cnt) << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> h[i];
  }
  solve();
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;


int main() {

	int n;
	int l[105];


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

	for (int i = 0; i < n-2; i++) {
		for (int j = i+1; j < n-1; j++) {
			for (int k = j + 1; k < n; k++) {
				if ((l[i] == l[j]) ||( l[j] == l[k]) || (l[i] == l[k]))continue;
				if ((l[i] >= (l[j] + l[k]) )|| (l[j] >= (l[i] + l[k]) )|| (l[k] >= (l[i] + l[j])))continue;
				ans++;
			}
		}
	}

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

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=(1<<31)-1;
const double pi=acos(-1);

double a,M=-1,m=inf;

int main(){
	while(cin>>a){
		M=max(M,a);
		m=min(m,a);
	}
	cout<<M-m<<endl;
}

Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<vector>
#define int long long
using namespace std;
vector<int> inv;
const int p=1e9+7;
const int N=2e5+5;
inline int pw(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%p;
		b>>=1;
		a=a*a%p;
	}
	return ans%p;
}
inline int c(int a,int b){
	int ans=1;
	for(int i=a;i>=a-b+1;--i)ans=(ans*i)%p;
	for(int i=b;i>=1;--i)ans=ans*inv[i]%p;
	return (ans%p+p)%p;
}
inline void init(){
    inv.push_back(0), inv.push_back(1);
	for (long long i = 2; i <= N; ++i) {
        int k = (p - p / i) * inv[p % i] % p;
        inv.push_back(k);
    }
}
signed main(){
	init();
	int n,a,b;
	cin>>n>>a>>b;
	int ans=pw(2,n)-1;ans%=p;
	ans-=(c(n,a)+c(n,b))%p;ans%=p;
	ans=(ans+p)%p;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep2(i, 1, n+1) {
    for (int j = i; j <= n; j += i) ans += ll(j);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int Q;
priority_queue<int> L;
priority_queue<int,vector<int>,greater<int>> R;
int q,a,b,ansmin;

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

    cin>>Q;
    cin>>q>>a>>b;
    ansmin+=b;
    L.push(a); R.push(a);

    rep(i,Q-1){
        cin>>q;
        if(q==1){
            cin>>a>>b;
            ansmin+=b;
            if(a>=L.top() and a<=R.top()){
                L.push(a); R.push(a);
            }else if(a>=L.top()){
                ansmin+=a-R.top();
                R.push(a); R.push(a);
            }else{
                ansmin+=L.top()-a;
                L.push(a); L.push(a);
            }
            if(L.size()>R.size()){
                R.push(L.top()); L.pop();
            }
            if(R.size()>L.size()){
                L.push(R.top()); R.pop();
            }
        }else{
            cout<<L.top()<<' '<<ansmin<<endl;
        }
    }

}

Measured memory_bytes: 4588
#include <iostream>
/*2つの整数K,Sに対して x,y,z <= K, x + y + z = S
 * となるようなx,y,zの組み合わせは何通りありますか*/
using namespace std;

int main(){
	int k, s, ans = 0;
	cin >> k >> s;
	if(3 * k >= s){
		for(int x = 0; x <= k; x++){
				for(int y = 0; y <= k;  y++){
					if(s - x - y >= 0 && s - x - y <= k) ans++;
				}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;
const int INF = 1 << 30;

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

    int f = 0;

    int i = 0;
    while (s.begin() + i != s.end()) {
        if (s[i] == '(') f++;
        else {
            if (f == 0) {
                s = '(' + s;
                i++;
            }
            else {
                f--;
            }
        }
        i++;
    }
    if (f > 0) {
        rep(i, f) s += ')';
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

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

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

struct Node{
	int parents, slibing, degree, depth, height, left, right;
	Node(){
		parents = -1;
		slibing = -1;
		degree = -1;
		depth = 0;
		height = 0;
	}
};

struct Tree{
	int size;
	Node *root;
	vector<Node> da;
	Tree() {}
	Tree(int _size) : size(_size){
		da = vector<Node>(size);
		root = nullptr;
	}
	void construct_parents(){
		rip(i,size,0){
			da[da[i].left].parents = i;
			da[da[i].right].parents = i;
		}
	}
	void construct_sibling(){
		rip(i,size,0) if(da[i].parents == -1) continue; else da[i].slibing = da[da[i].parents].left + da[da[i].parents].right - i;
	}
	void construct_degree(){
		rip(i,size,0) da[i].degree = min(da[i].left,0) + min(da[i].right,0) + 2;
	}
	Node *find_root(){
		rip(i,size,0) if(da[i].parents == -1) return &(*this).da[i];
	}
	void output(){
		rip(i,size,0){
			string state;
			if(da[i].parents == -1) state = "root";
			else if(da[i].degree == 0) state = "leaf";
			else state = "internal node";
			printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
			i, da[i].parents, da[i].slibing, da[i].degree, da[i].depth, da[i].height, state.c_str());
		}
	}
	void DFS(){
		if(!bool(root)) root = find_root();
		dfs(*root);
	}
	private : void dfs(Node &now){
		if(now.left >= 0){
			Node &next = da[now.left];
			next.depth = now.depth + 1;
			dfs(next);
			chmax(now.height, next.height + 1);
		}
		if(now.right >= 0){
			Node &next = da[now.right];
			next.depth = now.depth + 1;
			dfs(next);
			chmax(now.height, next.height + 1);
		}
	}
};

int main(){
	int n; cin >> n;
	Tree tr(n);
	rip(i,n,0){
		int id, left, right; cin >> id >> left >> right;
		tr.da[id].left = left;
		tr.da[id].right = right;
	}
	tr.construct_parents();
	tr.construct_sibling();
	tr.construct_degree();
	tr.DFS();
	tr.output();
}


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

int main(){
    ll h,n;
    cin >> h >> n;
    vector<ll> vec(100000001,1000000000);
    vec[0] = 0;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<h;j++){
            vec[j+a[i]]=min(vec[j+a[i]],vec[j]+b[i]);
        }
    }
    ll ans=1000000000;
    for(ll i=h;i<10000000;i++){
        ans=min(ans,vec[i]);
    }
    cout << ans << endl;
    
    return 0;
}









Measured memory_bytes: 781568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final long C = sc.nextLong();

		long[] sushiPos = new long[N];
		long[] sushiCal = new long[N];
		long[] accCal = new long[N];

		long sum = 0;

		long[] calLeft = new long[N];
		long[] calLeftRev = new long[N];
		long[] calRight = new long[N];
		long[] calRightRev = new long[N];

		for (int i = 0; i < N; i++) {
			sushiPos[i] = sc.nextLong();
			sushiCal[i] = sc.nextLong();
			sum += sushiCal[i];
			accCal[i] = sum;
			calLeft[i] = sum - sushiPos[i];
			long tmp = Math.max(sum - (sushiPos[i] * 2), 0);
			calRightRev[i] = (i == 0) ? tmp : Math.max(tmp, calRightRev[i - 1]);
		}

		sum = 0;
		for (int j = 0; j < N; j++) {
			int i = (N - j - 1);
			sum += sushiCal[i];
			calRight[i] = sum - (C - sushiPos[i]);
			long tmp = Math.max(sum - ((C - sushiPos[i]) * 2), 0);
			calLeftRev[i] = (j == 0) ? tmp : Math.max(tmp, calLeftRev[i + 1]);
		}

		long maxCal1 = 0;
		for (int i = 0; i < N; i++) {
			maxCal1 = Math.max(maxCal1, calLeft[i] + (i == (N - 1) ? 0 : calLeftRev[i + 1]));
		}

		long maxCal2 = 0;

		for (int j = N-1; j >=0; j--) {
			maxCal2 = Math.max(maxCal2, calRight[j] + (j == 0 ? 0 : calRightRev[j - 1]));
		}

		System.out.println(Math.max(maxCal1, maxCal2));
		sc.close();
	}

}


Measured memory_bytes: 99760
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[100005];
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		
		if (s[i] == 'B') {
			int j = i - 1;
			while (s[j]=='B'&&j>0) {
				j--;
			}
			s[j] = 'B';
		}
	}
	for (int i = 0; i < s.size(); i++) {
		if ( s[i] != 'B') {
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N;
int64_t A[200000];
std::map<int64_t, int64_t> num;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		in >> A[i];
		num[A[i]] += 1;
	}
	std::sort(A, A + N);

	int64_t B = 1 << 30;
	int64_t res = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		if (B == 1) { break; }
		if (num[A[i]] == 0) { continue; }
		while (B / 2 > A[i]) {
			B /= 2;
		}
		if (B - A[i] == A[i]) {
			if (num[(A[i])] >= 2) {
				++res;
				--num[A[i]];
				--num[B - A[i]];
			}
		}
		else if (num.count(B - A[i]) && num[(B - A[i])]) {
			++res;
			--num[A[i]];
			--num[B - A[i]];
		}
	}
	out << res << endl;

	return 0;
}
#endif


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

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

	ll n,W;
	cin>>n>>W;
	ll weg[n];
	ll val[n];
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>weg[i]>>val[i];
		sum+=val[i];
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, 1000000000));
	dp[0][0]=0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= sum; j++) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			if (j >= val[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - val[i]] + weg[i]);
		}
	}
	/*
	for(int i=0;i<=n;i++){
		for(int j=0;j<=sum;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	//*/
	ll ans=0;
	for(int i=0;i<=sum;i++){
		if(dp[n][i] <= W){
			ans=i;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll a, b;
  cin >> a >> b;
  if(b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 3 * 1e5 + 10;
typedef unsigned long long LL;
int n;
int data[MAXN] = {0};
int main()
{
    scanf("%d" , &n);
    n *= 3;
    for(int i = 0 ; i < n ; ++i)
        scanf("%d" , data + i);
    sort(data , data + n);
    int l = 0 , r = n - 2;
    LL ans = 0;
    int pos = 0;
    n /= 3;
    while(pos < n)
    {
        ans += data[r];
        r -= 2;
        ++pos;
    }
    printf("%lld" , ans);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int b=0,a=0;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    } 
    sort(A.begin(), A.end(), greater<int>());
    for (int i = 0; i < N; i++){
        if(i%2==0){
            a+=A.at(i);
        }else b+=A.at(i);
    }
    
    cout << a-b << endl;
}

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

using namespace std;

#define inf  -(1e9 + 5)

template<typename t>
void self_max(t& a, t b){
	a = max(a, b);
}

bool check(pair<int, int> a){
	return a.first==0 || a.second==0;
}

int main(){
	string a, b, s;
	cin>>a>>b;
	vector<vector<pair<int, pair<int, int>>>> dp((int)a.length()+1, vector<pair<int, pair<int, int>>>((int)b.length()+1, {inf, {0, 0}}));
	dp[0][0] = {0, {0, 0}};
	for(int i=0; i<(int)a.length(); i++){
		for(int j=0; j<(int)b.length(); j++){
			if(a[i] == b[j]){
				self_max(dp[i+1][j+1], make_pair(dp[i][j].first+1, make_pair(i, j)));
				
			}
			self_max(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i, j)));
			self_max(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i, j)));
		}
		
	}
	
	pair<int, pair<int, int>> ans = make_pair(0, make_pair(0, 0));
	
	for(int i=0; i<=(int)a.length(); i++){
		for(int j=0; j<=(int)b.length(); j++){
			self_max(ans, make_pair(dp[i][j].first, make_pair(i, j)));
		}
	}
	
	
	auto cur = ans.second;
	int i, j;
	while(!check(cur)){
		i = cur.first;
		j = cur.second;
	    auto prev = dp[i][j].second;
		if(prev == make_pair(i-1, j-1)){
			s +=a[i-1];
		}
		cur = prev;
	}
	reverse(begin(s), end(s));
	
	std::cout<<s;
}

Measured memory_bytes: 108032
#include<iostream>
using namespace std;
int main () {
   int H;
   int W;
while (1){
  cin >> H;
  cin >> W;
  if(H==0 && W==0) break;
  for (int i=1;i<=H;++i){
    for(int p=1;p<=W;++p){
      cout << '#'; 
    }
    cout << endl;
  }
  cout << endl;
} 
  return 0;
}



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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
 
const int MAX = 510000;
const int MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  ll d = pow(10, 9) + 7;
  COMinit();
  int r = N - K;
  for (int i = 1; i <= K; i++) {
    if (r + 1 < i) {
      cout << 0 << "\n";
    } else {
      ll t = r - i + 1;
      if (i == 1) {
        cout << r + 1 << "\n";
      } else {
        ll a = COM(K - 1, i - 1);
        ll k = r - (i - 1);
        ll b = COM(k + i, k) * a;
        b %= d;
        cout << b << "\n";
      }
    }
  }
  return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,M;
    cin >> N >> M;
    vector<ll> A(N),G(N+1);
    map<ll,ll> amari;
    rep(i,N){
        cin >> A[i];
        G[i+1] = G[i] + A[i];
        amari[G[i+1]%M]++;
    }
    amari[0]++;
    ll ans = 0;
    rep(i,N+1){
        if(amari[G[i]%M]>0){
            ans += amari[G[i]%M]*(amari[G[i]%M]-1)/2;
            amari[G[i]%M]=0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=2e3+5,mod=1e9+7,bit=61;

ll dp[N][N],n;
pll a[N];

ll solve(ll x,ll l,ll r)
{
    if(x>n)
    {
        return 0;
    }
    ll &ans=dp[x][l];
    if(ans!=-1)
    {
        return ans;
    }
    ans=max(abs(l-a[x].ss)*a[x].ff+solve(x+1,l+1,r),abs(r-a[x].ss)*a[x].ff+solve(x+1,l,r-1));
    return ans;
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        f(i,1,n)
        {
            cin>>a[i].ff;
            a[i].ss=i;
        }
        memset(dp,-1,sizeof(dp));
        sort(a+1,a+n+1,greater<pll>());
        cout<<solve(1,1,n)<<endl;
    }
    return 0;
}


















Measured memory_bytes: 35176
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
max_loop = min(k, n)

for left in range(max_loop + 1):
    for right in range(max_loop - left + 1):
        tmp = v[:left] + v[n-right:]
        m = sorted(filter(lambda x: x< 0, tmp))[:k - left - right]
        ans = max(ans, sum(tmp) - sum(m))
print(ans)


Measured memory_bytes: 3060
program prob1
    implicit none
    integer :: n, k
    integer :: ans, i
    integer, allocatable :: h(:)
    ans = 0
    read(*,*) n, k
    allocate(h(N))

    read(*,*) h

    do i = 1, n
        if(h(i) >= k) then
            ans = ans + 1
        end if
    end do
    write(*,*) ans

    stop
contains
end program prob1

Measured memory_bytes: 3132
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = n << 1; i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140148
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  int count = 0;
  bool d = false;

  cin >> N;
  rep(i, N)
  {
    int a, b;
    cin >> a >> b;
    if (a == b)
      count++;
    else
      count = 0;
    if (count >= 3)
      d = true;
  }

  if (d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3620
unittest
{
	assert( [ "100", "1" ].parse.expand.solve == 19 );
	assert( [ "25", "2" ].parse.expand.solve == 14 );
	assert( [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "3" ].parse.expand.solve == 117879300 );
	
	assert( [ "99", "3" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).array;
	input.popFront;
	auto k = input.front.to!( long );
	return tuple( n, k );
}

auto solve( long[] n, long k )
{
	return memoize!solve2( n, k, true );
}

long solve2( long[] n, long k, bool z )
{
	auto ans = 0L;
	foreach( i; 0L .. n.length.signed )
	{
		if( z )
		{
			if( n[ i ] == 0 ) continue;
			if( k == 1 ) ans += n[ i ];
			else         ans += ( n[ i ] - 1 ) * memoize!solve2( n[ i + 1 .. $ ], k - 1, false ) + memoize!solve2( n[ i + 1 .. $ ], k - 1, true );
		}
		else
		{
			if( k == 1 ) ans += 9;
			else         ans += 9 * memoize!solve2( n[ i + 1 .. $ ], k - 1, false );
		}
		z = false;
	}
	return ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,a[N],b[N],c[N];
bool solve(int k)
{
    int t=1<<k;
    for(int i=1;i<=n;i++) c[i]=b[i]%(2*t);
    sort(c+1,c+1+n);
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        int x=a[i]%(2*t);
        int l=lower_bound(c+1,c+1+n,t-x)-c;
        int r=lower_bound(c+1,c+1+n,2*t-x)-c-1;
        if(l<=r)
            flag^=(r-l+1)&1;
        l=lower_bound(c+1,c+1+n,3*t-x)-c;
        r=lower_bound(c+1,c+1+n,4*t-x)-c-1;
        if(l<=r)
            flag^=(r-l+1)&1;
    }
    return flag;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    int ans=0;
    for(int i=0;i<=30;i++)
        if(solve(i))
        ans|=1<<i;
    printf("%d\n",ans);
}


Measured memory_bytes: 2560