akhauriyash/Code-Regression huggingface dataset:
class NilClass
  def postorder
    nil
  end
end

class Node
  attr_accessor :id, :left_child, :right_child

  def initialize(id)
    @id = id
    @left_child = nil
    @right_child = nil
  end

  def postorder
    [@left_child.postorder, @right_child.postorder, @id].flatten.compact
  end

  def print_postorder
    puts postorder.join(" ")
  end
end

class TreeConstructor
  attr_accessor :root

  def initialize(preorder, inorder)
    if !preorder[0]
      return
    end

    @root = Node.new(preorder[0])

    inorder_right = inorder[(inorder.index(@root.id) + 1)..-1]
    inorder_left = inorder - [@root.id] - inorder_right
    preorder_right = preorder.reject { |item| [@root.id, *inorder_left].include? item }
    preorder_left = preorder - [@root.id] - preorder_right

    @root.left_child = TreeConstructor.new(preorder_left, inorder_left).root
    @root.right_child = TreeConstructor.new(preorder_right, inorder_right).root
  end
end

n = gets.to_i
preorder = gets.split(" ").map(&:to_i)
inorder = gets.split(" ").map(&:to_i)

tree_constructor = TreeConstructor.new(preorder, inorder)
root = tree_constructor.root
root.print_postorder


Measured memory_bytes: 7220
package main

import (
	"fmt"
)

func main() {
	var x1, x2, x3, x4 int
	var y1, y2, y3, y4 int
	fmt.Scan(&x1, &y1, &x2, &y2)

	x3 = x2 - (y2 - y1)
	y3 = y2 + (x2 - x1)
	x4 = x3 - (x2 - x1)
	y4 = y3 - (y2 - y1)

	fmt.Printf("%d %d %d %d", x3, y3, x4, y4)
	fmt.Println("")
}


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

using namespace std;

int solve(int N, int X, const vector<int>& xs)
{
    int D = 0, ans = 1;

    for (int i = 1; i <= N; ++i)
    {
        D += xs[i];

        if (D <= X)
            ++ans;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, X;
    cin >> N >> X;

    vector<int> xs(N + 1);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    auto ans = solve(N, X, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
 
  int d1[6],d2[6],i,j,blank;
 
  for(i = 0; i < 6; i++){
 
    scanf("%d",&d1[i]);
     
  }
   
  for(i = 0; i < 6; i++){
     
    scanf("%d",&d2[i]);
     
  }
 
  for(i = 0; d1[1] != d2[1] && i < 3; i++){
     
    //3S
    blank=d2[0];
    d2[0]=d2[4];
    d2[4]=d2[5];
    d2[5]=d2[1];
    d2[1]=blank;
     
  }
   
  if(d1[1] != d2[1]){
     
    //1E
    blank=d2[0];
    d2[0]=d2[3];
    d2[3]=d2[5];
    d2[5]=d2[2];
    d2[2]=blank;
 
    for(i = 0; d1[1] != d2[1] && i < 3; i++){
 
      //3S
      blank=d2[0];
      d2[0]=d2[4];
      d2[4]=d2[5];
      d2[5]=d2[1];
      d2[1]=blank;
 
    }
 
  }
 
  if(d1[1] != d2[1]){
 
    printf("No\n");
 
    return 0;
 
  }
   
  for(i = 0; d1[0] != d2[0]; i++){
     
    //3E
    blank=d2[0];
    d2[0]=d2[3];
    d2[3]=d2[5];
    d2[5]=d2[2];
    d2[2]=blank;
 
  }
 
  if(d1[0] != d2[0]){
     
    printf("No\n");
     
    return 0;
     
  }
 
  if(d1[2] == d2[2] && d1[3] == d2[3] && d1[4] == d2[4] && d1[5] == d2[5]){
 
    printf("Yes\n");
 
  } else {
 
    printf("No\n");
 
  }
 
  return 0;
 
}


Measured memory_bytes: 2104
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
#define Pr pair <int, int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int P = 998244353;
const int maxn = 1000006;
const int INF = 1000000000;
bool tag[maxn];
int read(){
	int c = 0, f = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || '9' < ch)) ch = getchar();
	if (ch == '-') f = -1, ch = getchar();
	while ('0' <= ch && ch <= '9') c = c * 10 + ch - '0', ch = getchar();
	return c * f;
}
int main(){
    string s;
    cin >> s;
    int n = s.length(), k, c = 0;
    cin >> k;
    for (int i = 1; i < n; ++ i)
        if (! tag[i - 1] && s[i] == s[i - 1])
            ++ c, tag[i] = true;
    if (! tag[n - 1] && s[n - 1] == s[0]){
        memset(tag, false, sizeof(tag));
        int c2 = tag[0] = 1;
        for (int i = 1; i < n; ++ i)
            if (! tag[i - 1] && s[i] == s[i - 1])
                ++ c2, tag[i] = true;
        if (! tag[n - 1])
            cout << c + 1LL * c2 * (k - 1) << endl;
        else
            cout << 1LL * (k + 1) / 2 * c + 1LL * (k / 2) * c2  << endl;
    }
    else
        cout << 1LL * c * k << endl;
}


