akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
                                                                                                      
int main() {                                                                                          
  string s, t, u;                                                                                     
  int a, b;                                                                                           
  cin >> s >> t;                                                                                      
  cin >> a >> b;                                                                                      
  cin >> u;                                                                                           
  if (u == s) {                                                                                       
    cout << a-1 << " " << b << endl;                                                                  
  } else {                                                                                            
    cout << a << " " << b-1 << endl;                                                                  
  }                                                                                                   
  return 0;                                                                                           
}                

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long A[200100],B[200100];
int N;
long long K;
bool Check(long long X)
{
	long long Sum=0;
	for(int i=0;i<N;i++)
	{
		int Y=min(X/B[i],A[i]);
		Sum+=A[i]-Y;
	}
	if(Sum<=K)
		return true;
	return false;
}
int main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
		cin>>A[i];
	for(int i=0;i<N;i++)
		cin>>B[i];
	sort(A,A+N);
	sort(B,B+N);
	reverse(B,B+N);
	long long L=0,R=1000000000000000000;
	while(L<R)
	{
		long long mid=(L+R)/2ll;
		if(Check(mid))
			R=mid;
		else	L=mid+1;
	}
	cout<<L<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int N,M,H,W,x,i,j,k,ans,count,cost,tmp,a,b,c,d,c1,c2,HP;
    long long int S[110000];
    //long long int T[11000];
    //long long int U[300000];
    //long long int Ssum[300000];
    string T[110],TA,V,G,ans2;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    ans=0;
    flag=false;
    cin >>N;
    for (i=0;i<N;i++){
        cin>>S[i];
        
    }
    

    
        //cin >> c >>d;
        //count=0;
    
    //cout << count<<endl;
    for (i=0;i<N-1;i++){
        for (k=i+1;k<N;k++){
            ans+=S[i]*S[k];
        }
    }
    
    
    
        cout << ans << endl;
    

    return 0;
    
}


Measured memory_bytes: 3640
# E - NEQ
import sys
sys.setrecursionlimit(10**6)
MOD = 10**9+7
mon_l = dict({})

def mon(m,n):
    if (m,n) in mon_l:
        return mon_l[(m,n)]
    if n==1:
        mon_l[(m,n)] = m-1
        return mon_l[(m,n)]
    if n==2:
        mon_l[(m,n)] = ((m-1)+(m-2)**2)%MOD
        return mon_l[(m,n)]
    else:
        mon_l[(m,n)] = ((n-1)*(mon(m-1,n-1)+mon(m-2,n-2)) + (m-n)*mon(m-1,n-1))%MOD
        return mon_l[(m,n)]
    
def permu(m,n):
    ans = 1
    for _ in range(n):
        ans = m*ans%MOD
        m -= 1
    return ans

N,M = map(int,input().split())
ans = permu(M,N)*mon(M,N)%MOD
print(ans)

Measured memory_bytes: 481388
#include<stdio.h>

void insertionSort(int a[], int n,int g);
void shellSort(int a[] ,int n);
int cnt=0;
int G[9999];
int m;
void insertionSort(int a[], int n, int g){
	int i,j,v;
	
	for(i = g;i < n;i++){
		v = a[i];
		j = i - g;
		while(j >=0 && a[j] > v){
			a[j+g] = a[j];
			j = j-g;
			cnt++;
		}
		a[j+g] = v;
	}
}
void shellSort(int a[] ,int n){
	cnt = 0;
	int i;
	G[0] = 1;
	
	for(i = 1;;i++){
		G[i] = G[i-1]*3+1;
		if(G[i]>n){break;}
	}
	m = i-1;
	for(i = m;i >=0;i--){
		insertionSort(a,n,G[i]);
	}
	
}
int main (void){
	int n,i;
	scanf("%d",&n);
	int a[n];
	for(i =0;i < n;i++){
		scanf("%d",&a[i]);
	}
	shellSort(a,n);
	
	printf("%d\n",m+1);
	for(i = m;i>0;i--){
		printf("%d ",G[i]);
	}
	printf("%d\n",G[0]);
	printf("%d\n",cnt);
	for(i = 0;i < n;i++){
		printf("%d\n",a[i]);
	}
	
}


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

int hantei(int i, int j, int k){
        if(i==j && j==k && i==k ){
                return 1;
        }
        if(i==j || i==k || j==k){
                return 2;
        }
        return 3;
}


