akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct UnionFind {
	vector<int> par,rank;
	int N;

	UnionFind(int n) {
		N = n;
		par.resize(n);
		rank.resize(n);

		rep(i,n) {
			par[i] = i;
			rank[i] = 0;
		}
	}

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

	void unite(int x,int y) {
		x = find(x);
		y = find(y);

		if(x == y) return;

		if(rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

	int size() {
		int cnt = 0;
		rep(i,N) if(find(i) == i) cnt++;
		return cnt;
	}
};

int main() {
	int n, m;

	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		vector<int> a(m), b(m), c(m);
		map<int, vector<P> > es;
		rep(i, m) {
			cin >> a[i] >> b[i] >> c[i];
			a[i]--; b[i]--;

			es[c[i]].push_back(P(a[i], b[i]));
		}

		int ans = INF;

		REP(i, 1, 10001) {
			if(es[i].size() == 0) continue;
			UnionFind uf(n);
			REP(j, i, 10001) {
				if(es[j].size() == 0) continue;
				rep(k, es[j].size()) {
					int a = es[j][k].first;
					int b = es[j][k].second;

					if(uf.same(a, b)) continue;
					uf.unite(a, b);
				}

				if(uf.size() == 1) {
					ans = min(ans, j - i);
					break;
				}
			}
		}

		if(ans == INF) cout << -1 << endl;
		else cout << ans << endl;
	}

	return 0;
}

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

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

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

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

vector<long long> lis_and_lds(long long n, long long a, long long b) {
    assert(a + b <= n + 1 && n <= a * b);
    vector<long long> res;
    for (int i = b-1; i >= 0; --i) res.push_back(i);
    if (a == 1) return res;

    long long rem = n - b;
    long long width = rem / (a-1);
    long long r = rem % (a-1);

    for (int i = 0; i < r; ++i) {
        int sz = (int)res.size();
        for (int j = 0; j < width + 1; ++j) {
            res.push_back(sz + width - j);
        }
    }
    for (int i = 0; i < a - 1 - r; ++i) {
        int sz = (int)res.size();
        for (int j = 0; j < width; ++j) {
            res.push_back(sz + width - 1 - j);
        }
    }

    return res;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a + b > n + 1 || n > a * b) {
        cout << "-1\n";
        return 0;
    }
    auto ans = lis_and_lds(n, a, b);
    rep(i, n) cout << ans[i] + 1 << (i == n-1 ? '\n' : ' ');
}


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

template<typename T>vector<T> dijkstra(vector<vector<pair<T,T>>> e,T s){
	priority_queue<pair<T,T>, vector<pair<T,T>>, greater<pair<T,T>>> q;
	const auto INF = numeric_limits< T >::max();
	vector<T> d(e.size(),INF);
	
	q.push({0,s});
	d.at(s) = 0;
	while(!q.empty()){
		auto p = q.top();
		q.pop();
		if(d.at(p.second)<p.first) continue;
		for(auto to:e.at(p.second)){
			if(d.at(to.second)<=to.first+p.first) continue;
			d.at(to.second) = to.first+p.first;
			q.push({d.at(to.second), to.second});
		}
	}
	for(auto &i:d) if(i==INF) i=-1;
	return d;
}

int main() {
	
	int n,x,y; cin >>n>>x>>y;
	x--; y--; 
	vector<vector<pair<int,int>>> e(n);
	for(int i=0; i<n; i++){
		if(i>0)e.at(i).push_back({1,i-1});
		if(i<n-1)e.at(i).push_back({1,i+1});
	}
	e.at(x).push_back({1,y});
	e.at(y).push_back({1,x});
	vector<vector<int>> dist(n,vector<int>(n));
	vector<int> ans(n);
	
	for(int i=0; i<n; i++){
		dist.at(i) = dijkstra(e,i);
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ans.at(dist.at(i).at(j))++;
		}
	}
	for(int i=1; i<n; i++) cout << ans.at(i)/2 << endl;
	
}

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

