akhauriyash/Code-Regression huggingface dataset:
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

typedef struct den {
	int sw[10];
	int scnt;
	int p;
} den;

int jcnt;
int jew[50];
int ocnt;

FILE *in, *ans;
int tno;

int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outd(double d) {
	char s[128];
	sprintf(s, "%.10lf\n", d);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int sortfnci(const void *v1, const void *v2) {
	int *i1 = (int *)v1;
	int *i2 = (int *)v2;

	if (*i1 > *i2) {
		return 1;
	}
	else if (*i1 < *i2) {
		return -1;
	}

	return 0;
}

int fnc() {
	int i, j, k;

	jcnt = geti();
	ocnt = geti();

	for (i = 0; i < jcnt; i++) {
		jew[i] = geti();
	}

	int max = 0;
	int lcnt;
	if (jcnt < ocnt) {
		lcnt = jcnt;
	}
	else {
		lcnt = ocnt;
	}
	for (i = 0; i <= lcnt; i++) {
		int jcnt2 = jcnt - i;
		int ocnt2 = ocnt - i;
		int rcnt;
		if (jcnt2 < ocnt2) {
			rcnt = jcnt2;
		}
		else {
			rcnt = ocnt2;
		}
		for (j = 0; j <= rcnt; j++) {
			int jcnt3 = i + j;
			if (jcnt3 == 0) {
				continue;
			}
			int jew2[50];
			if (i > 0) {
				memcpy(jew2, jew, sizeof(int) * i);
			}
			if (j > 0) {
				memcpy(&jew2[i], &jew[jcnt - j], sizeof(int) * j);
			}
			qsort(jew2, jcnt3, sizeof(int), sortfnci);

			int ocnt3 = ocnt2 - j;
			if (ocnt3 > jcnt3) {
				ocnt3 = jcnt3;
			}
			for (k = 0; k < ocnt3; k++) {
				if (jew2[k] < 0) {
					jew2[k] = 0;
				}
				else {
					break;
				}
			}
			int sum = 0;
			for (k = 0; k < jcnt3; k++) {
				sum += jew2[k];
			}
			if (max < sum) {
				max = sum;
			}
		}
	}

	outi(max);

	return 0;
}

int main() {

#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc();
#endif

	return 0;
}


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

typedef struct{
	int no;
	int walk;
}Patiant;

int main(void){
	int n;
	while(cin>>n,n){
		Patiant input,max;
		max.walk=-1;
		int inp,f,s;
		for(int i  = 0 ; i < n ; i ++){
			cin>>inp;	input.no=inp;
			cin>>f>>s; input.walk=f+s;
			if(input.walk>max.walk)
				max=input;
			
		}
		cout<<max.no<<" "<<max.walk<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ll, ii>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define multicase
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 2e3 + 5;

ll n;
ll dp[N];

ll add(ll x, ll y) {
    return ((x % MOD) + (y % MOD)) % MOD;
}

ll f(ll rem) {
    if(rem < 0) return 0;
    if(rem == 0) return 1;
    ll &sol = dp[rem];
    if(sol != -1) return sol;
    sol = 0;
    for(ll i = 3; i <= rem; i++) {
        sol = add(sol, f(rem - i));
    }
    return sol;
}

void solve() {
    ll T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    while(T--) {
        cin >> n;
        memset(dp, -1, sizeof(dp));
        cout << f(n) << "\n";
    }
}

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

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 1;
    char last = s[0];
    rep(i, n - 1) {
        if (last == s[i + 1]) continue;
        last = s[i + 1];
        cnt++;
    }
    int ans = n - cnt;
    rep(i, k) {
        if (cnt == 1) break;
        if (cnt == 2) ans++, cnt--;
        else ans += 2, cnt -= 2;
    }
    cout << ans << endl;
}

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



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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  vector<int> h(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &h.at(i));
  }

  sort(h.begin(), h.end());

  int ans = 1e9;
  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, (h.at(i + K - 1) - h.at(i)));
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 640
def _105(n):
    b = 0
    for i in range(105, n + 1, 2):
        ii = i
        l = []
        for j in range(2, i + 1):
            while True:
                if ii % j == 0:
                    l += [j]
                    ii /= j
                else:
                    break
        if len(l) == 3:
            if len(set(l)) == 3:
                b += 1
        if len(l) == 4:
            if len(set(l)) == 2:
                l.remove(set(l).pop())
                if len(l) == 3 or len(l) == 1:
                    b += 1
    return b

