akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main()
{
    char s[100];
    scanf("%s", s);
    if (strlen(s) < 6 || strlen(s) > 6)
    {
        printf("No\n");
        return 0;
    }
    if (s[2] == s[3] && s[4] == s[5])
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int hantei(int);
int main(){
  int i,n,A[10000],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    count+=hantei(A[i]);
  }
  printf("%d\n",count);
  return 0;
}

int hantei(int x){
  int i,count=0,hei;
  hei=sqrt(x);
  for(i=1;i<=hei;i++){
    if(x%i==0)count++;
  }
  if(count==1)return 1;
  else return 0;
}



Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split(" ");

		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);

		if(b % a == 0) {
			System.out.println((a+b));
		}else {
			System.out.println((b-a));
		}
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  int n,m;
  cin >> n >> m;
  dsu uf = dsu(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    uf.merge(a-1,b-1);
  }
  vector<vector<int>> g = uf.groups();
  cout << g.size()-1 << endl;
  
}

Measured memory_bytes: 9024
//  Created by Sengxian on 2017/5/22.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
//  AtCoder Regular Contest 066D
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 300000 + 3, MAX_M = 300000 + 3;
int n, m, t[MAX_N];
ll s[MAX_N], ans[MAX_M], f[MAX_N], g[MAX_N];
vector<pair<int, int> > vals[MAX_N];

ll solve(ll dp[]) {
	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + t[i];

	dp[0] = 0;

	static int q[MAX_N];
	int l = 0, r = 0;
	q[r++] = 0;

	#define x(i) ll(i)
	#define y(i) ((ll(i) * (i) - (i)) / 2 + s[i] + dp[i])

	for (int i = 1; i <= n; ++i) {
		while (r - l >= 2 && (y(q[r - 1]) - y(q[r - 2])) <= i * (x(q[r - 1]) - x(q[r - 2]))) --r;
		int j = q[r - 1];
		dp[i] = max(dp[i - 1], y(j) - i * x(j) + ((ll)i * i + i) / 2 - s[i]);
		while (r - l >= 2 && (y(i) - y(q[r - 1])) * (x(q[r - 1]) - x(q[r - 2])) >= (y(q[r - 1]) - y(q[r - 2])) * (x(i) - x(q[r - 1]))) --r;
		q[r++] = i;
	}

	return dp[n];

	#undef x
	#undef y
}

void solve(int l, int r, ll ans[]) {
	if (r - l == 1) return;
	static int q[MAX_N];
	static ll dp[MAX_N];
	int mid = (l + r) / 2, sz = 0;

	#define x(i) ll(i)
	#define y(i) ((ll(i) * (i) - (i)) / 2 + s[i] + f[i])
	
	for (int i = l; i <= mid; ++i) {
		while (sz >= 2 && (y(i) - y(q[sz - 1])) * (x(q[sz - 1]) - x(q[sz - 2])) >= (y(q[sz - 1]) - y(q[sz - 2])) * (x(i) - x(q[sz - 1]))) --sz;
		q[sz++] = i;
	}
	
	for (int i = mid + 1; i <= r; ++i) {
		while (sz >= 2 && (y(q[sz - 1]) - y(q[sz - 2])) <= i * (x(q[sz - 1]) - x(q[sz - 2]))) --sz;
		int j = q[sz - 1];
		dp[i] = y(j) - i * x(j) + ((ll)i * i + i) / 2 - s[i];
	}

	ll mx = LLONG_MIN;
	for (int i = r - 1; i >= mid; --i) {
		mx = max(mx, dp[i + 1] + g[i + 1]);
		for (int j = 0; j < (int)vals[i].size(); ++j)
			ans[vals[i][j].second] = max(ans[vals[i][j].second], mx + (t[i] - vals[i][j].first));
	}

	solve(l, mid, ans);
	solve(mid, r, ans);

	#undef x
	#undef y
}

int main() {
#ifdef DEBUG
	freopen("test.in", "r", stdin);
#endif
	n = readInt();
	for (int i = 0; i < n; ++i) t[i] = readInt();

	solve(f);
	reverse(t, t + n);
	solve(g);
	reverse(t, t + n);
	reverse(g, g + n + 1);

	m = readInt();
	for (int i = 0; i < m; ++i) {
		int pos = readInt() - 1, x = readInt();
		vals[pos].push_back(make_pair(x, i));
		ans[i] = f[pos] + g[pos + 1];
		/*
		t[n] = x, swap(t[n], t[pos]);
		printf("%lld\n", solve(dp));
		swap(t[n], t[pos]);
		*/
	}

	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + t[i];
	solve(0, n, ans);

	reverse(t, t + n), reverse(vals, vals + n);
	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + t[i];
	reverse(f, f + n + 1), reverse(g, g + n + 1), swap(f, g);
	solve(0, n, ans);

	for (int i = 0; i < m; ++i) printf("%lld\n", ans[i]);

	return 0;
}