Measured memory_bytes: 1280
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr auto mod = 1'000'000'007;

static array<int, 2'000'005> power26_table;
static array<int, 2'000'005> power25_table;
static array<int, 2'000'005> factorial_table;
static array<int, 2'000'005> inv_factr_table;

template <large M> static large power(large b, large e) {
    assert(e >= 0);
    if (e == 0)
        return 1;
    if (e == 1)
        return b % M;

    auto p = (e % 2 == 0 ? large{1} : b % M);
    return p * power<M>(b * b % M, e / 2) % M;
}

template <large M> static large factorial(large x) {
    assert(x >= 0);
    if (x <= 1)
        return 1;

    auto f = 1LL;
    while (x >= 2) {
        f *= x;
        f %= M;
        --x;
    }
    return f;
}

template <large M> static large inverse(large x) { return power<M>(x % mod, M - 2); }

template <large M> static large combination(large n, large k) {
    auto fn = factorial<M>(n);
    auto fk = factorial<M>(k);
    auto fnk = factorial<M>(n - k);

    //    n!
    // ---------
    // k! (n-k)!
    return fn * inverse<M>(fk * fnk % M) % M;
}

int main() {
    {
        auto x = 1LL;
        for (auto& elem : power26_table) {
            elem = x;
            x *= 26;
            x %= mod;
        }
        x = 1LL;
        for (auto& elem : power25_table) {
            elem = x;
            x *= 25;
            x %= mod;
        }
        x = 1LL;
        auto y = 1LL;
        for (auto& elem : factorial_table) {
            elem = x;
            x *= y;
            x %= mod;
            ++y;
            y %= mod;
        }
    }

    int k;
    string s;
    cin >> k >> s;

    const auto result_length = int(k + s.length()); // <= 2'000'000

    auto cases = 0LL;
    for (auto Sn_pos = int(large(s.length()) - 1); Sn_pos < result_length; ++Sn_pos) {
        const auto free_chars = Sn_pos - int(large(s.length()) - 1);
        assert(free_chars >= 0);
        const auto trailing = result_length - (Sn_pos + 1);
        assert(trailing >= 0);

        const auto fn = factorial_table[Sn_pos];
        const auto fk = factorial_table[s.length() - 1];
        const auto fnk = factorial_table[Sn_pos - (s.length() - 1)];
        const auto c = large(fn) * inverse<mod>(large(fk) * fnk % mod) % mod;
        const auto d = large(power25_table[free_chars]) * power26_table[trailing] % mod;
        cases += (c * d % mod);
        if (auto tmp = cases - mod; tmp >= 0)
            cases = tmp;
    }

    cout << cases << "\n";
    return 0;
}


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

#define LL long long

const int N = 200200;
const long long mod = 998244353;

using namespace std;

int n;
int a[N],b[N];
vector< int > v;

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin>>n;
    for( int i=1; i<=n; i++ ){
        cin>>a[i];
    }
    int ans = 0;
    for( int i=n; i >= 1; i-- ){
        int sum = 0;
        for( int j=i; j <= n; j+=i ){
            sum += b[j];
        }
        if( sum % 2 == a[i] )continue;
        b[i]++;
        v.push_back(i);
    }
    for( int i=1; i<=n; i++ ){
        int sum = 0;
        for( int j = i; j <= n; j+=i ){
            sum += b[j];
        }
        if( sum % 2 != a[i] ){
            cout<<-1;
            return 0;
        }
    }
    cout<<v.size()<<endl;
    for( auto x : v )cout<<x<<" ";
}


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