int main (){
        int a, b, c;
        cin >> a >> b >> c;
        cout << hantei(a, b, c);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in).useDelimiter("(\\s|,)+");
		String a;
		while (in.hasNext()) {
			String num = in.next();
			float w = in.nextFloat();
			float h = in.nextFloat();
			if (25 <= w / (h * h)) {
				System.out.println(num);
			}
		}
	}
}

Measured memory_bytes: 17488
#include <cstdio>


int w;

int main(){
    while(scanf("%d", &w) != EOF){
        if(w == -1) break;


        if(w <= 10){
            printf("%d\n", 4280 - 1150);
        }else if(w <= 20){
            printf("%d\n", 4280 - (1150 + (w - 10) * 125));
        }else if(w <= 30){
            printf("%d\n", 4280 - (1150 + 1250 + (w - 20) * 140));
        }else if(w >  30){
            printf("%d\n", 4280 - (1150 + 1250 + 1400 + (w - 30) * 160));
        }
    }

    return 0;
}

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

ll n, c[MAX_N], ans[MAX_N], sum = 0;
vector<vector<int> > g;
vector<int> deg;

void dfs(int now, int& m){
    ans[now] = c[m];
    m++;
    deg[now] = 0;
    for(auto to : g[now]){
        deg[to]--;
    }
    for(auto to : g[now]){
        if(deg[to] == 1){
            dfs(to, m);
        }
    }
}