Measured memory_bytes: 32512
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll N;
  cin >> N;
  ll sum = 0;
  vector<ll> vec(N);
  rep(i, N) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  ll ave = sum / N;
  ll ans = 0;
  ll ans2 = 0;
  rep(i, N) {
    ans += (vec.at(i) - ave) * (vec.at(i) - ave);
    ans2 += ((vec.at(i) - ave - 1) * (vec.at(i) - ave - 1));
  }
  cout << min(ans, ans2);
}

Measured memory_bytes: 3588
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Y = map(int, readline().split())
assert Y % 1000 == 0
Y //= 1000


def solve():
    for x1 in range(N + 1):
        for x2 in range(N - x1 + 1):
            x3 = N - x1 - x2
            if 10 * x1 + 5 * x2 + 1 * x3 == Y:
                print(x1, x2, x3)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 38768
from itertools import product
N = int(input())
n = 3
ans = 0
while True:
    for s in product('357', repeat=n):
        s = ''.join(s)
        if N < int(s):
            break
        if '3' in s and '5' in s and '7' in s:
            ans += 1
    else:
        n += 1
        continue
    break
print(ans)


Measured memory_bytes: 42864
import itertools

N = int(input())
P_list = list(map(int, input().split()))
Q_list = list(map(int, input().split()))


for i, v in enumerate(itertools.permutations(range(1,N+1))):
    if list(v) == P_list:
        a = i + 1
    if list(v) == Q_list:
        b = i + 1

print(abs(a-b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int n,m;
    cin >> n >> m;
    ll k;
    cin >> k;
    ll a[n+10]={0},b[m+10]={0};
    for(int i=1;i<=n;i++) {
        ll x;
        cin >> x;
        a[i]=a[i-1]+x;
    }
    for(int i=1;i<=m;i++) {
        ll x;
        cin >> x;
        b[i]=b[i-1]+x;
    }
    ll ans =0;
    ll j=m;
    for(ll i=0;i<=n;i++) {
        if(a[i]>k) {
            break;
        }
        while(j>0 && a[i]+b[j]>k) {
            j--;
        }
        ans = max(ans, i+j);
    }
    cout << ans << endl;
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 6716
//Author: Suifeng0214
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector <pair<int, int>> wv;
int dp[2][100100];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++){
		int W, V;
		cin >> W >> V;
		wv.emplace_back(W, V);
	}
	for (int i = 1; i <= wv.size(); i++){
		for (int j = 1; j <= w; j++){
			if (wv[i-1].first <= j){
				dp[i%2][j] = max(dp[!(i%2)][j-wv[i-1].first] + wv[i-1].second, dp[!(i%2)][j]);
			}else{
				dp[i%2][j] = dp[!(i%2)][j];
			}
		}
	}
	cout << dp[n%2][w] << "\n";
} 


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

int main(){
    int n;
    scanf("%d",&n);
    int p[n];
    vector<int> vec1;
    vector<int> vec2;
    for(int i=0;i<n;i++) scanf("%d",&p[i]);
    for(int i=0;i<n;i++) vec1.push_back(p[i]);
    for(int i=0;i<n;i++) vec2.push_back(p[i]);
    sort(vec1.begin(),vec1.end());
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            int save=vec2[i];
            vec2[i]=vec2[j];
            vec2[j]=save;
            if(vec2==vec1){
                printf("YES\n");
                return 0;
            }
            else{
                save=vec2[i];
                vec2[i]=vec2[j];
                vec2[j]=save;
            }
        }
    }
    printf("NO\n");

}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
B = [[0]*3 for _ in range(3)]
bingo = set(int(input()) for _ in range(int(input())))
for i in range(3):
    for j in range(3):
        if A[i][j] in bingo:
            B[i][j] = 1

ans = "No"
for i in range(3):
    if sum(B[i]) == 3: ans = "Yes"

for j in range(3):
    if B[0][j] + B[1][j] + B[2][j] == 3:
        ans = "Yes"

