akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b;
  cin >> a >> b;
  if(b % a == 0) {
    cout << a + b << endl;
  }else {
    cout << b - a << endl;
  }
}


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

int main(){
  int h,w;
  cin >> h >> w;
  char c[h+10][w+10];
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
    }
  }
  int count[h+10][w+10] = {};
  rep(i,h){
    rep(j,w){
      if(c[i][j] == '.'){
        if(c[i-1][j-1] == '#') count[i][j] += 1;
        if(c[i-1][j] == '#') count[i][j] += 1;
        if(c[i-1][j+1] == '#') count[i][j] += 1;
        if(c[i][j-1] == '#') count[i][j] += 1;
        if(c[i][j+1] == '#') count[i][j] += 1;
        if(c[i+1][j-1] == '#') count[i][j] += 1;
        if(c[i+1][j] == '#') count[i][j] += 1;
        if(c[i+1][j+1] == '#') count[i][j] += 1;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(c[i][j] == '.'){
        cout << count[i][j];
      }
      else cout << c[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            string s = ReadString(), t = ReadString();

            int ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == t[i])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

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

using namespace std;

#define ll long long

const int N = 1e6+3,M=55;

const ll oo=1e18;

int n,m,ans,tc,a[N],b[N],k;

#define f first

#define s second

const int dx[]={0,0,1,-1},
          dy[]={1,-1,0,0};

char s[N];

ll dp[105][105][105];

ll solve(int l,int r,int rem){
    if (rem<0)
        return -1e9;
    if (l>r)
        return 0;
    ll &ret = dp[l][r][rem];
    if (ret!=-oo)
        return ret;
    ret=0;
    ret=max(ret,max(a[l]+solve(l+1,r,rem-1),solve(l+1,r,rem-2)));
    return ret=max(ret,max(a[r]+solve(l,r-1,rem-1),solve(l,r-1,rem-2)));
}

int main(){
    for(int i=0;i<105;i++)
        for(int j=0;j<105;j++)
            for(int k=0;k<105;k++)
                dp[i][j][k]=-oo;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    printf("%lld",solve(0,n-1,k));
}




Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define VI vector<int>  
#define PII pair<int,int>
#define MII map<int,int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define usual int t; cin>>t; while(t--)
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int a; cin>>a;
    cout<<a + (a*a) + (a*a*a);

    return 0;
    
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   long long k,a,b;
   cin>>k>>a>>b;
   long long ans=1;
   long long yen=0;
   for(int i=1;i<k;i++){
      if(yen>=1){
         yen--;
         ans+=b;
         continue;
      }
      if(ans<a){
         ans++;
         continue;
      }
      else {
         if(b>a+2){
            ans-=a;
            yen++;
            continue;
         }
         else {
            ans++;
            continue;
         }
      }

   }
   if(yen>=1){
      yen--;
      ans+=b;
   }
   else ans++;
   cout<<ans<<endl;

   
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> v;
    v.push_back("ABC");
    v.push_back("DEF");
    v.push_back("GHI");
    for (int c = 0; c < 1000; c++) {
        string str;
        cin >> str;
        int x = 10000, y = 10000;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (v[i][j] == str[0]) x = i, y = j;

        bool flag = true;
        for (int k = 1; k < str.size(); k++) {
            int x_ = 10000, y_ = 10000;
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    if (v[i][j] == str[k]) x_ = i, y_ = j;

            if (abs(x_ - x) == 0 && abs(y_ - y) == 1);
            else if (abs(x_ - x) == 1 && abs(y_ - y) == 0);
            else flag = false;

            x = x_;
            y = y_;
        }

        if (flag) cout << str << endl;
    }

    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>

int main(void)
{
   int a[3], tmp;
   int i, flag;

   scanf("%d %d %d", &a[0], &a[1], &a[2]);

   do
   {     
       flag = 0;
       for(i = 0;i < 2;i++)
       {
           if(a[i] > a[i+1])
           {
               tmp = a[i];
               a[i] = a[i+1];
               a[i+1] = tmp;
               flag = 1;
            }
         }
      }while(flag == 1);

      printf("%d %d %d\n", a[0], a[1], a[2]);

    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<string.h>
int main(void)
{
	int	i,flg,n;
	char s[11],t[12];
	scanf("%s %s",s,t);
	n=strlen(s);
	flg=0;
	for (i=0;i<n;i++){
		if(s[i]!=t[i]){
			flg=1;
		}
	}
	if (flg==1){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}
		

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

int main(){
    stack<int> S1;
    stack<pair<int, int>> S2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++){
        if(ch == '\\'){
            S1.push(i);
        }
        else if(ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    
    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 3140
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while((line = br.readLine()) != null) {
                String[] list = line.split(" ", 0);
                int x = Integer.parseInt(list[0]);
                int y = Integer.parseInt(list[1]);
                if(x < y){
                    int r = x;
                    x = y;
                    y = r;
                }
                long check = getCubicOf(x,y);
                System.out.println(check);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private static long getCubicOf(int x, int y) {
    		while(y != 0) {
    			int r = x % y;
    			x = y;
    			y = r;
    		}
    		return x;
    }
}

Measured memory_bytes: 23972
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

struct Process {
    string name;
    int time;

    Process() : name(""), time(0) {}
};

class Queue {
   public:
    vector<Process*> q;
    int capacity;
    int begin;
    int end;
    int size;

    Queue(int cap) : q(cap, NULL), capacity(cap), begin(0), end(0), size(0) {}

    void enqueue(Process* p) {
        if (size + 1 <= capacity) {
            q[end] = p;
            ++end;
            end = end % capacity;
            ++size;
        }
    }

    Process* dequeue() {
        if (!empty()) {
            Process* p = q[begin];
            ++begin;
            begin = begin % capacity;
            --size;
            return p;
        } else {
            return NULL;
        }
    }

    bool empty() {
        if (size <= 0)
            return true;
        else
            return false;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<Process*> ps(N);
    Queue q(N);
    for (int i = 0; i < N; ++i) {
        Process* p = new Process;
        cin >> p->name >> p->time;
        q.enqueue(p);
        ps[i] = p;
    }

    int current = 0;
    while (!q.empty()) {
        Process* p = q.dequeue();
        if (p->time <= Q) {
            current += p->time;
            cout << p->name << ' ' << current << '\n';
        } else {
            p->time -= Q;
            current += Q;
            q.enqueue(p);
        }
    }

    for (int i = 0; i < N; ++i)
        delete ps[i];
}




Measured memory_bytes: 7492
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=6000;
vi P[MAX];
int c[MAX];
/*
void add(int x){
	for (int i=MAX-1;i>=0;i--)
		if (dp[i] && i+x<=MAX-1)dp[i+x]=true;
}
*/
int dfs(int u){
	bitset<MAX>dp;
	dp[0]=1;
	int sum=0;
	for (auto it:P[u]){
		int ile=dfs(it);
		sum+=ile+c[it];
		dp=(dp<<c[it])|(dp<<ile);
		//add(ile);
		//add(c[it]);
	}
	int largest=c[u];
	while (largest && !dp[largest])largest--;
	if(!dp[largest])cout<<"IMPOSSIBLE",exit(0);
	return sum-largest;
}
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  for (int i=2;i<=n;i++){
  	int a;
  	cin>>a;
  	P[a].pb(i);
  }
  for (int i=1;i<=n;i++)cin>>c[i];
  dfs(1);
  cout<<"POSSIBLE";
  return 0;
}


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

int main() {
	int n, a = 0, b = 0;
	std::cin >> n;
	
	for (int i = 0; i < n; i++) {
		std::string s, t;
		std::cin >> s >> t;
		
		if (s == t) {
			a++;
			b++;
		} else if (s > t) {
			a += 3;
		} else {
			b += 3;
		}
	}
	
	std::cout << a << ' ' << b << '\n';
	
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  ll n, k; cin >> n >> k;
  map<ll,ll> mp;
  ll a, b;
  rep(i,n){
    cin >> a >> b;
    mp[a] += b;
  }
  ll total = 0;
  for(auto x : mp){
    if(total < k and k <= total + x.snd){
      cout << x.fst << endl;
      return 0;
    }
    total += x.snd;
  }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vii;
typedef long long ll;
 
#define  modu 1000000007


int main() {
    
    {
        int n,a,b,k;
        cin>>a>>b>>k;
        int ah=a+k-1,bl=b-k+1;
        if(ah<bl)
        {
               for(int i=a;i<=a+k-1;i++)
        cout<<i<<endl;
        for(int i=b-k+1;i<=b;i++)
        cout<<i<<endl;  
        }
        else
        {
            for(int i=a;i<=b;i++)
            cout<<i<<endl;  
        
        }
     
    }
    return 0;
}

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

int n, m, x, y;
vector<int> G[N];
int dp[N];

int dfs(int u)
{
	int& ans = dp[u];
	if (ans > 0) return ans;
	for (int j = 0; j < G[u].size(); j++)
		ans = max(ans, dfs(G[u][j]) + 1);
	return ans;
}

int main() {
	//freopen("demo.in", "r", stdin);
	//freopen("demo.out", "w", stdout);
	
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, dfs(i));
	
	printf("%d\n", ans);
	

	return 0;
}


Measured memory_bytes: 8192
def resolve():
    D, N = map(int, input().split())
    if D == 0:
        if N == 100:
            print("101")
        else:
            print(N)
    elif D == 1:
        if N == 100:
            print("10100")
        else:
            print(100*N)
    else:
        if N == 100:
            print("1010000")
        else:
            print(10000*N)
resolve()

Measured memory_bytes: 9172
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def main():
    A,B,C,D = map(int,input().split())
    #Cで割り切れる数の探索
    tmpC = (A-1)//C
    tmpC2 = (B)//C
    numC = tmpC2 - tmpC
    #Dで割り切れる数の探索
    tmpD = (A-1)//D
    tmpD2 = (B)//D
    numD = tmpD2 - tmpD
    #CでもDで割り切れるもの
    if C == D:
        ans = B-A+1-numC
    else:
        tmpCD = (A-1)//lcm(C,D)
        tmpCD2 = (B)//lcm(C,D)
        numCD = tmpCD2 - tmpCD
        ans = B-A+1-numC-numD+numCD
    return ans
print(main())


Measured memory_bytes: 9104
// Shift-JIS（シフトジス）

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

int gcd(long long a, long long b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    long long L, R;
    cin >> L >> R;
    
    vector<int> N;
    long long temp;
    for (long long i = L; i <= R; i++)
    {
        if (i == L)
        {
            temp = L % 2019;
            N.push_back(i % 2019);
        }
        else if (i % 2019 == temp)
        {
            break;
        }
        else
        {
            N.push_back(i % 2019);
        }
    }

    int minRem = 2019;
    for (int i = 0; i < N.size() - 1; i++)
    {
        for (int j = i + 1; j < N.size(); j++)
        {
            if (minRem > (N[i] * N[j]) % 2019)
            {
                minRem = (N[i] * N[j]) % 2019;
            }
        }
    }

    cout << minRem << endl;

    return 0;
}

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


long long a[1000005];
long long f[1000005] ;
long long N , K , x ;
bool check( long long m ){
	long long c = 0 ;
	for( int i = 1 ; i <= N ; i++ ){
		c += max(0LL,( a[i] - m/f[N-i+1])) ;
		if(c>K) return false ;
	}
	return true ;
}

int main(){
	
	cin >> N >> K ;

	for( int i = 0 ; i < N ; i++ ){
		cin >> a[i+1] ;
	}
	for( int i = 0 ; i < N ; i++ ){
		cin >> f[i+1] ;
	}
	sort(a+1,a+N+1);
	sort(f+1,f+N+1);
	long long l = 0 , r = a[N]*f[N] , m ;
	while(l <= r){
		m = (l+r)/2 ;
		if(check(m)) r=m-1 ;
		else l = m+1 ;
	}
	if( check(l) )
		cout << l << endl ;
	else if( K == 0 ){
		long long ans = 0 ;
		for( int i = 1 ; i <= N ; i++ ){
			ans = max((a[i]*f[N-i+1]),ans);
		}
		cout << ans << endl ;
	}
	// long long cur = a[N] , c = 1 , i = N , C = 0 ;
	// while( K > 0 && i > 0  ){
	// 	// cout << K << " " << cur << " " << c << " " << i << endl ;
	// 	if( c * ( cur-a[i-1]) <= K  ){
	// 		K = K - c * ( cur-a[i-1]) ;
	// 		cur = a[i-1]; 
	// 		c++ ;
	// 		i--;
	// 		// cout << K << endl ;
	// 	}
	// 	else{
	// 		cur = cur - K/c ;
	// 		C = K % c ;
	// 		K = 0 ;
	// 	}
	// }
	// // cout << K << " " << cur << " " << c << endl ;
	// for( int i = 0 ; i < c ; i++ ){
	// 	a[N-i] = cur ;
	// }
	// if( C != 0 ){
	// 	for( int i = 0 ; i < C ; i++ ){
	// 		a[N-i]-- ;
	// 	}
	// }
	// sort(a+1,a+N+1);
	// long long ans = 0 ;
	// for( int i = 1 ; i <= N ; i++ ){
	// 	ans = max((a[i]*f[N-i+1]),ans);
	// }
	// cout << ans << endl ;

	


	return 0 ;
}

Measured memory_bytes: 5888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] a = fs.readArray(n);
        int cnt = 0;
        for(int i = 1; i <= n; i++){
            if(i%2 != 0 && a[i-1]%2 != 0) cnt++;
        }
        System.out.println(cnt);
    }

    static void sort(int[] a){
        ArrayList<Integer>l = new ArrayList<>();
        for(int i: a)
            l.add(i);
        Collections.sort(l);
        for(int i = 0; i < a.length; i++)
            a[i] = l.get(i);
    }

    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: 25392
#include<bits/stdc++.h>
using namespace std;

int main() {
	int N;

	cin >> N;

	if (N / 1000 == N % 1000 / 100 && N % 1000 / 100 == N % 1000 % 100 / 10)cout << "Yes";
	else if (N % 1000 / 100 == N % 1000 % 100 / 10 && N % 1000 % 100 / 10 == N % 1000 % 100 % 10)cout << "Yes";
	else cout << "No";
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
 
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  a+=b;c+=d;
  if(a>c) cout<<"Left"<<endl;
  else if(a<c) cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int N, K, R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    char a[N];
    ll ans = 0;
    rep(i, N){
        if (i < K) {
            if (T[i] == 'r') {
                ans += P;
                a[i] = 'p';
            } else if (T[i] == 's') {
                ans += R;
                a[i] = 'r';
            } else {
                ans += S;
                a[i] = 's';
            }
        } else {
            if (T[i] == 'r' && a[i-K] != 'p') {
                ans += P;
                a[i] = 'p';
            } else if (T[i] == 'r' && a[i-K] == 'p') {
                a[i] = 'e';
            } else if (T[i] == 's' && a[i-K] != 'r') {
                ans += R;
                a[i] = 'r';
            } else if (T[i] == 's' && a[i-K] == 'r') {
                a[i] = 'e';
            } else if (T[i] == 'p' && a[i-K] != 's') {
                ans += S;
                a[i] = 's';
            } else {
                a[i] = 'e';
            }
        }
//        cout << a[i] << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int X;
  cin >> X;
  int ma = 0;
  int co = 0;
  rep(i, 35) {
    if(X >= (i+1)*(i+1)) {
      co = (i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  rep(i, 10) {
    if(X >= (i+1)*(i+1)*(i+1)) {
      co = (i+1)*(i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  rep(i, 6) {
    if(X >= (i+1)*(i+1)*(i+1)*(i+1)) {
      co = (i+1)*(i+1)*(i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  rep(i, 4) {
    if(X >= (i+1)*(i+1)*(i+1)*(i+1)*(i+1)) {
      co = (i+1)*(i+1)*(i+1)*(i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  rep(i, 4) {
    if(X >= (i+1)*(i+1)*(i+1)*(i+1)*(i+1)) {
      co = (i+1)*(i+1)*(i+1)*(i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  rep(i, 4) {
    if(X >= (i+1)*(i+1)*(i+1)*(i+1)*(i+1)*(i+1)) {
      co = (i+1)*(i+1)*(i+1)*(i+1)*(i+1)*(i+1);
      ma = max(ma, co);
    }
  }
  cout << ma << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B=0,C=0,D=0,F=0;
  cin >> A;
  B=sqrt(A);
  Out(B*B);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct edge{
	ll to,cost,t;
};

struct state{
	ll d,city,ag;
};

bool operator>(const state& a,const state& b){
    return a.d>b.d;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m,s;
	cin>>n>>m>>s;
	vector<vector<edge>> g(n);
	rep(i,m){
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		u--,v--;
		g[u].push_back({v,a,b});
		g[v].push_back({u,a,b});
	}
	vector<ll> c(n),d(n);
	rep(i,n){
		cin>>c[i]>>d[i];
	}
	ll ma=1000;
	chmin(s,ll(ma));
	vector<vector<ll>> dist(n,vector<ll>(10001,inf));//j==maは銀貨無限枚
	priority_queue<state,vector<state>,greater<state>> que;
	dist[0][s]=0;
	que.push({0,0,s});
	while(!que.empty()){
		auto now=que.top();
		que.pop();
		ll v=now.city,ag=now.ag;
	//	if(dist[v][ag]<now.d) continue;
		for(auto to:g[v]){
			ll nag=ag;
			ll nt=to.t;
			if(nag==ma){
				if(chmin(dist[to.to][nag],dist[v][ag]+nt)){
					que.push({dist[to.to][nag],to.to,nag});
				}
				continue;
			}
			if(nag>=to.cost){
				if(chmin(dist[to.to][nag-to.cost],dist[v][ag]+nt)){
					que.push({dist[to.to][nag-to.cost],to.to,nag-to.cost});
				}
			}
			while(nag<ma){
				nag+=c[v];
				chmin(nag,ll(ma));
				nt+=d[v];
				if(nag>=to.cost){
					if(chmin(dist[to.to][nag-to.cost],dist[v][ag]+nt)){
						que.push({dist[to.to][nag-to.cost],to.to,nag-to.cost});
					}
				}
			}
		}
	}
	FOR(i,1,n){
		ll ans=inf;
		rep(j,ma+1) chmin(ans,dist[i][j]);
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 28136
def f(n):
    x = n // 2

    if n % 2 == 0:
        if x % 2 == 0:
            return 0 ^ n
        else:
            return 1 ^ n

    else:
        x += 1
        if x % 2 == 0:
            return 0
        else:
            return 1


A, B = map(int, input().split())

print(f(A-1) ^ f(B))


Measured memory_bytes: 2940
//divisor.cpp
#include<iostream>
using namespace std;

int main()
{
    int i,a,b,c,count;
    cin>>a>>b>>c;
    count=0;
    for ( i = a; i <= b; i++)
    {
        if (c%i==0)
        {
            count+=1;
        }
    }
    cout<<count<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
int pre[N], suf[N], arr[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
    // freopen("", "r", stdin);
    // freopen("", "w", stdout);
#endif
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){

		cin >> arr[i];
		pre[i] = arr[i];
		if(i)
			pre[i] = __gcd(pre[i], pre[i - 1]);
	}
	for(int i = n - 1; i >= 0; i--){
		suf[i] = arr[i];
		if(i != n - 1)
			suf[i] = __gcd(suf[i], suf[i + 1]);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(i == 0){
			ans = max(ans, suf[i + 1]);
		}
		else if(i == n - 1){
			ans = max(ans, pre[i - 1]);
		}
		else
			ans = max(ans, __gcd(pre[i - 1], suf[i + 1]));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4744
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Feb 24 20:05:30 2018
//
package main

import (
	"fmt"
)

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

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

	arr := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&arr[i])
	}

	Sn1 := 0
	Sn2 := 0
	count1 := 0
	count2 := 0
	for i := 0; i < N; i++ {
		if i%2 == 0 {
			if Sn1+arr[i] < 1 {
				count1 += abs(1 - arr[i] - Sn1)
				Sn1 = 1
			} else {
				Sn1 += arr[i]
			}

			if Sn2+arr[i] > -1 {
				count2 += abs(-1 - Sn2 - arr[i])
				Sn2 = -1
			} else {
				Sn2 += arr[i]
			}
		} else {
			if Sn1+arr[i] > -1 {
				count1 += abs(-1 - Sn1 - arr[i])
				Sn1 = -1
			} else {
				Sn1 += arr[i]
			}

			if Sn2+arr[i] < 1 {
				count2 += abs(1 - arr[i] - Sn2)
				Sn2 = 1
			} else {
				Sn2 += arr[i]
			}
		}
	}

	if count1 < count2 {
		fmt.Println(count1)
	} else {
		fmt.Println(count2)
	}
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    vector<vector<int>> cnt(H, vector<int>(W, INF));
    vector<vector<int>> flag(H, vector<int>(W, 0));
    REP(h, H)
    REP(w, W) {
        cin >> s[h][w];
    }
    priority_queue<pair<int, pair<int, int>>> q;
    q.push({0, {0, 0}});
    if (s[0][0] == '#') {
        cnt[0][0] = 1;
    } else {
        cnt[0][0] = 0;
    }
    while (!q.empty()) {
        auto now = q.top();
        int dist = now.first;
        dump(dist);
        auto pos = now.second;
        q.pop();
        REP(i, 2) {
            int h = pos.first + dx[i];
            int w = pos.second + dy[i];
            if (h >= H || w >= W) {
                continue;
            }
            if (s[h][w] == '#') {
                if (s[pos.first][pos.second] == '#') {
                    cnt[h][w] = min(cnt[h][w], cnt[pos.first][pos.second]);
                } else {
                    cnt[h][w] = min(cnt[h][w], cnt[pos.first][pos.second] + 1);
                }
            } else {
                cnt[h][w] = min(cnt[h][w], cnt[pos.first][pos.second]);
            }
            if (flag[h][w]) {
                continue;
            }
            flag[h][w] = 1;
            q.push({dist - 1, {h, w}});
        }
    }
    cout << cnt[H - 1][W - 1] << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n;
    cin >> n;
    int cnt=0;
    for(int i=1; i<=n; i++){
        int keta=log10(i)+1;
        if(keta%2==1) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3924
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	string s;
	getline(cin,s);
	while(n--){
		getline(cin,s);
		if(s.size()>6)rep(i,s.size()-6)if(s.substr(i,7)=="Hoshino")s[i+6]='a';
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    char b;cin>>b;
    if(b=='A'){
        cout<<'T';
    }
    else if(b=='T'){
        cout<<'A';
    }
    else if(b=='C'){
        cout<<'G';
    }
    else if(b=='G'){
        cout<<'C';
    }
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
using namespace std;
int main(){for(int T;scanf("%d",&T),T;puts("")){
	map<pair<int,int>,int>m;
	char C[2];
	int n,k;
	for(;T--&&scanf("%s%d",C,&n);){
		if(*C=='D'){
			for(auto it=m.begin();it!=m.end();)if(it->second==n)m.erase(it++);else ++it;
		}else if(*C=='R'){
			auto it=m.lower_bound(make_pair(n,2000000000));
			printf("%d\n",it==m.begin()||n<(--it)->first.first||it->first.second<n?-1:it->second);
		}else if(*C=='W'){
			int c=!scanf("%d",&k),d;
			for(auto it=m.begin();k&&it!=m.end();++it){
				d=it->first.first-c;
				if(d>k)d=k;
				if(d)m.insert({{c,c+d-1},n});
				k-=d;
				c=it->first.second+1;
			}
			if(k)m.insert({{c,c+k-1},n});
		}
	}
}}

Measured memory_bytes: 1236
#include <cstdio>
#include <functional>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;

int main() {
    int n; scanf("%d", &n);
    vector<vector<pair<int, int> > > g(n);
    repeat (i, n - 1) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c); -- a; -- b;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    int q, k; scanf("%d%d", &q, &k); -- k;
    vector<ll> dist(n, -1);
    function<void (int)> go = [&](int i) {
        for (auto e : g[i]) {
            int j, cost; tie(j, cost) = e;
            if (dist[j] != -1) continue;
            dist[j] = dist[i] + cost;
            go(j);
        }
    };
    dist[k] = 0;
    go(k);
    while (q --) {
        int x, y; scanf("%d%d", &x, &y); -- x; -- y;
        printf("%lld\n", dist[x] + dist[y]);
    }
    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
    using namespace std;
     
    #define       pb(a)             push_back((a))
    #define       mp(a,b)           make_pair((a),(b))
    #define       REP(a,b)          for(ll i=(a);i<(b);i++)
    #define       REP2(a,b)         for(ll j=(a);j<(b);j++)
    #define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
    #define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
    #define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
    #define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
    #define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
    #define       all(v)            (v).begin(),(v).end()
    #define       Trvs(c)           for (auto &it :c)
    #define       INF               INT_MAX
    #define       sz(x)             x.size()
    #define       flash             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define       F                 first
    #define       S                 second
    #define       MOD               1000000007

    using         ll     = long long;
    using         vll    = vector<ll>;
    using         vvll   = vector<vll>;
    using         pll    = pair<ll, ll>;
    using         vpll   = vector<pll>;
    using         vvpll  = vector<vpll>;
     


void solve(){
	string a; cin >> a;
	REP(0,sz(a))cout<<"x";
}
	

     
    	
int main(){
    	flash
    
    	
    	// ll t;cin>>t;while(t--)
    	solve();
    	return 0;
    } 	

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
#define NG {cout<<0<<endl;return 0;}
int main(){
    LL N,A,B;
    cin>>N>>A>>B;
    if(B<A)NG;
    if(N==1&&A!=B)NG;
    cout<<(B-A)*(N-2)+1<<endl;
    return 0;
}


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

int n, m, a, b, ans;
vector<int> v[10];

int dfs(int cnt, int nw, bitset<10> used){
	int res = 0;
	if(!cnt) return 1;
	used[nw] = true;
	for(int i : v[nw]){
		if(!used[i]) res += dfs(cnt-1, i, used);
	}
	used[nw] = false;
	return res;
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	bitset<10> used(0);
	ans = dfs(n-1, 1, used);
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n)
        cin >> a[i];
    bool ok = true;
    REP(i, n)
        if(a[i]%2==0&&a[i]%3>0&&a[i]%5>0) ok =false;
    cout << (ok ? "APPROVED" : "DENIED") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;
 
#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
 
lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}
 
int N, K;
int a[100000];
 
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP(i, N) cin >> a[i];
 
   int ans = 1 + (N-K)/(K-1) + (((N-K)%(K-1))!=0);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  
  ll n;
  cin >>n;
  if(n%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i=1;pow(5,i)<=n;i++){
    ans += n/(long long)(pow((double)5,i)*2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
s=input()
n=len(s)
ans=0
for i in range(n):
    if s[i]=="0" and i%2==0:
        ans+=1
    elif s[i]=="1" and i%2==1:
        ans+=1
ans1=0
for i in range(n):
    if s[i]=="1" and i%2==0:
        ans1+=1
    elif s[i]=="0" and i%2==1:
        ans1+=1

print(min(ans,ans1))

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	int answer = n;
	for(int c = 'a'; c <= 'z'; ++c){
		string t = s;
		int steps = 0;
		while(count(t.begin(), t.end(), c) != t.size()){
			string w(t.size() - 1, 'a');
			for(int i = 0; i + 1 < t.size(); ++i){
				if(t[i] == c || t[i + 1] == c){
					w[i] = c;
				}else{
					w[i] = t[i];
				}
			}
			t = move(w);
			++steps;
		}
		answer = min(answer, steps);
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        boolean[] isPrimes = new boolean[1000000];
        for (int x = 2; x < 1000000 / 2 + 1; x++) {
            if (!isPrimes[x]) {
                for (int y = 2; y < 999999 / x + 1; y++) {
                    isPrimes[x * y] = true;
                }
            }
        }

        int count = 0;
        int[] nPrimes = new int[1000000];
        for (int i = 2; i < 1000000; i++) {
            if (!isPrimes[i]) {
                count++;
            }
            nPrimes[i] = count;
        }

        while (sc.hasNext()) {
            int n = sc.nextInt();
            System.out.println(nPrimes[n]);
        }
    }
}

Measured memory_bytes: 32040
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

a = INT()
ans = a + a**2 + a**3
print(ans)


Measured memory_bytes: 9380
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
S = raw_input()
if N % 2 != 0:
    print "No"
elif S[:N / 2] == S[N / 2:]:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 4268
#include<stdio.h>
	int main(void){
		int i,j,k,n,x,count=0;
		while(1){
			scanf("%d %d",&n,&x);
			if(n==0 && x==0) break;
			for(i=1;i<=n;i++){
				for(j=i+1;j<=n;j++){
					for(k=j+1;k<=n;k++){
						if(i+j+k==x){
							if(i==j || i==k ||j==k){ 
								count=count;
							}else if(i<j && j<k){ 
								count++;
								//printf("%d %d %d \n",i,j,k);
							}
						}
					}
				}
			}
			printf("%d\n",count);
			count=0;
		}
		return 0;
	}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> v;
  map<int, pair<int, int>> m;
  map<int, int> u;
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    v.push_back(make_pair(y, p));
  }
  auto vorg = v;
  sort(v.begin(), v.end());
  for (auto i : v) {
    auto [y, p] = i;
    m[y] = make_pair(p, ++u[p]);
  }

  for (auto i : vorg) {
    auto [y, p] = i;
    cout << setfill('0') << right << setw(6) << m[y].first;
    cout << setfill('0') << right << setw(6) << m[y].second << endl;
  }
}


Measured memory_bytes: 15604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public int findNumPaths(char[][] grid, int m, int n) {
        int mod = 1000000007;
        int[][] dp =new int[m][n];
        dp[0][0]=1;
        for(int i=1;i<n;++i) {
            if(grid[0][i]!='#') {
                dp[0][i] = dp[0][i - 1];
            }
        }

        for(int j=1;j<m;++j) {
            if(grid[j][0]!='#') {
                dp[j][0] = dp[j - 1][0];
            }
        }

        for(int i=1;i<m;++i) {
            for(int j=1;j<n;++j) {
                if(grid[i][j]!='#') {
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
                }
            }
        }
        return dp[m-1][n-1];
    }
    public static void main(String[] args) {
        Main h = new Main();
        InputStreamReader r=new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(r);
        try {
            String[] line1 = reader.readLine().split(" ");
            int m = Integer.parseInt(line1[0]),n = Integer.parseInt(line1[1]);
            char[][] grid = new char[m][n];
            for(int i=0;i<m;++i) {
                grid[i]=reader.readLine().toCharArray();
            }
            System.out.println(h.findNumPaths(grid,m,n));
        } catch (IOException e) {

        }
    }
}


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

int main(){
    ll n, k;
    cin >> n >> k;
    while(n / k) {
        ll a = n / k;
        n -= a*k;
    }
    n = min(n, abs(n-k));
    cout << n << endl;
    return 0;
}

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

int main(){
	long n, m, l;
	cin >> n >> m >> l;
	vector< vector<long> > A(n);
	for (long i = 0; i < n; i++){
		A[i].resize(m);
	}
	for (long i = 0; i < n; i++){
		for (long j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	vector< vector<long> > B(m);
	for (long i = 0; i < m; i++){
		B[i].resize(l);
	}
	for (long i = 0; i < m; i++){
		for (long j = 0; j < l; j++){
			cin >> B[i][j];
		}
	}
	vector< vector<long> > C(n);
	for (long i = 0; i < n; i++){
		C[i].resize(l);
	}
	for (long i = 0; i < n; i++){
		for (long j = 0; j < l; j++){
			C[i][j] = 0;
			for (long k = 0; k < m; k++){
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}
	for (long i = 0; i < n; i++){
		for (long j = 0; j < l; j++){
			if (j < l - 1) cout << C[i][j] << " ";
			else cout << C[i][j] << endl;
		}
	}
	return 0;
}

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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

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

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	lint a = in(), b = in(), x = in();
	a += x;
	b += x;
	a = (a - 1) / x * x;
	b = b / x * x;

	cout << (b - a) / x << endl;
}



Measured memory_bytes: 256