int main(){
  int n; cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  
  vector<long long> dp(n, 0);
  
  dp[0] = 0; dp[1] = abs(h[0]-h[1]);
  
  for(int i = 2; i < n; i++){
  
  	dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    
    //cout << dp[i] << endl;
  
  }
  
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,cnt[100005],l,r;
bool nop[100005];
int main()
{
	nop[1]=1;
	for (i=2;i<=100000;i++)
	{
		if (nop[i]) continue;
		for (j=2;i*j<=100000;j++)
		{
			nop[i*j]=1;
		}
	}
	for (i=3;i<=100000;i++)
	{
		cnt[i]=cnt[i-1];
		if (i%2==1&&!nop[i]&&!nop[(i+1)/2]) cnt[i]++;
	}
	cin>>n;
	while (n--)
	{
		cin>>l>>r;
		cout<<cnt[r]-cnt[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int ms = 1e5+9;
typedef pair<int,int> ii;
int ans = 0;

vector<ii> vet;
vector<int> resp;
vector<int> g[ms];
int r[ms],p[ms], sz[ms],n,m,a,b;


int Ufind(int i){
  return (i == p[i])?i:p[i] = Ufind(p[i]);
}

void UF(int a, int b){
  a = Ufind(a), b = Ufind(b);
  if(a == b)
  	return ;
  	//cout<<sz[b]<<" "<<sz[a]<<endl;
	ans -= sz[b]*sz[a];
  
	if(r[a] > r[b]){
    p[b] = a;
    sz[a]+= sz[b];
  }else{
    p[a] = b;
    sz[b] += sz[a];
    
    if(r[a] == r[b])	r[b] ++;  
  }
  
}

main(){
  cin >> n >> m;
  for(int i = 1;i<=n;i++) p[i] = i;
  for(int i = 1;i<=n;i++) sz[i] = 1;
  for(int i= 0;i<m;i++){
  	cin >> a >> b;
    vet.push_back({a,b});
  }
  reverse(vet.begin(),vet.end());
  ans = (n*(n-1))/2;
  resp.push_back(ans);
  for(int i= 0;i<m-1;i++){
    UF(vet[i].first,vet[i].second);
    resp.push_back(ans);
  }
  reverse(resp.begin(),resp.end());
  for(auto it:resp)
  	cout<<it<<endl;
  
  
}

Measured memory_bytes: 9328
#include <iostream>
#include <math.h>

static const double PI = 6*asin(0.5);

using namespace std;

int debug = 0;

int main(void){
	int len, deg, direction=90;
	double x=0, y=0;
	int i_x, i_y;

	while(cin >> len){
		cin.ignore(); //read ,
		cin >> deg;

		if(len == 0 && deg == 0) break;

		//proceed
		x += len * cos(direction * PI / 180);
		y += len * sin(direction * PI / 180);
		
		//turn clockwise
		direction -= deg;

	}

	i_x = x;
	i_y = y;

	cout << i_x << endl;
	cout << i_y << endl;

	return 0;
}

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

int N, Q;
string S;
int l[(int)1e5], r[(int)1e5];
int dp[(int)1e5];

int main() {
    cin >> N >> Q >> S;
    rep(i, Q) cin >> l[i] >> r[i];
    
    int total = 0;
    for(int i = 0; i <= N - 2; i++) {
        dp[i + 1] = dp[i];
        if (S[i] == 'A' && S[i + 1] == 'C') {
            dp[i + 1]++;
        }
    }

    rep(i, Q) {
        cout << dp[r[i] - 1] - dp[l[i] - 1] << endl;
    }
    // rep(i, N) {
    //     cout << dp[i] << endl;
    // }
}

Measured memory_bytes: 2176
//om nama sivaya
#include<bits/stdc++.h>
#define M 1000000007
#define ll long long
using namespace std;
void solve(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(int i=k;i<n;i++){
        if(a[i]>a[i-k])
        cout<<"Yes\n";
        else
        cout<<"No\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5204
n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(n)]
a.sort(key=lambda x:x[1],reverse=1)
b.sort(key=lambda x:x[0])
ans=0
for i in a:
  for j in b:
    if i[0]<j[0] and i[1]<j[1]:
      b.remove(j)
      ans+=1
      break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    int N; cin>>N;
    ll A,B; cin>>A>>B;

    vector<ll> d(N);
    for(int i=0;i<N;i++) cin>>d.at(i);
    sort(d.begin(),d.end());
    ll OK=d.at(N-1)/B, NG=d.at(N-1)/A;
    OK++; NG--;

    while(OK>NG+1){
        ll MID=(OK+NG)/2;
        //bool able=true;
        ll count=0;
        for(int i=N-1;i>=0;i--){
            if(d.at(i)>MID*B) count+=((d.at(i)+A-B-1-MID*B)/(A-B));
            else break;
            if(count>MID) break;
        }

        if(count>MID) NG=MID;
        else OK=MID;
    }

    cout<<OK<<endl;
}

Measured memory_bytes: 1024
import itertools
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    H = sorted([int(input()) for _ in range(N)])
    ans = 1000000000
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1]-H[i])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 44380
a, b, c, k = map(int, input().split())
if a>=k:
    print(k)
else :
    kk = k-a%k
    A = a%k
    if b>=kk:
        print(a%k)
    else :
        kkk = kk-b%kk
        B = b%kk
        if c >= kkk:
            print(a%k-1*(k-A-B))

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

long long N, A,B, ans;

void solve(){
    if(N == 1){
        if ( A == B){
            ans = 1;
        }
        else{
            ans = 0;
        }
    }
    else {
        if(A > B){
            ans = 0;
        }
        else{
            ans = (B - A) * (N-2) + 1;
        }
    }
}

int main(){
    cin >> N >> A >> B;
    solve();
    cout << ans << endl;
    return 0;
}

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

ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a, b; cin>>a>>b;
	cout<<a*b/ebob(a,b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, k;
  cin >> n >> k;
  vi v(n);
  rep(i, n) {
    cin >> v[i];
  }

  int ans = 0;
  rep(i, n+1) {
    for (int j = 0; i+j <= n && i+j <= k; j++) {
      int cnt = 0;
      priority_queue<int> q;

      rep(ii, i) {
        cnt += v[ii];
        if (v[ii-1] < 0) {
          q.push(-v[ii-1]);
        }
      }
      rep(ii, j) {
        cnt += v[n-1-ii];
        if (v[n-ii-1] < 0) q.push(-v[n-ii-1]);
      }

      rep(ii, k-i-j) {
        if (!q.size()) break;
        cnt += q.top();
        q.pop();
      }

      cmax(ans, cnt);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string input = "";
  cin >> input;
  bool is_only = false;
  bool flag1 = true;
  bool flag = true;
  if(input.at(0)=='A'){
    for(int i=2;i<=input.length()-2;++i){
      if(input.at(i)=='C'&&flag1){
        flag1 = false;
        is_only = true;
      }else{
        if(input.at(i)=='C'&&flag1==false)is_only=false;
      }
    }
    for(int i=0;i<input.length();++i){
      char now = input.at(i);
      if(!(i==0&&now=='A')&&now!='C'){
        if(now<0x61||now>0x7a){
          flag = false;
        }
      }
    }
    if(flag&&is_only){
      cout << "AC" << endl;
      return 0;
    }
  }
  cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, M;
  get(N, M);
  vector<int> S(N), T(M);
  getv(S);
  getv(T);
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 1));
  FORIN(i, 1, N + 1) {
    FORIN(j, 1, M + 1) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
      } else {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
      }
    }
  }
  print(dp[N][M]);
  return 0;
}