if B[0][0] + B[1][1] + B[2][2] == 3:
    ans = "Yes"

if B[0][2] + B[1][1] + B[2][0] == 3:
    ans  = "Yes"

print(ans)

Measured memory_bytes: 38384
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2019-3-24 21:02:22
# Powered by Visual Studio Code
#

ans = 0
s = gets.chomp
ary = []
s.chars{|c|
  if ['A', 'C', 'G', 'T'].include?(c)
    ary << true
  else
    ary << false
  end
}
temp = 0
ary.each{|x|
  if x
    temp += 1
    ans = [ans, temp].max
  else
    temp = 0
  end
}
puts ans


Measured memory_bytes: 1788
n=int(input())
t=int(input())
min_t=t
t1 = int(input())
if min_t > t1:
    min_t = t1
maxdt=t1-t
for i in range(2,n):
    t=int(input())
    if maxdt < t-min_t:
        maxdt = t-min_t
    if t<min_t:
        min_t=t
print(maxdt)


Measured memory_bytes: 5608
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a[3000];
signed main(){
    int n,k;
    cin >> n >> k;
    REP(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    int ans = 0;
    REP(i,k){
        ans += a[i];
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int x,y,p; cin >> x >> y >> p;
    int ma=0,mb=0;
    rep(i,p){
        int a,b,c; cin >> a >> b >> c;
        if(c==1){
            ma = max(ma,a);
        }else if(c==2){
            x = min(x,a);
        }else if(c==3){
            mb = max(mb,b);
        }else{
            y = min(y,b);
        }
    }
    if(ma>=x || mb>=y){
        cout << 0 << endl;
    }else{
        cout << (x-ma)*(y-mb) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
// #include <queue>
// #include <map>

using namespace std;

namespace atcoder {
namespace {

pair<float, int> solve(istream& in)
{
  int W, H, x, y;
  in >> W >> H >> x >> y;
  assert(0 < W && 0 < H);
  return make_pair(0.5 * W * H, (W == 2 * x && H == 2 * y) ? 1 : 0);
}

[[gnu::unused]] void test()
{
  {
    constexpr auto str = R"(
2 3 1 2
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 3.0000);
    assert(ans.second == 0);
  }

  {
    constexpr auto str = R"(
2 2 1 1
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 1);
  }
  {
    constexpr auto str = R"(
2 2 0 0
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 0);
  }
  {
    constexpr auto str = R"(
2 2 2 2
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 0);
  }
  {
    constexpr auto str = R"(
2 3 0 0
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 3.0000);
    assert(ans.second == 0);
  }
}

} // namespace
} // namespace atcoder

////////////////////////////////////////////////////////////////
int main()
{
  using namespace atcoder;
  // test();
  const auto ans = solve(cin);
  cout << ans.first << ' ' << ans.second << '\n';
}


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

using namespace std;
int l[100005];
int k[100005];
int main(){
	int n,x;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	k[0]=0;
	for(int i=1;i<=n;i++){
		k[i]=k[i-1]+l[i-1];
	}
	int ans=0;
	for(int i=0;i<=n;i++){
		if(k[i]<=x)ans++;
//		cout<<k[i]<<" ";
	}
	cout<<ans<<endl; 
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
	return '"' + s + '"';
}

string to_string(const char *s)
{
	return to_string((string)s);
}