int main() {
    cin >> n;
    g.resize(n);
    deg.resize(n,0);
    REP(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    REP(i,n){
        cin >> c[i];
        sum += c[i];
    }
    sort(c,c+n);
    //reverse(c,c+n);
    sum -= c[n-1];

    fill(ans, ans+n, -1);
    int num = 0;
    REP(i,n){
        if(deg[i]<=1 && ans[i]==-1){
            dfs(i, num);
        }
    }

    cout << sum << endl;
    REP(i,n){
        cout << ans[i] << " \n"[i==n-1];
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define INF 1e9
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n];
	rep(i,n)cin>>w[i]>>v[i];
	ll v_max=0;
	rep(i,n)v_max+=v[i];
	vector<ll> dp(v_max+1,INF);
	dp[0]=0;
	rep(i,n){
		for(ll j=v_max;j>=v[i];j--){
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	int answer=0;
	rep(i,v_max+1){
		if(dp[i]<=W){
			answer=max(answer,i);
		}
	}
	puts(answer);
	
}


Measured memory_bytes: 4052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
	private	static	BufferedReader	br = null;
	private	static	int[]			dc = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		long[][]	dates  = null;
		while ((dates = parseDates()) != null) {
			System.out.println(countDay(dates[1]) - countDay(dates[0]));
		}
	}

	private static long countDay(long[] date) {
		long	day = 365 * date[0] + date[2];
		boolean	uru = date[0] % 400 == 0 || date[0] % 4 == 0 && date[0] % 100 != 0;

		day += ((date[0]-1) / 4 - (date[0]-1) / 100 + (date[0]-1) / 400);

		for (int i = 0; i < date[1]-1; i++) {
			day += dc[i];
			day += (i == 1 && uru) ? 1 : 0;
		}

		return day;
	}

	private static long[][] parseDates() {
		long[][]	dates = null;
		String		stdin = parseStdin();

		if (stdin != null) {
			if (!stdin.contains("-")) {
				String[]	lines = stdin.split(" ");

				dates       = new long[2][3];
				dates[0][0] = Long.parseLong(lines[0]);
				dates[0][1] = Long.parseLong(lines[1]);
				dates[0][2] = Long.parseLong(lines[2]);
				dates[1][0] = Long.parseLong(lines[3]);
				dates[1][1] = Long.parseLong(lines[4]);
				dates[1][2] = Long.parseLong(lines[5]);
			}
		}

		return dates;
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			String  tmp = br.readLine();
			if (tmp != null) {
				if (!tmp.isEmpty()) stdin = tmp;
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 16932
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string s;
    cin >> s;
    int res = 0;
    if (s == "RRR")
        cout << 3 << endl;
    else if (s == "RRS" || s == "SRR")
        cout << 2 << endl;
    else if (s == "SSS")
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
	int n;
	cin >> n;
	ll a[n], b[n], c[n];
	for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
	ll dp[n][3];
	dp[0][0] = a[0];	dp[0][1] = b[0];	dp[0][2] = c[0];
	for (int i = 1; i < n; ++i){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + c[i];
	}
	cout << max( max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 256
n = int(input())
maxpd = 1
pd = {0:0}
for a in range(1,n+1):
    t6 = 1
    t9 = 9
    pd[a] = a
    while a >= t6:
        pd[a] = min(pd[a],pd[a-t6]+1,)
        t6 = 6*t6
    while a >= t9:
        pd[a] = min(pd[a],pd[a-t9]+1,)
        t9 = 9*t9
    maxpd = max(maxpd,pd[a])
print(pd[n])

Measured memory_bytes: 15092
#include <iostream>

using namespace std;
int n;
int xOld = -2, x, cnt = 0, sum;
int f[25], c[25];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        //a[i]=x;
        if(x == xOld+1){
            f[cnt]=xOld;
            cnt++;
        }
        xOld = x;
    }
    for(int  i = 0; i < n; i++){
        cin >> x;
        sum+=x;
    }
    for(int  i = 0; i < n-1; i++){
        cin >> x;
        c[i]=x;
    }
    for(int  i = 0; i < cnt; i++){
        sum+=c[f[i]-1];
        //cout << 3;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define MAX 200005

using namespace std;
using vi=vector<int>;
using pii=pair<int, int>;
using ull=unsigned long long;

vector<int> adj[MAX];
ull op[MAX];

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
	int n, q; cin >> n >> q;

	for (int i=0; i < n-1; i++)
	{
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
	}

	while(q--)
	{
		int p, x; cin >> p >> x;
		op[p] += x;
	}

	for (int i = 1; i <= n; i++)
	{
		for (auto e : adj[i])
			op[e] += op[i];
	}

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

	cout << "\n";
}


Measured memory_bytes: 14976
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String SS = scanner.next();
        SS = SS + SS;
        char[] S = SS.toCharArray();
        char[] F = SS.toCharArray();
        long K = scanner.nextLong();

        long count1 = 0;
        long count2 = 0;
        long edge = 1;
        char e = S[0];
        for(int i = 1; i < S.length; i++) {
            if(e != S[i]) edge = 0;
            if(S[i-1] == S[i] ) {
                if(i < S.length / 2) {
                    count1++;
                }else{
                    count2++;
                }
                S[i] = '_';
            }
        }

        long ans;
        if(edge == 1) {
            ans = (count1 * ((K / 2) + K % 2)) + (count2 * (K / 2));
        } else {
            ans = (count1) + (count2 * (K - 1));
        }


        System.out.println(ans);
    }
}


Measured memory_bytes: 22740
S = input()
K = int(S[0]+S[1])
L = int(S[2]+S[3])
if 1<=K<=12 and 1<=L<=12:
    print("AMBIGUOUS")
if 1<=K<=12 and L == 0:
    print("MMYY")
if 1<=K<=12 and 13<=L<=99:
    print("MMYY")
if K ==0 and L == 0:
    print("NA")
if K == 0 and 1<=L<=12:
    print("YYMM")
if K == 0 and 13<=L<=99:
    print("NA")
if 13<=K<=99 and L == 0:
    print("NA")
if 13<=K<=99 and 1<=L<=12:
    print("YYMM")
if 13<=K<=99 and 13<=L<=99:
    print("NA")

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(long double p){printf("%.10Lf\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  ld L;in(L);
  ld l=L/3.0;
  out(l*l*l);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << ((s.size() % 2) ^ (s.front() == s.back()) ? "First\n" : "Second\n");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
     
int main() {
    /*1≤N≤100*/
  int n=0 , k = 1;
  string s = "";
  cin >> n;
  
  for (int i=0 ; i < n ; i++){
    cin >> s;
    if (s=="P") k *= 2;
    if (s=="W") k *= 3;
    if (s=="G") k *= 5;
    if (s=="Y") k *= 7;
    if (k%210 == 0) break;
    k %= 210;
  }
  
  if (k%210 == 0) cout << "Four";
  else cout << "Three";
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 998244353; //1e9+7;
const int MAXN = 1e6+1;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    double l; cin >> l;
    l /= 3;
    l = l*l*l;
    cout << fixed << setprecision(8) << l << endl;
    return 0;
}


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


int main(){
  ll n,k;cin >> n >> k;
  vector<ll> h(n);
  rep(i,n) cin >> h.at(i);

  vector<ll> dp(n);
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1)-h.at(0));
  for(ll i=1;i<min(n,k);++i){
    dp.at(i) = 1000000000000;
    for(ll j=0;j<i;++j){
      dp.at(i) = min( dp.at(i),dp.at(j)+abs( h.at(i)-h.at(j) ) );
    }
  }
  if( n > k ){
    for(ll i=k;i<n;++i){
      dp.at(i) = 1000000000000;
      for(ll j=i-k;j<i;++j){
        dp.at(i) = min( dp.at(i),dp.at(j)+abs( h.at(i)-h.at(j) ) );
      }
    }
  }
  // rep(i,n) cout << dp.at(i) << endl;
  cout << dp.back() << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;
ll ans=0;
ll dp[10001][101];
int d;
void solve(string &a , int p){
    int no=a.back()-'0';
    a.pop_back();
    int len=(int)a.length();
    if(a.length()==0){
        for(int i=0 ;i<=no; i++)
            if(i%d==p)
                ans++;
        return;
    }
    for(int i=no-1; i>=0; i--){
        ans+=dp[len][((p+d-i)%d+d)%d];
        ans%=mod;
    }
    if(a.length()>0)
        solve(a,((p+d-no)%d+d)%d);
}



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,y,l,r;
    string s;
    cin >> s;
    reverse(all(s));
    n=(int)s.length();
    cin >> d;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0; i<10000; i++){
        for(int j=0; j<101; j++){
            if(dp[i][j]!=0){
                for(int k=0; k<=9; k++){
                    dp[i+1][(j+k)%d]+=dp[i][j];
                    dp[i+1][(j+k)%d]%=mod;
                }
            }
        }
    }
    solve(s,0);
    cout << (ans-1+mod)%mod << el;
    
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>

using namespace std;

int main() {
  int H;
  int N;
  int sum = 0;
  cin >> H >> N;
  int A[N];
  
  for(int i =0; i<N ; i++){
      cin >> A[N];
      sum += A[N];
  }
  
  if(sum >= H){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		auto m = readln.chomp.to!int;
		auto p = m;
		foreach (i; 1..n) {
			auto a = readln.chomp.to!int;
			if (p < 0) p = a;
			else p += a;
			m = max(m, p);
		}
		m.writeln;
	}
}

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

#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    int n;
    string s;
    cin>>s;
    long long dp[500500];
    dp[0]=0;
    for(int i=1;i<500500;i++)dp[i]=dp[i-1]+i;
    char pre;
    int cnt=0;
    long long ans=0;
    vector<int>v;
    for(int i=0;i<s.size();i++){
        if(i==0){
            cnt++;
            pre=s[i];
        }else{
            if(pre==s[i]){
                cnt++;
            }else{
                v.PB(cnt);
                pre=s[i];
                cnt=1;
            }
        }
    }
    v.PB(cnt);
    int st=0;
    int en=v.size()-1;
    if(s[0]=='>'){
        ans+=dp[v[0]];
        st++;
    }
    if(s[s.size()-1]=='<'){
        ans+=dp[v[v.size()-1]];
        en--;
    }
    for(int i=st;i<en;i+=2){
        int a=v[i];
        int b=v[i+1];
        if(a>b)swap(a,b);
        ans+=dp[b]+dp[a-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5888
#include <stdio.h>
int main(){
    int n, count = 0, resp=0 ;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i){
        if((i%2 != 0) && (n >= 105)){
            count = 0;
            for(int j = 1;j<=i;++j){
                if(i%j == 0) ++count;
                if(count == 9) break;
            }
            if(count == 8) ++resp;
        }
    }
    printf("%d\n", resp);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

ll mod = 1000000007;

ll expo(ll a, ll b) {
	if(a == 0) return 0;
	ll ret = 1;
	while(b) {
		if(b&1) {
			ret = (ret * a) % mod;
		}
		b /= 2;
		a = (a * a) % mod;
	}
	return ret;
}

ll fact(ll x) {
	ll ret = 1;
	for(int i = 1; i <= x; ++i) {
		ret = (ret * i) % mod;
	}
	return ret;
}

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

	ll x, y;
	cin >> x >> y; 
	if((2*x - y) % 3 != 0) {
		cout << 0;
		return 0;
	}
	ll a = (2*x - y)/3;
	if(x - 2*a < 0 || a < 0) {
		cout << 0;
		return 0;
	}
	ll b = x - 2*a;
	ll r1 = fact(a+b);

	ll r2 = expo(fact(a), mod - 2);
	ll r3 = expo(fact(b), mod - 2);
    
	r1 = (r1 * r2) % mod;
    r1 = (r1 * r3) % mod;
    cout << r1; 
    return 0;
}

Measured memory_bytes: 256
// B - Shift only

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

int N;
int A[200];
int solve();

int main() {
  // ここにプログラムを追記

  cin >> N;
  for(int i =0; i<N; i++){
    cin >>A[i];
  }


  cout << solve() << endl;
}

int solve(){
  bool flag = true;
  int count =-1;
  while(flag){
    for(int i =0; i<N; i++){
      if(A[i] % 2 == 0){
        A[i] /=2;
      }else{
        flag = false;
        break;
      }
    }
    count++;

  }
  return count;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),l(n+1),r(n+1);
    for(auto &t : a) cin>>t;
    for(int i=1;i<n;++i){
        l[i] = max(l[i-1],a[i-1]);
    }
    r[n-1] = a[n-1];
    for(int i=n-2;i>=0;--i){
        r[i] = max(r[i+1],a[i]);
    }
    
    for(int i=0;i<n;++i){
        cout << max(l[i],r[i+1]) << endl;
    }
    return 0;
}



Measured memory_bytes: 3968
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
 */
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);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int T = in.nextInt();
            out.println(T / A * B);
        }

    }
}



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n+1);
	
	rep(i, n+1) cin >>a[i];
	if(n==0){ puts(a[0]==1? "1":"-1"); return 0;}
	if(a[0]>0 && n>0){ puts("-1");return 0;}
	if(a.back()==0){ puts("-1");return 0;}
	const ll INF = 1LL<<61;
	VL mz(n+1), pz(n+1);
	mz[0]=1;
	rep(i, n){
		mz[i+1]=min(INF, (mz[i] - a[i]) * 2LL);
		if(mz[i]<a[i]){ { puts("-1");return 0;}}
	}
	ll cr=0;
	repr(i, n, 0){
		cr += a[i];
		pz[i] = cr;
	}
	//for(auto x :mz) cerr<<x<<" "; dbg();
	//for(auto x :pz) cerr<<x<<" "; dbg();
	ll ans = 0;
	rep(i, n+1){
		if(mz[i] < a[i]){puts("-1");return 0;}
		ans += min(pz[i], mz[i]);
	}
	cout << ans <<"\n";
	return 0;
}


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