int main(){
  int t,w,l,d,s[10],r[10];
  string n[10];
  bool use[10],f = false;

  while(1){
    cin >> t;
    if(!t)break;
    if(f)cout << endl;
    f = true;

    for(int i=0;i<t;i++){
      cin >> n[i] >> w >> l >> d;
      s[i] = w*3 + d;
    }

    for(int i=0;i<t;i++)use[i] = false;
    
    for(int i=0;i<t;i++){
      int m = -1,pos = -1;
      for(int j=0;j<t;j++){
	if(!use[j]){
	  if(m<s[j]){
	    m = s[j];
	    pos = j;
	  }
	}
      }
      r[i] = pos;
      use[pos] = true;
    }

    for(int i=0;i<t;i++)cout << n[r[i]] << "," << s[r[i]] << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int x; cin >> x;
    cout << x*x*x << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
string s, t;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>s>>t;
    for(int i=0; i<=sz(s); i++)
    {
        string a=s.substr(0, i), b=s.substr(i, sz(s)-i);
        if(b+a==t)return cout<<"Yes\n", 0;
    }
    cout<<"No\n";
    return 0;
}


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

ui MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;
    vector<long double> p(n + 1);

    for (int i = 1; i <= n; i++)
    {
        cin >> p[i];
    }

    long double dp[n + 1][n + 1];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = 0.0;

    dp[1][0] = (1-p[1]);
    dp[1][1] = p[1];
    for (int i = 2; i <= n; i++)
    {
        dp[i][0] = (1 - p[i]) * dp[i - 1][0];
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
        }
    }

    // for (int i = 0; i <= n; i++)
    // {

    //     for (int j = 0; j <= n; j++)
    //     {
    //         cout << fixed << setprecision(5) << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    double ans = 0;
    for (int i = n; i >= (n + 1) / 2; i--)
        ans += dp[n][i];
    cout << fixed << setprecision(9) << ans;
    return 0;
}


Measured memory_bytes: 140928
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        k = n - (i + j)
        if (i * 10000) + (j * 5000) + (k * 1000) == y:
            print("{} {} {}".format(i, j, k))
            exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int mod = (1e+9) + 7;
void add(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}

int main() {
  string s;

  cin >> s;
  vector<vector<long long>> dp(s.size() + 1, vector<long long>(13, 0));
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 13; j++) {
      if (s[i] == '?') {
        for (int k = 0; k < 10; k++) {
          add(dp[i + 1][(j * 10 + k) % 13], dp[i][j]);
        }
      } else {
        int k = s.at(i) - '0';
        add(dp[i + 1][(j * 10 + k) % 13], dp[i][j]);
      }
    }
  }
  cout << dp[s.size()][5];

  return 0;
}


Measured memory_bytes: 13568
#include "bits/stdc++.h"
#define hhh printf("hhh\n")
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int vis[4];

int main() {
    vis[read()]=1,vis[read()]=1;
    for(int i=1; i<=3; ++i) if(!vis[i]) return printf("%d\n", i), 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: usize = read()[0];
    let v: Vec<Vec<Vec<usize>>> = (0..n)
        .map(|_| {
            let m: usize = read()[0];
            (0..m).map(|_| read()).collect()
        })
        .collect();

    let mut ans: usize = 0;
    for b in 0..1 << n {
        let res =
            (0..n).all(|j| (b >> j) & 1 == 0 || v[j].iter().all(|q| (b >> (q[0] - 1)) & 1 == q[1]));
        if res {
            let cnt = (0..n).filter(|&i| (b >> i) & 1 == 1).count();
            ans = std::cmp::max(ans, cnt);
        }
    }
    println!("{}", ans);
}


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

int main() {
  int n;
  int now=1;
  int ans=1000000;
  int pre=-1;
  int cnt=0;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  cnt=0;
    //cout << pre << " " <<now << " " << cnt <<endl;
  rep(i,n+1){
    pre=now;
    now=a.at(pre-1);
    cnt++;
    //cout << pre << " " <<now << " " << cnt<<endl;
    if(now==2){
      cout << cnt << "\n";
      break;
    }
    else if (pre==now){
      cout << -1 << "\n";
      break;
    }
    
    
  }
  if(cnt>=n){
    cout << -1 << "\n";
  }
  
  
}  

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define debug4(n, m, x, y) cout << "DEBUG4 " << n << ' ' << m << ' ' << x << ' ' << y << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) rrn < 0) n = 0
#define alive(n) cout << "Alive here: checkpoint " << n << endl
#pragma GCC optimize("Ofast")
using namespace std;
void yes() {
    cout << "Yes\n";
    return;
}
void no() {
    cout << "No\n";
    return;
}
int hamm_dist(string str, string tar) {
	int cnt = 0;
	for (int i = 0;i < str.length();i++) {
		if (str[i] != tar[i]) cnt++;
	}
	return cnt;
}
void solve(int case_no) {
    // implementation
    string str, tar;
    cin >> str >> tar;
    int strl = str.length(), tarl = tar.length();
    int best = INT_MAX;
    for (int i = 0;i <= strl - tarl;i++) {
    	best = min(best, hamm_dist(str.substr(i, tarl), tar));
	}
	cout << best << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(NULL));
    int t = 1;
//    cin >> t;
    for (int i = 1;i <= t;i++) solve(i);
}
/*

*/

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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    string c; cin >> c;
    int r = 0;
    rep(i,n) if (c[i] == 'R') r++;
    int WtoR = 0, RtoW = 0;
    rep(i,n) {
        if (i < r && c[i] == 'W') WtoR ++;
        if (i >= r && c[i] == 'R') RtoW ++;
    }
    int swap = min(WtoR,RtoW);
    int change = max(WtoR,RtoW)-swap;


  
    cout << swap+change << endl;

    return 0;
}