string to_string(bool b)
{
	return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
	string res = "";
	for (size_t i = 0; i < N; i++)
	{
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v)
{
	bool first = true;
	string res = "{";
	for (const auto &x : v)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	string s;
	cin >> s;
	if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0;
    long[] a=new long[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextLong();
      if(a[i]%2!=0){
        f++;
      }
    }
    if(f%2==0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 51760
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bitset<64> mask[n];
    for(int i = 0; i < n; i++)
    {
        int k; cin >> k;
        for(int j = 0; j < k; j++)
        {
            ull x;
            cin >> x;
            mask[i].set(x);
        }
    }
    int q;
    cin >> q;
    bitset<64> bs;
    for(int i = 0; i < q; i++)
    {
        ull x, m;
        cin >> x >> m;
        if(x == 0) cout << bs.test(m) << endl;
        if(x == 1) bs |= mask[m];
        if(x == 2) bs &= ~mask[m];
        if(x == 3) bs ^= mask[m];
        if(x == 4) cout << ((bs & mask[m]) == mask[m]) << endl;
        if(x == 5) cout << (bs & mask[m]).any() << endl;
        if(x == 6) cout << (bs & mask[m]).none() << endl;
        if(x == 7) cout << (bs & mask[m]).count() << endl;
        if(x == 8) cout << (bs & mask[m]).to_ullong() << endl;
    }
    return 0;
}




Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    long long int K,N,M,A[100001],MAX=0,cnt=0,sum=0;
    cin >> N >> K;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++)
        sum += A[i];
    vector<long long int> vec(0),yakusu(0);
    for(int i=1;i*i<=sum;i++){
        if(sum % i == 0){
            yakusu.push_back(i);
            yakusu.push_back(sum/i);
        }
    }
    long long int ssum = 0;
    sort(yakusu.begin(),yakusu.end());
    for(int i=0;i<yakusu.size();i++){
        ssum=0;
        vector<long long int> kari(0);
        long long int r = N-1,carry=0;
        for(int j=0;j<N;j++){
            kari.push_back(A[j] % yakusu[i]);
        }
        sort(kari.begin(),kari.end());
        for(int l=0;l<r;l++){
            ssum += kari[l];
            carry += kari[l];
            while (kari[r] + carry >= yakusu[i]){
                if(r == l)
                    break;
                carry =(kari[r] + carry) - yakusu[i];
                r--;
            }
        }
            if(ssum <= K){
            MAX = max(yakusu[i],MAX);
        }
    }
    cout << MAX << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

k = ni()
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for p in range(1,k+1):
            a = math.gcd(i,j)
            ans += math.gcd(a,p)

print(ans)

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

const int MOD = 1e9+7;
const int MAXN = 3210;

typedef struct def{
	int a,b,c;

	def(){}
	def(int a2, int b2, int c2){
		a = a2; b = b2; c = c2;
	}
	bool operator < (def comp) const{
		if(a!=comp.a) return a < comp.a;
		else return b < comp.b;
	}
} generico;

typedef pair<int,int> pii;
typedef long long int ll;

#define INF 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define x first
#define y second

string s;
string t;

char k [3210];

int dp[MAXN][MAXN];

int solve (int ats, int att){
	
	if(dp[ats][att] != -1) return dp[ats][att];
	if(ats == s.size() || att == t.size()) return 0;
	
	if(s[ats]==t[att]) return dp[ats][att] = solve(ats + 1 , att + 1) + 1;
	else return dp[ats][att] = max( solve(ats , att + 1) , solve(ats + 1 , att) );
}

void backtrack (int ats, int att, int atk){
	
	if(ats == s.size() || att == t.size()) return;
	
	if(s[ats] == t[att]){
		k[atk] = s[ats];
		return backtrack(ats + 1, att + 1, atk + 1);
	}
	
	if(dp[ats + 1][att] > dp[ats][att + 1]) return backtrack(ats + 1, att, atk);
	else return backtrack(ats, att + 1, atk);
}
	
int main(){
	
	memset(dp,-1,sizeof dp);
	
	cin>>s>>t;
	
	solve(0,0);
	
	backtrack(0,0,0);
	
	for(int i = 0 ; i < 3210 ; i++){
		if(k[i]=='\0') break;
		printf("%c", k[i]);
	}
	
	return 0;
}

Measured memory_bytes: 40832
function main (input) {
  const inputRows = input.split('\n');
  let price = Number(inputRows[0].split(' ')[0]);
  const hateNumberLen = Number(inputRows[0].split(' ')[1]);
  const hateNumbers = inputRows[1].replace(' ', '');
  const regex = new RegExp(`[${hateNumbers}]`);

  while (regex.test(String(price))){
    price++;
  }

  // console.log(price);
  return price;
}

const input = `1000 8
1 3 4 5 6 7 8 9`;
// console.log(main(input));

console.log(main(require("fs").readFileSync("/dev/stdin","utf8")));



Measured memory_bytes: 34472
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	vector<long long> a;
	a.emplace_back(0);
	rep(i,n){
		long long in;
		cin >> in;
		a.emplace_back(in);
	}
	a.emplace_back(0);

	long long ans = 0;
	rep(i,a.size() - 1){
		ans += abs(a[i] - a[i + 1]);
	}

	range(i,1,n + 1){
		if(a[i - 1] <= a[i] and a[i] <= a[i + 1]) cout << ans << endl;
		else if(a[i - 1] >= a[i] and a[i] >= a[i + 1]) cout << ans << endl;
		else{
			cout << ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
		}
	}
}


Measured memory_bytes: 2164
#include <stdio.h>