Measured memory_bytes: 31616
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int[] a = new int[1000000];
  Arrays.fill(a,0);
  a[n]=1;
  int cnt = 1;
  for(;;){
    if(n%2==0){
      n /= 2;
    }
    else{
      n = n*3 + 1;
    }
    if(a[n] == 1){
      break;
    }
    else{
      a[n] = 1;
      cnt++;
    }
  }
  System.out.println(cnt+1);
}}
      


Measured memory_bytes: 26708
#include <stdio.h>
int main(void) {
  int n, a[100];
  int i, j, tmp;
  int cnt = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for (i = 0; i < n; i++) {
    for (j = 1; j < n - i; j++) {
      if (a[j - 1] > a[j]) {
        tmp = a[j - 1];
        a[j - 1] = a[j];
        a[j] = tmp;
        cnt++;
      }
    }
  }

  printf("%d", a[0]);
  for (i = 1; i < n; i++)
    printf(" %d", a[i]);
  printf("\n%d\n", cnt);

  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> a(N,0);
  vector<int> x(N,0);
  int sum=0;
  int temp=0;
  for (int i=0;i<N;i++){
    cin>>a[i];
    sum=sum+a[i];
  }
  for(int i=1;i<N-1;i=i+2){
    temp=temp+a[i];
  }
  x[0]=sum-2*temp;
  //cout<<"sum"<<sum<<" temp "<<temp<<" x[0]"<<x[0]<<endl;
  for(int i=1;i<N;i++){
    x[i]=2*a[i-1]-x[i-1];
  }
  
  for(int i=0;i<N-1;i++){
    cout<<x[i]<<" ";
  }
  cout<<x[N-1]<<endl;
  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define maxn 100007
#define ll long long int
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;
}