int64_t gcd (int64_t a, int64_t b){
   if (b == 0){
       return a;
   }
   else{
       return(gcd(b, a%b));
   }
}
int64_t lcm (int64_t a, int64_t b){
   return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    vector<int64_t>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int64_t ans = 1;
    for(int i=0; i<n; i++){
        ans = lcm(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

int a[105][105], b[105][105];

int main() {
    for (int i = 1; i <= 3; ++i)
        for (int j = 1; j <= 3; ++j)
            scanf("%d", &a[i][j]);
    int n;
    scanf("%d", &n);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        for (int j = 1; j <= 3; ++j)
            for (int k = 1; k <= 3; ++k)
                if (a[j][k] == x)
                    b[j][k] = 1;
    }
    for (int i = 1; i <= 3; ++i) {
        int fail = 0;
        for (int j = 1; j <= 3; ++j)
            if (!b[i][j]) {
                fail = 1;
                break;
            }
        if (!fail) return puts("Yes"), 0;
    }
    for (int i = 1; i <= 3; ++i) {
        int fail = 0;
        for (int j = 1; j <= 3; ++j)
            if (!b[j][i]) {
                fail = 1;
                break;
            }
        if (!fail) return puts("Yes"), 0;
    }
    if (b[1][1] && b[2][2] && b[3][3]) return puts("Yes"), 0;
    if (b[1][3] && b[2][2] && b[3][1]) return puts("Yes"), 0;
    return puts("No"), 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
bool check(int num){
    int a,b,c,d;
    a=num%10;
    b=num/10000%10;
    c=num/10%10;
    d=num/1000%10;
    if(a==b&c==d)return true;
    else return false;
}
int main(void){
 int a,b;
 cin>>a>>b;
 int ans=0;
 for (int i=a;i<=b;i++){
     if(check(i)){
         ans++;
     }
 }   
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 2e5+10;
long long n;
int main(){
    scanf("%lld",&n);
    long long ans = (n/11)*2;
    if(n% 11 == 0)   ans = ans;
    else if(n%11 <= 6 )   ans = ans+1;
    else   ans = ans+2;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  unordered_set<int> rem;
  int seven = 0;
  int answer = 1;
  while (1) {
    seven = seven * 10 + 7;
    seven %= K;
    if (seven == 0) break;
    if (rem.count(seven)) {
      answer = -1;
      break;
    }
    rem.emplace(seven);
    ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 42716
N = int(input())
l = list(map(int, input().split()))

output = 100
for i in range(N-1):
  sum_a = 0
  sum_b = 0
  #2つのグループの重さの合計を計算
  for j in range(N):
    if j<=i:
      sum_a += l[j]
    else:
      sum_b += l[j]
  tmp = abs(sum_a - sum_b)
  if output>tmp:
    output = tmp

print(output)

Measured memory_bytes: 3060
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

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

    string s;
    cin >>s;

    int cnt=1;
    for(int i=1; i<n; i++)
    {
        if(s[i]!=s[i-1])
            cnt++;
    }
    cout << cnt << "\n";

    return 0;
}






Measured memory_bytes: 3768
#include <iostream>


#define oo 10000000


using namespace std;

int demslc2(int a)
{
    int dem=0;
    while (a>0)
    {
        if (a%2==0)
        {
            dem++;
            a=a/2;
        }
        else break;
    }
    return dem;
}

int main()
{
    int n;
    cin>>n;
    int maxc=-1;
    int i,luui=0;
    for(i=1;i<=n;i++)
    {
        int kq=demslc2(i);
        if (kq>maxc)
            {maxc=kq;
            luui=i;}
    }
    cout<<luui<<endl;

   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;

int main(void) {
  int i, j, k, l, n;
  double ans = 0;
  scanf("%d", &n);
  int a[n];
  pair<int, int> d[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n, greater<int>());
  for(i = 0; i < n - 1; ++i) d[i].first = a[i] - a[i + 1], d[i].second = i;
  sort(d, d + n - 1);
  if(d[0].second && d[0].second != 1) ans = (double)(a[0] + a[1]) / d[0].first;
  else {
    for(i = 0; i < 4; ++i) for(j = 0; j < 4; ++j) for(k = 0; k < 4; ++k) for(l = 0; l < 4; ++l) if(i != j && j != k && k != l && l != i && i != k && j != l) if(ans < (double)(a[i] + a[j]) / (a[k] - a[l])) ans = (double)(a[i] + a[j]) / (a[k] - a[l]);
    if(d[1].second && d[1].second != 1) {
      if(ans < (double)(a[0] + a[1]) / d[1].first) ans = (double)(a[0] + a[1]) / d[1].first;
    } else {
      if(ans < (double)(a[0] + a[1]) / d[2].first) ans = (double)(a[0] + a[1]) / d[2].first;
    }
  }
  printf("%f\n", ans);
  return 0;
}


Measured memory_bytes: 2784
#include <stdio.h>
 
int main(){
int N,a,i,gray=0,brown=0,green=0,water=0,blue=0,yel=0,ore=0,red=0,upper=0,min;
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&a);
if(0<a && a<400){
gray=1;
}
if(400<=a && a<800){
brown =1;
}
if(800<=a && a<1200){
green =1;
}
if(1200<=a && a<1600)water=1;
if(1600<=a && a<2000)blue=1;
if(2000<=a && a<2400)yel =1;
if(2400<=a && a<2800)ore=1;
if(2800<=a && a<3200)red=1;
if(a>=3200)upper++;
}
if(gray+brown+green+water+blue+yel+ore+red==0){
min =1;
}else{
min=gray+brown+green+water+blue+yel+ore+red;
}
printf("%d ",min);
printf("%d",gray+brown+green+water+blue+yel+ore+red+upper);
 
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <utility>
using namespace std;

int sort(int a[], int n);

int main(void)
{	
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	
	int num = sort(a, n);
	
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i < n - 1) cout << " ";
		else cout << endl;
	}
	cout << num << endl;
	
	return 0;
}

int sort(int a[], int n)
{
	int i, j, cnt = 0;
	for (i = 0; i < n; i++) {
		int minj = i;
		for (j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			swap(a[i], a[minj]);
			cnt++;
		}
	}
	
	return cnt;
}

Measured memory_bytes: 3088
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    char ret = 'A';

    for(;;){
        string s;
        if(!(cin >> s))
            break;

        if(ret == s[0])
            ret = s[2];
        else if(ret == s[2])
            ret = s[0];
    }

    cout << ret << endl;
    return 0;
}

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

int ans;
string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	
 	cin >> s;
 	ans++;
 	char prev = s[0];
 	for (int i = 0; i < s.size(); i++) {
 		if (s[i] != prev) {
 			ans++;
 		}
 		prev = s[i];
 	}

 	cout << ans-1 << '\n';
 	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[60];
ll dp[60][3000];
int main(){
  ll n,x,ans=0;
  cin>>n>>x;
  rep(i,0,n)cin>>a[i];
  dp[0][0]=1;
  rep(i,0,n){
    irep(j,n-1,0){
      rep(k,0,2501) {
        if(dp[j][k]>0){
          dp[j+1][k+a[i]]+=dp[j][k];
        }
      }
    }
  }
  rep(i,1,n+1)ans+=dp[i][i*x];
  cout<<ans;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define  LL long long
const LL mod = 1e9+7;


int main()
{
	int a[111];
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int ans=0;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		if(a[i]<=x){
			ans++;
			x-=a[i];
			if(i==n&&x>0)
				ans--;
		}
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    int j=0;
    int check=0;
    
    cin >> S;
    for(int i=0;i<S.length();i++){
        
        if(j==0){
            if(S.at(i)=='h'){
                j=1;
            }else{
                check=1;
                break;
            }
        }else{
            if(S.at(i)=='i'){
                j=0;
            }else{
                check=1;
                break;
            }
            
        }
    }
    
    if(check==1){
        cout << "No" << endl;
    }else if(j==1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
d,n = map(int,input().split())

if d is 0:
    print(n + n//100)
if d is 1:
    if n is 100:
        print(100*100+100)
    else:
        print(n*100)
if d is 2:
    if n is 100:
        print(100*10000+10000)
    else:
        print(n*10000)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string a, b, c, ans="NO";
    cin >> a >> b >> c;
    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) ans = "YES";
    cout << ans << endl;

}

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

struct perm {
	vector <int> v;
	void input(int n) {
		v.resize(n);
		for (int i = 0; i < n; i++) {
			scanf("%d", &v[i]);
			v[i]--;
		}
	}
	void output() {
		for (int i = 0; i < v.size(); i++)
			printf("%d ", v[i] + 1);
		puts("");
	}
	int& operator [](int id) {
		return v[id];
	}
};

perm inv(perm a) {
	vector <int> res(a.v.size(), 0);
	for (int i = 0; i < res.size(); i++)
		res[a[i]] = i;
	return {res};
}

perm operator *(perm a, perm b) {
	vector <int> res(a.v.size(), 0);
	for (int i = 0; i < a.v.size(); i++)
		res[i] = a[b[i]];
	return {res};
}

perm operator ^(perm a, int n) {
	perm res;
	for (int i = 0; i < a.v.size(); i++)
		res.v.push_back(i);
	for (; n; n /= 2) {
		if (n % 2)
			res = res * a;
		a = a * a;
	}
	return res;
}

int N, K;
perm p, q;

void load() {
	scanf("%d%d", &N, &K);
	p.input(N);
	q.input(N);
}

perm solve() {
	for (; K > 2 && K % 3 != 2; K--) {
		perm t = q;
		q = q * inv(p);
		p = t;
	}
	
	if (K == 1)
		return p;
	if (K == 2)
		return q;
	
	int diff = K / 3 + 1;
	int same = K / 3 - 1;
	perm pref = q * inv(p) * inv(q) * p;
	pref = pref ^ (diff / 2);
	if (diff % 2)
		pref = pref * q * inv(p);
	perm a = inv(q) * inv(p);
	perm b = q * p;
	if (same % 2) 
		swap(a, b);
	perm suff = a * b;
	suff = suff ^ (same / 2);
	if (same % 2)
		suff = suff * a;
	return pref * suff * inv(q);
}

int main() {
	load();
	solve().output();
	return 0;
}

Measured memory_bytes: 5920
def get_cusum(lst):
    cusum = [0] + lst
    for i in range(1, len(cusum)):
        cusum[i] = cusum[i] + cusum[i-1]
    return cusum


def main():

    n, m, k = map(int, input().split(" "))
    book_a = get_cusum(list(map(int, input().split(" "))))
    book_b = get_cusum(list(map(int, input().split(" "))))
    ans = 0
    top = m

    # print(book_a)
    # print(book_b)

    for i in range(n + 1):
        if book_a[i] > k:
            break

        while book_b[top] > k - book_a[i]:
            top -= 1

        ans = max(ans, i+top)

    print(ans)


main()


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N, M, C;
vector<ll> B;
vector< vector<ll> > A;

signed main()
{
    cin >> N >> M >> C;
    B.resize(M);
    REP(i, M) { cin >> B[i]; }
    A.assign(N, vector<ll>(M));
    REP(i, N) { REP(j, M) { cin >> A[i][j]; } }

    ll ans = 0;
    REP(i, N) {
        ll sum = 0;
        REP(j, M) {
            sum += A[i][j] * B[j];
        }
        sum += C;
        if(sum > 0) { ans++; }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    int a;
    int b;
    cin >> a >> b;
    int o = a+ b;
    int y = a - b;
    int h = a*b, max;;
    if(o>=y && o>=h)
        max = o;
    else if(y>=h && y>=o)
        max = y;
    else if(h>=y && h>=o)
        max = h;
        
    cout << max << endl;    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 1e5 + 10;
int n;
double T,A;
double arr[maxn];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
//    ifstream cin("in.txt");
    cin >> n >> T >> A;
    for(int i =0 ;i < n; i ++){
        cin >>arr[i];
    }
    vector<pair<double, int> > v;
    for(int i =0 ; i < n; i ++){
        double p = T - (arr[i] * (double)(0.006));
        v.push_back(make_pair(max(A, p) - min(A, p), i + 1));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

using namespace std;

const int N = 1e5+100;

long long int dp[N];

bool ok[N];

int main () {
    memset(dp,63,sizeof(dp));
    ok[0]=1;
    dp[0]=0;
    long long int n, w;
    cin >> n >> w;
    for(int i = 0 ; i < n ; i++ ) {
        long long int x, y;
        cin >> x >> y;
        for(int j = 1e5 ; j >= 0 ; j--) {
            if(j-y<0)break;
            if(ok[j-y]) {
                dp[j]=min(dp[j],dp[j-y]+x);
                ok[j]=1;
            }
        }
    }
    long long int ans = 0;
    for(int i = 0 ; i <= 1e5 ; i++ ) if(dp[i]<=w) ans=i;
    cout << ans;
}


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

int main(){
    int n;
    string X;

    cin >> n;

    string s[n];
    int t[n];
    for(int i=0;i<n;i++){
        cin >> s[i] >> t[i];
    }

    cin >> X;

    int idx;
    for(int i=0;i<n;i++){
        if (s[i] == X){
            idx = i;
            break;
        }
    }

    int ret;
    for(int i=idx+1;i<n;i++){
        ret += t[i];
    }

    cout << ret << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int idx[]={0,-1,0,1};
int idy[]={1,0,-1,0}; int n,m;
int cnt,edge;
const int mod=1e9+7;
const int N=1e5+7;
int dp[N][13];

 int32_t main()
 {
    string s; cin>>s; int n=s.size(); //s='*'+s;
    dp[0][0]=1;  int ans=0;  // no of possible first digit i such that rem with 13 is j
    for(int i=0;i<n;i++)
    {
       bool flag=0; int xx;
       if(s[i]=='?') flag=1; else xx=s[i]-'0';
       for(int j=0;j<=9;j++)
       {
          if(!flag and xx!=j) continue;
          for(int k=0;k<=12;k++)
            { dp[i+1][(k*10+j)%13]+=dp[i][k]; dp[i+1][(k*10+j)%13]%=mod; }
        } 

    }
    cout<<dp[n][5]<<endl;  return 0;
 }


Measured memory_bytes: 10624