Measured memory_bytes: 3708
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(a: str, b: str):
    if a == 'H':
        ret = b
    elif b == 'H':
        ret = 'D'
    else:
        ret = 'H'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = next(tokens)  # type: str
    b = next(tokens)  # type: str
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>

int main()
{
    int n;
    scanf("%d", &n);

    int a[n + 1] = {0};
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    
    int idx = 1;
    int cnt = 1;
    for (int i = 0; i < n; i++) {
        if (a[idx] == 2) {
            printf("%d\n", cnt);
            break;
        } else {
            idx = a[idx];
            cnt++;
        }
    }
    if (cnt == n + 1) printf("%d\n", -1);
}


Measured memory_bytes: 512
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


ll GCD(ll a,ll b){

    if(a>b){

        return GCD(b,a);

    }

    else{

    ll r=b%a;

    while(r!=0){

        b=a;

        a=r;

        r=b%a;

    }

    return a;

    }

}

ll LCM(ll a,ll b){
    return b/GCD(a,b)*a;
}


int main(){
    
    ll N,t[110];cin>>N;
    rep(i,0,N)cin>>t[i];
    ll l=t[0];
    rep(i,1,N){
        l=LCM(l,t[i]);
    }
    cout<<l<<endl;
    
}






Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;

bool slove(int *A,int k, int m){
	if(m==0)
		return true;
	if(m<0||k==n)
		return false;
	return slove(A,k+1,m-A[k])||slove(A, k+1, m);
	
}

int main(){
	
//	int n;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++)
		cin>>A[i];
	
	int q;
	cin>>q;
	int M[q];
	for(int i=0;i<q;i++){
		cin>>M[i];
		if((slove(A, 0, M[i]))==true)
			cout<<"yes"<<endl;
		else
			cout<<"no"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    scanf("%d",&n);
    int a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b,b+n);
    int mid=b[(n/2-1)];
    int midn=b[(n/2)];
    for(int i=0;i<n;i++){
        if(a[i]<=mid){
            printf("%d\n",midn);
        }
        else
           printf("%d\n",mid);
    }

}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<pair<long long, long long>> vec(N);
  for (int i = 0; i < N; ++i) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(), vec.end(), [](const pair<long long, long long> &lhs, const pair<long long, long long> &rhs) {
    return lhs.first + lhs.second > rhs.first + rhs.second;
  });
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) ans += vec[i].first;
    else ans -= vec[i].second;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
using namespace std;

int T;
vector<int> card(9);

bool is_same_number(int a, int b, int c) {
    if (a == b && b == c) {
        return true;
    } else {
        return false;
    }
}


bool is_sequence(int a, int b, int c) {
    if (a+2 == b+1 && b+1 == c) {
        return true;
    } else {
        return false;
    }
}

bool is_good_set(int a, int b, int c) {
    return is_same_number(a, b, c) || is_sequence(a, b, c);
}

bool is_all_good_set(){
    if (is_good_set(card[0], card[1], card[2]) &&
        is_good_set(card[3], card[4], card[5]) &&
        is_good_set(card[6], card[7], card[8])){
        return true;
    } else {
        return false;
    }
}

int win(){
    sort(card.begin(), card.begin()+9);
    do {
        if (is_all_good_set()){
            return 1;
        }
    } while (next_permutation(card.begin(), card.end()));
    return 0;
}

int main() {
    cin >> T;
    for (int t=0; t<T; ++t) {
        for (int i=0; i<9; ++i) {
            cin >> card[i];
//            cout << card[i] << " ";
        }
//        cout << endl;
        string color;
        for (int i=0; i<9; ++i) {
            cin >> color;
//            cout << color << " ";
            if (color == "G") card[i] += 10;
            else if (color == "B") card[i] += 20;
        }
//        cout << endl;

/*
        for (int i=0; i<9; ++i) {
            cout << card[i] << "*" ;
        }
*/
//        cout << endl;
        cout << win() << endl;
    }
}



Measured memory_bytes: 3012
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	string s;
	cin >> s;
	bool ok = s[0] != s[1] && s[1] != s[2] && s[2] != s[3];
	dump(ok ? "Good" : "Bad");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define rep(i, n) for(int i=0 ; i<n; ++i)
#define rep2(i, j, n) for(int i=j; i<n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long ul;

