akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static int countAB(String str) {
		int cnt = 0;
		int start = 0;
		while(true) {
			int ix = str.indexOf("AB", start);
			if (ix < 0) {
				return cnt;
			}
			cnt++;
			start = ix + 1;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int incAB = 0;
		int endA = 0;
		int startB = 0;
		int bothAB = 0;
		for (int i = 0; i < N; i++) {
			String s = sc.next();
			incAB += countAB(s);
			if (s.charAt(0) == 'B') {
				if (s.charAt(s.length() - 1) == 'A') {
					bothAB++;
				} else {
					startB++;
				}
			} else if (s.charAt(s.length() - 1) == 'A') {
				endA++;
			}
		}
		// System.out.println("incAB  = " + incAB);
		// System.out.println("endA   = " + endA);
		// System.out.println("startB = " + startB);
		// System.out.println("bothAB = " + bothAB);


		int ans = incAB;
		int plus;
		if (endA == 0) {
			if (startB == 0) {
				plus = Math.max(bothAB - 1, 0);
			} else {
				// startBのみ
				plus = bothAB;
			}
		} else {
			if (startB == 0) {
				plus = bothAB;
			} else {
				plus = bothAB + Math.min(endA, startB);
			}
		}
		System.out.println(incAB + plus);

		// System.out.println(Math.max(x, y));
	}
}


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

int main(){

    int n;

    cin>>n;

    int a[n];
    pair<int,int> sorting[n],max,next;
    
    for(int i=0;i<n;i++){

        cin>>a[i];

        sorting[i].first = a[i];
        sorting[i].second = i;
    }
        
    sort(sorting, sorting+n);
    max = sorting[n-1];
    next = sorting[n-2];

    for(int i=0;i<n;i++){
        if(i == max.second){
            cout<<next.first<<endl;
        }
        else{
            cout<<max.first<<endl;
        }
    }
    
    return 0;
}


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

const int inf = 1e9 + 7;
LL n, k;

int main()
{
    while(~scanf("%lld %lld", &n, &k))
    {
        LL sum = 0;
        if(k == 0)
        {
            cout << n * n << endl;
            continue;
        }
        for(LL i = k + 1; i <= n; ++i)
        {
            sum += (i - k) * (n / i);
            if(n % i >= k) sum += n % i - k + 1;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,a,b,c[1001],x,x1,x2,x3;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0||b==0) break;
		x=0; x1=0;
		for(i=0;i<a;i++){
			scanf("%d",&c[i]);
			x1+=c[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(c[i]<c[j]){
					x=c[i];
					c[i]=c[j];
					c[j]=x;
				}
			}
		}
		x2=0; x3=0;
		for(i=0;i<a;i++){
			x2++;
			if(x2%b==0){
				x3+=c[i];
			}
		}
		printf("%d\n",x1-x3);
	}
	return 0;
}

Measured memory_bytes: 604
all_cards = [x + " " + str(y) for x in ["S", "H", "C", "D"] for y in range(1, 14)]
N = int(input())
i = 0
while i < N:
    has_card = input()
    if has_card in all_cards:
        all_cards.remove(has_card)
    i += 1
for j in all_cards:
    print(j)



Measured memory_bytes: 5604
from functools import lru_cache

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

N, M = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(M + 100)

ans = 0
for k in range(N + 1):
    ans += comb.ncr(N, k) * ((-1)**k) * comb.npr(M, k) * (comb.npr(M - k, N - k)**2)
    ans %= MOD
print(ans)


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

string ss[4] = {"dream","dreamer","erase","eraser"};
ll dp[101010];

bool dfs(const string& s,ll p){
	if(dp[p]!=-1) return dp[p];
	if(p==s.size()) return dp[p]=true;
	bool ret=false;
	REP(i,4){
		if(p+ss[i].size() > s.size()) continue;
		string s2=s.substr(p,ss[i].size());
		if(s2==ss[i]) if(dfs(s,p+ss[i].size())) ret=true; 
	}
	//cout<<p<<" "<<ret<<en;
	return dp[p]=ret;
}