inline void writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	int a=read(),b=read(),c=read(),k=read();
	int d=1<<k,ans=0;
	if (a>=b&&a>=c) ans=a*d+b+c;
	if (b>=a&&b>=c) ans=b*d+a+c;
	if (c>=b&&c>=a) ans=c*d+a+b;
	write(ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String N = in.next();
            int n = Integer.parseInt(N);
            int sn = 0;
            for (int i = 0; i < N.length(); i++) {
                sn += N.charAt(i) - '0';
            }
            if (n % sn == 0) out.println("Yes");
            else out.println("No");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
 
#define IN_REP          int tt; cin >> tt; while(tt--)
#define sim             template<class T
#define ris 						return * this
#define dor 						> debug & operator <<
#define eni(x) 			sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim > struct rge { T b, e; };
sim > rge<T> range(T i, T j) { return rge<T>{i, j}; }
sim > auto dud(T* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
	eni(!=) { cerr << boolalpha << i; ris;}
	eni(==) { ris << range(begin(i), end(i)); }
	sim, class U dor(pair<U,T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
	sim dor(rge<T> d) {
		*this << "[";
		for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
		ris << "]";
	}
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define F               first
#define S               second
#define all(a)          std::begin(a), std::end(a)
#define sz(x)           (ll)(x).size()
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL)
#define EPS             (ld) 1e-9
const ll MOD = (ll) 1e9 + 7;
const ld PI = acos(-1);
sim>T gcd(T x, T y) {return (y==0) ? x : gcd(y, x % y);}
sim>void mini(T &a, T b) { a = min(a, b); }
sim>void maxi(T &a, T b) { a = max(a, b); }
sim>T mul(T x, T y) {return (x * y) % MOD;}
sim>inline T power(T a, T b) {T res = 1;while (b > 0) {if (b&1) { res = mul(res, a); }a = mul(a, a);b >>= 1;}return res%MOD;}
sim>inline T modInverse(T n) { return power(n, MOD - 2, MOD) % MOD; }
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
sim, class U>string to_string(pair<T, U> p) {return to_string(p.F) + " " + to_string(p.S);}

const int MX = (int) 6e3 + 5;
 
int main(int argc, char** argv){
    int n;
    string s;
    cin >> n >> s;
    if(n < 3200) s = "red";
    cout << s << endl;
    return 0;
}
 


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, a;
	cin >> n >> a;
	if (n % 500 <= a)
	{
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d", &a);
	scanf("%d", &b);
	if (a > b)
		printf("a > b\n");
	else if (a == b)
		printf("a == b\n");
	else
		printf("a < b\n");
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <set>

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

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

  set<int> s;

  int d,a;
  for (auto i = 0; i != k; ++i) {
    cin >> d;
    for (auto j = 0; j != d; ++j) {
      cin >> a;
      s.insert(a);
    }
  }

  cout << n - s.size() << endl;
  return 0;
}


Measured memory_bytes: 3632
from itertools import combinations

n, m = [int(i) for i in input().split()]
c1, c2 = 0, 0
if n != 1:
    c1 = len(list(combinations(list(range(2, n * 2 + 1, 2)), 2)))
if m != 1:
    c2 = len(list(combinations(list(range(1, m * 2 + 1, 2)), 2)))
print(c1 + c2)


Measured memory_bytes: 3572
n, m, x = map(int, input().split())
G = []
ans = float('inf')
for _ in range(n):
    G.append(list(map(int, input().split())))
for i in range(1<<n):
    dummy = 0
    l = [0]*m
    flag = True
    for j in range(n):
        if (i>>j)&1 == 1:
            for k in range(m):
                l[k] += G[j][k+1]
            dummy += G[j][0]
    for p in range(m):
        if l[p] < x:
            flag = False
            break
    if flag == True:
        ans = min(ans, dummy)

print(ans if ans != float('inf') else -1)


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    string str;
    map<string, int> m;
    ll ans = 0;
    cin >> n;
    loop(i,n){
        cin >> str;
        sort(ALL(str));
        ans += m[str]++;
    }

    cout << ans << endl;


    return 0;
}


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

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

    pair<int, int> p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }

    pair<ll, ll> ans;
    ans.first = p[0].first;
    ans.second = p[0].second;

    for(int i = 1; i < n; i++){
        ll t = ans.first / p[i].first;
        ll k = ans.second / p[i].second;
        if(ans.first % p[i].first != 0){
            t++;
        }
        if(ans.second % p[i].second != 0){
            k++;
        }

        if(t <= k){
            ans.first = p[i].first * k;
            ans.second = p[i].second * k;
        }else{
            ans.first = p[i].first * t;
            ans.second = p[i].second * t;
        }
    }

    cout << ans.second + ans.first << endl;
}