print(_105(int(input())))


Measured memory_bytes: 3064
#ifdef __APPLE__
#include <cassert>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <list>
#include <cmath>
#include <limits>
#include <bitset>
#include <numeric>
#include <climits>
#include <complex>
#else
#include<bits/stdc++.h>
#endif // __APPLE__
using namespace std;
typedef pair<int,int>   II;
typedef vector<II>     VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int LL;
typedef  unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define ALL(c) (c).begin(),(c).end()
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)	{
cerr << name << " : " << arg1 << std::endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
     const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif
//D




LL a[45],b[45],c[45];

LL DP[45][450][450];

int main()
{
	//fr;fw;
	fast_io;
    int n,A,B;
    cin>>n>>A>>B;
    
    REP(i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }

    REP(i,0,45)
    REP(j,0,450)
    REP(k,0,450)
    DP[i][j][k]=1LL*(INT_MAX);
    
    DP[0][a[0]][b[0]]=c[0];
    DP[0][0][0]=0;
    REP(i,1,n)
    {
        REP(j,0,450)
        {
            REP(k,0,450)
            {
                if(j==0 && k==0)
                {DP[i][j][k]=0LL;continue;}
                if(j>=a[i] && k>=b[i])
                {
                    DP[i][j][k]=min(DP[i-1][j][k],DP[i-1][j-a[i]][k-b[i]]+c[i]);
                }
                else
                {
                    DP[i][j][k]=DP[i-1][j][k];
                }
                
            }
        }
    }
    
    
    LL ans=LLONG_MAX;
    REP(i,1,450)
    {
        REP(j,1,450)
        {
            LL gg=__gcd(i,j);
            if(i/gg==A && j/gg==B)
                ans=min(ans,DP[n-1][i][j]);
        }
    }
    ans=min(ans,DP[n-1][A][B]);
    if(ans>=INT_MAX)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }

	return 0;
}





Measured memory_bytes: 71424
#include <stdio.h>
int main(){
	int n,ans,d[6],temp;
	char c[100];
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(int i=0;i<6;i++)d[i]=i+1;
		ans=1;
		while(n--){
			scanf("%s",c);
			if(c[0]=='N'){
				temp=d[0];
				d[0]=d[1];
				d[1]=d[5];
				d[5]=d[4];
				d[4]=temp;
			}
			else if(c[0]=='E'){
				temp=d[0];
				d[0]=d[3];
				d[3]=d[5];
				d[5]=d[2];
				d[2]=temp;
			}
			else if(c[0]=='W'){
				temp=d[0];
				d[0]=d[2];
				d[2]=d[5];
				d[5]=d[3];
				d[3]=temp;
			}
			else if(c[0]=='S'){
				temp=d[0];
				d[0]=d[4];
				d[4]=d[5];
				d[5]=d[1];
				d[1]=temp;
			}
			else if(c[0]=='L'){
				temp=d[1];
				d[1]=d[3];
				d[3]=d[4];
				d[4]=d[2];
				d[2]=temp;
			}
			else{
				temp=d[1];
				d[1]=d[2];
				d[2]=d[4];
				d[4]=d[3];
				d[3]=temp;
			}
			ans+=d[0];
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 2696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadInts();
            WriteLine(nk[0] % nk[1]);
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
        static long fibonacci(int n)
        {
            switch (n)
            {
                case 0:
                case 1:
                    return n;
                default:
                    return fibonacci(n - 2) + fibonacci(n - 1);
            }
        }
    }
}