void solve(){
	string s;
	cin>>s;
	REP(i,s.size()+1) dp[i]=-1;
	cout<<(dfs(s,0)?"YES":"NO")<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
  using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define fr(i,a,b) for(int i =a ; i < b; i++)
    #define FR(i,a,b) for(int i =a ; i > b; i--) 
    #define frj(j,a,b) for(int j =a ; j < b; j++)
    #define FRE(i,a,b) for(int i =a ; i >= b; i--) 
    #define fre(i,a,b) for(int i =a ; i <= b; i++)
    #define fra(s) for(auto it = s.begin(); it != s.end() ; ++it)

    #define mkp make_pair 
    #define pb push_back
    #define pii pair<int,int>
    #define speed   ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
    #define c(a,b) cout<<a<<"--"<<b<<endl;
    #define frv(i,a,v) for(int i =  a ; i < v.size() ; ++i)
    #define cp(a,i)  cout<<a[i].first<<" "<<a[i].second<<endl;
    #define pp(a) cout<<a.first<<" "<<a.second<<endl;
    //sum array
    #define sa(n) int a[n]; int s[n];cin>>a[0];s[0]=a[0];fr(i,1,n) {cin>>a[i];s[i]=s[i-1]+a[i];}
    #define sa1(n) int a[n+1]; long long s[n+1]; a[0]=0; s[0]=0;cin>>a[1];s[1]=a[1];fr(i,2,n+1) {cin>>a[i];\
    s[i]=s[i-1]+a[i];}

    #define pr(a,n) fr(i,0,n){cout<<a[i]<<" ";}cout<<endl;
    #define prv(v)   for(auto it = v.begin() ; it!= v.end() ;++it){cout<<*it<<" ";}cout<<endl;
    #define prs(s)   for(auto x : s){cout<<x<<" ";}cout<<endl;
    
    #define all(x)           x.begin(), x.end()
    #define prm(m,r,c) fr(i,0,r){frj(j,0,c){cout<<m[i][j]<<" "; }cout<<endl;}
    #define fillm(m,r,c,k) fr(i,0,r)frj(j,0,c)m[i][j]=k;
    constexpr auto PI  = 3.14159265358979323846L;
    constexpr auto eps = 1e-6;
    constexpr auto mod = 1000000007;
    #define MOD 1000000007
   // #define maxv 200005
    #define MAXN 100001

  template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


    const int INF = 1e9 +5;
int main(){
      
      speed;

      int n ;
      cin>>n;
      int h[n];
      fr(i,0,n)
      cin>>h[i];

      vector<int> dp (n,INF);
      dp[0]=0;
      fr(i,0,n)
        {
          for(int j : {i+1,i+2})
          {
            if(j<n)
                {
                  dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
                }

          }
        }

        cout<<dp[n-1]<<endl;
      return 0;

  }



Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

bool isPrime(ll a) {
  if (a == 2) return true;
  if (a < 2 || a % 2 == 0) return false;
  int b = sqrt(a);
  for (register int i = 3; i <= b; i += 2)
    if (a % i == 0) return false;
  return true;
}

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

  ll X;
  cin >> X;
  while (!isPrime(X)) {
    X++;
  }
  out(X);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string s;cin >> s;
	int n = s.size();
	int ret = 0;
	for(int l = 0,r = n;l < r;l++,r--){
		ret += s[l] != s[r-1];
	}
	cout << ret << endl;
	return 0;
}

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

