akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void){
    string input;
    int cnt = 0;
    
    while(getline(cin, input), !cin.eof()){
        int x;
        
        sscanf(input.c_str(), "%d", &x);
        if(x == 0) break;
        printf("Case %d: %d\n", ++cnt, x);
    }
    
    return(0);
}



Measured memory_bytes: 3184
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric> // next_parmutation

using namespace std;

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

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

}

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  for(int i = 0; i < N; i++){
    cin >> X[i];
  }
  ll ptr = X[0];
  ll res = 0;
  for(int i = 1; i < N; i++){
    res += min((X[i] - X[i-1]) * A, B);
  }
  cout << res << endl;
}


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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

ll n, m;
vvll g;

vll dp;

ll dfs(int idx) {
  ll ans = 0;
  for (auto to : g[idx]) {
    if (!dp[to]) {
      dfs(to);
    }
    chmax(ans, dp[to]);
  }
  ans++;
  dp[idx] = ans;
  return ans;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> n >> m;
  g = vvll(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
  }

  dp = vll(n);

  rep(i, n) {
    if (!dp[i]) {
      dfs(i);
    }
  }

  cout << *max_element(all(dp)) - 1 << endl;

  return 0;
}


Measured memory_bytes: 8576
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003



int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);
	
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);
	
	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);
	
	return ret;

}

int number(State &begin){
	int ret =0;
	
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}






int main(void){
	
	ll n,a,b;
	
	cin>>n>>a>>b;
	
	if(a>b)
		cout<<0<<endl;
	else if(n==1){
		if(a==b)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}
	else
	cout<<(b-a)*(n-2)+1<<endl;

}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, m;
	

	cin >> n;

	double sum = 0;

	for (int i = 0; i < n; i++) {
		double x;
		string s;
		cin >> x >> s;

		if (s == "JPY") {
			sum += x;
		}
		else {
			sum += (380000 * x / 1.0);
		}
	}

	cout <<fixed << setprecision(6) << sum << endl;




	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
const int N = 1e5+10;
ll res[N];
ll n, k;
ll qmi(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1) {
            res *= a;
            res %= mod;
        }
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return res % mod;
}
int main() {
    cin >> n >> k;
    for(ll i = k; i >= 1; i --) {
        ll temp = qmi(k/i, n);
        //cout << i << " " << temp << endl;
        for(ll j = 2; j*i <= k; j ++) {
            temp += (mod - res[j*i]);
            temp %= mod;
        }
        
        res[i] = temp;
    }
    ll ret = 0;
    for(ll i = 1; i <= k; i ++) {
        ret += i*res[i];
        ret %= mod;
    }
    cout << ret << endl;
}

Measured memory_bytes: 4420
#include <iostream>
#include <string>

using namespace std;

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

int main() {
  string s, sr, a, ar;
  cin >> s;
  sr = s;
  reverse(sr.begin(), sr.end());
  int q;
  cin >> q;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 1) {
      swap(s, sr);
      swap(a, ar);
    } else {
      int f; char c;
      cin >> f >> c;
      if(f == 1) a = a + c;
      else ar = ar + c;
    }
  }
  reverse(a.begin(), a.end());
  cout << a + s + ar << endl;
  return 0;
}

Measured memory_bytes: 4024
N = int(input())
A = [int(i) for i in input().split()]

A.sort()

num = 0

if N == A.count(A[0]):
    num = 1
else:
    l = A
    x = []

    while True:
        x = []
        x.append(l[0])
        for i in range(1, len(l)):
            if 0 < l[i] % l[0]:
                x.append(l[i] % l[0])

        if len(x) == 1:
            break

        x.sort()

        l = x

print(A[0] if num == 1 else x[0])


Measured memory_bytes: 14252
//a/b programing

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
int a,b,d,r;
double f;

cin>>a>>b;

d=a/b;
r=a%b;
f=(double)a/b;