Measured memory_bytes: 13140
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll 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<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=2e5+5;
ll n,a[maxn],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1,greater<int>{});
	ans=a[1];
	int pos=2;
	for(int i=2;i<n;i++){
		if(i&1) ans+=a[pos++];
		else ans+=a[pos];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5348
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG
 
#include "cpp-pyprint/pyprint.h"
 
#endif
 
void Main() {
    int N, M;
    cin >> N >> M;
    int min_num = 0;
    int max_num = 100005;
    for (int i = 0; i < M; ++i) {
        int l, r;
        cin >> l >> r;
        min_num= max(min_num, l);
        max_num = min(max_num, r);
    }
    if (max_num - min_num >= 0){
        cout << max_num - min_num + 1 << endl;
    }else{
        cout << 0 << endl;
    }
 
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/STACK: 2000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define deb(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
 
using namespace std;
 
int main(){
    IOS;
  
  int n, m; cin>>n>>m;
  vec<int> cant(m, 0);
  for(int i=0; i<n; i++){
    int k; cin>>k;
    while(k--){
      int x; cin>>x;
      cant[x-1]++;
    }
  }
  int res = 0;
  for(auto &it: cant){
    if(it==n) res++;
  }
  cout<<res<<endl;
 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
vector<double> R;
int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    int r; scanf("%d",&r); R.push_back( r );
  }
  vector<double> L;
  for(int i=0;i<N;i++){
    double nl=R[i];
    for(int j=0;j<i;j++){
      double x = R[i] + R[j];
      double y = abs(R[i]-R[j]);
      double z = sqrt( x*x - y*y );
      nl = max( nl, L[j] + z );
    }
    L.push_back( nl );
  }
  double res = 0.0;
  for(int i=0;i<L.size();i++)
    res = max( res, L[i] + R[i] );
  printf("%.9lf\n",res);
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char s;
    cin >> s;
    if(s-'a'>=0) cout << "a" << "\n";
    else cout << "A" << "\n";

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <climits>
using namespace std;
using ll = long long;
int main() {
    ll N, ans = LLONG_MAX;
    cin >> N;
    for (ll i = 1; i * i <= N; i++) {
        ll t = i + N / i - 2;
        if (N % i == 0 && t < ans)  ans = t;
    }
    cout << ans << endl;
}


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

int main(void){
	int H,W;
	cin >> H >> W;
	char a[H][W];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> a[i][j];
		}
	}
	
	for(int i=0;i<H;i++){
		int count=0;
		for(int j=0;j<W;j++){
			if(a[i][j]=='.') count++;
		}
		if(count==W){
			for(int j=0;j<W;j++) a[i][j]='x';
		}
	}
	for(int j=0;j<W;j++){
		int count=0;
		for(int i=0;i<H;i++){
			if(a[i][j]=='.'||a[i][j]=='x') count++;
			if(count==H){
				for(int i=0;i<H;i++) a[i][j]='x';
			}
		}
	}
	
	for(int i=0;i<H;i++){
		int count=0;
		for(int j=0;j<W;j++){
			if(a[i][j]!='x'){
				cout << a[i][j];
				count++;
			}
		}
		if(count!=0) cout << endl; 
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rev(i,n,a) for(ll i=n-1;i>=a;i--)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve(){
    ll x,n;
    cin>>x>>n;

    map<ll,ll>mp;

    ll val;
    rep(i,0,n){
        cin>>val;
        mp[val]=1;
    }
    ll lo=INT_MAX;
    for(int i=x;i>=0;i--){
        if(mp.find(i)==mp.end()){
            lo=i;
            break;
        }
    }
    ll hi=INT_MAX;

    for(int i=x;i<=INT_MAX;i++){
        if(mp.find(i)==mp.end()){
            hi=i;
            break;

        }
    }

    if(abs(x-lo)==abs(x-hi)){
        cout<<lo<<endl;
    }
    else{
        abs(x-lo)<abs(x-hi)?cout<<lo<<endl:cout<<hi<<endl;
    }
    
}


int main()
{
    secreterror()
    // ll t;
    // cin>>t;
    //while(t--){
        solve();
        
    //}

}

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

#define REP(i,a,b)	for (int i = (a); i < (b); i++)
#define FOR(i,n)	REP(i,0,n)

int main(void)
{
  int n, a[100];
  cin >> n;
  FOR(i, n)	cin >> a[i];
  sort(a, a + n, greater<int>());

  int alice = 0;
  int bob = 0;
  FOR(i, n)
  {
    if (i % 2 == 0)
    {
      alice += a[i];
    }
    else
    {
      bob += a[i];
    }
  }
  cout << abs(alice - bob) << endl;
  return 0;
}


Measured memory_bytes: 256
h1,m1,h2,m2,k=input().split()

h1 = int(h1)
m1 = int(m1)
h2 = int(h2)
m2 = int(m2)
k = int(k)

if h1 > h2:
  h2 += 24
  
h = h2 - h1
hm = h * 60

print(hm - m1 + m2 - k)

Measured memory_bytes: 9188
K,N=gets.chomp.split.map(&:to_i)
distance=gets.chomp.split.map(&:to_i)

max_distance=0
startpoint=0
goalpoint=0

(2..N).each do |a|
    if max_distance<distance[a-1]-distance[a-2]
        max_distance=distance[a-1]-distance[a-2]
        startpoint=a-1
        goalpoint=a-2
    end
end

if max_distance<distance[0]+K-distance[N-1]
    max_distance=distance[0]+K-distance[N-1]
    startpoint=N-1
    goalpoint=0
end

route_a=distance[startpoint]-distance[goalpoint]
route_b=(K-distance[startpoint])+distance[goalpoint]

puts [route_a,route_b].max

Measured memory_bytes: 16652
import java.util.*;

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

		// argumentの取得
		Scanner scanner = new Scanner(System.in);
        Integer x = scanner.nextInt();
        Integer y = scanner.nextInt();
        String ans = "No";

        // debug
        // System.out.println(x);
        // System.out.println(y);
      
        for (int i = 0; i < x + 1; i++){
          Integer sum = 2 * i + 4 * (x - i);
          if (sum == y)
            ans = "Yes";
        }
      
		// 戻り値の返却
		System.out.println(ans);
	
	} 
}

Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	int price =0;
	for(int i=0;i<k;i++){
		price+=a[i];
	}
	cout<<price<<"\n";
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;
	long long s[n+1];
	for (int i=1; i<=n; i++){
		cin >> s[i];
		if (s[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i=2; i<=n; i++){
		if(1000000000000000000ll/s[i-1]<s[i]){
			cout << -1 << endl;
			return 0; 
		}
		s[i]*=s[i-1];
	}
	cout << s[n] << endl;
	return 0;
}


Measured memory_bytes: 4260
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a.sort()
b = []
for i in range(0,n-1,2):
  if a[i] != a[i+1]:
    b.append(a[i])
    b.append(a[i+1])
  else:
    continue
if n%2 == 1:
  b.append(a[-1])
#print(b)
ans = []
if b != []:
  ans.append(b[0])
  for j in range(1,len(b)-1,2):
    if b[j] != b[j+1]:
      ans.append(b[j])
      ans.append(b[j+1])
  if len(b)%2 == 0:
    ans.append(b[-1])
#print(ans)
if ans == []:
  print(0)
else:
  print(len(ans))

Measured memory_bytes: 8908
package main

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

func main() {
	n := nextInt()
	m := nextInt()
	var X, Y int
	for i := 0; i < n; i++ {
		x := nextInt()
		X += i*x - (n-(i+1))*x
	}
	for i := 0; i < m; i++ {
		y := nextInt()
		Y += i*y - (m-(i+1))*y
	}

	p := int(1e9) + 7
	fmt.Println((X % p) * (Y % p) % p)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 3840
using System;
class Program
 {
        static void Main()
        {
            int x;
            x = int.Parse(Console.ReadLine()); //標準入力
            // string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            // b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            // c = int.Parse(str[1]);
            if(x==3 || x==5 || x==7)
            {
                Console.Write("YES");//改行なし出力
            }
            else
            {
                Console.Write("NO");//改行なし出力
            }
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
        }
 }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int n,m,s,t;
vector <long long> dijkstra(int s, vector <vector <int> > graph, map <pair<int,int>,long long> fee);
int main()
{
    long long money=1000000000000000;
    int u,v;
    long long a,b;
    cin >> n>>m>>s>> t;
    s--;
    t--;
    vector <vector <int> > graph(n);
    map <pair<int,int>,long long> fee_yen;
    map <pair<int,int> ,long long> fee_snuuk;
    for (int i=0;i<m;i++)
    {
    cin >> u >> v >> a >> b;
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
    fee_yen.insert(make_pair(make_pair(u,v),a));
    fee_yen.insert(make_pair(make_pair(v,u),a));
    fee_snuuk.insert(make_pair(make_pair(u,v),b));
    fee_snuuk.insert(make_pair(make_pair(v,u),b));
    }
    vector<pair<long long,int>> sumfee(n);
    vector<long long> d1;
    vector<long long> d2;
    d1=dijkstra(s,graph,fee_yen);
    d2=dijkstra(t,graph,fee_snuuk);
    for (int i=0;i<n;i++)
    {
        pair <long long,int> fees;
        fees.first=d1[i]+d2[i];
        fees.second=i;
        sumfee[i]=fees;
    }
    sort(sumfee.begin(),sumfee.end());
    auto itr=sumfee.begin();
    pair <long long ,int> pa;
    
    for (int i=0;i<n;i++)
    {
        pa=*itr;
        if (i<pa.second+1) cout << money-pa.first << endl;
        else
        {
            while (i>=pa.second+1) 
            {
                itr++;
                pa=*itr;
            }
            cout << money-pa.first << endl;
        }
        
    }


}

vector<long long> dijkstra(int s, vector <vector <int> > graph, map <pair<int,int>,long long> fee)
{
    vector<long long> d(n);
    priority_queue <pair<long long,int>, vector<pair<long long,int>>,greater<pair<long long,int>>> que; 
    for (int i=0;i<n;i++) 
    {
        if (i==s) d[i]=0;
        else d[i]=10000000000000000;
        que.push(make_pair(d[i],i));
    }
    int v;
    long long alt;
    pair <long long,int> u;
    while (!que.empty())
    {
        u=que.top();
        que.pop();
        for (int i=0;i<graph[u.second].size();i++)
        {
            v=graph[u.second][i];
            alt=d[u.second]+fee[make_pair(u.second,v)];
            if (d[v]>alt)
            {
                d[v]=alt;
                que.push(make_pair(alt,v));
            }
        }

    }
return d;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 310;
const ll MOD = 998244353;

int N;
string S;
int K;

int N0, N1;
int nbuck[MAXN];
int ps[MAXN];

ll dp[MAXN][2*MAXN][MAXN]; // i=bucket, j=#1s, k=sum of smaller vals
ll dps[MAXN][2*MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> S >> K;
    N = S.length();
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == '0') N0++;
        else
        {
            nbuck[N0]++;
            N1++;
        }
    }

    ps[0] = 0;
    for (int i = 0; i < MAXN - 1; i++)
        ps[i+1] = ps[i] + nbuck[i];

    N0++;
    dp[0][0][0] = 1;
    for (int i = 0; i <= N0; i++)
    {
        //cout << i << " " << nbuck[i] << "\n";
        for (int k = 0; k <= N; k++)
        {
            for (int j = 1; j <= N; j++)
            {
                dps[i][j][k] += dps[i][j-1][k];
                dps[i][j][k] %= MOD;
            }
        }

        for (int j = ps[i]; j <= N1; j++)
        {
            for (int k = 0; k <= N; k++)
            {
                dp[i][j][k] = (dp[i][j][k] + dps[i][j][k]) % MOD;
                if (!dp[i][j][k]) continue;
                //cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n";
                for (int l = 0; l < nbuck[i]; l++)
                {
                    dp[i+1][j+l][k+nbuck[i]-l] += dp[i][j][k];
                    dp[i+1][j+l][k+nbuck[i]-l] %= MOD;
                }
                dps[i+1][j+nbuck[i]][k] += dp[i][j][k];
                dps[i+1][j+nbuck[i]][k] %= MOD;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= N; i++)
    {
        if (i <= K)
            ans = (ans + dp[N0][N1][i]) % MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 225272
uses crt;
var n,a,b:longint;
begin
        readln(n);
        a:=n div 100;
        b:=n mod 100;
        if(a<12)and(a<>0)and(b<>0)and(b<=12)then write('AMBIGUOUS')else
        if(a=12)and(b=12)then write('AMBIGUOUS')else
        if(a>12)and(b>12)then write('NA')else
        if(a>12)and(b=0)then write('NA') else
        if(a=0)and(b=0)then write('NA')else
        if(a=0)and(b>12)then write('NA')else
        if (a<12)and(a>1)and(b>12)then write('MMYY') else
        if (a=12)and(b>12)then write('MMYY') else
        if (a=1)and(b>12)then write('MMYY') else
        if (a=12)and(b<=12)then write('MMYY') else
        if(a<>0)and(b<=1) then write('MMYY')else
        if (a=1)and(b>=1)then write('MMYY') else
        if (a>12)and(b<>0)and(b<=12)then write('YYMM')else write('YYMM');
        readln
end.


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    ll k = pow(10LL, n);

    vector<int> v(10);
    iota(v.begin(), v.end(), 0);

    string ans;
    ll maxd = -1;
    do
    {
        string t = "";
        for(int i = 0; i < n; i++) t += v[i] + '0';
        ll a = stoll(s), b = stoll(t);
        ll d = min(abs(a - b), k - abs(a - b));
        if(d == maxd and stoll(t) < stoll(ans)) ans = t;
        else if(d > maxd)
        {
            ans = t;
            maxd = d;
        }
    }
    while(next_permutation(v.begin(), v.end()));

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




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

int main() {
  int N, L;
  cin >> N >> L;
  if (L >= 0) cout << (N-1)*L + N*(N-1)/2 << endl;
  else if (L < 0 && L >= (-1)*N + 1) {
    cout << N*L + N*(N-1)/2 << endl; 
  }
  else cout << (N-1)*L + N*(N-1)/2 - (N-1) << endl;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    ll ans = 0;
    vector<ll> digit;
    while(N > 0)
    {
        digit.push_back(N % 10);
        N /= 10;
    }

    REP(i, digit.size())
    {
        ll d = digit[i];
        if (i + 1 < digit.size())
        {
            if (d != 9)
            {
                digit[i + 1]--;
            }
            ans += 9;
        }
        else
        {
            ans += d;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i=0 ; i<N ; i++ )
    cin >> V.at(i);
  
  sort(V.begin(),V.end());
  reverse(V.begin(),V.end());
  
  for (int i=0 ; i<N ; i++){
    if (V.at(i)<K){
    cout << i << endl;
    return 0;
  }
  }
 cout << N << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[n],i,s=0;
    for(i=0;i<n;i++){
        cin>>a[i];s+=a[i];
    }
    int k=0;
    for(i=0;i<n;i++){
        if(a[i]>=((.25*s)/m)){
            k++;
        }
    }
            if(k>=m){
                cout<<"Yes";
            }
            else
            cout<<"No";
} 

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static List<Integer> primes;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        primes = new ArrayList<>();
        primes.add(2);

        while (true) {
            int a = sc.nextInt();
            int d = sc.nextInt();
            int n = sc.nextInt();
            if ((a | d | n) == 0) {
                break;
            }
            int c = 0;
            int i = a;
            while (true) {
                if (isPrime(i)) {
                    // System.out.println(i);
                    c++;
                    if (c == n) {
                        break;
                    }
                }
                i += d;
            }
            System.out.println(i);
        }
    }

    public static boolean isPrime(int n) {
        if (n == 1) {
            return false;
        } else if (n == 2) {
            return true;
        } else if (n % 2 == 0) {
            return false;
        }
        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 30432
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;


int main() {
	int a, b, c, d,ans;
	cin >> a >> b >> c >> d;
	ans = max((a*b), (c*d));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin >> str;
	vector<int> v(4);
	for(int i=0;i<4;++i){
		v[i] = str[i]-'0';
	}

	for(int s=0;s<(1<<3);++s){
		int res = v[0];
		for(int i=0;i<3;++i){
			if( (s>>i)&1 ){
				res -= v[i+1];
			}else{
				res += v[i+1];
			}
		}
		if( res == 7 ){
			cout << v[0];
			for(int i=0;i<3;++i){
				if( (s>>i)&1 ){
					cout << '-';
				}else{
					cout << '+';
				}
				cout << v[i+1];
			}
			cout << "=7" << endl;
			return;
		}
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 384
#include <iostream>

int main() {
  int M, D;
  std::cin >> M >> D;

  int64_t count = 0;

  for (int m = 1; m <= M; ++m) {
    for (int d2 = 2, ed2 = D / 10; d2 <= ed2; ++d2) {
      for (int d1 = 2; d1 < 10; ++d1) {
        if (d2 * 10 + d1 > D) {
          break;
        }

        if (d2 * d1 == m) {
          ++count;
        }
      }
    }
  }

  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 256
# Strange Bank
N = int(input())

dp = ['inf']*(N+1)

init = 6 if N > 5 else N+1
for n in range(init):
	dp[n] = n

for n in range(6,N+1):
	cnd = [dp[n-1]+1]
	for i in range(1,7):
		if n > 6**i-1:
			cnd.append(dp[n-6**i]+1)
	for j in range(1,6):
		if n > 9**j-1:
			cnd.append(dp[n-9**j]+1)
	dp[n] = min(cnd)
	
print(dp[N])

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int x;
  cin >> x;
  int ans = 1;
  rep(i, x) {
    for (int j = 2; j < x; j++) {
      if (x >= pow(i, j)) {
        if (ans < pow(i, j)) {
          ans = pow(i, j);
        }
      } else {
        break;
      }
    }
  }
  cout << ans;
}

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

const ll int INF = 1e18 + 5;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n,k;
    cin>>n>>k;
    ll int dp[k+1] = {0};
    ll int a[n];
   	for(ll int i=0;i<n;i++){
   		cin>>a[i];
   		dp[a[i]] = 1;
   	}
   	for(ll int i=0;i<=k;i++){
   		ll int x = 1;
   		for(ll int j=0;j<n;j++){
   			if((i-a[j])>=0){
   				x = min(x,dp[(i-a[j])]);
   			}
   		}
   		dp[i] = ~x;
   	}
   	if(dp[k] == 1){
   		printf("%s\n","First" );
   	}
   	else{
   		printf("%s\n", "Second");
   	}
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    string n; ll k; cin >> n >> k;
    ll N = sz(n);
    ll dp[N+1][k+1][2];
    string t = "";
    t.pb(n[0]);
    int c = stoi(t);
    dp[1][0][1] = 1;
    dp[1][0][0] = 0;
    dp[1][1][1] = c-1;
    dp[1][1][0] = 1;
    rep(i, 2, k+1){
        dp[1][i][0] = 0;
        dp[1][i][1] = 0;
    }
    rep(i, 2, N+1){
        rep(j, 0, k+1){
            string r = ""; r.pb(n[i-1]);
            int f = stoi(r);
            if(j == 0){
                dp[i][j][0] = 0;
                dp[i][j][1] = 1;
            }else{
                if(f == 0){
                    dp[i][j][0] = dp[i-1][j][0];
                    dp[i][j][1] = 9*dp[i-1][j-1][1] + dp[i-1][j][1];
                }else{
                    dp[i][j][0] = dp[i-1][j-1][0];
                    dp[i][j][1] = dp[i-1][j-1][1]*9 + dp[i-1][j][1] + dp[i-1][j][0] + (f-1)*dp[i-1][j-1][0];
                }
            }
        }
    }
    prtl(dp[N][k][0] + dp[N][k][1]);
}



Measured memory_bytes: 3632
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    AIN(ll, A, N);
    ll ok = INF;
    ll ng = 0;
    while (ok - ng > 1)
    {
        ll mid = (ok + ng) / 2;
        ll c = 0;
        REP(i, N)
        {
            c += (A[i] + mid - 1) / mid - 1;
        }
        if (c <= K)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    OUT(ok);
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pii pair<ll,ll>
#define pb push_back
#define m_p make_pair
#define MOD 1000000009
#define fi first
#define se second
#define vii vector<ll>
#define all(v) v.begin(),v.end()
#define rep(i,l,r) for(unsigned long long i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vp vector< pair<ll,ll> >
const int maxn=3003;
int dp[maxn][maxn];
int b[maxn][maxn];
string s,t;
void printlcs(int i,int j)
{
    if(i==0|| j==0)
    {
        return;
    }
    if(b[i][j]==1)
    {

        printlcs(i-1,j-1);
        cout<<s[i-1];
    }
    else
        if(b[i][j]==3)
    {
        printlcs(i-1,j);
    }
        else
        {
            printlcs(i,j-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>s;
    cin>>t;
    int n=s.length();
    int m=t.length();
    for(int j=0;j<m;j++)
    {
        dp[0][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i]==t[j])
            {
                dp[i+1][j+1]=dp[i][j]+1;
                b[i+1][j+1]=1;

            }
            else
            {
                //dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                if(dp[i][j+1]>=dp[i+1][j])
                {
                    dp[i+1][j+1]=dp[i][j+1];
                    b[i+1][j+1]=3;
                }
                else
                {
                    dp[i+1][j+1]=dp[i+1][j];
                    b[i+1][j+1]=2;
                }
            }
        }
    }
    //cout<<dp[n][m]<<"\n";
    printlcs(n,m);
    return 0;


}


Measured memory_bytes: 70784
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        OMatching solver = new OMatching();
        solver.solve(1, in, out);
        out.close();
    }

    static class OMatching {
        final int MOD = 1_000_000_000 + 7;

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

        int insert0(int bits, int pos) {
            pos -= 1;
            if (pos == 0) {
                return bits << 1;
            }
            int s1 = (bits >>> pos) << (pos + 1);
            int s2 = bits & ((1 << pos) - 1);
            int res = s1 | s2;
            return res;
        }

        int minSet(int size) {
            return (1 << size) - 1;
        }

        int maxSet(int size, int nBits) {
            return minSet(size) << (nBits - size);
        }

        int next(int set) {
            if (set == 0) {
                throw new RuntimeException();
            }
            int i = 0;
            int nOnes = 0;
            for (; !(((set >> i) & 1) == 1 && ((set >> (i + 1)) & 1) == 0); i++) {
                if (((set >> i) & 1) == 1) {
                    nOnes++;
                }
            }
            int mask = Integer.MAX_VALUE << (i + 1);
            return (set & mask) | (1 << (i + 1)) | minSet(nOnes);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            boolean[][] a = new boolean[N + 1][N + 1];
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    a[i][j] = (in.nextInt() != 0);
                }
            }
            int[][] ways = new int[N + 1][1 << N];
            ways[0][0] = 1;
            for (int j = 1; j <= N; j++) {
                ways[1][1 << (j - 1)] = a[1][j] ? 1 : 0;
            }
            for (int i = 2; i <= N; i++) {
                final int minS = minSet(i - 1);
                final int maxS = maxSet(i - 1, N - 1);
                for (int j = 1; j <= N; j++)
                    if (a[i][j]) {
                        for (int s = minS; s <= maxS; s = next(s)) {
                            int oldS = insert0(s, j);
                            int newS = oldS | 1 << (j - 1);
                            ways[i][newS] = add(ways[i][newS], ways[i - 1][oldS]);
                        }
                    }
            }
            out.println(ways[N][(1 << N) - 1]);
        }

    }
}



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

int main(){
int n;
cin>>n;
int v[n];
bool us[n];
for(int i=0;i<n;i++){
	cin>>v[i];
	us[i]=false;
}

int pos=0,ans=0;
while(us[pos]==false&&pos!=1){
	us[pos]=true;
	pos=v[pos]-1;
	ans++;
	//cout<<pos<<endl;
}
if(pos==1)
cout<<ans<<endl;
else
cout<<-1<<endl;

return 0;
}


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

typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "

ll a[4000][4000];
ll par[4000][4000];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s,t;
  cin>>s>>t;
  ll i,j;

  ll n=s.length();
  ll m=t.length();
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=m;j++)
    {
      if(s[i-1] == t[j-1]){
        a[i][j]=a[i-1][j-1]+1;
        par[i][j]=2;
      }
      else {
        
        if(a[i-1][j]>a[i][j-1])
        {
          a[i][j]=a[i-1][j];
          par[i][j]=1;
        }else{
          a[i][j]=a[i][j-1];
          par[i][j]=3;
        }

      }
    }
  }

  stack<char> st;
  i=n;j=m;
  while(i && j)
  {
    if(par[i][j]==2)
    {
      st.push(s[i-1]);
      i--;
      j--;
    }
    else if(par[i][j]==1)i--;
    else j--;
  }

  while(st.empty()==0)
  {
    cout<<st.top();
    st.pop();
  }

  return 0;
 }

Measured memory_bytes: 188416