int main(){
	int N, Q; cin >> N >> Q;
	int D[Q];
	vector<pair<int, pair<int, int>>> ve;
	for(int i=0; i<N; i++){
		int s, t, x; cin >> s >> t >> x;
		ve.push_back({x, {s, t}});
	}
	sort(ve.begin(), ve.end());
	set<int> st;
	for(int i=0; i<Q; i++){
		cin >> D[i];
		st.insert(D[i]);
	}
	map<ll, ll> ans;
	for(int i=0; i<N; i++){
		int p = ve[i].second.first - ve[i].first;
		int q = ve[i].second.second - ve[i].first;
		auto j = st.lower_bound(p);
		while(*j < q && j != st.end()){
			ans[*j] = ve[i].first;
			j = st.erase(j);
		}
	}
	auto j = st.lower_bound(-1);
	while(*j <= 1e9 && j != st.end()){
		ans[*j] = -1;
		j = st.erase(j);
	}
	for(int i=0; i<Q; i++){
		cout << ans[D[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 19184
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  vector<lli> b;
  cin >> n;
  read_n(b, n, 1);
  b[0] = -1;
  vector<lli> c;
  while (b.size() >= 2) {
    lli j=b.size()-1;
    for ( ; j>0; --j) {
      if (b[j] == j) {
        b.erase(begin(b)+j);
        c.push_back(j);
        break;
      }
    }
    if (j == 0) {
      cout << -1 << '\n'; return 0;
    }
  }
  for (lli i=c.size()-1; i>=0; --i) cout << c[i] << '\n';
  return 0;
}


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

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

    string s;
    cin >> s;
    int ans = 0;
    string pos = "000";
    do {
        int p = 0;
        for (char i : s)
            if (i == pos[p]) {
                p++;
                if (p == 3) {
                    ans++;
                    break;
                }
            }
        if (pos[2] == '9') {
            pos[2] = '0';
            if (pos[1] == '9') {
                pos[1] = '0';
                if (pos[0] == '9')
                    break;
                else
                    pos[0]++;
            } else
                pos[1]++;
        } else
            pos[2]++;
    } while (pos != "000");
    cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  int X;
  cin >> X;
  int ans = 1;
  for(int i=2;i<=31;i++){
    int N = i*i;
    while(N <= X){
      ans = max(ans, N);
      N *= i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))

//#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
const ll maxn = 2*100005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
long long  gcd(long long  a, long long b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main(){
    fast;
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
}


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

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

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vi x(N), y(N);
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    vi ord(N);
    for(int i=0; i<N; i++) ord[i]=i;
    double avg=0;
    do{
        for(int i=0; i<N-1; i++){
            double dx, dy;
            dx=x[ord[i+1]]-x[ord[i]];
            dy=y[ord[i+1]]-y[ord[i]];
            avg+=sqrt(dx*dx+dy*dy);
        }
    }while(next_permutation(all(ord)));
    for(int i=1; i<=N; i++){
        avg/=i;
    }
    cout << fixed << setprecision(7);
    cout << avg << endl;
    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <vector>

int main(){
  int r, D, x_2000;
  std::cin>>r>>D>>x_2000;
  std::vector<long> x_i;
  x_i.push_back(x_2000);
  for(int i = 1 ; i <= 10 ; i++ ){
    x_i.push_back(r * x_i[i-1] - D);
    std::cout<<x_i[i]<<std::endl;
  }
  return 0;
}


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

int main()
{
    std::string s;
    std::cin >> s;
    int q;
    std::cin >> q;

    int rev = 0;
    for (int i = 0; i < q; i++) {
        int a;
        std::cin >> a;
        if (a == 1) {
            if (rev == 0)
                rev = 1;
            else
                rev = 0;
        }
        else {
            int b;
            std::cin >> b;
            std::string c;
            std::cin >> c;
            if ((b == 1 && !rev) || (b != 1 && rev))
                s.insert(0, c);
            else
                s += c;
        }
    }

    if (!rev) {
        for (size_t i = 0; i < s.length(); i++) {
            printf("%c", s[i]);
        }
    } else {
        for (size_t i = s.length(); i > 0; i--) {
            printf("%c", s[i-1]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 900
import numpy as np
W, H, N = map(int,input().split())
Map = np.ones((H, W),dtype = int)
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        Map[:,:x] = 0
    elif a == 2:
        Map[:,x:] = 0
    elif a == 3:
        Map[:y,:] = 0
    else:
        Map[y:,:] = 0
print(Map.sum())    

Measured memory_bytes: 12536
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(500010), INF(0x3f3f3f3f);
struct edge { int next, to; } e[N << 1];
int head[N], e_num, n, K, cnt, a[N], p[N], deg[N], min[N << 2];
inline void add_edge(int from, int to)
{
	e[++e_num] = (edge) {head[from], to};
	head[from] = e_num, ++deg[to];
}

void Insert(int p, int v, int x = 1, int l = 1, int r = n)
{
	if (l == r) return (void) (min[x] = v);
	int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1;
	if (p <= mid) Insert(p, v, ls, l, mid);
	else Insert(p, v, rs, mid + 1, r);
	min[x] = std::min(min[ls], min[rs]);
}

int Query(int ql, int qr, int x = 1, int l = 1, int r = n)
{
	if (ql > qr) return INF;
	if (ql <= l && r <= qr) return min[x];
	int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1, ans = INF;
	if (ql <= mid) ans = Query(ql, qr, ls, l, mid);
	if (mid < qr) ans = std::min(ans, Query(ql, qr, rs, mid + 1, r));
	return ans;
}

void bfs()
{
	std::priority_queue<int, std::vector<int>, std::greater<int> > Q;
	for (int i = 1; i <= n; i++) if (!deg[i]) Q.push(i);
	while (!Q.empty())
	{
		int x = Q.top(); Q.pop(); p[x] = ++cnt;
		for (int i = head[x]; i; i = e[i].next)
			if (!--deg[e[i].to]) Q.push(e[i].to);
	}
}

int main()
{
	n = read(), K = read(), memset(min, 0x3f, sizeof min);
	for (int i = 1; i <= n; i++) a[read()] = i;
	for (int i = n, t; i; i--)
	{
		t = Query(a[i] + 1, std::min(a[i] + K, n));
		if (t != INF) add_edge(a[i], a[t]);
		t = Query(std::max(1, a[i] - K + 1), a[i] - 1);
		if (t != INF) add_edge(a[i], a[t]);
		Insert(a[i], i);
	}
	for (int i = (bfs(), 1); i <= n; i++)
		printf("%d\n", p[i]);
	return 0;
}


Measured memory_bytes: 27008
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int main()
{
    int r, d, x;
    scanf("%d%d%d", &r, &d, &x);
    long long nw = x;
    for (int i = 1; i <= 10; i++)
    {
        nw = nw * r - d;
        printf("%lld\n", nw);
    }
    return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Measured memory_bytes: 52448
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

ll n, k;
vector<ll> a;

void input() {
	cin >> n >> k;
	a.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a.begin(), a.end());
}

// かけてb以下になるペアが何個あるかをカウントする
ll count(ll b) {
	ll res = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] < 0) {
			ll mn = b / a[i] + ((b < 0 && b % a[i] != 0) ? 1 : 0);
			auto iter = lower_bound(a.begin() + i + 1, a.end(), mn);
			res += a.end() - iter;
		}
		else if (a[i] == 0) {
			if (b < 0) continue;
			res += (ll)n - i - 1LL;
		}
		else {
			ll mx = b / a[i] - ((b < 0 && b % a[i] != 0) ? 1 : 0);
			auto iter = upper_bound(a.begin() + i + 1, a.end(), mx);
			res += iter - (a.begin() + i + 1);
		}
	}
	return res;
}

int main() {
	input();
	ll ng = -1000000000000000001LL; // かけてng以下になるペアがk個未満
	ll ok = 1000000000000000000LL; // かけてok以下になるペアがk個以上
	while (ok - ng > 1) {
		ll mid = ng + (ok - ng) / 2;
		if (count(mid) < k) ng = mid;
		else ok = mid;
	}
	cout << ok << endl;
	return 0;
}


Measured memory_bytes: 1920
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func check(maxA int, minA int, maxB int, minB int) int {
     ans := -1
     if (maxA < minB) || (maxB < minA) {
     	return -1
     } else {
        for i := maxA; i >= minA; i-- {
	    if (minB <= i) && (i <= maxB) {
	       ans = i
	    }
	}
     }
     return ans
}

func main() {
     sc.Split(bufio.ScanWords)
     a := nextInt()
     b := nextInt()

     maxA := int(math.Ceil(float64(a+1) * 12.5)) - 1
     minA := int(math.Ceil(float64(a) * 12.5))
     minB := b * 10
     maxB := minB + 9

     fmt.Println(check(maxA,minA,maxB,minB))
}     

Measured memory_bytes: 640
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<long double, long double>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;



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

  ll n;
  std::cin>>n;

  std::vector<P> point(n);
  rep(i,0,n){
    long double a,b;
    std::cin>>a>>b;
    point[i]={a,b};
  }

  std::vector<ll> per(n);
  rep(i,0,n)per[i]=i;

  long double ans=0;

  do{
    rep(i,1,n){
      ans+=sqrtl(powl((point[per[i]].first-point[per[i-1]].first),2)+powl((point[per[i]].second-point[per[i-1]].second),2));
    }
  }while(std::next_permutation(all(per)));

  rep(i,1,n+1)ans/=(long double)i;

  std::cout<<std::setprecision(10)<<std::fixed<<ans;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long


using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL);
    
    int n; cin >> n;
    
    unordered_set<string> s;
    
    for(int i = 0; i < n; i++)
    {
		string str; cin >> str;
		s.insert(str);
	}
    
    cout << s.size() << endl;
    
    return 0;
}


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

int main() {
    ll t1,t2,a1,a2,b1,b2;
    std::cin >> t1>>t2;
    std::cin >> a1>>a2;
    std::cin >> b1>>b2;
    
    if(a1*t1+a2*t2 == b1*t1+b2*t2){
        std::cout << "infinity" << std::endl;
        return 0;
    }
    
    if(a1*t1+a2*t2 < b1*t1+b2*t2){
        swap(a1,b1);
        swap(a2,b2);
    }
    
    if( t1*(b1-a1) < 0 ){
        std::cout << 0 << std::endl;
        return 0;
    }
    ll res = (a1-b1)*t1/((b1-a1)*t1+(b2-a2)*t2);
    
    if(  (a1-b1)*t1%((b1-a1)*t1+(b2-a2)*t2)==0){
        std::cout << res*2 << std::endl;
    }else{
        std::cout << res*2+1 << std::endl;
    }
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        int cnt = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == t[i])
                cnt++;
        }
        
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
package main

import (
    "fmt"
)

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

    var result string = "ABC"

//    var slice = strings.Split(s, "")

    var j int = 0
    for i := 0; i <= n-3; i++  {
        var char string = s[i:i+3]
        if char == result {
            j++
        }
    }
    fmt.Println(j)

}



Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

ll price[100005];
pair <int, int> rebr[100005];
pair <ll, int> spis[100005];
int par[100005], sz[100005], remov[100005];
ll wei[100005];

int find_parent(int a)
{
    if (a == par[a]) return a;
    return par[a] = find_parent(par[a]);
}

void unions(int a, int b)
{
    a = find_parent(a), b = find_parent(b);
    if (a != b)
    {
        if (sz[a] < sz[b]) swap(a, b);
        sz[a] += sz[b], wei[a] += wei[b], remov[a] += remov[b];
        par[b] = a;
    }
    remov[a]++;
    return;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> price[i];
        par[i] = i, sz[i] = 1, wei[i] = price[i];
    }
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        ll w;
        cin >> a >> b >> w;
        rebr[i] = mp(a, b);
        spis[i] = mp(w, i);
    }
    sort(spis + 1, spis + m + 1);

    for (int i = 1; i <= m; i++)
    {
        int a = rebr[spis[i].y].x, b = rebr[spis[i].y].y;
        unions(a, b);
        int v = find_parent(a);
        if (wei[v] >= spis[i].x) remov[v] = 0;
    }
    int v = find_parent(1);
    cout << remov[v];
    return 0;
}


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

