akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int abs(int a,int b){

  int result;

  if(a<b)
    result=b-a;
  else
    result=a-b;
  return result;
};

int main(void){

  int n;
  int min=1000001;
  int  temp;
  
  while(cin >> n,n){

      vector <int> student(n);
    
    for(int i=0;i<n;i++){
      cin >> student[i];
    }

    sort(student.begin(),student.end(),greater<int>());

    for(int i=0;i<n-1;i++){
      
      temp=abs(student[i],student[i+1]);
      //cout << temp <<endl;

      if(min>temp)
	min=temp;
    }

    cout << min <<endl;

    student.clear();
    min=1000001;

  }

  return 0;
  
}

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

using namespace std;

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

    int *z = new int[n];
    for(int i = 0; i < n; i++) {
        z[i] = 0;
    }

    int *d = new int[k];
    for(int i = 0; i < k; i++) {
        int x;
        cin >> x;
        for(int j = 0; j < x; j++) {
            int y;
            cin >> y;
            z[y - 1] = 1;
        }
    }

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


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

int main(){
    string s; cin >> s;
    sort(s.begin(),s.end());
    char ans = 'a';
        for(int j=0;j<s.size();j++){
            if(ans == s[j]){
                ans++;
            }
        }

        if(ans > 'z'){
            cout << "None" << endl;
        }else{
            cout << ans << endl;
        }
}



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

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> t;
  for(int i = 0;i < n;i++){
    string a;
    int b;
    cin >> a >> b;
    t.emplace_back(a,100-b,i);
  }
  sort(t.begin(),t.end());
  for(int i = 0;i < n;i++){
    cout << get<2>(t[i]) + 1 << endl;
  }
  
}


Measured memory_bytes: 3656
#!/usr/bin/env ruby

N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)

cnt = Hash.new(0)

A.each do |a|
  cnt[a] += 1
end

sum = 0

cnt.each do |a, c|
  sum += c * (c - 1) / 2
end

A.each do |a|
  puts sum - cnt[a] + 1
end


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define double      long double
//std::cout << std::fixed;std::cout << std::setprecision(10);

