akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


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

	int ans = 1;
	for (int i=2; i<=X; i++) {
		int res = i;
		while (res<=X) {
			res*=i;
			if (res<=X) {
				ans = max(ans, res);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 1000000007;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
bool saw[100000];
vector<int> d[100000];
vector<int> v[100000];

int dfs(int x){
    int ret = 0;
    saw[x] = true;
    rep(i,v[x].size()){
        if(saw[v[x][i]]) continue;
        int z = dfs(v[x][i]);
        if(d[x].size() < 2) d[x].push_back(z);
        else{
            if(z > d[x][1]) d[x][1] = z;
        }
        if(d[x].size() == 2 && d[x][0] < d[x][1]) swap(d[x][0],d[x][1]);
        ret = max(ret,d[x][0]);
    }
    return ret+1;
}

void dfs2(int x){
    saw[x] = true;
    rep(i,v[x].size()){
        if(!saw[v[x][i]]) continue;
        int dep;
        if(d[x].size() != 0) dep = d[x][0];
        else dep = 0;
        if(1+dep != d[v[x][i]][0]){
            d[x].push_back(d[v[x][i]][0]+1);
        } else{
            if(d[v[x][i]].size() == 1) d[x].push_back(1);
            else d[x].push_back(d[v[x][i]][1]+1);
        }
    }
    sort(d[x].begin(),d[x].end(),greater<int>());
    rep(i,v[x].size()){
        if(saw[v[x][i]]) continue;
        dfs2(v[x][i]);
    }
}

int main(){
    cin >> n;
    rep(i,n-1){
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0);
    rep(i,n) sort(d[i].begin(),d[i].end(),greater<int>());
    rep(i,n) saw[i] = false;
    dfs2(0);
    rep(i,n) printf("%d\n",(n-1)*2-d[i][0]);
}

Measured memory_bytes: 20088
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

require 'prime'

N = get_int

count = 0

1.step(N) do |i|
  x = N / i
  count += i * (x * (x + 1)) / 2
end

puts count


Measured memory_bytes: 14564
n = int(input())
s = input()
ans = 0
for i in range(1000):
    count = 0
    index = 0
    i = str(i)
    if len(i) < 2:
        i = "00"+i
    elif len(i) < 3:
        i = "0"+i
    for j in i:
        for k in range(index, n):
            if j == s[k]:
                index = k+1
                count += 1
                break
    if count == 3:
        ans += 1
print(ans)

Measured memory_bytes: 43100
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
med_1 = q[n//2-1]
med_2 = q[n//2]

for i in range(n):
    if p[i] == med_1:
        print(med_2)
    elif p[i] == med_2:
        print(med_1)
    elif p[i] < med_1:
        print(med_2)
    else:
        print(med_1)


Measured memory_bytes: 26772
var
  a,i:longint;
  s,t:string[32];
begin
  t := 'CODEFESTIVAL2016';
  readln(s);
  a := 0;
  for i:=1 to length(s) do
  if s[i] <> t[i] then a:=a+1;
  write(a);
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long

using namespace std;


int main()
{
    ll n,ans,t;
    cin>>n;
    n--;
    cin>>ans;
    while(n--)
    {
        cin>>t;
        ll g= __gcd(ans,t);
        ans=(ans/g)*t;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
dic={")":"(","]":"["}
while True:
    s=raw_input()
    if s==".":break
    ST=[]
    flag=True
    for i in s:
        if i=="(" or i=="[":
            ST.append(i)
        elif i in dic:
            if len(ST)>0 and ST[-1]==dic[i]:
                ST.pop()
            else:
                flag=False
                break
    print "yes" if flag and len(ST)==0 else "no"

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

char chris[10] = "Christmas\0";
char eve[5] = " Eve\0";

int main()
{
	int day = 0;
	scanf("%d",&day);
	switch(day) {
	case 25:
		printf("%s\n",chris);
		break;
	case 24:
		printf("%s%s\n",chris,eve);
		break;
	case 23:
		printf("%s%s%s\n",chris,eve,eve);
		break;
	case 22:
	default:
		printf("%s%s%s%s\n",chris,eve,eve,eve);
		break;
	}
	return 0;
}

Measured memory_bytes: 128
/**
 * Created by hiramekun at 20:53 on 2020-05-02.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */


void solve() {
    ll n, m, q;
    cin >> n >> m >> q;
    vl a(q), b(q), c(q), d(q);
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }

    ll ans = 0;
    auto rec = [&](auto &&f, ll now, vl &nums) -> void {
        if (nums.size() == n) {
            ll tmp = 0;
            rep(i, q) {
                if (nums[b[i]] - nums[a[i]] == c[i]) tmp += d[i];
            }
            ans = max(tmp, ans);
            return;
        }
        for (ll i = now; i <= m; ++i) {
            nums.eb(i);
            f(f, i, nums);
            nums.pop_back();
        }
    };
    vl v;
    rec(rec, 1, v);
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3644
using System;

class main
{
    static void Main(string[] args)
    {
        string s;
        int f = 90, f2 = 0;
        double x = 0, y = 0;
        while ((s = Console.ReadLine()) != null)
        {
            string[] d = s.Split(',');
            if (d[0] == "0" && d[1] == "0")
            {
                break;
            }
            int m = int.Parse(d[0]);
            int n = int.Parse(d[1]);
            x += (Math.Cos(f * (Math.PI / 180)) * m);
            y += (Math.Cos(f2 * (Math.PI / 180)) * m);
            f -= n;
            f2 += n;
        }
        Console.WriteLine((int)x);
        Console.WriteLine((int)y);
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
const int INF = 1e9;

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

	ll L, R;
	ll ans = 0;

	cin >> L >> R;

	ll a = L % 2019;
	ll b = R % 2019;
	ll min = INF;
	ll tmp = 0;
	if (R - L >= 2019) {
		// contain 0
		ans = 0;
	}
	else {
		rep(i, R-L+1) {
			rep2(j, i+1, R-L+1) {
				tmp = (((a + i) % 2019) * ((a + j) % 2019))%2019;
				if (tmp < min) min = tmp;
			}
		}
		ans = min;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int res = t;
		int c = 0;
		while(res % 360 != 0) {
			res += t;
			c++;
		}
		System.out.println(c+1);
	}
}

Measured memory_bytes: 35624
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}


int main()
{

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

     sum%=mod;

     sum*=sum;
     sum%=mod;

     ll is=0;

     for(int i=0;i<n;i++) is+= arr[i]*arr[i],is%=mod;


     ll ans=sum-is;
     ans+=mod;
     ans%=mod;


     ll fin=powmod(2LL,mod-2);

     ans=(ans%mod)*(fin%mod);
     ans%=mod;
     cout<<ans<<endl;











	return 0;
}


Measured memory_bytes: 5200
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int A,B;

signed main(){
	cin>>A>>B;
	cout<<A*B<<endl;
	return 0;
}


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

using namespace std;

constexpr int N = 1e5 + 10;

long long n, q, a, ps[N], cnt[N], tool;
vector <long long> v;

inline int bin (int b, int e) {
    if (b + 1 == e)
        return b;
    int mid = (b + e) >> 1;
    if (v[mid] < tool)
        return bin (mid, e);
    return bin (b, mid);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    v.push_back (n);
    for (int i = 0; i < q; i++) {
        cin >> a;
        while ((int)v.size() && v.back() >= a)
            v.pop_back();
        v.push_back (a);
    }
    cnt[(int)v.size() - 1] = 1;
    for (int i = (int)v.size() - 1; i; i--) {
        tool = v[i];
        int p = (int)v.size(), x;
        while (tool) {
            if (tool < v[0]) {
                ps[1] += cnt[i];
                ps[tool + 1] -= cnt[i];
                break;
            }
            p = bin (0, (int)v.size());
            cnt[p] += cnt[i] * (tool / v[p]);
            tool %= v[p];
        }
    }
    ps[1] += cnt[0];
    ps[v[0] + 1] -= cnt[0];
    for (int i = 1; i <= n; i++) {
        ps[i] += ps[i - 1];
        cout << ps[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<string, int> mp;
    REP(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int m;
    cin >> m;
    REP(i,m) {
        string s;
        cin >> s;
        mp[s]--;
    }
    int ans=0;
    for ( auto p:mp ) {
        chmax(ans, p.second);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long long int i, h, b=0, c=0;
    
    scanf("%ld", &h);

    for( i = 0; h > 0; i++ ){
        h /= 2;
        c++;
    }
    
    for( i = 0; i < c; i++ ){
       b = 2*b + 1; 
    }
    
    printf("%lld\n", b);
    return 0;
        
}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

ll modInv(ll vl, ll pw = MOD-2){
    ll rs = 1;
    while( pw ){
        if( pw&1 )
            rs = ( rs * vl )%MOD;
        vl = ( vl * vl )%MOD;
        pw = pw>>1;
    }

    return rs;
}

int main(){

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

    ll num = 1, cur = 1;
    while( cur < k ){
        num = ( num*cur )%MOD;
        cur++;
    }

    ll iden = modInv(num);
    vector<ll> minv(n+1);
    for(int i = 1; i <= n; i++)
        minv[i] = modInv(i);

    sort(arr.begin(), arr.end());
    ll add = 0, sub = 0;
    for(ll r = k-1, l = 1, s = n-k; r < n; r++, l++, s--){
        add = ( add + (arr[r]*((num*iden) %MOD))%MOD )%MOD;
        sub = ( sub + (arr[s]*((num*iden) %MOD))%MOD )%MOD;
        num = ( num * (r+1) )%MOD;
        num = ( num * minv[l])%MOD;
    }
    
    ll res = add-sub;
    res = res+MOD;
    res = res%MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, t, a;
  cin >> n >> t >> a;
  double ans=1000;
  vector<pair<double,ll>> h;
  rep(i,n){
    double x;
    cin >> x;
    x = t - x * 0.006;
    double y = abs(a - x);
    h.pb(mp(y, i + 1));
  }
  sort(all(h));
  print(h[0].S);
}

Measured memory_bytes: 256
N, x = map(int, input().split())
if x==1 or x==2*N-1:
    print("No")
else:
    print("Yes")
    res = [0]*(2*N-1)
    res[N-2]=1
    res[N-1]=x
    res[N]=2*N-1
    k=1
    for i in range(2*N-1):
        if i not in {N-2,N-1,N}:
            while k in {1,x,2*N-1}:
                k+=1
            res[i] = k
            k += 1
    print(*res, sep="\n")

Measured memory_bytes: 82776
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		char[] c = S.toCharArray();
		for(int i = 0; i < 3; i++) {
			if(c[i] == c[i+1]) {
				System.out.println("Bad");
				System.exit(0);
			}
		}
		System.out.println("Good");

	}

}

Measured memory_bytes: 23124
N,A,B=list(map(int,input().split(" ")))
sumn=0 # 求める総和

# 1以上N以下の数について
for i in range(1,N+1):
    sumi=sum(list(map(int,list(str(i))))) # 各桁の総和を求める

    if A<=sumi<=B: # 総和が範囲内なら
        sumn+=i

print(sumn)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>

typedef long long int64;

int main(void) {
  std::string s;
  std::cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 998244353;

int main() {
  int N;cin >> N;
  vint A(N);
  int sum=0;
  bitset<2000*2000+1> dp(1);
  repeat(i,N){
     cin >> A[i];
     sum += A[i];
     dp |= dp<<A[i];
  }
  int ans = 0;
  for(int i=(sum+1)/2;i<=sum;i++){
    if(dp[i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#define IsDigit(x) ((x) >= '0' && (x) <= '9')
#define LowBit(x) ((x) & -(x))
using namespace std;

int n, m;
int tree[100002];
struct Interval{
	int l, r;
	Interval() {}
	Interval(int x, int y)
		: l(x), r(y)
	{}
	bool operator<(const Interval &x) const{ return r - l < x.r - x.l; }
}sou[300000];


int Read(void)
{
	int c, ret(0);
	
	c = getchar();
	while (!IsDigit(c))
		c = getchar();
	do
		ret = ret * 10 + c - '0';
	while ((c = getchar()) && IsDigit(c));
	return ret;
}


void Add(const int val, int pos)
{
	while (pos <= m + 1) {
		tree[pos] += val;
		pos += LowBit(pos);
	}
	return;
}


int Sum(int pos)
{
	int ret(0);
	
	while (pos) {
		ret += tree[pos];
		pos -= LowBit(pos);
	}
	return ret;
}


int main()
{
	int l, r, pos(0), ans;
	
	n = Read();
	m = Read();
	for (int i = 0; i < n; ++i) {
		l = Read();
		r = Read();
		sou[i] = Interval(l, r);
	}
	sort(sou, sou + n);
	for (int step = 1; step <= m; ++step) {
		while (pos < n && sou[pos].r - sou[pos].l + 1 < step) {
			Add(1, sou[pos].l);
			Add(-1, sou[pos].r + 1);
			++pos;
		}
		ans = n - pos;
		for (int i = step; i <= m; i += step)
			ans += Sum(i);
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 3712
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if ((n | m) == 0)
                break;
            int[] ds = new int[n + 1];
            ds[0] = 0;
            for (int i = 1; i <= n; i++) {
                ds[i] = sc.nextInt();
            }
            int[] qs = new int[(n + 1) * n / 2 + n + 1];
            int k = 0;
            for (int i = 0; i <= n; i++) {
                for (int j = i; j <= n; j++) {
                    qs[k++] = ds[i] + ds[j];
                }
            }
            Arrays.sort(qs);
            int max = 0;
            for (int i = 0; i < qs.length; i++) {
                int lb = 0;
                int ub = qs.length - 1;
                while (ub - lb > 1) {
                    int mid = (lb + ub) / 2;
                    if (qs[i] + qs[mid] <= m) {
                        lb = mid;
                    } else {
                        ub = mid;
                    }
                }
                if (qs[i] + qs[lb] <= m)
                    max = Math.max(max, qs[i] + qs[lb]);
            }
            System.out.println(max);
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 14000
n = input()
n = int(n)
a = input().split()
a = [int(aa) for aa in a]
 
ans = 10000000000000000
 
l = -100000000000
r =  100000000000
 
for count in range(100):
    mid = (l + r) // 2
    temp = 0
    for i in range(n):
        temp1= abs(a[i] - (mid + i + 1))
        temp2= abs(a[i] - ((mid - 1) + i + 1))
        temp += temp1 - temp2
    if temp > 0:
        r = mid
    else:
        l = mid
for b in range(l, r + 1):
    temp = 0
    for i in range(n):
        temp += abs(a[i] - (b + i + 1))
    ans = min(ans, temp)
print(ans)

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

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

class BBreakNumber {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;

        int max_cnt = 0;
        int ans = 1;
        for (int i = 1; i <= N; ++i) {
            int cnt = 0;
            int current = i;
            while (current % 2 == 0) {
                current /= 2;
                ++cnt;
                if (cnt > max_cnt) {
                    max_cnt = cnt;
                    ans = i;
                }
            }
        }

        out << ans;
    }
};


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


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
stack<ll> tmp;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A, B; cin >> N >> A >> B;
  if(B < (N + A - 1) / A || B > N - (A - 1)) {
    cout << -1 << endl;
    return 0;
  }
  if(A == N && B == 1) {
    FOR(i, 0, N) cout << i + 1 << " ";
  } else if(A == 1 && B == N) {
    FOR(i, 0, N) cout << N - i << " ";
  } else {
    for(int b = B; b > 0; b--) cout << b << " ";
    int cntMax = (N - B) / (A - 1);
    int cnt = 0;
    int up = (N - B) % (A - 1); /// up個は+1
    FOR(b,B+1,N+1) {
      tmp.push(b);
      cnt++;
      if(cnt == cntMax + (up > 0 ? 1 : 0)) {
        while(!tmp.empty()) {
          cout << tmp.top() << " ";
          tmp.pop();
        }
        cnt = 0;
        up--;
      }
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll h,w;
	cin>>h>>w;
	if (h==1||w==1){
		cout<<1<<endl;
		return 0;
	}
	if (w%2==0){
		cout<<(w/2)*h<<endl;
	} else {
		ll wm = ((w+1)/2);
		ll wl = ((w-1)/2);
		if (h%2==0){
			cout<<wm*(h/2)+wl*(h/2)<<endl;
		} else {
			cout<<wm*(h+1)/2+wl*(h-1)/2<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<int> prime;
vector<int> ls;

void sieve(int N){
    prime.resize(N+1,1);
    prime[0] = prime[1] = 0;
    for(int i=2;i*i<=N;i++){
        for(int j=i*i;j<=N;j+=i){
            prime[j] = 0;
        }
    }
    for(int i=2;i<=N;i++){
        if(prime[i])ls.push_back(i);
    }
}

int main() {
    sieve(int(1e5));
    int n;
    while(cin >> n, n){
        int cnt = 0;
        for(int i=0;ls[i]*2<=n;i++){
            if(prime[n-ls[i]]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int A[n][m];
    int b[m];

    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for (int j=0;j<m;j++){
        cin >> b[j];
    }

    for (int i=0;i<n;i++){
        int S = 0;
        for (int j=0;j<m;j++){
            S += A[i][j] * b[j];
        }
        cout << S << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>
main(void){
   
  int a,b,c,x,y,z;
   
  scanf("%d%d%d",&a,&b,&c);
   
  if(a > b){ 
    x = a;
    a = b;
    b = x;
  }
   
  if(b > c){
    y = b;
    b = c;
    c = y;
  }
   
  if(a > b){
    z = a;
    a = b;
    b = z;
  }
   
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n, m; cin>>n>>m;
    vector<int> cnt(m, 0);
    for(int i=0; i<n; i++){
        int k; cin>>k;
        for(int j=0; j<k; j++){
            int a; cin>>a;
            a--;
            cnt[a]++;
        }
    }

    int ans=0;
    for(int i=0; i<m; i++){
        if(cnt[i]==n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
pairs = []
for i in range(m):
  pair = list(map(int,input().split()))
  pairs.append(pair)
answer = {}
count = 0
for j in range(1,n+1):
  count = 0
  for k in range(m):
    if pairs[k][0] == j or pairs[k][1] == j:
      count += 1
  print(count)

Measured memory_bytes: 3060
N,M = [int(i) for i in input().split()]
food = list();
for i in range(M):
	food.append(0)
for i in range(N):
	a = list(map(int,input().split()));
	for j in range(a[0]):
		food[a[j+1]-1] += 1
ans = 0
for i in range(M):
	if food[i]==N:
		ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,W;
  cin >> N >> W;
  vector<pair<long long,long long>> wv(N);
  for(int i = 0; i < N; ++i) cin >> wv[i].first >> wv[i].second;
  vector<long long> val(W+1);
  for(int i = 0; i < N; ++i){
    for(int w = W-wv[i].first; w >= 0; --w){
      val[w+wv[i].first] = max(val[w+wv[i].first],val[w]+wv[i].second);
    }
  }
  cout << *max_element(begin(val),end(val));
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
vector<ll> par;


int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll tmp = N / (A + B);
	ll a = tmp * A;
	ll b = N % (A + B);
	if (0 < b - A) {
		a += A;
	}
	else {
		a += b;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#define MAX_N 100000
using namespace std;

//要素数はN個
int par[MAX_N];
int ufrank[MAX_N];

void init(int n)
{
    for (int i = 0; i < n; ++i)
    {
        par[i] = i;
        ufrank[i] = 0;
    }
}

//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;

    if (ufrank[x] < ufrank[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (ufrank[x] == ufrank[y])
            ufrank[x]++;
    }
}

//xとyが同じ集合に属するか調べる
bool same(int x, int y)
{
    return find(x) == find(y);
}


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

    vector<int> v(n);
    for (int i = 0; i < n;++i){
        cin >> v[i];
    }
    init(n + 1);
    int x, y;
    for (int i = 0; i < m; ++i)
    {
        cin >> x >> y;
        unite(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if(same(i+1,v[i])){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1536
import heapq
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]
for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(-r)

m = 0
heap = []
for i in range(M):
    for a in jobs[i]:
        heapq.heappush(heap, a)
    if len(heap) > 0:
        b = heapq.heappop(heap)
        m += -b
print(m)

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

int main() {
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> ab(n-1);
    for (auto& e : ab) cin >> e.first >> e.second;
    vector<pair<int, int>> px(q);
    for (auto& e : px) cin >> e.first >> e.second;

    vector<vector<int>> c(n+1);
    for (auto e : ab) {
        c[e.first].push_back(e.second);
        c[e.second].push_back(e.first);
    }

    vector<bool> visited(n+1, false);
    vector<int> values(n+1, 0);
    for (auto e : px) values[e.first] += e.second;
    queue<int> nexts;
    nexts.push(1);
    while (!nexts.empty()) {
        int next = nexts.front(); nexts.pop();
        for (auto e : c[next]) {
            if (!visited[e]) {
                values[e] += values[next];
                nexts.push(e);
            }
        }
        visited[next] = true;
    }

    for (int i = 1; i <= n; i++) cout << values[i] << " ";
}


Measured memory_bytes: 18676
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  ll N;
  while (cin >> N) {
    if (N == 0) {
      cout << "0" << endl;
      continue;
    }
    string res = "";
    while (N != 0) {
      int r = (N % 2 + 2) % 2;
      if (r == 0) {
        res += '0';
      } else {
        res += '1';
        N -= 1;
      }
      N /= -2;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
integer(8)::a(9)=(/1,2,4,7,12,20,29,38,52/),f(10)=0
read(*,*) n
f(3)=1
do i=4,n
 f(i)=f(i-1)*(a(i-2)+a(i-3)+1)
enddo
do i=1,n
 do j=1,n
  write(*,*) merge(0_8,f(max(i,j))*a(min(i,j))+1,i==j)
 enddo
enddo
end

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int index = K - 1;
	if (S[index] == 'A'){
		S[index] = 'a';
	} else if (S[index] == 'B') {
		S[index] = 'b';
	}else if (S[index] == 'C') {
		S[index] = 'c';
	}


	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int[] hw;
    static char[,] map;
    static int h;
    static int w;

    static void Main()
    {
        hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        h = hw[0];
        w = hw[1];

        map = new char[h, w];
        for(int i = 0; i < h; i++)
        {
            string s = Console.ReadLine();
            for(int j = 0; j < w; j++)
            {
                map[i, j] = s[j];
            }
        }

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if(map[i, j] == '#')
                {
                    if (!Dfs(i, j))
                    {
                        Console.WriteLine("No");
                        return;
                    };
                }
            }
        }
        Console.WriteLine("Yes");
        return;
    }

    static Boolean Dfs(int y, int x)
    {
        int[] dx = { -1, 1, 0, 0 };
        int[] dy = { 0, 0, -1, 1 };
        Boolean isPaintable = false;
        map[y, x] = '.';


        for (int i = 0; i < 4; i++)
        {
            int ny = y + dx[i];
            int nx = x + dy[i];

            if (ny >= 0 && nx >= 0 && ny < h && nx < w && map[ny, nx] == '#')
            {
                Dfs(ny, nx);
                isPaintable = true;
            }
        }
        return isPaintable;
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 26;

int largest(int a, int b){
	return (a<b)?b:a;
}


int main() {
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); ++i){
		cout << 'x';
	}
	cout << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
M = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [0] + [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)
    print(*sndf[i][1:])

Measured memory_bytes: 7768
# coding: utf-8
# Here your code !
N=int(input().rstrip())
K=int(input().rstrip())
xi=map(int,input().rstrip().split())

idoSum=0

for x in xi:
    roboA=x*2
    roboB=abs(K-x)*2
    idoSum+=( roboB if( roboB < roboA) else roboA )
print(idoSum,flush=True)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#define sq(a) ((a)*(a))
#define INFTY (1<<30)
using namespace std;
int main(){
	while(true){
		int ans = INFTY;
		int s[4];
		int a,b;
		scanf("%d%d", &a, &b);
		if( a==0 && b==0 ) break;
		for(int i = 1; i <= a; ++i){
			if( a % i == 0 ){
				for(int j = 1; j <= b; ++j){
					if( b % j == 0 ){
						s[0] = i;
						s[1] = a / i;
						s[2] = j;
						s[3] = b / j;
						sort(s, s+4);
						int sum = sq(s[3]-s[2])+sq(s[2]-s[1])+sq(s[1]-s[0]);
						/*for(int k = 0; k < 4; ++k){
							for(int l = 0; l < 4; ++l){
								if( k == l )continue;
								for(int m = 0; m < 4; ++m){
									if( l == m || k == m ) continue;
									for(int n = 0; n < 4; ++n){
										if( l == n || k == n || m == n )continue;
										int sum = sq(s[k]-s[l]) + sq(s[l]-s[m]) + sq(s[m]-s[n]);
										ans = min(ans, sum);
									}
								}
							}
						}*/
						ans = min(ans, sum);
					}
				}
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 876
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[200010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    sort(a+1,a+n+1);
    bool bk=true;
    for(int i=2;i<=n;i++)if(a[i]==a[i-1]){bk=false;break;}
    if(bk==true)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)

ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
ll intpoint(ll x1, ll y1, ll x2, ll y2) { return ( __gcd(abs(x1-x2),abs(y1-y2))+1); }
bool isvalid(ll x,ll y,ll n,ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int pp = uniform_int_distribution<int>(0, kk-1)(rng);
// ---------------------///////////////---------------------------------
// ---------------------///////////////----------------------------------
// -------------/////////////////---------------------------------///////
ll dp[3011][3011];
int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
    ll t,i,j,l,r,q,k,kk,m,n,p;
    
    string s,sp;
    cin>>s>>sp;

    n = s.size();
    m = sp.size();

    // ll dp[n+11][m+11];

    for(i=1;i<=n;i++){
    	for(j=1;j<=m;j++){
    		if(s[i-1] == sp[j-1]){
    			dp[i][j] = max(dp[i-1][j-1]+1,dp[i-1][j]);
    		}else{
    			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    }

    string ans = "";
    i = n;
    j = m;
    while(j!=0&&i!=0){
    	if(dp[i][j] == dp[i-1][j]){
    		i--;
    	}else if(dp[i][j] == dp[i][j-1]){
    		j--;
    	}else{
    		i--;
    		j--;
    		ans.push_back(s[i]);
    	}
    }

    reverse(ans.begin(),ans.end());

    cout<<ans;
    // for(i=n;i>=1;i--){
    // 	for(j=m;j>=1;j--){
    // 		if(dp[i][j] == dp[i-1][j]){

    // 		}
    // 	}
    // }

    // cout<<dp[n][m];

    return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int H,W,M;
int main() {
  cin >> H >> W >> M;
  set<ii> st;
  map<int, int> mpH,mpW;
  rep(i,M) {
    int h,w;cin >> h>>w;
    mpH[h]++;
    mpW[w]++;
    st.insert({h,w});
  }

  int mxH=-1;
  int mxW=-1;
  set<int> hpos, wpos;
  for (auto p: mpH) {
    auto [pos, h] = p;
    if (chmax(mxH, h)) hpos = set<int>();
    if (mxH == h) hpos.insert(pos);
  }
  for (auto p: mpW) {
    auto [pos, w] = p;
    if (chmax(mxW, w)) wpos = set<int>();
    if (mxW == w) wpos.insert(pos);
  }

  int ans = mxH + mxW - 1;
  for (int h: hpos) {
    for (int w: wpos) {
      if (st.find({h,w}) == st.end()) {
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 73920
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  string s;
  cin>>s;
  ll ans=0,ca=0,cb=0,a,b;
  int r=1; rep(i,0,s.size()-1) r*=2;
  rep(i,0,r){
    a=i;
    ca=s[0]-48;
    rep(j,1,s.size()){
      if(a%2==1){
        cb+=ca;
        ca=0;
      }
      ca=10*ca+s[j]-48;
      a/=2;
    }
    ans+=ca+cb;
    ca=0; cb=0;
  }
  co(ans);
      
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
enum color{white,red};
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        char ch;
        cin>>ch;
        if(ch=='R')
        a[i] = 1;
        else
            a[i] = 0;
    }
    int ans = 0;
    int pointer1 = 0,pointer2 = n-1;
    while(pointer1<pointer2)
    {
        if(a[pointer1]==red)
        pointer1++;
        else if(a[pointer2]==white)
        pointer2--;
        else
        {
            swap(a[pointer2],a[pointer1]);
            ans++;
            pointer2--;
            pointer1++;
        } 
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 4396
#include<stdio.h>

int main(void)

{

 int a,b,c;

 int count=0;

 int i;

   scanf("%d %d %d",&a,&b,&c);

   for(i=a;i<=b;i++)

  {

  if(c%i==0) count++;

 }

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

   return 0;

}

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

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> X[i];
	}
	int ans = 1e8;
	rep(i,101)
	{
		int temp = 0;
		rep(j,N)
		{
			temp += (X[j] - i) * (X[j] - i);
		}
		ans = min(ans,temp);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long lint;

const int MAXN = 60;
const int MOD = 1e9+7;
lint dp[MAXN][4][4];

int main() {
  int N;
  cin >> N;
  vector<string> S(2);
  for (int i = 0; i < 2; i++) {
    cin >> S[i];
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < N; ) {
    if (S[0][i] == S[1][i]) {
      // 同じドミノ
      for (int c = 1; c < 4; c++) {
        for (int c1 = 0; c1 < 4; c1++) {
          for (int c2 = 0; c2 < 4; c2++) {
            if (c != c1 && c != c2) {
              dp[i+1][c][c] += dp[i][c1][c2];
              dp[i+1][c][c] %= MOD;
            }
          }
        }
      }
      i++;
    } else {
      // 異なるドミノ
      // dp[i+1] = dp[i] として i は 2 つ進める
      for (int c1 = 1; c1 < 4; c1++) {
        for (int c2 = 1; c2 < 4; c2++) {
          if (c1 == c2) continue;
          for (int c3 = 0; c3 < 4; c3++) {
            for (int c4 = 0; c4 < 4; c4++) {
              if (c1 == c3 || c2 == c4) continue;
              dp[i+1][c1][c2] += dp[i][c3][c4];
              dp[i+1][c1][c2] %= MOD;
            }
          }
        }
      }
      for (int c1 = 0; c1 < 4; c1++) {
        for (int c2 = 0; c2 < 4; c2++) {
          dp[i+2][c1][c2] = dp[i+1][c1][c2];
        }
      }
      i += 2;
    }
  }
  lint ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      ans += dp[N][i][j];
    }
  }
  cout << ans%MOD << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-13;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int c[700];
long long f[700];
long long C[700][10];
int main(){
	long long a;scanf("%lld",&a);
	C[0][0]=1;
	for(int i=0;i<650;i++){
		for(int j=0;j<9;j++){
			C[i+1][j]+=C[i][j];
			C[i+1][j+1]+=C[i][j];
		}
	}
	for(int i=0;i<600;i++){
		f[i]=C[i+7][7];
	}
	for(int i=599;i>=0;i--){
		c[i]=a/f[i];
		a%=f[i];
	}
	for(int i=0;i<600;i++){
		printf("FESTIVA");
		for(int j=0;j<c[i];j++)printf("L");
	}
	printf("\n");
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char const *argv[])
{
   int n;
   cin >> n;
   vector<int> p(n);
   for(int i = 0; i < n; i++)
   {
      cin >> p[i];
   }

   int ans = 0;
   for(int i = 1; i < n-1; i++){
      if(p[i] > p[i-1] && p[i] < p[i+1])
      {
         ans++;
      }
      if(p[i] > p[i+1] && p[i] < p[i-1])
      {
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  int a2[a], b2[b];
  for(int i=0; i<a; i++) cin >> a2[i];
  for(int i=0; i<b; i++) cin >> b2[i];
  int x[m], y[m], c[m];
  for(int i=0; i<m; i++) {
    cin >> x[i] >> y[i] >> c[i];
  }
  long ans1=1e12;
  for(int i=0; i<m; i++) {
    if(ans1>a2[x[i]-1]+b2[y[i]-1]-c[i]) ans1=a2[x[i]-1]+b2[y[i]-1]-c[i];
  }
  sort(a2, a2+a);
  sort(b2, b2+b);
  if(ans1>a2[0]+b2[0]) ans1=a2[0]+b2[0];
  cout << ans1 << endl;
}

Measured memory_bytes: 2176