int main(){
    long N, A;
    cin >> N >> A;
    vector<long> x(N);
    ll ***array=new ll**[51];
    rep(i, 51){
        array[i] = new ll*[51];
        rep(j, 51) array[i][j] = new ll[2510];
    }
    //int array[51][51][2510];
    rep(i, N) cin>>x[i];
    array[0][0][0]=1;
    rep(i, N) rep(j, N) rep(k, 2510) if(array[i][j][k]){
        array[i+1][j][k] += array[i][j][k];
        array[i+1][j+1][k+x[i]] += array[i][j][k]; 
    }
    ll ans = 0;
    rep2(i, 1, N+1) ans+=array[N][i][i*A];
    cout<<ans<<endl;
    for(int z = 0; z < 51; z++) {
        for (int x = 0; x < 51; x++) {
            delete[] array[z][x]; // 1
        }
        delete[] array[z]; // 2
    }
    delete[] array; // 3
}

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

string s1, s2;
int memo[1010][1010];

/*
 * i : s1の添字
 * j : s2の添字
 */
int calc(int i, int j) {

    //文字数が足りなくなったら残りは全て削除または全て挿入
    if (i == s1.length()) {
        return memo[i][j] = (int)s2.length() - j;
    }
    if (j == s2.length()) {
        return memo[i][j] = (int)s1.length() - i;
    }

    //計算済み
    if (memo[i][j] != -1) return memo[i][j];

    int res = 1e9;

    //操作なし
    if (s1[i] == s2[j]) res = min(res, calc(i+1, j+1));

    //削除
    res = min(res, calc(i, j+1) + 1);

    //挿入
    res = min(res, calc(i+1, j) + 1);

    //置換
    res = min(res, calc(i+1, j+1) + 1);

    return memo[i][j] = res;

}

int main()
{
    cin >> s1 >> s2;

    for (int i=0; i<1010; i++) {
        for (int j=0; j<1010; j++) {
            memo[i][j] = -1;
        }
    }

    cout << calc(0, 0) << endl;

    return 0;
}


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


int main() {
  int64_t N,M;
  cin>>N>>M;
  
  if(abs(N-M)>=2){
    cout<<0<<endl;
    return 0;
  }
  else{
    if(N==M){
      int64_t sum=1;
      for(int i=N;i>=1;i--){
        sum=(sum*i)%1000000007;
      }
      for(int i=M;i>=1;i--){
        sum=(sum*i)%1000000007;
      }
      sum=(sum*2)%1000000007;
      cout<<sum<<endl;
    }
    else{
      int64_t sum=1;
      for(int i=N;i>=1;i--){
        sum=(sum*i)%1000000007;
      }
      for(int i=M;i>=1;i--){
        sum=(sum*i)%1000000007;
      }
      cout<<sum<<endl;
    }
  }
      
  
}

Measured memory_bytes: 3672
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int[] w = new int[n];

    for (int i = 0; i < n; i++) {
      w[i] = sc.nextInt();
    }

    int min = Integer.MAX_VALUE;
    for (int t = 0; t < n - 1; t++) {
      int s1 = 0;
      int s2 = 0;
      for (int l = 0; l <= t; l++) {
        s1 += w[l];
      }
      for (int r = t + 1; r < n; r++) {
        s2 += w[r];
      }
      min = Math.min(min, Math.abs(s2 - s1));
    }
    os.println(min);
  }
}

Measured memory_bytes: 23764
s = list(input())
l = int(input())
s1 = sorted(s)
ans = set()

for i in range(len(s)):
    sta = s1[i]
    for j in range(len(s)):
        if s[j] == sta:
            ans.add(s[j])
            check = s[j]
            for k in range(j+1,min(len(s),j+5)):
                check = check+s[k]
                ans.add(check)
    if len(ans) >= l:
        ans1 = sorted(ans)
        print(ans1[l-1])
        exit()
ans1 = sorted(ans)
print(ans1[l-1])

Measured memory_bytes: 3188
import Data.Array.Unboxed
import Data.List

type Arr = UArray (Int, Int) Int

main = do
  c <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  let ans1 = solve c
      ans2 = solve $ transpose c
  if ans1 && ans2
    then putStrLn "Yes"
    else putStrLn "No"

solve :: [[Int]] -> Bool
solve (x:y:[]) = solve' x y
solve (x:y:ys) = if solve' x y
                   then solve (y:ys)
                   else False

solve' :: [Int] -> [Int] -> Bool
solve' x y = (== 1) . length . group $ zipWith (-) x y


Measured memory_bytes: 508
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

int main()
{ 
    int n;
    cin>>n;
    string s;
    cin>>s;
    int flg=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A'){
            flg=1;
        }
        else if(s[i]=='B'){
            if(flg==1){flg=2;}
            else{flg=0;}
        }
        else if(s[i]=='C'){
            if(flg==2){cnt++;}
            flg=0;
        }
        else{flg=0;}
    }

    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int h, w, d; cin >> h >> w >> d;
    map<int, pair<int,int>> mp;
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            int a; cin >> a;
            mp[a] = make_pair(i, j);
        }
    }

    vector<int> cum(100000, 0);
    for(int i=1; i<=d; ++i) cum[i] = 0;
    for(int i=d+1; i<=h*w; ++i) cum[i] = cum[i-d] + abs(mp[i].first-mp[i-d].first) + abs(mp[i].second - mp[i-d].second);

    int q; cin >> q;
    vector<int> ans(q);
    for(int i=0; i<q; ++i){
        int l, r; cin >> l >> r;
        if(l<=d) ans[i] = cum[r];
        else ans[i] = cum[r] - cum[l];
    }

    for(auto e:ans) cout << e << '\n';

	return 0;
}