Measured memory_bytes: 3596
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        k: usize,
    }
    if 2 * k > (n - 1) * (n - 2) {
        println!("-1");
        return;
    }
    let mut node = Vec::new();
    for i in 1..n {
        node.push((0+1, i+1));
    }
    let mut ret = (n-1) * (n-2) / 2 - k;
    for i in 2..n + 1{
        for j in 2..i {
            if ret > 0 {
                node.push((i, j));
                ret -= 1;
            }
        }

    }
    println!("{}", node.len());
    for (k, v) in node {
        println!("{} {}", k, v);
    }
    /*
    println!("{}", (n-1)*(n-2)/2 - k);
    for i in 1..n {
        println!("{} {}", 0+1, i+1);
    }
    let r = (n-1)*(n-2) / 2 - k;
    for i in 0..r {
        println!("{} {}", i+1, i+2);
    }
    */
}

Measured memory_bytes: 4352
#160-4
n,x,y=map(int,input().split())
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
    for j in range(i+1,n+1):
        dist1=j-i
        dist2=abs(x-i)+abs(y-j)+1
        dist3=abs(y-i)+abs(x-j)+1
        d=min(dist1,dist2,dist3) #最短距離は上式により求められる
        ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
    print(ans[i])



Measured memory_bytes: 3444
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e6+10;
int a[N],  pos[N], sum1[N<<2], sum2[N<<2], n,  ans;
// 1 奇数 , 2 偶数
typedef pair<int,int> pi;
struct node
{
    int first,second,l,r;
    bool operator <(const node &A)const
    {
        return A.first<first;
    }
};
vector<node>p;
void build(int l,int r,int rt)
{
    if(l==r)
    {
        scanf("%d", &a[l]);
        if(l&1)   sum1[rt]=a[l],sum2[rt]=0x3f3f3f3f;
        else sum1[rt]=0x3f3f3f3f,sum2[rt]=a[l];
        pos[a[l]]=l;
        return ;
    }
    int mid=(l+r)/2;
    build(l,mid,rt*2);
    build(mid+1,r,rt*2+1);
    sum1[rt]=min(sum1[rt<<1],sum1[rt<<1|1]);
    sum2[rt]=min(sum2[rt<<1],sum2[rt<<1|1]);
    return ;
}
int query1(int l,int r,int rt,int L,int R)
{
    if(L<=l&&R>=r)  return sum1[rt];
    int mid=(l+r)/2;
    int ans=0x3f3f3f3f;
    if(L<=mid) ans=min(ans,query1(l,mid,rt*2,L,R));
    if(R>mid) ans=min(ans,query1(mid+1,r,rt*2+1,L,R));
    return ans;
}
int query2(int l,int r,int rt,int L,int R)
{
    if(L<=l&&R>=r)  return sum2[rt];
    int mid=(l+r)/2;
    int ans=N+1;
    if(L<=mid) ans=min(ans,query2(l,mid,rt*2,L,R));
    if(R>mid) ans=min(ans,query2(mid+1,r,rt*2+1,L,R));
    return ans;
}
priority_queue<node>q;