const int N=1e5 + 5;
const int M=1e9 + 7;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
  int n;
  cin >> n;
  cout << n*n << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    li n;
    cin >> n;
    
    vector<li> xs, ys;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (n % 2 == 1) {
                if (j == n - 1) {
                    xs.push_back(i + 1);
                    ys.push_back(j + 1);
                } else if (i + 1 + j + 1 != n) {
                    xs.push_back(i + 1);
                    ys.push_back(j + 1);
                } 
            } else {
                if (i + 1 + j + 1 != n + 1) {
                    xs.push_back(i + 1);
                    ys.push_back(j + 1);
                }
            }
        }
    }
    
    cout << xs.size() << endl;
    for (int i = 0; i < xs.size(); ++i) {
        cout << xs[i] << " " << ys[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  int n, x;
  cin >> n >> x;
  int l[n];
  rep(i, n) cin >> l[i];
  int ans = 1, now = 0;
  rep(i, n) {
    now += l[i];
    if(now > x) {
      break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

void computeLPSArray(char* pat, int M, int* lps); 
  
// Prints occurrences of txt[] in pat[] 
int KMPSearch(char* pat, char* txt) 
{ 
    int M = strlen(pat); 
    int N = strlen(txt); 
  
    // create lps[] that will hold the longest prefix suffix 
    // values for pattern 
    int lps[M]; 
  
    // Preprocess the pattern (calculate lps[] array) 
    computeLPSArray(pat, M, lps); 
  
    int i = 0; // index for txt[] 
    int j = 0; // index for pat[] 
    while (i < N) { 
        if (pat[j] == txt[i]) { 
            j++; 
            i++; 
        } 
  
        if (j == M) { 
            return i-j;
            j = lps[j - 1]; 
        } 
  
        // mismatch after j matches 
        else if (i < N && pat[j] != txt[i]) { 
            // Do not match lps[0..lps[j-1]] characters, 
            // they will match anyway 
            if (j != 0) 
                j = lps[j - 1]; 
            else
                i = i + 1; 
        } 
    } 
    return -1;
} 
  
// Fills lps[] for given patttern pat[0..M-1] 
void computeLPSArray(char* pat, int M, int* lps) 
{ 
    // length of the previous longest prefix suffix 
    int len = 0; 
  
    lps[0] = 0; // lps[0] is always 0 
  
    int i = 1; 
    while (i < M) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            // This is tricky. Consider the example. 
            // AAACAAAA and i = 7. The idea is similar 
            // to search step. 
            if (len != 0) { 
                len = lps[len - 1]; 
  
                // Also, note that we do not increment 
                // i here 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
} 


bool ispossible(string s,int len){
    string a;
    for(int i=0;i<len-1;i++){
        a+=(s[i]);
    }
    for(int i=len-1;s[i];i++){
        a+=(s[i]);
        string ss;
        for(int j=i+1;s[j];j++){
            ss+=(s[j]);
        }
        char text[ss.length()+1];
        strcpy(text, ss.c_str()); 
        char pat[a.length()+1];
        
        strcpy(pat, a.c_str()); 
        
        if(KMPSearch(pat,text)!=-1){
            return true;
        }
        a.erase(a.begin());
    }
    return false;
}


signed main() {
    
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    int si=0,ei=n;
    while(si<=ei){
        int mid=(si+ei)>>1;
        if(ispossible(s,mid)){
            ans=mid;
            si=mid+1;
        }
        else{
            ei=mid-1;
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
K = int(input())
A, B = map(int,input().split())

i = 1
flg = 0
tmp = K
while(K <= B):
    K =  tmp * i
    #print(K)
    if(A <= K <= B):
        flg = 1
        break
    i += 1

if(flg == 1):
    print('OK')
else:
    print('NG')

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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,Ans,A[200000];
int main()
{
	n=read(); 
	for(int i=1;i<=n;i++) A[i]=read();
	for(int i=1;i<=n;i++)
	{
		int j=i+1;
		while(A[j]==A[i]&&j<=n) j++; 
		if(A[j]>A[i]) while(A[j+1]>=A[j]&&j+1<=n) j++;
		else while(A[j+1]<=A[j]&&j+1<=n) j++;
		i=j; Ans++;
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
 
def longSub():
    seq1 = raw_input()
    seq2 = raw_input()
 
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        #x1 = [0 for i2 in range(b+1)]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
 
n = input()
for i2 in range(n):
 
    print longSub()

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,ans=0,sum=0; cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    rep(i,n-1){
        sum -= a[i];
        ans += sum%mod*a[i];
        ans %= mod;
    }
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4796
//**************************
//*** writer  :  Alan Hu **
//************************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MAX=2e5+10;
int l[MAX],r[MAX],d[MAX];
vi adj[MAX],edg[MAX];
bool vis[MAX];
int cnt[MAX];

void dfs(int v)
{
	vis[v]=true;
	rept(i,0,adj[v].size())
	{
		int u=adj[v][i];
		if (vis[u] && (cnt[u]!=edg[v][i]+cnt[v]))
    	{
    		cout<<"No";
    		exit(0);
    	}
    	if (!vis[u])
		{
			cnt[u]=cnt[v]+edg[v][i];
			dfs(u);
		}
	}
}

int n,m;

int main()
{
	cin>>n>>m;
	rept(i,1,m+1) 
	{
		cin>>l[i]>>r[i]>>d[i];
		adj[l[i]].pb(r[i]);
		adj[r[i]].pb(l[i]);
		edg[l[i]].pb(d[i]);
		edg[r[i]].pb(-d[i]);
	}
	rept(i,1,n+1)
	{
		if (!vis[i]) dfs(i);
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    k--;
    cout<<a[k]<<endl;
}

Measured memory_bytes: 256
#include <iostream>

unsigned long long lcm(unsigned long long, unsigned long long);
unsigned long long gcd(unsigned long long, unsigned long long);
int main()
{
	unsigned long long a, b;
	std::cin >> a >> b;
	std::cout << lcm(a,b);
	return 0;
}

unsigned long long lcm(unsigned long long a, unsigned long long b) {
	return a * b / gcd(a, b);
}

unsigned long long gcd(unsigned long long a, unsigned long long b) {
	if (a < b)
		return gcd(b, a);
	while (b != 0)
	{
		unsigned long long r = a % b;
		a = b;
		b = r;
	}
	return a;
}

Measured memory_bytes: 764
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(u==s){
  	a-=1;
  }
  
  else if(u==t){
  	b-=1;	
  }
  cout<<a<<" "<<b<<endl;
  
  return 0;
}
  

Measured memory_bytes: 3652
n,y=map(lambda x:int(x),input().split())
if y%1000 or n*1000>y:print('-1 -1 -1')
else:
    y=y//1000
    b=(y-n)*7%9
    c=(y-n-4*b)//9
    if c<0:print('-1 -1 -1')
    else:
        a=n-b-c
        if a<0:print('-1 -1 -1')
        else:print("%d %d %d"%(c,b,a))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int bit(int x){
	int r=0;
	while(x){
		r|=1<<(x%10);
		x/=10;
	}
	return r;
}
int main(){
	int n,k,b=0;
	scanf("%d %d",&n,&k);
	while(k--){
		int x;
		scanf("%d",&x);
		b|=1<<x;
	}
	while(bit(n)&b) n++;
	printf("%d\n",n);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <int> a(n), b(n), c(n - 1);
    for (int tsumugi = 0; tsumugi < n; tsumugi++){
        cin >> a[tsumugi];
    }
    for (int matsuri = 0; matsuri < n; matsuri++){
        cin >> b[matsuri];
    }
    for (int kaori = 0; kaori < n - 1; kaori++){
        cin >> c[kaori];
    }

    int ans = 0;
    int meal;
    int beforemeal = 100;
    for (int karen = 0; karen < n; karen++){
        meal = a[karen];
        ans += b[meal - 1];
        if (beforemeal + 1 == meal){
            ans += c[beforemeal - 1];
        }
        beforemeal = meal;
        // cout << "Ans:" << ans << endl;
    }

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

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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;


#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M; cin >> N >> M;
  vector<vll> demands(N);
  rep(_, M){
    ll a, b;
    cin >> a >> b;
    demands[b-1].push_back(a-1);
  }

  ll ans = 0, cnt = 0;
  rep(i, N){
    for(ll d : demands[i]){
      if(i - cnt <= d){
        ans++;
        cnt = 0;
        break;
      }
    }
    cnt++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5116
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll power(ll x) {
	return x * x * x * x * x;
}
int main()
{
	ll X;
	cin >> X;
	for (ll A = 0; A <= 7000; A++) {
		ll num = X - power(A);
		if (num >= 0) {
			for (int B = 0; power(B) >= -num; B--) {
				if (power(A) - power(B) == X) {
					cout << A << " " << B << endl;
					return 0;
				}
			}
		}
		else {
			for (int B = 0; power(B) <= -num; B++) {
				if (power(A) - power(B) == X) {
					cout << A << " " << B << endl;
					return 0;
				}
			}
		}
	}

}

Measured memory_bytes: 3672
package main

import (
	"fmt"
)

func dfs(a int, t,c [][]int, ans []int) {
	for i, e := range t[a] {
		if ans[e]!=-1 {
			continue
		}
		ans[e] = (ans[a]+c[a][i])%2
		dfs(e,t,c,ans)
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	t := make([][]int,n)
	c := make([][]int,n)

	for i:=0; i<n-1; i++ {
		var u,v,w int
		fmt.Scan(&u,&v,&w)
		u--
		v--
		t[u],c[u] = append(t[u],v),append(c[u],w)
		t[v],c[v] = append(t[v],u),append(c[v],w)
	}

	ans := make([]int,n)

	for i:=0; i<n; i++ {
		ans[i] = -1
	}

	ans[0] = 0

	dfs(0,t,c,ans)

	for i:=0; i<n; i++ {
		fmt.Println(ans[i])
	}
}


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

int main() {
    ll H, W;
    cin >> H >> W;

    ll ans = 999999;
    rep(h, H/2+1) {
        ll A   = h * W;
        ll B1  = ((H - h) / 2) * W;
        ll C1  = H * W - (A + B1);
        ll mn1 = max({A, B1, C1}) - min({A, B1, C1});

        ll B2  = (H - h) * (W / 2);
        ll C2  = H * W - (A + B2);
        ll mn2 = max({A, B2, C2}) - min({A, B2, C2});

        ans = min({ans, mn1, mn2});
    }

    rep(w, W/2+1) {
        ll A   = H * w;
        ll B1  = H * ((W - w) / 2);
        ll C1  = H * W - (A + B1);
        ll mn1 = max({A, B1, C1}) - min({A, B1, C1});

        ll B2  = (H / 2) * (W - w);
        ll C2  = H * W - (A + B2);
        ll mn2 = max({A, B2, C2}) - min({A, B2, C2});

        ans = min({ans, mn1, mn2});
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
sx, sy, tx, ty = list(map(int, input().split()))

def get_path(moves):
  path = ''
  for y, x in moves:
    if y > 0:
      path += 'U' * y
    else:
      path += 'D' * -y
    if x > 0:
      path += 'R' * x
    else:
      path += 'L' * -x
  return path

first_moves = []
foward_y = ty - sy
foward_x = tx - sx
first_moves.append((foward_y, foward_x))
first_moves.append((-foward_y, -foward_x))

second_moves = []
foward_y = (ty + 1) - sy
foward_x = tx - (sx - 1)
second_moves.append((0, -1))
second_moves.append((foward_y, foward_x))
second_moves.append((-1, 0))
second_moves.append((0, 1))
second_moves.append((-foward_y, -foward_x))
second_moves.append((1, 0))

print(get_path(first_moves + second_moves))

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;
  int ans = N+N;
  rep(i, N) {
    bool flag = true;
    for(int j=0; i+j<N; j++) {
      if(s[i+j] != t[j]) {
        flag = false;
        break;
      }
    }
    if(flag) {
      ans = N+i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)

inline int mul(int a,int b){return (a*1ll*b)%MOD;}
inline int add(int a,int b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,MOD-2);}


int dp[1003][1003];

signed main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    dp[1][1]=1;

    int m,n;
    cin>>n>>m;
    string s[n];
    forn(i,0,n-1)
        cin>>s[i];

    forn(i,1,n)
        forn(j,1,m)
            if(i+j!=2 and s[i-1][j-1]=='.')
                dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;    
    cout<<dp[n][m];




     return 0;

}

//       g++ -g c3.cpp ; ./a.exe

Measured memory_bytes: 9216
import std;
import core.bitop;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "c");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    long[long] R;
    foreach (i; iota(n))
    {
        if ((i - a[i]) in R)
            R[(i - a[i])]++;
        else
            R[(i - a[i])] = 1;
    }

    long cnt;
    foreach (i; iota(n))
    {
        cnt += (i + a[i]) in R ? R[i + a[i]] : 0;
    }
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 22256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    cout<<setprecision(20);
    ll k,n;
    cin>>n>>k;
    double ans=0,t=1;
    rep(i,n){
        t=1/(double)n;
        ll a=i+1;
        while(a<k){
            a*=2;
            t/=2.0;
        }
        ans+=t;
    }
    cout<<ans;
}
/*

*/


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;

//input
ll n;
vector<ll>a;

Graph g;

vector<ll>dp;

ll rec(ll v,ll p){
    if(dp[v]>=0)return dp[v];
    ll res = 0;
    vector<ll>tmp;
    for(ll x:g[v]){
        if(x==p)continue;
        tmp.push_back(rec(x,v));
    } 
    sort(tmp.rbegin(),tmp.rend());
    rep(i,tmp.size()){
        chmax(res,tmp[i]+i+1);
    }
    return dp[v]=res;
}
int main(){
    //input
    cin >> n;
    g.resize(n);
    rep(i,n-1){
        int a;
        cin >> a;
        a--;
        g[i+1].push_back(a);
        g[a].push_back(i+1);
    }
    dp.resize(n,-1);
    cout << rec(0,-1) << endl;
    /*
    cout << endl;
    rep(i,n){
        cout << dp[i] << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 20244
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;


int main(){
	ll n;
	cin>>n;
	if(n%1000==0) cout<<0;
	else cout<<((n/1000)+1)*1000-n;
}

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

using namespace std;

int main(){
    int A, B, C, D; cin >> A >> B >> C >> D;

    if(A+B > C+D){
        cout << "Left" << endl;
    }else if(A+B < C+D){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int nMAX = 1000000;
static const int mMAX = 100;
int cnt = 0;

int insertionSort(int* A, int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return 0;
}

int shellSort(int* A, int n) {
	int m = 0;
	int g = 0;
	while (g <= n) {
		g = g * 3 + 1;
		m++;
	}
	g = g / 3;
	m = m - 1;
	int* G = new int[mMAX];
	for (int i = 0; i < m; i++) {
		G[i] = g;
		g = g / 3;
	}
	cout << m << endl;
	for (int i = 0; i < m-1; i++) {
		cout << G[i]<<' ';
	}
	cout << G[m-1] << endl;
	
	for (int i = 0; i < m; i++) {
		insertionSort(A, n, G[i]);
	}
	return 0;
}

int main() {
	int n;
	cin >> n;
	int* A = new int[nMAX];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	shellSort(A, n);
	cout << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 7008
n = int(input())
alist = [0]*n#umi
blist = [0]*n#yama
clist = [0]*n#HW
for i in range(n):
  alist[i],blist[i],clist[i] = map(int,input().split())

dpa = [alist[0]] + [0]*(n-1)
dpb = [blist[0]] + [0]*(n-1)
dpc = [clist[0]] + [0]*(n-1)
for i in range(1,n):
  dpa[i] = max(dpb[i-1], dpc[i-1]) + alist[i]
  dpb[i] = max(dpa[i-1], dpc[i-1]) + blist[i]
  dpc[i] = max(dpb[i-1], dpa[i-1]) + clist[i]
print(max(dpa[-1], dpb[-1], dpc[-1]))

Measured memory_bytes: 27492
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
        if (in(x - r, 0, w) && in(x + r, 0, w) && in(y - r, 0, h) && in(y + r, 0, h)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
    public static boolean in(int value, int min, int max) {
        return value >= min && value <= max;
    }
}

Measured memory_bytes: 17352
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n), b(n), c(n);
    if (2 * k - 1 > n) {
        cout << -1 << '\n';
    } else {
        if (n & 1) {
            for (ll i = 0; i < n; i++) {
                (i <= n / 2 ? a[i * 2] : a[2 * (i - n / 2 - 1) + 1]) = k + i;
                (i < n / 2 ? b[i * 2 + 1] : b[2 * (i - n / 2)]) = k + n + i;
                c[i] = k + 2 * n + i;
            }
            for (ll i = 0; i < n; i++) cout << a[i] << ' ' << b[i] << ' ' << c[i] << '\n';
        } else {
            for (ll i = 0; i < n; i++) {
                (i < n / 2 ? a[i * 2] : a[2 * (i - n / 2) + 1]) = k + i;
                (i < n / 2 ? b[i * 2 + 1] : b[2 * (i - n / 2)]) = k + n + i;
                c[i] = k + 2 * n + i;
            }
            for (ll i = 0; i < n; i++) cout << a[i] << ' ' << b[i] << ' ' << c[i] << '\n';
        }
    }
    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

template<typename T>
void cmpmax(T* reference, T value) {
	*reference = max(*reference, value);
}

template<typename T>
void cmpmin(T* reference, T value) {
	*reference = min(*reference, value);
}

const ll mod = 1000000007;

static const ll INF = 1e15;


int main() {
	string k;
	int d;
	cin >> k;
	cin >> d;
	int n = k.size();
	vector<int> digits(n, 0);
	rep(i, n) {
		digits[i] = k[i] - '0';
	}
	vector<vector<ll>> dp[2];
	dp[0].assign(n, vector<ll>(d, 0));
	dp[1].assign(n, vector<ll>(d, 0));
	for (int i = 0; i < digits[0]; i++) {
		dp[0][0][i % d] ++;
	}
	dp[1][0][digits[0] % d] = 1;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < d; j++) {
			for (int a = 0; a < 10; a++) {
				int r = j + a;
				r %= d;
				dp[0][i][r] += dp[0][i - 1][j];
				dp[0][i][r] %= mod;
			}
		}
		for (int j = 0; j < d; j++) {
			if (dp[1][i-1][j]) {
				for (int a = 0; a < digits[i]; a++) {
					int r = j + a;
					r %= d;
					dp[0][i][r] += dp[1][i - 1][j];
					dp[0][i][r] %= mod;
				}
				{
					int r = j + digits[i];
					r %= d;
					dp[1][i][r] += dp[1][i - 1][j];
					dp[1][i][r] %= mod;
				}
			}
		}
	}
	ll sum = 0;
	sum += dp[0][n - 1][0];
	sum += dp[1][n - 1][0];
	sum %= mod;
	sum += mod - 1;
	sum %= mod;
	cout << sum << endl;
	return 0;
}
	


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int, int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define ar array
//#define endl '\n'
#define FOR(i, s, e) for (int i = s; i < e; ++i)
#define FORL(i, s, e) for (ll i = s; i < e; ++i)
#define RFOR(i, s, e) for (int i = e - 1; i >= s; --i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define MOD 1000000007LL
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof a);

#ifdef TRACE
#define lol std::cout << "Calling " << __func__ << endl

#else
#define lol
#endif

ll modpow(ll a, ll b, ll m = MOD)
{
	a %= m;
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}
ll bpow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll modinv(ll a, ll m = MOD) { return modpow(a, m - 2, m); }

void solve(int t)
{
//	cout << "Case #" << t << ": ";
	string a,b;
	cin >> a >> b;
	int al = a.size(),bl = b.size();
	if(al ==(bl-1) && a==b.substr(0,al)) cout << "Yes" << endl; 
	else cout << "No"<< endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef IOF
	freopen("alchemy_input.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	//cin >> t;
	for (int tc = 1; tc <= t; tc++)
		solve(tc);
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

long long int arr[(int)1e5 + 1];
long long int temp[(int)1e5 + 1];

int main() {

	int n,bag; cin >> n >> bag;
	
	vector<long long int> v;
	vector<long long int> w;

	while(n--){
		long long int val,weight;
		cin >> weight >> val;
		v.push_back(val);
		w.push_back(weight);
	}

	for(int i = 0; i < (int)v.size(); i++) {

		for(int j = 1; j <= bag; j++){
			if(j < w[i]){
				temp[j] = max(arr[j],temp[j-1]);
			}else {
				temp[j] = max(arr[j-w[i]] + v[i], temp[j-1]);
				temp[j] = max(temp[j],arr[j]);
			}
		}
		
		for(int j = 1; j <= bag; j++){
			arr[j] = temp[j];
			temp[j] = 0;
		}	
	}

	cout << arr[bag] << endl;

	return 0;
}

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

int64_t divceil(int64_t a, int64_t b) {
    return a / b + (a % b ? 1 : 0);
}

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t N;
    cin >> N;
    vector<int64_t> x(5);
    for(int i = 0; i < 5; i++) {
        cin >> x[i];
    }
    cout << (divceil(N, *min_element(x.begin(), x.end()))) + 4;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.util.Collections;
import java.util.ArrayList;

class Main {
	public static void main(String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		try {
			int n = Integer.parseInt(br.readLine());
			for (int i=0;i<n;i++) {
				String buf = br.readLine();
				StringTokenizer st = new StringTokenizer(buf);
				ArrayList<Integer> a = new ArrayList<Integer>();
				a.add(Integer.parseInt(st.nextToken()));
				a.add(Integer.parseInt(st.nextToken()));
				a.add(Integer.parseInt(st.nextToken()));
	
				Collections.sort(a);
				if (Math.pow(a.get(0),2)+Math.pow(a.get(1),2)==Math.pow(a.get(2),2))
					System.out.println("YES");
				else System.out.println("NO");
			}
		} catch (IOException e) {
			System.out.println("IOException!");
		}
	}
}

Measured memory_bytes: 18668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
// const int INF = 1e9 + 7;
 
void test_case() {
    int n;
    cin >> n;
    vector<int> dp(3);
    for (int day = 0; day < n; day++) {
        vector<int> new_dp(3);
        vector<int> h(3);
        for (int i = 0; i < 3; i++) cin >> h[i];
 
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (i != j) new_dp[j] = max(new_dp[j], h[j] + dp[i]);
		dp = new_dp;
    }
	cout<<max({dp[0], dp[1],dp[2]})<<endl;
}
 
int main() {
    int t = 1;
    // cin >> t;
    while (t--) test_case();
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>

using int64 = long long;

static constexpr int inf = (1 << 28);

static int N;
static std::vector<int> ABC(3), l;

int dfs(int index, std::vector<int>& state) {
    if (index == state.size()) {
        int cost = 0;
        std::vector<int> count(3, 0), sum(3, 0);

        for (int i = 0; i < state.size(); i++) {
            if (state[i] >= 0) {
                count[state[i]]++;
                sum[state[i]] += l[i];
            }
        }

        for (int i = 0; i < 3; i++) {
            if (count[i] == 0) return inf;
            cost += 10 * (count[i] - 1) + std::abs(ABC[i] - sum[i]);
        }
        return cost;
    }

    int res = inf;
    for (int s : {-1, 0, 1, 2}) {
        state[index] = s;
        res = std::min(res, dfs(index + 1, state));
    }
    return res;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;
    for (int i = 0; i < 3; i++) {
        std::cin >> ABC[i];
    }

    l.resize(N);
    for (int i = 0; i < N; i++) {
        std::cin >> l[i];
    }

    std::vector<int> state(N, -1);
    std::cout << dfs(0, state) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

const ll inf = 10000000000000000;
ll n, k, a[200005], mux, l, r, m;
bool check(ll mun, ll kol) {
    ll ans = 0;
    if (mun > 0)
        for (ll i = 0; i < n; ++i)
            ans += ((a[i] / mun) + (a[i] % mun != 0) - 1);
    else
        for (ll i = 0; i < n; ++i)
            ans += (a[i] * 3);
    return (ans <= kol);
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        mux = max(mux, a[i]);
    }
    r = mux + 1;
    l = 0;
    while (r - l > 1) {
        m = l + (r - l) / 2;
        //cout << "LOL\n";
        if (check(m, k))
            r = m;
        else
            l = m;
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 5168
#include<cstdio>
using namespace std;
int main()
{
    char c;
    int a=0;
    for(int i=0;i<100,scanf("%c",&c)!=EOF;i++)
    {
        if(c=='C'&&a!=1)a=1;
            else if(c=='F'&&a==1){printf("Yes");return 0;}
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,i=1;
    cin>>a>>b;
    if(b==1)cout<<0<<endl;
    else{
        int count=a;
        if(a<b)
        for(i=2;;i++){
            count=count+a-1;
            if(count>=b)break;
        }
        cout<<i<<endl;
    }
    return 0;
}


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

void swap_char(int idx1, int idx2, string& str) {
  char tmp = str[idx1];
  str[idx1] = str[idx2];
  str[idx2] = tmp;
  return;
}

void sort_str(string& str, bool order) {
  	int len = str.size();
	for(int i=0;i<len-1;i++) {
    	for(int k=0;k<len-1-i;k++) {
        	if(order) {
              if(str[k]>str[k+1]) swap(str[k], str[k+1]);
            } else {
              if(str[k]<=str[k+1]) swap(str[k], str[k+1]);
            }
        }
    }
	return;
}

int main() {
	string s, t;
	cin >> s >> t;
  	//cout << s << " " << t << endl;

  	// sort
	sort_str(s, true);
	sort_str(t, false);
  	//cout << "sorted." << endl;
  	//cout << s << " " << t << endl;
  
	// compare
  	if(s<t) cout << "Yes" << endl;
	else cout << "No" << endl;
  
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            // 整数配列の入力
            var x = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var sortX = x.ToList();
            sortX.Sort();

            var middle = (n + 1) / 2;
            var middleNum = sortX[middle - 1];

            for(int i = 0; i < n; i++) {
                if(x[i] <= middleNum) {
                    Console.WriteLine(sortX[middle]);
                } else {
                    Console.WriteLine(sortX[middle - 1]);
                }
            }

            Console.Out.Flush();
        }
    }
}


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 1e5 + 10;
using namespace std;

int main() {
    IO;
    int n;
    cin >> n;
    vector<pair<int, int>> a;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a.push_back({x, y});
    }
    bool ok = 0;
    for (int i = 0; i < n - 2; ++i) {
        if (a[i].first == a[i].second and a[i + 1].first == a[i + 1].second and a[i + 2].first == a[i + 2].second) {
            ok = 1;
            break;
        }

    }


    if (ok) cout << "Yes";
    else cout << "No";


}

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

using namespace std;

int findMin(vector<int> &x, int a, vector<int>& h, int k)
{
	if(x[a] != -1)
		return x[a];
	if(a == x.size()-1)
		x[a] = 0;
	else if(a==x.size()-2)
		x[a] = abs(h[a]-h[a+1]);
	else
	{
		int t = INT_MAX, i;
		for(i = 1; i <= k && (i+a) < x.size(); i++)
			t = min(t,abs(h[a]-h[a+i]) + findMin(x,a+i,h,k));
		x[a] = t;
	}
	return x[a];
}

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

	int i,n,k;
	cin>>n>>k;
	vector<int> h(n),x(n,-1);
	for(i=0; i<n; i++)
		cin>>h[i];

	cout<<findMin(x,0,h,k)<<endl;
	return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef vector<int> vint;

class st{
public:
  int now,cost;
  bool operator<(const st & a)const{
    return cost > a.cost;
  }
};

const int N = 8;
const int inf = (1<<27);
int edge[N][N];
map<int,vint> M;
map<vint,int> L;

vint getState(int now,map<int,vint> &M){
  return M[now];
}

int getNum(vint now,map<vint,int> & M){
  return L[now];
}

const int node = 3628800;
int cost[node];

int dijkstra(int n,int num){
  rep(i,num)cost[i] = inf;
  priority_queue<st> Q;
  cost[0] = 0;
  Q.push((st){0,0});
  while(!Q.empty()){
    st now = Q.top();Q.pop();
    vint cur = getState(now.now,M);
    if (cost[now.now] != now.cost)continue;
    /*    rep(i,cur.size())cout << cur[i]+1 <<" " ;cout << endl;
    cout <<"cost " << now.cost << endl;
    */

    rep(i,n){
      REP(j,i+1,n){
	vint next = cur;
	swap(next[i],next[j]);
	int nec = cost[now.now] + edge[cur[i]][cur[j]];
	int nextnum = getNum(next,L);
	if (cost[nextnum] > nec){
	  cost[nextnum] = nec;
	  Q.push((st){nextnum,nec});
	}
      }
    }
  }
  int ret = 0;
  rep(i,num)ret = max(ret,cost[i]);
  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    M.clear();
    L.clear();
    rep(i,n)rep(j,n)cin>>edge[i][j];
    vector<int> a(n);
    rep(i,n)a[i] = i;
    int num = 0;
    do{
      M[num] = a;
      L[a] = num;
      num++;
    }while(next_permutation(a.begin(),a.end()));
    cout << dijkstra(n,num) << endl;
  }
}

Measured memory_bytes: 7924
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	char col = s[0];
	int ans = 1;

	for (int i = 1; i < n; i++)
	{
		if (col != s[i])
		{
			ans++;
			col = s[i];
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int height, width;
  cin >> height >> width;
  vector<string> input(height);
  for(int i = 0; i < height; i++)
	cin >> input.at(i);
  for(int i = 0; i < height + 2; i++){
	if(i == 0 || i == height + 1){
      for(int j = 0; j < width + 2; j++){
        cout << '#';
      }
      cout << endl;
    } else {
      cout << '#' << input.at(i-1) << '#' << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s,t;
  cin>>s;
  cin>>t;
  if(s.size()>t.size()){
    cout<<"GREATER"<<endl;
  }else if(s.size()<t.size()){
    cout<<"LESS"<<endl;
  }else if(s==t){
    cout<<"EQUAL"<<endl;
  }else{
    for(int i=0;i<s.size();i++){
      if(s[i]>t[i]){
        cout<<"GREATER"<<endl;
        break;
      }else if(s[i]<t[i]){
        cout<<"LESS"<<endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);
//string = to_string(数値)
//int = stoi(文字列)
//(int)(char-'0')
//string = itoa(int)
//円周率: M_PI

int main() {
    int n,m; cin >>n>>m;
    vector<int> H(n+1);
    vector<int> A(m);
    vector<int> B(m);
    vector<int> kai(n+1,1); ///何個良いのがあるか
    kai[0]=0;
    rep(i,n) cin>>H[i+1];
    rep(i,m){
        cin >> A[i];
        cin >> B[i];
        int zako;
        if(H[A[i]]<H[B[i]]) kai[A[i]]=0;
        else if(H[A[i]]>H[B[i]]) kai[B[i]]=0;
        else {
            kai[A[i]]=0;
            kai[B[i]]=0;
        }

    }
    int cnt=0;
    rep(i,n) cnt+=kai[i+1];
    cout << cnt << endl;


}





Measured memory_bytes: 4828
while(1)
aa,op,bb=gets.chomp.split(" ").map(&:to_s);
a=aa.to_i
b=bb.to_i
if(op=="+")
r=a+b
elsif(op=="-")
r=a-b
elsif(op=="*")
r=a*b
elsif(op=="/")
r=a/b
else
 break
end
print"#{r}\n"
end



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

int main()
{
	string s;
	int n = 0;

	cin >> s;

	int sn = s.size();
	n = s.size();

	if (sn > 1){
		for (int i = 0; i < sn - 1; i++) {
			if (s[i] != s[i + 1])
				n = min(n, max(i + 1, sn - i - 1));
		}
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 512
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

LL n,a,b,c,d;

bool solve() {
    n--;
    REP1(i,0,n) {
        LL l=i*-d+(n-i)*c;
        LL r=i*-c+(n-i)*d;
        // dump(i,l,r);
        if ( a+l<=b && b<=a+r ) return 1;
    }
    return 0;
}

int main() {
    R(n,a,b,c,d);
    W(solve() ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
S = input()
lenS = len(S)

i=0
while i < lenS:
  if S[i:i+5] =='dream':
    i+=5
    if S[i:i+2] == 'er' and S[i:i+5] != 'erase':i+=2
  elif S[i:i+6] == 'eraser': i+=6
  elif S[i:i+5] == 'erase': i+=5
  else:
    print('NO')
    exit()
print('YES')

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef long double DB;
mt19937 mrand(random_device{}()); 
const LL mod=1000000007;
int rnd(int x) { return (int)mrand() % x;}
LL powmod(LL a,LL b) { LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
// head

int x,y;
int main() {
	scanf("%d%d",&x,&y);
	int suc=0;
	rep(i,0,x+1) {
		if (2*i+4*(x-i)==y) suc=1;
	}
	if (suc) puts("Yes"); else puts("No");
}


Measured memory_bytes: 3584
#include <stdio.h>

int t[365]={0};

int last(int d,int i){
  for(int j=d;j>=0;j--){
    if(t[j]==i) return (j+1);
  }

  return 0;
}

int main() {
  int D=0;
  int c[26]={0};
  int s[365][26]={0};


  int v[365]={0};

  scanf("%d",&D);
  for(int i=0;i<26;i++) scanf("%d",&c[i]);
  for(int i=0;i<D*26;i++) scanf("%d",&s[i/26][i%26]);
  for(int i=0;i<D;i++) scanf("%d",&t[i]);

  for(int i=0;i<D;i++){
    if(i != 0) v[i] += v[i-1];

    v[i] += s[i][t[i]-1];
    
    for(int j=0;j<26;j++){
      v[i] -= c[j] * ((i+1)-last(i,j+1));
    }

    printf("%d\n",v[i]);
  }

  return 0;
}


Measured memory_bytes: 1768