int main(){
  int N;
  cin >>N;
 
  vector<int> p(N);
  rep(i,0,N) cin >>p[i];
  
  sort(p.begin(),p.end(),greater<int>());
  
  int ans = p.front()/2;
  rep(i,1,N) ans += p[i];
  
  cout <<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;

class Dice
{
  String[] face;
  int[] num;

  public Dice(String str) //?????????
  {
    this.face = new String[6];
    this.face = str.split(" ");
    this.num = new int[6];
    for(int i = 0; i < this.face.length; i++) num[i] = i;
  }

  public String get(int n) { return this.face[num[n]]; } //?????°?????¢?????????

  public void roll(char way) //?????¢???????????????????????¢?????????????????´??????
  {
    int tmp;
    switch(way){
      case 'N':
        tmp = num[0];
        this.num[0] = this.num[1];
        this.num[1] = this.num[5];
        this.num[5] = this.num[4];
        this.num[4] = tmp;
        break;
      case 'S':
        tmp = this.num[0];
        this.num[0] = this.num[4];
        this.num[4] = this.num[5];
        this.num[5] = this.num[1];
        this.num[1] = tmp;
        break;
      case 'E':
        tmp = this.num[0];
        this.num[0] = this.num[3];
        this.num[3] = this.num[5];
        this.num[5] = this.num[2];
        this.num[2] = tmp;
        break;
      case 'W':
        tmp = this.num[0];
        this.num[0] = this.num[2];
        this.num[2] = this.num[5];
        this.num[5] = this.num[3];
        this.num[3] = tmp;
        break;
      default:
        break;
    }
  }
}

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

    Dice dice = new Dice(str);

    str = br.readLine();
    for(int i = 0; i < str.length(); i++){
      dice.roll(str.charAt(i));
    }
    System.out.println(dice.get(0));
  }
}