int main()
{
    scanf("%d", &n);
    build(1,n,1);
    int x=query1(1,n,1,1,n);
    int y=query2(1,n,1,pos[x]+1,n);
    q.push((node){x,y,1,n});
    for(int i=1;i<=n/2;i++)
    {
        node tmp=q.top();q.pop();
        p.push_back(node{tmp.first,tmp.second,0,0});
        int al=pos[tmp.first], ar=pos[tmp.second];
        if(tmp.l<al-1)
        {
            if(tmp.l&1)
            {
                x=query1(1,n,1,tmp.l,al-1);
                y=query2(1,n,1,pos[x]+1,al-1);
            }
            else
            {
                x=query2(1,n,1,tmp.l,al-1);
                y=query1(1,n,1,pos[x]+1,al-1);
            }
            q.push(node{x,y,tmp.l,al-1});
        }
        if(al<ar-1)
        {
            if((al+1)&1)
            {
                x=query1(1,n,1,al+1,ar-1);
                y=query2(1,n,1,pos[x]+1,ar-1);
            }
            else
            {
                x=query2(1,n,1,al+1,ar-1);
                y=query1(1,n,1,pos[x]+1,ar-1);
            }
            q.push(node{x,y,al+1,ar-1});
        }
        if(ar<tmp.r-1)
        {
            if((ar+1)&1)
            {
                x=query1(1,n,1,ar+1,tmp.r);
                y=query2(1,n,1,pos[x]+1,tmp.r);
            }
            else
            {
                x=query2(1,n,1,ar+1,tmp.r);
                y=query1(1,n,1,pos[x]+1,tmp.r);
            }
            q.push(node{x,y,ar+1,tmp.r});
        }
    }
    for(int i=0; i<p.size(); i++)
    {
        if(i==p.size()-1)printf("%d %d\n",p[i].first,p[i].second);
        else printf("%d %d ",p[i].first,p[i].second);
    }
    return 0;
}










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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back
#define fir first
#define sec second

const int N = 2e5L + 11;
const db pi = 4 * atan(1);

int x[N], y[N];

int s[N];
bool vis[N];

int main() {
	
	ios :: sync_with_stdio(0);
	
	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	
	if(sx > tx) {
		swap(sx, tx);
		swap(sy, ty);
	}

	int n; cin >> n;
	vector <pair <int, int>> v;
	
	bool sp = 0;
	for(int i = 0; i < n; i ++) {
		cin >> x[i] >> y[i];
		if(sy > ty) y[i] = -y[i];
	}
	if(sy > ty) { sy = -sy; ty = -ty; }
	
	for(int i = 0; i < n; i ++)
		if(x[i] == sx && y[i] == ty || x[i] == tx && y[i] == sy) {
			sp = 1; vis[i] = 1;
		}
	
	for(int i = 0; i < n; i ++) {
		if(x[i] >= sx && x[i] <= tx && y[i] >= sy && y[i] <= ty)
			v.pb({x[i], y[i]});
	}
	
	sort(v.begin(), v.end());
	
	int cnt = 0;
	for(int i = 0; i < v.size(); i ++) {
		int l = 0, r = cnt + 1;
		while(l + 1 < r) {
			int m = (l + r) / 2;
			if(v[i].second > s[m])
				l = m;
			else
				r = m;
		}
		if(l == cnt) s[++ cnt] = v[i].second;
		else s[l + 1] = v[i].second;
	}
	
	db ans = 100.0 * (tx - sx) + 100.0 * (ty - sy) - cnt * (20 - 5 * pi);
	//if(sp) ans = min(ans, 100.0 * (tx - sx) + 100.0 * (ty - sy) - (20 - 5 * pi));
	
	if(cnt == tx - sx + 1 || cnt == ty - sy + 1)
		ans = 100.0 * (tx - sx) + 100.0 * (ty - sy) - (cnt - 1) * (20 - 5 * pi) + (10 * pi - 20);
	
	cout << fixed << setprecision(12);
	cout << ans << '\n';
	
	return 0;
}