Measured memory_bytes: 7552
#include<stdio.h>

#define MAX 100000

int n,k;
long long  T[MAX];

int check(long p){
	
	int i=0;
	for(int j=0;j<k;j++){
		long long s=0;
		while((s+T[i])<=p){
			s+=T[i];
			i++;
			if(i==n)return n;
		}
	}
	return i;
}

int solve(){
	long long left=0,right=100000*10000,mid;
	while(right-left>1){
		//printf("%lld ",right);
		//printf("%lld\n",left);
		mid =(right+left)/2;
		int v=check(mid);
		if(v>=n)right=mid;
		else left = mid;
	}
	return right;
}

int main(void){
	
	scanf("%lld",&n);
	scanf("%lld",&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&T[i]);
	}
	
	long long ans=solve();
	printf("%lld\n",ans);
	
	return 0;
	
}


Measured memory_bytes: 2580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int a, b;
  cin >> a >> b;
  if (((a * b) % 2) == 0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_142
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[][] vals = new int[n][];
            for(int i = 0; i < n; i++)
            {
                vals[i]=new int[2]{ array[i],i};
            }
            Array.Sort(vals, (a, b) => a[0] - b[0]);
            for(int i = 0; i < n; i++)
            {
                Write(vals[i][1] + 1);
                if (i < n - 1) Write(" ");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 28504
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

int main()
{
	int S, W;
	cin >> S >> W;
	if(W >= S){
		cout << "unsafe" << endl;
	}
	else{
		cout << "safe" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


bool comp(const string &s, const string &t)
{
    return s + t < t + s;
}

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

    string s;
    vector<string> v;
    for(int i=0; i < n; i++) {
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end(), comp);

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

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>
using namespace std;
int main()
{
    int N;
    int ans = 0;
    cin >> N;
    vector<int> D(N);
    
    for (int i = 0; i < N; i++){
        cin >> D[i];
    }
    for (int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            ans += D[i] * D[j];
        }
    }
    cout << ans<< endl;;
    return 0;    
}


Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {    
    int y, m, d;
    char c1, c2;

    cin >> y >> c1 >> m >> c2 >> d;

    if (m <= 4) {
        print("Heisei");
    } else {
        print("TBD");
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


lli r,l,n;
int main(void){
	scanf("%lld",&n);
	l=0;r=1000005;
	while(l+1<r){
		lli m=(l+r)/2;
		if(m*(m+1)>=n*2)r=m;
		else l=m;
	}
	lli d = (r*(r+1))/2-n;
	//printf("%lld %lld\n",d,r);
	reg(i,1,r){
		if(d==i)continue;
		printf("%d\n",i);
	}
	
	return 0;
}






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

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

using namespace std;

typedef long long ll;

bool isEightDivisors(int p,int q,int m,int n){
  if( p ==  1 && q ==  0 ) return true;
  if( p ==  0 && q ==  1 ) return true;
  if( p == -1 && q ==  0 ) return true;
  if( p ==  0 && q == -1 ) return true;
  if( p ==  m && q ==  n ) return true;
  if( p == -n && q ==  m ) return true;
  if( p == -m && q == -n ) return true;
  if( p ==  n && q == -m ) return true;
  return false;
}

#define EPS (1e-8)

bool isSqrt(ll x){
  ll tmp = sqrt(x) + EPS;
  return tmp * tmp == x;
}

bool isPrime(int p,int q){
  int p2 = p * p, q2 = q * q;
  for(int a=1;a*a<=p2+q2;a++) {
    if( ( p2 + q2 ) % a ) continue;
    int b = ( p2 + q2 ) / a;

    int base_a = sqrt(a);
    int base_b = sqrt(b);

    for(int m=-base_a;m<=base_a;m++) {
      if( base_a * base_a > a ) continue;
      int n2 = a - m * m;

      if( !isSqrt(n2) ) continue;

      int n = sqrt(n2);

      if( ( m*m + n*n ) == 0 ) continue;

      if( !( ( m*p + n*q ) % ( m*m+n*n ) == 0 &&
             ( m*q - n*p ) % ( m*m+n*n ) == 0 ) ) continue;

      for(int x=-base_b;x<=base_b;x++){
        if( base_b * base_b > b ) continue;
        int y2 = b - x * x;
        if( !isSqrt(y2) ) continue;
        int y = sqrt(y2);
        
        if( !isEightDivisors(m,n,p,q) && !isEightDivisors(n,m,p,q) ) {
          return false;
        }

        if( !isEightDivisors(x,y,p,q) && !isEightDivisors(y,x,p,q) ) {
          return false;
        }
        
      }
    }
  }
  return true;
}

int main(){
  int T;
  cin >> T;
  rep(_,T){
    int n,m;
    cin >> n >> m;
    puts(isPrime(n,m)?"P":"C");
  }
  return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n,W;cin>>n>>W;
    ll w[n+1],v[n+1];rep(i,1,n)cin>>w[i]>>v[i];
    ll dp[n+1][W+1];
    dp[0][0]=0;
    rep(i,1,W){
        dp[0][i]=-inf;
    }
    rep(i,1,n){
        rep(j,0,W){
            if(j-w[i]<0){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,W){
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }*/
    ll ans=0;
    rep(i,0,W){
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;

const long long mod = 1e18;
const long long INF=1e9;
ll ci;

//dx[5] = {-1, 0, 1, 0, 0};
//dy[5] = {0, 1, 0, -1, 0};
//1行目を辞書順で繰り返す
//for(int i=0; i<1<<n; ++i){}
//2進数を入力
//for(int j=0; j<n; ++j) g[0][i] = (i>>j)&1==1;

/*unique文字の確認
    set<int> all;
    all.insert(a[i]);
    map<int, int> count;
    count[a[i++]]++;
    if(count[a[j++]]++==0) num++; 
*/
//typedef pair<int, int> P;

//配列
//vector<long long> v(max_n);
//vector<int> v[max_n];
//vector<vector<int>> v(max_n);
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; 降順;
//priority_queue<pair<int, int>, vector<pair<int, int>>, less<>> q; 昇順;

//tips
//最大値の最小化は２分探索
//printf("IMPOSSIBLE"\n);
//printf("%d%c", opt[i][j], j+1==N? \n : '');

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n) cin >> a[i+1];
    vector<ll> dp(n+1);
    dp[0] = 1000;
    for(int k=1; k<=n; ++k){
        dp[k] = 0;
        for(int i=0; i<k-1; ++i){
            int m = 99999;
            for(int j=i+1; j<k; j++){
                m = min(m, a[j]);
            }
            dp[k] = max(dp[k], dp[i]/m*a[k]+dp[i]%m);
        }
    }
    ll ans = 0;
    rep(i, n+1) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

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

int main() 
{
    int a, b, k;
    cin >> a >> b >> k;
    int ans = 0;
    int cnt = 0;
    for (int i=min(a,b); i >= 1; i--) {
        if (a%i == 0 && b%i == 0) {
            ans = i;
            cnt++;
        }
        if (cnt == k) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
   /* ll t;
    cin>>t;
    while(t--)			
    {
        
    }*/
    ll n;
    cin>>n;
    ll x=n%10;
    if(x==2||x==4||x==5|x==7||x==9)
    cout<<"hon";
    else if(x==3)
    cout<<"bon";
    else
    cout<<"pon";
}


Measured memory_bytes: 3608
r,c = map(int,input().split())

a = [list(map(int,input().split(" "))) for i in range(r)]

for i in range(r):
    r_total = sum(a[i])
    a[i].append(r_total)

c_total = []

for j in range(c+1):
    s = 0
    for k in range(r):
        s += a[k][j]
    c_total.append(s)

a.append(c_total)

for z in range(r+1):
    for w in range(c+1):
        print(a[z][w],end="")
        if w != c:
            print(" ",end="")
    print()

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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

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

    int min=101;
    for(char c='a';c<='z';c++){
        string t=s+c;
        int max=0,cnt=0;
        for(int i=t.size()-2;i>=0;i--){
            if(t[i]==c){
                if(cnt>max) max=cnt;
                cnt=0;
            }else cnt++;
        }
        if(cnt>max) max=cnt;
        if(max<min) min=max;
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>

#define fprintf(...) void(0)

template <intmax_t X=943681729, intmax_t MOD=1000000007>
class RollingHash {
  std::vector<intmax_t> hash;
  intmax_t offset(size_t len) const {
    intmax_t res=1;
    for (intmax_t dbl=X%MOD; len; len>>=1) {
      if (len & 1) res = res*dbl % MOD;
      dbl = dbl*dbl % MOD;
    }
    return res;
  }

public:
  RollingHash(const std::string &s): hash(s.length()+1) {
    for (size_t i=0; i<s.length(); ++i)
      hash[i+1] = (hash[i]*X+s[i]) % MOD;
  }

  intmax_t operator ()(size_t i, size_t j) const {
    // s[i..j-1]
    assert(i < j);
    intmax_t res=hash[j];
    res = (res - offset(j-i)*hash[i]) % MOD;
    if (res < 0) res += MOD;
    return res;
  }
};

using RHash=RollingHash<>;

int main() {
  char buf[1234567];
  scanf("%s", buf);
  std::string s=std::move(buf);
  RHash rh(s);

  uintmax_t aa=s.length(), bb=s.length();
  for (size_t i=1; i<s.length(); ++i) {
    size_t al=i;
    fprintf(stderr, "al: %zu\n", al);
    if (al*3 >= s.length())
      continue;
    if ((s.length()-al*3) % 2 > 0) continue;
    size_t bl=(s.length()-al*3)/2;
    fprintf(stderr, "bl: %zu\n", bl);
    assert(al+bl+al+bl+al == s.length());

    intmax_t ah1=rh(0, al);
    intmax_t bh1=rh(al, al+bl);
    intmax_t ah2=rh(al+bl, al+bl+al);
    intmax_t bh2=rh(al+bl+al, al+bl+al+bl);
    intmax_t ah3=rh(al+bl+al+bl, al+bl+al+bl+al);

    fprintf(stderr, "%zu/%zu, %jd %jd %jd %jd %jd\n",
            al, bl, ah1, bh1, ah2, bh2, ah3);

    if (!(ah1 == ah2 && ah2 == ah3 && bh1 == bh2)) continue;

    if (aa+bb > al+bl) {
      assert(al && bl);
      aa = al;
      bb = bl;
    }
  }

  if (aa == s.length()) {
    assert(bb == s.length());
    printf("mitomerarenaiWA\n");
  } else {
    assert(aa < s.length() && bb < s.length());
    printf("Love %s%s!\n", s.substr(0, aa).c_str(), s.substr(aa, bb).c_str());
  }
}



Measured memory_bytes: 12700
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;


public class Main {

    public static void main(String[] args) {
    
    	FastScanner scan = new FastScanner();
    	
    	int n = scan.nextInt(), k = scan.nextInt();
    	int [] arr = new int [n];

    	for(int i=0; i<k; i++) {
    		int d = scan.nextInt();
    		for(int j=0; j<d; j++) {
    			int x = scan.nextInt();
    			x--;
    			arr[x] ++;
    		}
    	}
    	int count = 0;
    	for(int i=0; i<arr.length; i++) {
    		if(arr[i] == 0) count++;
    	}
    		System.out.println(count);
    }

   
    static class FastScanner{
    	
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}
    	
    	int nextInt() {
    		return Integer.parseInt(next());
    	}
    	
    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}
    	
    	long nextLong() {
    		return Long.parseLong(next());
    	}
    	
    	
    }
    
   
}



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

int main(void)
{
  std::string num;
  std::cin >> num;

  std::string tmp;
  int ans = 0;

  for (int i = 0; i < (1 << 3); i++) {
    tmp = num[0];
    ans += num[0] - '0';

    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) {
        tmp += '+';
        tmp += num[j+1];
        ans += num[j+1] - '0';
      }
      else {
        tmp += '-';
        tmp += num[j+1];
        ans -= num[j+1] - '0';
      }
    }
    if (ans == 7) {
      break;
    }
    ans = 0;
  }
  std::cout << tmp << "=7" << std::endl;
  return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>

int judge(int num){
int i;
if(num == 2) return 1;
if(num % 2 == 0 || num == 1) return 0;
for(i=3; i * i <= num; i = i+2){
if(num % i == 0) return 0;
}
return 1;
}

int main(void){
  int a, i,n,count=0;
  scanf("%d",&n);
  for (i=0; i<n; i++){
    scanf("%d",&a);
    if(judge(a) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}

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

int main(){
    int X;
    cin >> X;
    int i = 1;
    while(1){
        if((360 * i) % X == 0) {
            break;
        }
        i += 1;
    }
    cout << (360 * i) / X << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> x(n);
    for(int i=0;i<n;++i) cin >> x[i];

    ll ans = LINF;
    for(int i=1;i<=100;++i) {
        ll tmpans = 0LL;
        for(int j=0;j<n;++j) {
            tmpans += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, tmpans);
    }
    cout << ans << endl;
}


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

dp = [-1]*N
dp[0] = 1000
dp[1] = 1000
#dp[i] = max(dp[i-2],dp[i-1], (dp[i-2]//A[i-2])*A[i]+dp[i-2]%A[i-2])
for i in range(1,N):
  dp[i] = max(dp[i-1], (dp[i-1]//A[i-1])*A[i]+dp[i-1]%A[i-1])
print(dp[N-1])


Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
 
void solve()
{
    int k; cin >> k;

    while (k--) cout << "ACL";
} 
 
signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--) solve();
  return 0;
}

Measured memory_bytes: 3612