typedef struct node_t {
	int val;
	struct node_t *next;
} node;

node* new_node(int val) {
	static int it = 0;
	static node pool[200000];
	pool[it] = (node) { val, NULL };
	return &pool[it++];
}

node* st[1000];

int main(void)
{
	int n, q, com, t, x;
	node *tmp;
	scanf("%d%d", &n, &q);
	while (q--) {
		scanf("%d%d", &com, &t);
		if (com == 0) {
			scanf("%d", &x);
			tmp = new_node(x);
			tmp->next = st[t];
			st[t] = tmp;
		}
		else if (com == 1) {
			if (st[t]) printf("%d\n", st[t]->val);
		}
		else {
			if (st[t]) st[t] = st[t]->next;
		}
	}
	return 0;
}



Measured memory_bytes: 4808
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

S = input()
K = int(input())
li = []
for i in range(len(S)):
	for j in range(1,6):
		li.append(S[i:i+j])

li = list(set(li))
li.sort()
print(li[K-1])

Measured memory_bytes: 6120
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,x[200010];
L p,a[200010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i;
	L k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	for(i=1;i<n;i++)
	  {
	   if(x[i+1]<x[i])
	     x[i+1]+=m;
	   p+=x[i+1]-x[i];
	   a[x[i]+2]++;
	   a[x[i+1]+1]-=x[i+1]-x[i];
	   a[x[i+1]+2]+=x[i+1]-x[i]-1;
	   x[i+1]%=m;
	  }
	for(i=1;i<=2*m;i++)
	  a[i]+=a[i-1];
	for(i=1;i<=2*m;i++)
	  a[i]+=a[i-1];
	for(i=1,k=0;i<=m;i++)
	  k=max(k,a[i]+a[i+m]);
	printf("%lld\n",p-k);
	return 0;
}


Measured memory_bytes: 2176
//
// Created by watemus on 24.06.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

template<typename T>
using vec = vector<T>;

template<typename T>
using uset = unordered_set<T>;

template<typename T1, typename T2>
using umap = unordered_map<T1, T2>;

#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
const ld PI = acos(-1);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

vector<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif

void run() {
    vec<int> a(5);
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
        if (a[i] == 0) cout << i + 1 << '\n';
    }
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    cout << fixed << setprecision(20);
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    vi p(n);
    rep(i,n) cin>>p[i];
    vi s(n+1,0);
    rep(i,n) s[i+1]=s[i]+p[i]+1;
    double ans=0.0;
    rep(i,n-k+1){
        chmax(ans,(double)(s[i+k]-s[i])/2);
    }
    cout<<setp(12)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
while (true){
String str = sc.next();
if (str.equals("-"))break;
int leng = str.length();
int shuffle = sc.nextInt();
for(int i=0;i<shuffle;i++){
int n = sc.nextInt();
str = str.substring(n, leng) + str.substring(0, n);
}
System.out.println(str);
}
sc.close();
}
}


Measured memory_bytes: 26416
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int max = Math.Min(inp[1], inp[2]);
            int tmp = inp[0] - (inp[1] + inp[2]);
            int min = tmp > 0 ? 0 : Math.Abs(tmp);

            Console.WriteLine($"{max} {min}");
        }
    }
}

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

using namespace std;

int main()
{
	long long n,m;
	cin >> n >> m;
	int count=1;
	long long bef=n;
	while(true)
	{
		bef=bef*2;
		if(bef<=m)count++;
		else break;
	}
	cout << count << endl;
		



	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_map>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[22], B[22], C[22];
    int ans = 0;
    for(int i = 1;i <= N;i++){
        cin >> A[i];
    }
    for(int i = 1;i <= N;i++){
        cin >> B[i];
    }
    for(int i = 1;i <= N-1;i++){
        cin >> C[i];
    }
    for(int i = 1;i <= N;i++){
        ans += B[A[i]];
        if(A[i] == A[i+1]-1)ans += C[A[i]];
    }
    cout << ans;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int A = in.nextInt();
			int B = in.nextInt();
			if(A < B) {
				out.println(A);
			}else{
				out.println(B);
			}
			if(N - (A + B) < 0) {
				out.println(Math.abs(N - (A + B)));
			}else{
				out.println(0);
			}
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 21332
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;

int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    int a=n/x;
    if(n%x!=0)
    {
        a++;
    }
    cout<<a*t<<endl;
    return 0;
}


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

typedef long long ll;