Measured memory_bytes: 4336
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll x;
	cin>>x;
	for(int i=0; i<10001; i++){
		for(int j=0; j<10001; j++){
			ll t2=(i+j)*(i*i*i*i+i*i*i*j*(-1)+i*i*j*j+i*j*j*j*(-1)+j*j*j*j);
			ll z=(i-j)*(i*i*i*i+i*i*i*j+i*i*j*j+i*j*j*j+j*j*j*j);
			if(z==x)cout<<i<<" "<<j<<endl;
			else if(t2==x)cout<<i<<" -"<<j<<endl;
			else continue;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    int d[k];
    bool ng[10];
    fill(ng,ng+10,false);
    rep(i,0,k){
        cin>>d[i];
        ng[d[i]]=true;
    }
    rep(i,n,10000000){
        int u=i;
        int r=0;
        while(u!=0){
            int y=u%10;
            if(ng[y]){
                r=1;
                break;
            }
            u/=10;
        }
        if(r==0){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll _main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> tele(n);
    for(ll i=0;i<n;i++){
        cin >> tele[i];
    }
    ll loop_end1,loop_end2;
    vector<bool> loop1(n),loop2(n);
    for(ll i=0;i<n;i++){
        loop1[i]=0;
        loop2[i]=0;
    }
    ll now=1;
    ll cnt=0;
    while(!loop1[now-1]){
        cnt++;
        loop1[now-1]=true;
        now=tele[now-1];
        if(cnt==k)return now;
    }
    loop_end1=cnt;
    while(!loop2[now-1]){
        cnt++;
        loop2[now-1]=true;
        now=tele[now-1];
        if(cnt==k)return now;
    }
    loop_end2=cnt;

    ll jissitu=(k-loop_end1)%(loop_end2-loop_end1)+loop_end1;
    now=1;
    for(ll i=0;i<jissitu;i++){
        now=tele[now-1];
    }
    return now;
}
int main(){
    cout << _main();
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<string> S(n);
  vector<int> T(n);
  rep(i, n) cin >> S[i] >> T[i];
  string x; cin >> x;
  ll ans = 0;
  REP(i, find(all(S), x)-S.begin()+1, n) {
    ans += T[i];
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3628
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: usize,
    }


    let t = d + (d+1);
    if n %  t == 0 {
        println!("{}", n/t);
    } else {
        println!("{}", n/t+1);
    }


}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 0 && b >= 0){
        cout << "Zero" << endl;
        return 0;
    }else if(a > 0){
        cout << "Positive" << endl;
        return 0;
    }else{
        int x = min(0, b-1);
        if((x - a) % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(std::string s)
{
    int ans = INT_MAX;
    for (char i = 'a'; i <= 'z'; i++)
    {
        int cnt = 0;
        int tmp = -1;
        for (int j = 0; j < s.size(); j++)
        {
            if (s[j] != i)
            {
                cnt++;
            }else{
                tmp = max(tmp,cnt);
                cnt = 0;
            }
        }
        tmp = max(tmp,cnt);

        ans = min(ans,tmp);
    }
    cout << ans << endl;
}

int main()
{
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#define vi vector<int>
#define pub push_back
using namespace std;
const int SZ = (1 << 19) + 69;
int seg[SZ], n, val[200001] = {}, it, res[200001] = {};
map<int, int> compress;
vector<vector<int>> adj;
int qry(int idx, int L, int R, int l, int r)
{
	if (l <= r)
	{
		if (L == l && R == r) {return seg[idx];}
		else
		{
			int M = (L + R) >> 1;
			return max(qry(2 * idx, L, M, l, min(r, M)), qry(2 * idx + 1, M + 1, R, max(M + 1, l), r));
		}
	}
	return 0;
}
int upd(int idx, int L, int R, int x, int v, int over)
{
	if (L == x && R == x) 
	{
		int prv = seg[idx]; 
		if (over) 
		{
			seg[idx] = v; 
		}
		else
		{
			seg[idx] = max(seg[idx], v);
		}
		return prv;
	}
	else
	{
		int M = (L + R) >> 1, ret;
		if (x <= M)
		{
			ret = upd(2 * idx, L, M, x, v, over);
		}
		else
		{
			ret = upd(2 * idx + 1, M + 1, R, x, v, over);
		}
		seg[idx] = max(seg[2 * idx + 1], seg[2 * idx]);
		return ret;
	}
}
void dfs(int u, int p)
{
	int befupd = upd(1, 0, n, compress[val[u]], qry(1, 0, n, 0, compress[val[u]] - 1) + 1, 0);
	res[u] = qry(1, 0, n, 0, n);
	for (auto v : adj[u])
	{
		if (v ^ p) {dfs(v, u);}
	}
	upd(1, 0, n, compress[val[u]], befupd, 1);
}
int main()
{	
	cin >> n;
	for (int i = 0; i < n; i++) {adj.pub(vi()); cin >> val[i]; compress[val[i]] = 1;}
	for (int i = 0; i < n - 1; i++)
	{
		int u, v; cin >> u >> v;
		adj[u - 1].pub(v - 1);
		adj[v - 1].pub(u - 1);
	}
	compress[0] = 1; 
	it = 0;
	for (auto &x : compress) {x.second = it++;}
	dfs(0, -1);
	for (int i = 0; i < n; i++)
	{
		cout << res[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 42580
a,s=map(int,input().split())
sa,ss=[input() for i in range(2)]
if a<s:
    a,s=s,a
    sa,ss=ss,sa
from fractions import gcd
g=gcd(a,s)
x,y=a//g,s//g
for i in range(g):
    if sa[x*i]!=ss[y*i]:print(-1);break
else:print(x*s)

Measured memory_bytes: 5304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	ll n; cin >> n;
    string s; cin >> s;
	ll res = 0, i =0, j= n-1;
	while(i<j){
		char f = s[i], l = s[j];
		if(f=='R'){
			i++;
		} else if(l=='W'){
			j--;
		} else {
			res++;
			i++, j--;
		}
	}
	cout << res << endl;

}

Measured memory_bytes: 3736
"""
AtCoder Beginner Contest 064
A - RGB Cards
@author Ren Serizawa
"""

import sys
nums = [num for num in input().split(" ")]
num3digit = int(("").join(nums)) if ("").join(nums).isdigit() else -1
if num3digit < 0 or not len(nums) == 3:
    sys.stderr.write("Error: Invalid input\n")
    exit()
isMultipleOf4 = "YES" if num3digit % 4 == 0 else "NO"
print(isMultipleOf4)
exit()

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

int main(){
    int n;
    scanf("%d",&n);
    double x[n], y[n], p1, p2, pinf;
    p1 = 0;
    p2 = 0;
    double p3 = 0;
    pinf = 0;
    for (int i=0; i<n; i++) scanf("%lf",&x[i]);
    for (int i=0; i<n; i++) scanf("%lf",&y[i]);
    for (int i=0; i<n; i++){

        p1 += abs(x[i] - y[i]);
        p2 += (x[i]-y[i])*(x[i]-y[i]);
        p3 += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
        pinf = (pinf > abs(x[i]-y[i]))? pinf: abs(x[i]-y[i]);
    }

    printf("%.6lf\n", p1);
    printf("%6lf\n", sqrt(p2));
    printf("%6lf\n", cbrt(p3));
    printf("%6lf\n", pinf);

    return 0;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main(){
    int n,k;
    cin>>n>>k;
    vector<double> p(n);
    for(int i=0; i<n; i++) cin>>p[i];
    vector<double> kitai(n);
    for(int i=0; i<n; i++){
        kitai[i]=(p[i]+1.0)/2.0;
    }
    vector<double> sum(n+1,0),sumd(n+1,0);
    for(int i=0; i<n; i++){
        sum[i+1]=sum[i]+kitai[i];
        sumd[i+1]=sumd[i]+p[i];
    }
    double a=0;
    for(int i=0; i<n-k+1; i++){
        a=max(a,(double)(sum[i+k]-sum[i]));
    }
    cout<<fixed<<setprecision(10)<<a<<endl;
}


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

int main() {
	long long M, N; cin >> M >> N;
	long long num = 1;
	while (N > 0) {
		if (N & 1) num = num * M % 1000000007;
		M = M * M % 1000000007;
		N >>= 1;
	}
	cout << num << endl;
}



Measured memory_bytes: 3096
from collections import deque
s = input()
q = int(input())
S = [c for c in s]
deque = deque(S)
reversed = 0
for i in range(q):
    line = input()
    if line[0] == '1':
        reversed = reversed ^ 1
    else:
        op, f, c = line.split()
        f = int(f)
        if reversed == 0:
            if f == 1:
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == 1:
                deque.append(c)
            else:
                deque.appendleft(c)
if reversed:
    deque.reverse()
result = "".join(deque)
print(result)

Measured memory_bytes: 103444
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
  int n;
  cin >> n;
  cout << n/3 << endl;
  return 0;
}


Measured memory_bytes: 256