cout<<d<<" "<<r<<" ";
printf("%.8f\n",f);

return 0;
}

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

int main() {
    double N, K;
    cin >> N >> K;
    vector<double> p(N);
    rep(i, N) {
        double tmp;
        cin >> tmp;
        p[i] = (tmp + 1)/2;
    }
;
    double zero = 0;
    double pre = p[0];
    double ans = accumulate(p.begin(), p.begin() + K, zero);
    double now = ans;
    for (int i = K; i < N; i++) {
        now = now + p[i] - pre;
        ans = max(ans, now);
        pre = p[i - K + 1];
    }
    printf("%.7lf", ans);
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>

int selectionSort(int A[], int N){
	int i, j, t, sw = 0, minj;
	for(i = 0; i < N-1; i++){
		minj = i;
		for(j = i; j < N; j++){
			if(A[j] < A[minj]) minj = j;
		}
		t = A[i]; A[i] = A[minj]; A[minj] = t;
		if(i != minj) sw++;
	}
	return sw;
}

int main(void){
	int A[100], N, i, sw;
	
	scanf("%d", &N);
	for(i = 0; i < N; i++) scanf("%d", &A[i]);
	
	sw = selectionSort(A, N);
	
	for(i = 0; i < N; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
		
	}
	printf("\n");
	printf("%d\n", sw);
	
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    vector <string> dash={"AC", "WA", "TLE" , "RE" };
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n;
    vector <string> v1(n);
    for(int i=0;i<n;i++)cin>>v1[i];
    for(int i=0;i<4;i++)cout<<dash[i]<<" x "<<count(v1.begin(),v1.end(),dash[i])<<endl;
    return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>K;
    vector<vector<bool> > dp(N+1, vector<bool>(K+1,0)), rdp(N+1, vector<bool>(K+1, 0));
    vec a(N);
    rep(i,N) cin>>a[i];
    dp[0][0] = rdp[0][0] = 1;
    reps(i,1,N+1){
        rep(j,K+1){
            if(dp[i-1][j]) dp[i][j] = 1;
            if(rdp[i-1][j]) rdp[i][j] = 1;
            if(dp[i-1][j] && (j + a[i-1] <= K)) dp[i][j + a[i-1]] = 1;
            if(rdp[i-1][j] && (j + a[N-i] <= K)) rdp[i][j + a[N-i]] = 1;
        }
    }
    ll ans = N;
    /*rep(i,N+1){
        rep(j,K+1) cout<<rdp[i][j]<<' ';
        cout<<endl;
    }*/
    rep(i,N){
        vector<bool> &now = dp[i], &rnow = rdp[N - i - 1];
        ll idn = 0, idrn = K;
        /*if(i == 1){
            rep(j,K+1) cout<<now[j]<<' ';
            cout<<endl;
            rep(j,K+1) cout<<rnow[j]<<' ';
            cout<<endl;
        }*/
        while(idn < K || idrn > 0){
            while(now[idn] == 0 && idn < K) ++idn;
            while(rnow[idrn] == 0 && idrn > 0) --idrn;
            if(now[idn] && rnow[idrn] && (idrn + idn) < K && (idrn + idn) >= K - a[i]){
                --ans;
                break;
            }
            if(((idrn + idn) >= K) && (idrn != 0)) {
                --idrn;
            }else if(idn != K){
                ++idn;
            }
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n >= 30) Yes();
    else No();
}

Measured memory_bytes: 3652
N=int(input())
*A1,=map(int, input().split())
*A2,=map(int, input().split())
a2=A2[:]
for i in range(N-2,-1,-1):
    a2[i]+=a2[i+1]
ans=0
ac=0
for i in range(N):
    ac+=A1[i]
    ans = max(ans, ac+a2[i])
print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }
  count := 0
  flag := true
  for flag {
    for i := range a {
      if a[i]%2 == 0 {
        a[i] /= 2
        continue
      }
      flag = false
    }
    if flag {
      count++
    }
  }
  fmt.Println(count)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
vector<pair<ll,ll> >v;
int main(){
    ll n;
    cin>>n;
    rep(i,n){
	ll x,l; cin>>x>>l;
	v.push_back(make_pair(x+l,x-l));
    }   
    sort(v.begin(),v.end());
    ll bef=-1e18,ans=0;
    rep(i,n){
	ll r=v[i].first,l=v[i].second;
	if(bef<=l){
	    bef=r;
	    ans++;
	}
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 2420
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<vector>
#include <algorithm>
#include <sstream>
#include <iomanip>


int main(){
  int n;
  double r = 0.0;
  std::cin >> n;
  std::vector<double> vec;
  for(int i=0; i<n; i++){
      double v;
      std::cin >> v;
      vec.push_back(v);
  }
  std::sort(vec.begin(), vec.end());
  
  double val = vec.at(0);
  for(int i=1; i<n; i++){
    val = (val + vec.at(i))/2.;
  }
  std::cout << std::setprecision(6) << val << std::endl;
  
  return 0;
}



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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

const int MAX = 100000;

int dp[MAX + 1] = {};

int main() {
	int n; cin >> n;
	
	int a, b, res = 0;
	REP( i, n ) {
		cin >> a >> b;
		FOR( i, a, b + 1 ) {
			dp[i]++;
			if( dp[i] == i - 1 ) res = max( dp[i], res );
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 3452
#include<iostream>
using namespace std;
int main(){
	int monny;
	int coin[]={500,100,50,10,5,1};
	while(cin>>monny&&monny!=0){
		monny=1000-monny;
		int answer=0;
		for(int i=0;i<6;++i){
			answer+=monny/coin[i];
			monny%=coin[i];
		}
		cout<<answer<<endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

struct E {
  int a, b, c;
};

vector<E> g[100000+5];
int cs[100000+5];
bool visited[100000+5];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n-1) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    --u;
    --v;
    g[u].push_back((E){u, v, w});
    g[v].push_back((E){v, u, w});
  }

  visited[0] = true;
  cs[0] = 1;
  queue<int> q;
  q.push(0);
  while(!q.empty()) {
    int u = q.front(); q.pop();
    REP(i, g[u].size()) {
      const E &e = g[u][i];
      if(!visited[e.b]) {
        visited[e.b] = true;
        cs[e.b] = e.c % 2 ? !cs[e.a] : cs[e.a];
        q.push(e.b);
      }
    }
  }
  REP(i, n) {
    printf("%d\n", cs[i]);
  }
  return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];

int main() {
    cio;
    int a,b;
    cin >> a >> b;
    if (a - b * 2 > 0)
        cout << a - b*2;
    else
        cout << 0;
    cn;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int add(int x, int y){return (x+y)%MOD;}
int mul(int x, int y){return (1LL*x*y)%MOD;}

int dp[128][16384];
int pk1[128];
int n,k;

int f(int n, int o){
	if(dp[n][o]>=0)return dp[n][o];
	int r=0;
	fore(j,0,k+1){
		if(j>n){r=add(r,add(mul(pk1[n-1],j+o),f(n-1,o)));}
		else {
			r=add(r,add(mul((j+o)%n,pk1[n-1]),f(n-1,o+(j+o)/n)));
		}
	}
	//printf("%d %d %d\n",n,o,r);
	return dp[n][o]=r;
}

int main(){
	scanf("%d%d",&n,&k);
	pk1[0]=1;
	fore(i,1,128)pk1[i]=mul(pk1[i-1],k+1);
	memset(dp,-1,sizeof(dp));
	fill(dp[0],dp[0]+16384,0);
	printf("%d\n",f(n,0));
	return 0;
}

Measured memory_bytes: 8448
from bisect import bisect_left
from sys import setrecursionlimit

setrecursionlimit(3*10**5)

INF = 10**10

N = int(input())
a = list(map(int,input().split()))
T = [set() for x in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    T[u].add(v)
    T[v].add(u)

search = [0]*N

A = [INF]*N

ans = [-1]*N

def dfs(V):
    num = a[V]
    num = a[V]
    k = bisect_left(A,num)
    v = A[k]
    A[k] = num
    ans[V] = bisect_left(A,INF)
    for VV in T[V]:
        if search[VV]:
            continue
        search[VV] = 1
        dfs(VV)
    A[k] = v

search[0] = 1
dfs(0)

print(*ans,sep="\n")

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


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

    bool nb = false, wb = false, sb = false, eb = false;
    rep(i, s.size()) {
        char c = s[i];
        if (c == 'N') nb = true;
        if (c == 'W') wb = true;
        if (c == 'S') sb = true;
        if (c == 'E') eb = true;
    }

    if ((nb ^ sb) || (wb ^ eb)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

}


Measured memory_bytes: 256
function main()
  
  O = split(readline(),"")
  E = split(readline(),"")
  
  for i in 1:length(O)+length(E)
    
    if i % 2 == 1 && div(i+1,2) <= length(O)
      print(O[div(i+1,2)])
    elseif div(i,2) <= length(E)
      print(E[div(i,2)])
    end
    
  end
  
end

main()

Measured memory_bytes: 165520
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//https://atcoder.jp/contests/abc103/tasks/abc103_d

int main() {
    int N, M; cin >> N >> M;
    P ab[M];
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        ab[i] = {b, a};
    }
    sort(ab, ab + M);

    int cnt = 0;
    int now = 0;
    REP(i, M) {
        int l = ab[i].second;
        int r = ab[i].first;

        if (l >= now) {
            cnt++;
            now = r;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1152
def floor_sum(n, m, a, b):
    res = 0
    while True:
        if a >= m:
            res += (n - 1) * n * (a // m) // 2
            a %= m
        if b >= m:
            res += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        if y_max == 0: break
        x_max = b - y_max * m
        res += (n + x_max // a) * y_max
        n, m, a, b = y_max, a, m, x_max % a
    return res

def inv_gcd(a, b):
    a %= b
    if a == 0: return b, 0
    s = b
    t = a
    m0 = 0
    m1 = 1
    while t:
        u = s // t
        s -= t * u
        m0 -= m1 * u
        s, t = t, s
        m0, m1 = m1, m0
    if m0 < 0: m0 += b // s
    return s, m0

def inv_mod(x, m):
    assert 1 <= m
    g, im = inv_gcd(x, m)
    assert g == 1
    return im


def f(x):
  r=[]
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      r.append([i,0])
      while x%i==0:
        x//=i
        r[-1][1]+=1
  if x!=1:
    r.append([x,1])
  return r

def crt(r, m):
    assert len(r) == len(m)
    n = len(r)
    r0 = 0
    m0 = 1
    for i in range(n):
        assert 1 <= m[i]
        r1 = r[i] % m[i]
        m1 = m[i]
        if m0 < m1:
            r0, r1 = r1, r0
            m0, m1 = m1, m0
        if m0 % m1 == 0:
            if r0 % m1 != r1: return 0, 0
            continue
        g, im = inv_gcd(m0, m1)
        u1 = m1 // g
        if (r1 - r0) % g: return 0, 0
        x = (r1 - r0) // g * im % u1
        r0 += x * m0
        m0 *= u1
        if (r0 < 0): r0 += m0
    return r0, m0

N=int(input())
X=f(N*2)
if len(X)==1:
  print(2*N-1)
  exit()
X2=[X[i][0]**X[i][1] for i in range(len(X))]
Y=[1]
for i in range(len(X)):
  Y.append(Y[i]*X2[i])
P=10**20
M=len(Y)-1
for i in range(1,(1<<M)-1):
  A=[((i&(1<<j))>>j) for j in range(M)]
  P=min(P,crt(A,X2)[0])
print(P-1)

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int h, w , k; cin >> h >> w >> k;
  char s[h][w];
  int hsh = 0;
  for (int i = 0; i < h; ++i){
    for (int j = 0; j < w; ++j){
      cin >> s[i][j];
      if(s[i][j]=='#')  hsh++;
    }
  }
  int ans = 0;
  for (int i = 0; i < (1<<h); ++i){
    for (int j = 0; j < (1<<w); ++j){
      int minus = 0;
      for (int ii = 0; ii < h; ++ii){
        for (int jj = 0; jj < w; ++jj){
          if( bool(i&(1<<ii)) or bool(j&(1<<jj)) ){
            if(s[ii][jj]=='#')  minus++;
          }
        }
      }
      if(hsh-minus == k){
        ans++;
      }
    }
  }
  cout << ans << "\n";

  return 0;
}

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

string tani[]={
	"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"
};


string add(string a,string b){
	if(a.size()<b.size())swap(a,b);
	while(a.size()>b.size())b="0"+b;
	int c=0;
	for(int i=a.size()-1;i>=0;i--){
		a[i]+=(b[i]-'0'+c);
		if(a[i]>'9'){
			a[i]-=10;
			c=1;
		}
		else c=0;
	}
	if(c)a="1"+a;
	return a;
}

string x10(string a,int n){
	while(n--)a+="0";
	return a;
}

string mlt(string a,string b){
	string tmp[10];
	tmp[0]="0";
	tmp[1]=a;
	for(int i=2;i<=9;i++)tmp[i]=add(tmp[i-1],a);
	string res=tmp[b[b.size()-1]-'0'];
	for(int i=1;i<b.size();i++){
		res=add(res,x10(tmp[b[b.size()-1-i]-'0'],i));
	}
	return res;
}

string pow(string a,int n){
	string res=a;
	for(n--;n--;)res=mlt(res,a);
	return res;
}

int main(){
	
	string s;
	int n;
	while(cin>>s>>n){
		if(s=="0"&&n==0)break;
		string ans=pow(s,n);
		reverse(ans.begin(),ans.end());
		vector<string>V;
		for(int i=0;i<ans.size();i+=4){
			string tmp="";
			for(int j=0;j<4;j++){
				if(i+j>=ans.size())break;
				tmp+=ans[i+j];
			}
			reverse(tmp.begin(),tmp.end());
			V.push_back(tmp);
		}
		reverse(V.begin(),V.end());
		for(int i=0;i<V.size();i++){
			if(V[i]=="0000")continue;
			while(V[i][0]=='0')V[i]=V[i].substr(1);
			cout<<V[i];
			cout<<tani[V.size()-i-1];
		}
		cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 101;
char s[mxn];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x; cin>>x;
	cout << 1-x << '\n';

	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 3644
S = str(input())
N = int(input())
for _i in range(N):
    line = input().split()
    start = int(line[1])
    end = int(line[2])

    if line[0] == 'print':
        print(S[start:end + 1])
    if line[0] == 'reverse':
        reversed_word = list(S[start:end + 1])
        reversed_word.reverse()
        S = S[:start] + ''.join(reversed_word) + S[end + 1:]
    if line[0] == 'replace':
        S = S[:start] + line[3] + S[end + 1:]



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Power Socket
            var line = ReadLine();
            int A = line[0];
            int B = line[1];

            int sockets = 1;
            int i = 0;

            while (sockets < B)
            {
                sockets += A - 1;
                i++;
            }

            Console.WriteLine(i);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner jk = new Scanner(System.in);
		double n = jk.nextDouble();
		double[] arr = new double[(int) n];
		double den = 0.0;
		for (int i=0; i<n; i++)
		{
			arr[i] = jk.nextDouble();
			den+=(1/arr[i]);
		}
		System.out.println(1/den);
		
		
	}

}


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A(M, 0);
    for(int i=0; i<N; ++i) {
        int K;
        cin >> K;
        for(int j=0; j<K; ++j) {
            int a;
            cin >> a;
            ++A[a-1];
        }
    }

    int res = 0;
    for(int i=0; i<M; ++i) {
        if(A[i] == N) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
        "math"
)

func solution(n, k int) float64 {

        memo := make([]float64, n+1)

        for i := 1; i < n+1; i++ {
                if i < k {
                        x := helper(i, k)
                        memo[i] = 1 / (float64(n) * math.Pow(2, x))
                } else {
                        memo[i] = 1 / float64(n)
                }
        }

        out := 0.0
        for i := 1; i < n+1; i++ {
                out += memo[i]
        }
        return out
}

func helper(i, k int) float64 {
        x, out := i, 0.0
        for k > x {
                x *= 2
                out++
        }
        return out
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        fmt.Printf("%.9f\n", solution(n, k))
}

Measured memory_bytes: 2644
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,ans,x,i,l,j;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++){
		for(int l=0;l<=b;l++){
			for(int j=0;j<=c;j++){
				if(500*i+100*l+50*j==x)
    			ans++;	
    			if(500*i+100*l+50*j>x)
    			break;
			}
			
		}
			
	}

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

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

int main(){
  int n,d;
  scanf("%d %d",&n,&d);
  int x[10][10];
  int i,j,k;
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  int count = 0;
  double d2,dis;
  for(i=0;i<=n-2;i++){
    for(j=i+1;j<=n-1;j++){
      d2 = 0;
      for(k=0;k<d;k++){
        d2 += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      }
      dis = sqrt(d2);
      if(ceil(dis) == floor(dis)){
        count += 1;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> pll;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
const int MOD = 1000000007;
// constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
template <class T> bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    ll t = 0;
    ll res = 0;
    rep(i,1000) {
        t += x;
        res++;
        if (t%360 == 0) break;
    }
    print(res);

    return 0;
}


Measured memory_bytes: 3616
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(" ")))

    variation = set(a)
    a_count_dict = defaultdict(int)
    for j in a:
        a_count_dict[j] += 1

    total = 0
    c_dict = {}
    for i in variation:
        count = a_count_dict[i]
        if count > 1: # 2個以上
            # c = combinations_count(count, 2)
            c = count * (count - 1) // 2
        else:
            c = 0
        c_dict[i] = c
        total = total + c

    # total = 0
    # c_list = []
    # a_count_list = []
    # for i in range(n):
    #     count = a.count(i + 1)
    #     a_count_list.append(count)
    #     # print(count)
    #     if count > 1: # 2個以上
    #         # c = combinations_count(count, 2)
    #         c = count * (count - 1) // 2
    #     else:
    #         c = 0
    #
    #     c_list.append(c)
    #     total = total + c

    # print(a, c_list, total, a_count_list)
    for k in range(n):
        ck = c_dict[a[k]]
        ca = a_count_dict[a[k]]
        if ck == 1 or ck == 0:
            q = ck
        else:
            # q = c_list[a[k] - 1] - 1
            q = ck - ck * (ca - 2) // ca


        # if c_list[a[k] - 1] == 1:
        #     q = 1
        # elif c_list[a[k] - 1] == 0:
        #     q = 0
        # else:
        #     # q = c_list[a[k] - 1] - 1
        #     q = c_list[a[k] - 1] - c_list[a[k] - 1] * (a_count_list[a[k] - 1] - 2) // a_count_list[a[k] - 1]
        print(total - q)

Measured memory_bytes: 36124
#include <bits/stdc++.h>  
using namespace std;  
int main() {  
    string a,b;
    cin>>a;
    cin>>b;
    int x=b.size(),y=a.size();
    for(int i=0;i<x;i++)
    	cout<<b[i];
    for(int i=0;i<y;i++)
    	cout<<a[i];
    return 0;  
} 

Measured memory_bytes: 256
a, b = input().split()
a = int(a)
b = int(b)
min_stone = -1000000
max_stone = 1000000
ans_list = []
for i in range(max(min_stone, b - a + 1), min(max_stone, b + a)):
    ans_list.append(str(i))
print(" ".join(ans_list))

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

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	string s, t;
	cin>>s>>t;
	int n = s.length(), m = t.length();
	int dp[n][m]={};
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++)
			dp[i][j]=0;
	}
	// if(s[0]==t[0])
	// 	dp[0][0]=1;
	// for(int i = 1; i < m; i++) {
	// 	if(s[0]==t[i]) dp[0][i]=dp[0][i-1]+1;
	// 	else dp[0][i]=dp[0][i-1];
	// }
	// for(int i = 1; i < n; i++) {
	// 	if(s[i]==t[0]) dp[i][0]=dp[i-1][0]+1;
	// 	else dp[i][0]=dp[i-1][0];
	// }
	if(s[0]==t[0])
		dp[0][0]=1;
	for(int i = 1; i < n; i++) {
		if(s[i]==t[0]) dp[i][0]=1;
		else dp[i][0]=dp[i-1][0];
	}
	for(int i = 1; i < m; i++) {
		if(s[0]==t[i]) dp[0][i]=1;
		else dp[0][i]=dp[0][i-1];
	}
	for(int i = 1; i < n; i++) {
		for(int j = 1; j < m; j++) {
			int mx1=0, mx2=0, mx3=0;
			if(s[i]==t[j])
				mx1=dp[i-1][j-1]+1;
			mx2=dp[i-1][j];
			mx3=dp[i][j-1];
			dp[i][j]=max(max(mx1, mx2), mx3);
		}
	}
	if(!dp[n-1][m-1]) {
		cout<<endl;
		return 0;
	}
	int r=n-1, c=m-1;
	vector<char> ans;
	while(1) {
		if(r==0 && c==0){
			if(s[r]==t[c])
				ans.pb(s[r]);
			break;
		}
		else if(r==0) {
			if(s[r]==t[c]){
				ans.pb(s[r]);
				break;
			}
			c--;
		} else if(c==0){
			if(s[r]==t[c]) {
				ans.pb(s[r]);
				break;
			}
			r--;
		}
		// if(r==0 || c==0) { 
		// 	if(s[r]==t[c])
		// 		ans.pb(s[r]);
		// 	break;
		// }
		else {
			if(s[r]==t[c] && dp[r-1][c-1]+1==dp[r][c]) {
				ans.pb(s[r]);
				r--; c--;
			} else if(dp[r-1][c]==dp[r][c]) {
				r--;
			} else {
				c--;
			}
		}
	}
	// for(int i = 0; i < n; i++) {
	// 	for(int j = 0; j < m; j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	for(int i = ans.size()-1; i>= 0; i--)
		cout<<ans[i];
	cout<<endl;
	// cout<<dp[n-1][m-1]<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 70656
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim X As Integer = NextInt()
        Dim Y As Integer = NextInt()
        Dim Z As Integer = NextInt()

        Dim ans As Integer = (X - Z) \ (Y + Z)
        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

int main()
{
    string s, t;
    cin >> s >> t;
    for(int i=0; i<s.size(); ++i) {
        if(s==t){
           cout << "Yes" << endl;
           return 0;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define ll long long
int main()
{
    ll n;
    ll v[200];
    int i = 1;
    std::cin >> n;
    if (n == 0) {
        std::cout << 0;
        return 0;
    }
    while (n != 0) {
        int remainder = n % -2;
		n = n / -2;

		if (remainder < 0)
		{
			remainder += 2;
			n += 1;
		}
        v[i] = remainder;
        i++;
    }
    for (int j = i - 1; j >= 1; j--)
        std::cout << v[j];
    return 0;
}


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

ll dp[1001][1001];
ll fact[1001];
ll mod_pow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res;
}
ll ppow(ll a) {
	return mod_pow(a, MOD - 2);
}
ll perm(ll a, ll b) {//a個の中からb個選んで順列を作成
	return (fact[a] * ppow(fact[a - b])) % MOD;
}
ll calc(ll a, ll b, ll c) {
	return (((perm(a, b*c)*mod_pow(ppow(fact[c]), b)) % MOD)*ppow(fact[b])) % MOD;
}
int main() {
	fact[0] = 1;
	int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	for (int i = 1; i <= n; i++)fact[i] = (fact[i - 1] * i) % MOD;
	rep(i, n)dp[i][0] = 1;
	for (int i = a - 1; i < b; i++) {
		for (int j = 0; j <= n; j++) {
			if (j)(dp[i + 1][j] += dp[i][j]) %= MOD;
			if (j - c*(i + 1) < 0)continue;
			for (int k = c; j - k*(i + 1) >= 0 && k <= d; k++) {
				ll o = calc(n - (j - k*(i + 1)), k, i + 1);
				(dp[i + 1][j] += dp[i][j - k*(i + 1)] * o) %= MOD;
			}
		}
	}
	cout << dp[b][n] << endl;
}

Measured memory_bytes: 8064
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b = nm()

    ans = a
    if b < a:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll h,w;
  cin >> h >> w;
  if(h%3==0 or w%3==0) {
    cout << 0 << endl;
    return 0;
  }

  ll mi = min(h,w);
  ll ma = max(h,w);

  ll ss = mi * ma;
  ll ans = 100000001;
  orep(i,ma/2) {
    ll t = i * mi;
    ll r = (ma - i)*(mi/2);
    ll s = ss - t - r;
    ll mmi = min(t,r);
    mmi = min(mmi,s);
    ll mma = max(t,r);
    mma = max(s,mma);
    ans = min(ans,mma-mmi);

    r = mi*((ma-i)/2);
    s = ss - t - r;
    mmi = min(t,r);
    mmi = min(mmi,s);
    mma = max(t,r);
    mma = max(s,mma);
    ans = min(ans,mma-mmi);
  }
  ll t = mi;
  mi = ma;
  ma = t;
  orep(i,ma/2) {
    ll t = i * mi;
    ll r = (ma - i)*(mi/2);
    ll s = ss - t - r;
    ll mmi = min(t,r);
    mmi = min(mmi,s);
    ll mma = max(t,r);
    mma = max(s,mma);
    ans = min(ans,mma-mmi);

    r = mi*((ma-i)/2);
    s = ss - t - r;
    mmi = min(t,r);
    mmi = min(mmi,s);
    mma = max(t,r);
    mma = max(s,mma);
    ans = min(ans,mma-mmi);
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
const ll MOD=1000003;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}


int main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<pair<ll,ll>,ll>> p(m);
    rep(i,0,m) {
        cin>>p[i].first.first>>p[i].first.second;
        p[i].second=i;
    }
    sort(range(p));
    p[0].first.second=1;
    rep(i,1,m){
        if(p[i].first.first==p[i-1].first.first) p[i].first.second=p[i-1].first.second+1;
        else p[i].first.second=1;
    }
    vector<pair<ll,ll>> ans(m);
    for(auto i:p) ans[i.second]=i.first;
    rep(i,0,m) printf("%06lld%06lld\n",ans[i].first,ans[i].second);
}

Measured memory_bytes: 5376
#include<stdio.h>
#include <unistd.h>
int a[128];
int main(){
	char c;
	while(read(0,&c,1))a[c]++;
	for(int i=0;i<26;i++)printf("%c : %d\n",'a'+i,a['a'+i]+a['A'+i]);
}


Measured memory_bytes: 2052