ll N, K;
vector<ll> X;
ll R = 1ll << 60;

ll calc(ll l, ll r) {
  if (r <= 0)
    return abs(l);
  else if (0 <= l)
    return abs(r);
  else
    return abs(l) + abs(r) + min(abs(l), abs(r));
}
int main() {
  cin >> N >> K;
  X.resize(N);
  for (ll i = 0; i < N; ++i) cin >> X[i];
  for (ll i = 0; i < N - K + 1; ++i) {
    ll l = X[i], r = X[i + K - 1];
    R = min(R, calc(l, r));
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	long double a, b;
	cin >> a >> b;
	ll ans = floor(a*b);
	cout << ans << endl;
	return 0;
}


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

int howManyWays(int end_val, int target_val)
{
    int ways = 0; // ????????????????????°
    int target_val_tmp = 0;

    for(int i = 1; i <= end_val; i++) {
        for(int j = i+1; j <= end_val; j++) {
            for(int k = j+1; k <= end_val; k++) {
                target_val_tmp = target_val - i - j - k;
                if(target_val_tmp == 0) {
                    ways++;
                    break;
                }
            }
        }
    }

    return ways; // ?????????????????°?????????????????????
}

int main()
{
    // ???????????????????????\???
    int n, x;
    int end_val[512], target_val[512];
    int vi = 0;
    while(cin >> n >> x) {
        end_val[vi]    = n;
        target_val[vi] = x;
        if(n == 0 && x == 0) break;
        vi++;
    }

    for(int i = 0; i < vi; i++) {
        cout << howManyWays(end_val[i], target_val[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c)
	cout<<"Yes";
	else if(b==c&&b!=a)
	cout<<"Yes";
	else if(c==a&&c!=b)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  vector<int> a(n + 5, 0);

  for (int i = 0; i < n; i++){
    if(s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T'){
      a[i] = 1;
    }else{
      a[i] = 0;
    }
  }
  int ans = 0, count = 0;

  for (int i = 0; i < n; i++){
    if(a[i] == 1){
      int flag = true;
      while(flag){
        if (a[i] == 0){
          flag = false;
          if(ans<count){
            ans = count;
          }
          count = 0;
        }else{
          i++;
          count++;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a='a';
    string s;
    cin>>s;
    vec A;
    reverse(all(s));
    int b=0;
    int alp[26]={0};
    rep(i,s.size()){
        alp[s[i]-'a']++;
        int z=1;
        rep(j,26) if(alp[j]==0) z=0;
        if(z){
            b++;
            fill(alp,alp+26,0);
        }
        A.push_back(b);
    }
    fill(alp,alp+26,0);
    reverse(all(s));
    reverse(all(A));
    string ans;
    char now='z';
    int z=1;
    rep(i,s.size()){
        if(ans.size()&&ans[ans.size()-1]==s[i]){
            if(z==0) alp[s[i]-'a']--;
            z=1;
        }
        if(i==s.size()-1||A[i]!=A[i+1]){
            if(i==s.size()-1) alp[s[i]-'a']++;
            rep(j,26){
                if(alp[j]==0){
                    ans+=a+j;
                    break;
                }
            }
            fill(alp,alp+26,0);
            z=0;
            if(ans[ans.size()-1]==s[i]) z=1;
            continue;
        }
        if(z==0) continue;
        alp[s[i]-'a']++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 5496
import sys
input = sys.stdin.readline

N = int(input().strip())
M = N*(N-1)//2

graph = [[] for i in range(M)]
in_cnt = [0 for i in range(M)]
for x in range(1,N+1):
  l = list(map(int,input().split()))
  y = l[0]
  b,s = max(x,y),min(x,y)
  prev = (b-1)*(b-2)//2+s-1
  for y in l[1:]:
    b,s = max(x,y),min(x,y)
    now = (b-1)*(b-2)//2+s-1
    graph[prev].append(now)
    in_cnt[now] += 1 
    prev = now

d = [1 for k in range(M)]
q = [i for i in range(M) if not in_cnt[i]]

if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.pop()
  for y in graph[x]:
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in range(M) if in_cnt[i]]:
  print(-1)
  exit()

print(ans)

Measured memory_bytes: 171912
A = int(input())
B = int(input())
C = int(input())
D = int(input())

pattern = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c == D:
                pattern += 1

print(pattern)


Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
using V = vector<int>;
using VV = vector<V>;
const int MOD = 998244353;

int main() {
  int N, S; cin >> N >> S;
  V a(N);
  rep(i, N) cin >> a[i];

  VV dp(N+1, V(S+1));
  rep(r, N+1) dp[r][0] = r;

  rep(r, N) rep2(s, 1, S+1) {
    dp[r+1][s] = dp[r][s];
    dp[r+1][s] += (s >= a[r]) ? dp[r][s-a[r]] : 0;
    dp[r+1][s] += (s == a[r]) ? 1 : 0;
    dp[r+1][s] %= MOD;
  }

  int ans = 0;
  rep(r, N) (ans += dp[r+1][S]) %= MOD;
  cout << ans << endl;
  return 0;
}


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

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

int main() {
  string s;
  cin >> s;
  int cnt1 = 0, cnt2 = 0;
  rep(i, s.size()) {
    if (s[i] == '0') {
      if (i % 2 == 0)
        cnt1++;
      else
        cnt2++;
    } else {
      if (i % 2 == 0)
        cnt2++;
      else
        cnt1++;
    }
  }
  cout << min(cnt1, cnt2) << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0) v += MOD; }

  Mint operator-() { return Mint(-v); };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0) return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

const int SIZE = 11234567;
mint fact(int n) {
  static vector<mint> factorial = []() {
    vector<mint> _f(SIZE, 1);
    for(int i=1; i<SIZE; i++) _f[i] = _f[i-1] * i;
    return _f;
  }();
  return factorial[n];
}
mint perm(int n, int k) { return n<k ? 0 : fact(n) / fact(n-k); }
mint comb(int n, int k) { return n<k ? 0 : perm(n, k) / fact(k); }

int main() {
  lint N;
  cin >> N;
  vector<lint> A(N), S(N);
  for(auto& elem : A) cin >> elem;
  partial_sum(A.begin(), A.end(), S.begin());
  S.insert(S.begin(), 0);

  mint ans = 0;
  for(lint i=0; i<N; i++) {
    ans += mint(A[i]) * mint(S[N] - S[i+1]);
  }
  cout << ans << endl;
}

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

int main(void)
{
    string s;

    cin >> s;

    bool flag = false;
    for(int i = 0; i < s.size()-1; ++i)
    {
        if(s[i] == s[i+1])
        {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }

        if(i+2 < s.size() && s[i] == s[i+2])
        {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}



Measured memory_bytes: 3784
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n = 3;
    int k;
    vector<int> m(n);
    vector<vector<long long> > v(n);
    for(int i=0; i<n; ++i)
        cin >> m[i];
    cin >> k;
    for(int i=0; i<n; ++i){
        v[i].resize(m[i]);
        for(int j=0; j<m[i]; ++j)
            cin >> v[i][j];
        sort(v[i].rbegin(), v[i].rend());
    }

    long long init = 0;
    for(int i=0; i<n; ++i)
        init += v[i][0];

    priority_queue<pair<long long, vector<int> > > pq;
    set<vector<int> > history;
    pq.push(make_pair(init, vector<int>(n, 0)));
    history.insert(vector<int>(n, 0));
    while(--k >= 0){
        long long sum;
        vector<int> index;
        tie(sum, index) = pq.top();
        pq.pop();
        cout << sum << endl;

        for(int i=0; i<n; ++i){
            if(index[i] < m[i] - 1){
                vector<int> index2 = index;
                ++ index2[i];
                if(history.find(index2) == history.end()){
                    long long sum2 = sum - v[i][index[i]] + v[i][index2[i]];
                    pq.push(make_pair(sum2, index2));
                    history.insert(index2);
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << min(A, K) - max(0LL, K - A - B) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll x,y;
  	ci(x>>y)
if(x<y){
    co(rM(abs(x-y),abs(x+y)+1))
  }
else if(x*y>0){
  co(abs(x-y)+2)
}
  else{
    co(abs(x+y)+1)
  }
}

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

int main(void){
    string s;
    cin>>s;
    
    int res=10000000;
    
    for(int i=0;i<26;i++){
        char word='a'+i;
        int num=0;
        string tmp1=s,tmp2;
        while(count(tmp1.begin(),tmp1.end(),word)!=tmp1.size()){
            tmp2=tmp1;
            tmp1="";
            for(int i=0;i<tmp2.size()-1;i++){
                if(tmp2[i]==word||tmp2[i+1]==word){
                    tmp1+=word;
                }else{
                    tmp1+=tmp2[i];
                }
            }
            num++;
        }
        res=min(res,num);
    }
    
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first 
#define S second 
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ; 
#define pb push_back
#define pf push_front  
#define mp make_pair
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define Rep(i,a,b) for ( int i = a ; i < b ; i++)
#define range(i,s) for ( auto i : s) 
#define sor(v) sort ( v.begin() , v.end()) ;
#define rev(v) reverse(v.begin() , v.end()) ; 
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
typedef long long ll ;
typedef unsigned long long ull ; 
typedef long double ld ; 
using namespace std ;
const int N = 1e5 + 100  ; 
const ll mod = 1e9 + 7  ;


ll n , tot_w  , ans[N][105];
pair<ll , ll > items[105] ;  


int _3102_ {
    Gamed
    cin >> n >> tot_w ;
    for ( int i = 1 ; i <= n ; i ++){
        cin >> items[i].first >> items[i].second ; 
    }    

    for ( int i = 0 ; i <= tot_w ; i ++){
        for ( int j = 0 ; j <= n ; j ++){
            if ( i == 0 || j == 0) {
                ans[i][j] = 0 ;
                continue ;  
            }
            if ( items[j].first > i ){
                ans[i][j] = ans[i][j-1] ; 
            }
            else {
                ans[i][j] = max( ans[i][j-1] , ans[i-items[j].first][j-1]+ items[j].second) ; 
            }
            
            
        }
    }
    cout << ans[tot_w][n] << endl ; 
    return 0 ;  
}


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

#define MOD 1000000007


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int i,n,j;
    cin>>n;
    int c[n-1],f[n-1];
    long int s[n-1];
    for(i=0;i<n-1;i++)
       {
       	cin>>c[i]>>s[i]>>f[i];
       }
   for(i=0;i<n-1;i++)
      {   long int ans=c[i]+s[i];
      	for(j=i+1;j<n-1;j++)
      	  {
      	     if(ans<=s[j])
      	       ans+=(c[j]+s[j]-ans);
      	     else
      	       {    long int a=ans-s[j];
      	            a=a%f[j];
      	            if(a==0)
      	              {
      	              	ans+=c[j];
      	              	continue;
      	              }
      	            a=f[j]-a;
      	            
      	       	ans+=a;
      	       	ans+=c[j];
      	       }
      	  }
      	 cout<<ans<<"\n"; 
      }
    cout<<0;  
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int par[100010]; 
int depth[100010]; 
int size[100010];
int N, M, K; 
void init(){
	for(int i = 0; i < N; i++){
		par[i] = i; depth[i] = 0; size[i] = 1; 
	}
}
int find(int x){
	if(par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]); 
	}
}
void unite(int x, int y){
	x = find(x); 
	y = find(y); 
	if(x == y) return;
	else if(depth[x] < depth[y]){
		par[x] = y; 
		size[y] += size[x]; 
	}else{
		par[y] = x; 
		size[x] += size[y];  
		if(depth[x] == depth[y]) depth[x] ++; 
	}
}
bool same(int x, int y){
	return find(x) == find(y); 
}
int siz(int x){
	return size[find(x)]; 
}
int main(){
	cin >> N >> M >> K; 
	init(); 
	int direct[100010] = {}; 
	int block[100010] = {}; 
	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b; 
		a--; b--; 
		unite(a, b); 
		direct[a] ++; direct[b] ++; 
	}
	for(int i = 0; i < K; i++){
		int c, d; cin >> c >> d; 
		c--; d--; 
		if(same(c, d)){
			block[c] ++; block[d] ++; 
		}
	}
	for(int i = 0; i < N; i++){
		cout << siz(i) - direct[i] - block[i] - 1 << " "; 
	}
	cout << endl; 
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int n;
vector<ll> h;
vector<ll> dp;

ll rec(int i) {
    if(dp[i] < 1LL << 60) return dp[i];
    if(i == 0) return 0;
    ll res = 1LL << 60;
    res = min(res, rec(i - 1) + abs(h[i] - h[i - 1]));
    if(i > 1) res = min(res, rec(i - 2) + abs(h[i] - h[i - 2]));
    return dp[i] = res;
}

int main() {
    cin >> n;
    h.resize(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp.assign(n, 1LL << 60);
    // 貰うDPで
    cout << rec(n - 1) << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long idx=0;
    string S;
    cin >> S;
    bool isBus = false;
    for(size_t i = 1;i<S.size(); i++)
    {
        if(S[0] != S[i]) isBus = true;
    }
    if(isBus) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256