Measured memory_bytes: 24464
K, N = map(int, input().split())
A = list(map(int, input().split()))

ans = A[-1] - A[0]

for i in range(len(A) - 1):
    # print(i)
    tmp = A[i] - (A[i + 1] - K)
    if ans > tmp:
        ans = tmp

print(ans)


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

int main(){
  int c[4][4];
  for(int i = 1;i <= 3;i++){
    for(int j = 1;j <= 3;j++){
      cin >> c[i][j];
    }
  }
  if(c[1][1] - c[2][1] == c[1][2] - c[2][2] &&
     c[1][1] - c[2][1] == c[1][3] - c[2][3] &&
     c[2][1] - c[3][1] == c[2][2] - c[3][2] &&
     c[2][1] - c[3][1] == c[2][3] - c[3][3] &&
     c[1][1] - c[1][2] == c[2][1] - c[2][2] &&
     c[2][1] - c[2][2] == c[3][1] - c[3][2] &&
     c[1][2] - c[1][3] == c[2][2] - c[2][3] &&
     c[2][2] - c[2][3] == c[3][2] - c[3][3] ){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main() {
 UL N; cin>>N;
 UL ans=0;
 rep(i,N){
  UL a; cin >>a;
  if((i%2==0)&&(a%2==1)) ans++;
 }
 cout<<ans<<endl;
 return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
	
signed main(){
	ll i, j;
	string s, t;
	cin >> s >> t;
	ll ns = s.length();
	ll nt = t.length();
	ll dp[ns+1][nt+1];
	memset(dp,0,sizeof(dp));
	for( i = 1 ; i <= ns ; i++ ){
		for( j = 1 ; j <= nt ; j++ ){
			if( s[i-1] == t[j-1] ){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = max( dp[i-1][j] , dp[i][j-1] );
			}
		}
	}
	// for( i = 0 ; i <= ns ;  i++ ){
	// 	for( j= 0 ; j <= nt ; j++ ){
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << endl;
	// }
	// cout << dp[ns][nt] << endl;
	string ans;
	i = ns;
	j = nt;
	while( i > 0 && j > 0 ){
		if( s[i-1] == t[j-1] ){
			ans += s[i-1];
			i--;
			j--;
		}else{
			if( dp[i-1][j] >= dp[i][j-1] ){
				i--;
			}else{
				j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
	return 0;
}	

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


const int MAX_N = 100000000;

int par[MAX_N];
vector<int> rankTree;
vector<int> siz;

void init(int n){
    for(int i=0; i<n;i++){
        par[i] = i;
    }
    rankTree.resize(n,1);
    siz.resize(n,1);
}

int find(int x){
    if(par[x] == x){
        return x;
    }
    return find(par[x]);
}

bool same(int x,int y){
    return find(x) == find(y);
}

void unite(int x, int y){
    if(same(x,y)){
        return;
    }

    int rootx = find(x);
    int rooty = find(y);
    
    if(rankTree[rootx] < rankTree[rooty]){
        siz[rooty] += siz[rootx];
        par[rootx] = rooty;
        return;
    }
    par[rooty] = rootx;
    siz[rootx] += siz[rooty];
    if(rankTree[rootx] == rankTree[rooty]){
        rankTree[rootx] ++;
    }
}
int getsize(int x){
    return siz[find(x)];
}




void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D){
    vector<long long> friends(N,0);
    vector<long long> blocks(N,0);
    for(int i=0; i<M;i++){
        friends[A[i]]++;
        friends[B[i]]++;
        unite(A[i],B[i]);
    }
    for(int i=0;i<K;i++){
        if(same(C[i],D[i])){
            blocks[C[i]] ++;
            blocks[D[i]] ++;
        }
    }
    // for(int i=0;i<N;i++){
    //     cerr <<"member =" << i << endl;
    //     cerr << getsize(i) << endl;
    //     cerr << friends[i] << endl;
    //     cerr << blocks[i] << endl;
    // }
    for(int i=0;i<N;i++){
        if(i != N){
    cout << getsize(i) - friends[i] -blocks[i]-1 << " ";
        }else{
            cout << getsize(i) - friends[i] -blocks[i]-1 << endl;
        }
    
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    init(N);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        int a,b;
        cin >> a>> b;
        a--;b--;
        A[i] =a;
        B[i] =b;

    }
    std::vector<long long> C(K);
    std::vector<long long> D(K);
    for(int i = 0 ; i < K ; i++){
        int a,b;
        cin >> a>> b;
        a--;b--;
        C[i] =a;
        D[i] =b;
    }
    solve(N, M, K, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}


Measured memory_bytes: 6656
#include <stdio.h>

int calc(int x,int y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){
	int x,y;
	scanf("%d %d",&x,&y);
	if(x >= y)
		printf("%d\n",calc(x,y));
	else{
		printf("%d\n",calc(y,x));
	}
}



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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    rep(I, n){
        string s;
        cin >> s;

        deque<char> ans;
        vector<bool> used(26);
        ans.push_back(s[0]);
        used[s[0] - 'a'] = true;

        for(int i = 3, i_len = s.size() ; i < i_len ; i += 3){
            if(!used[s[i] - 'a']){
                used[s[i] - 'a'] = true;
                if(s[i - 1] == '>'){
                    ans.push_back(s[i]);
                }else{
                    ans.push_front(s[i]);
                }
            }
        }

        rep(i, ans.size()){
            cout << ans[i];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3016
#include<iostream>

using namespace std;

int main(void){
    int S[10000],T[10000],A[10000],count = 0;
    long long int n,q;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> S[i];
    }
    cin >> q;
    for (int j = 0; j < q; j++){
        cin >> T[j];
    }
    for (int j = 0; j < q; j++){
        for (int i = 0; i < n; i++){
            if (T[j] == S[i]){
                count++;
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	vector<int> x(n), a(n);
	rep(i, n) {
		cin >> x[i];
		a[i] = x[i];
	}

	sort(all(x));

	rep(i, n) {
		if (x[n / 2 - 1] >= a[i]) {
			out(x[n / 2]);
		}
		else {
			out(x[n / 2 - 1]);
		}
	}

	return 0;
}

Measured memory_bytes: 3840
NX = []
NX_hairetsu = []
while True:
    n, x = [int(e) for e in input().split()]
    if n==0 and x==0:
        break
    else:
        NX = [n, x]
        NX_hairetsu.append(NX)
        
for i in range(len(NX_hairetsu)):
    count = 0
    N = [e for e in range(1, NX_hairetsu[i][0]+1)]
    for a in range(len(N)-2):
        for b in range(a+1, len(N)-1):
            for c in range(b+1, len(N)):
                if N[a]+N[b]+N[c]==NX_hairetsu[i][1]:
                    count += 1
    print(count)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
const int mo=1000000007;
const int N=(1<<20)+5;
int wei[25][25];
int c[N],f[N],g[N];
int n,m,k,ans;
void upd(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<1<<n;i++)
		c[i]=i-(i&(-i));
	for (int i=1;i<=k;i++){
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		wei[x][y]=v+1;
	}
	f[0]=1;
	for (int i=1;i<=m;i++)
		for (int j=1;j<n;j++){
			for (int k=0;k<1<<n;k++) if (f[k]){
				int pre=k&((1<<(j-1))-1),aft=k-pre;
				if (wei[i][j]!=2&&!(aft&(1<<(j-1)))) upd(g[k],f[k]);
				if (wei[i][j]!=1) upd(g[pre|(1<<(j-1))|c[aft]],f[k]);
			}
			for (int k=0;k<1<<n;k++)
				f[k]=g[k],g[k]=0;
		}
	for (int i=0;i<1<<n;i++)
		upd(ans,f[i]);
	printf("%d",ans);
}

Measured memory_bytes: 12672
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    n = len(s)
    f = defaultdict(lambda : float("inf"))
    for i in range(n):
        for j in range(n):
            if j < i:
                f[(i,s[j])] = min(f[(i,s[j])],n-j-1)
            else:
                f[(i,s[j])] = min(f[(i,s[j])],j-i)
    ans = float("inf")
    for a in s:
        m = 0
        for i in range(n):
            m = max(m, f[(i,a)])
        if m < ans:
            ans = m
    print(ans)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 42608
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    string S, T;
    cin >> S >> T;
    ll mc = INF;
    for (size_t i = 0; i < S.length() - T.length() + 1; i++) {
        ll c = 0;
        for (size_t j = 0; j < T.length(); j++) {
            if (S[i+j] != T[j]) c++;
        }
        mc = min(mc, c);
    }
    cout << mc << endl;
    return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
vector<set<int>> h,v;
map<int,vector<int>> mp;
map<int,vector<set<int>>> mp1;

int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    h.assign(n,set<int>());
    v.assign(m,set<int>());
    for(int i=0;i<x;i++)
    {
        int x,y;
        cin>>x>>y;
        --x;
        --y;
        h[x].insert(y);
        v[y].insert(x);
    }
    int mx1=0,mx2=0,mx3=0,mx4=0;
    for(int i=0;i<m;i++)
    {
        int ok=v[i].size();
        mp[ok].push_back(i);
        if(mp[ok].size()<=1)
        {
            if(ok>mx1)
            {
                mx2=mx1;
                mx1=ok;
            }
            else if(ok>mx2 or ok==mx1)
            mx2=ok;
        }
    }
    for(auto x:h)
    {
        int ok=x.size();
        mp1[ok].push_back(x);
        if(ok>mx3)
        {
            mx4=mx3;
            mx3=ok;
        }
        else if(ok>mx4 or ok==mx3)
        mx4=ok;
    }
    int res=0;
    for(auto i:{mx3,mx4})
    {
        for(auto y:mp1[i])
        {
            for(auto j:{mx1,mx2})
            {
                int ss=0;
                for(auto xx:mp[j])
                {
                    if(y.count(xx))
                    res=max(res,i+j-1);
                    else
                    {
                        res=max(res,i+j);
                        break;
                    }
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 113140
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
const int MAXN = 1e2 + 5;

bool ok(string s)
{
	int n=s.size();
	for(int i=0; i<(n>>1); ++i)
		if(s[i]!=s[n-i-1]) return 0;
	return 1;
}

int main(void)
{
	string s;
	cin>>s;
	int n=s.size();
	if(ok(s) && ok(s.substr(0,(n-1)/2)) && ok(s.substr((n+3)/2-1,n))) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void print_v(vector<int> v)
{
    for (auto it = v.begin(); it != v.end() - 1; it++)
    {
        cout << *it << ' ';
    }
    cout << v.back() << endl;
}
int main()
{
    int n;
    cin >> n;
    vector<int> v;
    v.reserve(n);

    for (int i = 0; i < n; i++)
    {
        int m;
        cin >> m;
        v.push_back(m);
    }

    vector<int> prev, next;
    prev = v;
    next = v;

    if (prev_permutation(prev.begin(), prev.end()))
    {
        print_v(prev);
        print_v(v);
        if (next_permutation(next.begin(), next.end()))
        {
            print_v(next);
        }
    }
    else
    {
        print_v(v);
        if (next_permutation(next.begin(), next.end()))
        {
            print_v(next);
        }
    }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  int n,x;
  cin>>n>>x;
  int tmp = 0;
  REP(i,n){
    int k;
    cin>>k;
    int tp = abs(k-x);
    tmp = __gcd(tmp,tp);
  }
  cout<<tmp<<endl;
}


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

int main()
{
    int N, M;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++)
        cin >> s.at(i);

    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++)
        cin >> t.at(i);

    map<string, int> mp;
    for (string x : s)
    {
        if (mp.count(x) == 0)
            mp[x] = 1;
        else
            mp[x]++;
    }

    for (string x : t)
    {
        if (mp.count(x) == 0)
            mp[x] = -1;
        else
            mp[x]--;
    }

    int ans = 0;
    for (auto x : mp)
        ans = max(ans, x.second);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<int> renew;
		while(n){
			int digit=n%8;
			if(digit>=4)	digit++;
			if(digit>=6)	digit++;
			renew.push_back(digit);
			n/=8;
		}
		for(int i=renew.size()-1;i>=0;i--)	cout<<renew[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 908