akhauriyash/Code-Regression huggingface dataset:
A, B = map(int, input().split())
if A%2==0:
  if B%2==0:
    if (B-A)%4==0:
      print(0^B)
    else:
      print(1^B)
  else:
    if (B-A+1)%4==0:
      print(0)
    else:
      print(1)
else:
  if B%2==0:
    if (B-A-1)%4==0:
      print(A^0^B)
    else:
      print(A^1^B)
  else:
    if (B-A)%4==0:
      print(A^0)
    else:
      print(A^1)

Measured memory_bytes: 3064
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    string va;
    set<string> seti;
    rep(i,n){
    	cin>>va;
    	seti.insert(va);
    }
    if(seti.size()==3){
    	cout<<"Three"<<endl;
    }
    else{
    	//cout<<seti.size()<<endl;
    	cout<<"Four"<<endl;
    }
    return 0;
    return 0;  
    
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char str[21]; // ¶ñ
char result[21]; // ½]µ½Êðüêé
int n; // ¶ñÌ·³ 
int i;
int main(void){
  scanf("%s",str); //¶ñðL[{[h©çÇÝÞ
  n=strlen(str); //¶ñÌ·³ðnÉüêé

  for(i=0;i<n;i++){
    result[i]=str[n-i-1]; // ¶ñð½]·é
  }

  printf("%s\n",result); // ½]µ½Êð\¦

  return 0;
}

Measured memory_bytes: 0
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

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


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

    if(s[s.size()-1] == 's'){
        s.push_back('e');
        s.push_back('s');
    }else{
        s.push_back('s');
    }

    cout << s << endl;
}




Measured memory_bytes: 3620
N = int(input())
str2N = bin(abs(N))[2:]
S = ''
inc = 0
for i, s in enumerate(str2N[::-1]):
  S += str((int(s) + inc) % 2)
  if N > 0:
    if i % 2 == 0:
      inc = (int(s) + inc) // 2
    else:
      inc = 1 if (int(s) + inc) else 0
  else:
    if i % 2 == 0:
      inc = 1 if (int(s) + inc) else 0
    else:
      inc = (int(s) + inc) // 2
S += str(inc)
if abs(N) > 0:
  S = S[::-1][S[::-1].find('1'):]
  if N > 0:
    if len(S) % 2 == 0:
      S = '1' + S
  else:
    if len(S) % 2 != 0:
      S = '1' + S
  print(S)
else:
  print('0')

Measured memory_bytes: 3316
#include<cstdio>
#include<vector>
#include<cstring>

using namespace std;

int m,n;
vector<int> g[21];
vector<int> rg[21];
bool used[21];
vector<int> vs;
int cmp[21];

void dfs(int v){
	used[v]=true;
	for(int i=0;i<g[v].size();i++){
		if(!used[g[v][i]])dfs(g[v][i]);
	}
	vs.push_back(v);
}

void scc(){
	memset(used,0,sizeof(used));
	vs.clear();
	for(int v=1;v<=m;v++){
		if(!used[v])dfs(v);
	}
}

int main(void){
	scanf("%d",&m);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
	}
	scc();
	for(int i=vs.size()-1;i>=0;i--)printf("%d\n",vs[i]);
	return 0;
}

Measured memory_bytes: 1052
h,w = map(int, input().split())
original = [list(input()) for _ in range(h)]
for i in range(h-1):
  for j in range(w-1):
    if original[i][j]=='#' and original[i-1][j]!='#' and original[i+1][j]!='#' and original[i][j-1]!='#' and original[i][j+1]!='#':
      print('No')
      exit()
      
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int r, g, b;
	cin >> r >> g >> b;
	int num = r * 100 + g * 10 + b;
	if (num % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
while true
  n = gets.to_i
  break if n==0

  s = 2*n
  x = 2  
  ptn = 0
  while x<=n
    if s%x == 0
      y = s/x
      k2 = x+y-1
      l2 = y-x+1
      ptn += 1 if k2>0 && l2>0 && k2%2==0 && l2%2==0
    end
    x += 1
  end

  puts ptn
end

Measured memory_bytes: 8632
#include<bits/stdc++.h>
using namespace std;
int n, c, dp[1001][1001];
size_t a, b;
string s, t;
int main() {
	cin >> s >> t;
	a = s.length(), b = t.length();
	for (int i = 1; i <= a; ++i) dp[i][0] = i;
	for (int i = 1; i <= b; ++i) dp[0][i] = i;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			if (s[i]==t[j]) c = 0; else c = 1;
			dp[i+1][j+1] = min(dp[i][j+1]+1, min(dp[i+1][j]+1, dp[i][j]+c));
		}
	}
	cout << dp[a][b] << "\n";
}

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

INF = 10**10
L_min = [INF] * N
for i in range(N):
  L_min[i] = min(L_min[i-1], A[i])
#print(L_min)

P_max = -1
for i in range(N):
  P_max = max(P_max, A[i] - L_min[i])
#print(P_max)

answer = 0
for i in range(N):
  if P_max == A[i] - L_min[i]:
    answer += 1
print(answer)

Measured memory_bytes: 62704
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] cnt = new int[200010];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            cnt[a[i]]++;
        }

        long prepSum = 0;
        for (int i = 0; i < cnt.length; i++) {
            int tmp = cnt[i];
            long prep = 0;
            for (int j = 1; j < tmp; j++) {
                prep += tmp - j;
            }
            prepSum += prep;
        }

        for (int i = 0; i < n; i++) {
            if (cnt[a[i]] > 1)
                pw.println(prepSum - cnt[a[i]] + 1);
            else
                pw.println(prepSum);
        }

        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 50944
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n, d, x, sum=0;
    cin>>n>>d>>x;

    while(n--){
        ll a;
        cin>>a;

        if((d)%a == 0){
            sum = sum + (d)/a;
        }

        else if((d)%a != 0){
            sum = sum + (d)/a + 1;
        }

    }
    cout<<sum+x;



}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
#include <algorithm>
#include <cstring>
using namespace std;

#define INF INT_MAX/2
int N;
int t[16][17];

int dp[16][1<<16];

int solve(int v, int s) {
    if (dp[v][s] >= 0) {
        return dp[v][s];
    }
    int minv = t[v][0];
    for (int i = 0; i < N; i++) {
        if ((s >> i) & 1) {
            minv = min(minv, t[v][i+1]);
        }
    }
    if (s == 0) return dp[v][s] = minv;
    int mins = INF;
    for (int i = 0; i < N; i++) {
        if ((s >> i) & 1) {
            mins = min(mins, solve(i, s - (1 << i)));
        }
    }
    if (s == (1<<N)-1) minv=0;
    return dp[v][s] = minv+mins;
}


int main() {
    while (cin >> N) {
        if (N == 0) break;
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N+1; j++) {
                cin >> t[i][j];
            }
        }
        int minx = INF;
        for (int i = 0; i < N; i++) {
            minx = min(minx, solve(i, (1<<N)-1));
        }
        cout << minx << endl;
    }
    return 0;
}

Measured memory_bytes: 4964
N = int(input())
A = [0]
A += list(map(int,input().split()))
A.append(0)
s = 0
for i in range(N+1): s += abs(A[i]-A[i+1])
for i in range(1,N+1): print(s + abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))

Measured memory_bytes: 13920
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int a,b;
ll C[2011][2011],Cs[2011][2011],Css[2011][2011];
ll f(int a,int b){return b==0?1:Css[b-1][a];}
ll f2(int a,int b)
{
//	cerr<<"f2:"<<a<<" "<<b<<endl;
	ll ret=0;
	for(int i=0;i<=min(a,b);i++)
	{
//		cerr<<C[b][i]<<":"<<f(a-i,i)<<endl;
		ret+=C[b][i]*f(a-i,i)%mod;
	}
//	cerr<<"ret="<<ret<<endl;
	return ret;
}
int main()
{
	for(int i=0;i<=2005;i++)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
		Cs[i][0]=1;
		for(int j=1;j<=2005;j++)Cs[i][j]=(C[i][j]+Cs[i][j-1])%mod;
		Css[i][0]=1;
		for(int j=1;j<=2005;j++)Css[i][j]=(Cs[i][j]+Css[i][j-1])%mod;
		
	}
	cin>>a>>b;
	ll ans=0;
	for(int i=0;i<=a;i++)
	{
		ans+=f2(a-i,b-1);
	}
	cout<<ans%mod;
	return 0;
}


Measured memory_bytes: 95104
import java.util.Scanner;

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

		int n = sc.nextInt();
		int x = sc.nextInt();
		
		int donutWeights[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			donutWeights[i] = sc.nextInt();
		}
		
		int essentialWeight = 0;
		
		for (int i = 0; i < n; i++) {
			essentialWeight += donutWeights[i];
		}
		
		int min = donutWeights[0];
		
		for (int i = 0; i < n; i++) {
			if (min > donutWeights[i]){
				min = donutWeights[i];
			} 
		}
		
		int minDonatPieces = (x - essentialWeight) / min;
		
		System.out.println(n + minDonatPieces);
	}
}

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

typedef long long int ll;
 
int main()
{
  string s;
  cin >> s;
  
  string t="";
  for(ll i=0;i<s.length()/2;i++)
    	t += s[i];
  
  string t1 = t;
  reverse(t1.begin(),t1.end());
  
  if(t!=t1)
  {
    cout << "No" << endl;
    return 0;
  }
  
  string t2="";
  for(ll i=s.length()/2 + 1;i<s.length();i++)
    t2 += s[i];
  
  string t3=t2;
  
  reverse(t3.begin(),t3.end());
  string s1 = s;
  reverse(s1.begin(),s1.end());
  if(s1==s && t3==t2)
    cout << "Yes" << endl;
  else	
    cout << "No" << endl;
  
  
  
  	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	ll N;
	cin >> N;
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 != 0 && i % 5 != 0)ans += i;
	}
	puts(ans);
	return 0;
}

Measured memory_bytes: 3652
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w,k = na()
s = []
for i in range(h):
    o = list(map(int, list(ns())))
    q = 0
    r = []
    for x in o:
        q += x
        r.append(q)
    s.append(r)

ans = 1000000000000000000

for i in range(2**(h-1)):
    b = [0]*w
    c = []
    d = 0 #分割数
    for j in range(h):
        b = [x + y for (x, y) in zip(b, s[j])]
        if j == h:
            break
        if ((i >> j) & 1):
            c.append(b)
            b = [0]*w
            d += 1
    c.append(b)
    e = -1
    for p in range(w):
        flag = False
        for l in c:
            u = 0 if e == -1 else l[e]
            if l[p]-u > k:
                if p-e == 1:
                    flag = True
                    break
                e = p-1
                d += 1
                break
        if flag:
            d = 1000000000000000000
            break
    ans = min(ans, d)

print(ans)

Measured memory_bytes: 46428
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
#define FF first
#define SS second

int main(){
	FASTIO;
	ll n; cin >> n;
	ll sum = 7 % n;
	ll len = 1;
	if (n % 2 == 0)
		return cout << -1 << endl, 0;
	while (sum % n && len < 10000000) {
		sum = (sum * 10) % n;
		sum += 7;
		sum %= n;
		len++;
	}
	if (len >= 10000000)
		return cout << -1 << endl, 0;
	cout << len << endl;
	return 0;
}

Measured memory_bytes: 3696
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int ca = 0;
    int cb = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'a') {
            if (ca + cb < a + b) {
                cout << "Yes" << endl;
                ++ca;
            } else {
                cout << "No" << endl;
            }
        } else if (s[i] == 'b') {
            if (ca + cb < a + b && cb < b) {
                cout << "Yes" << endl;
                ++cb;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 848
N =int(input())
A = [int(input()) for i in range(N)]
mx1=max(A)
mx1p = A.index(max(A))
Awomax=A
Awomax[mx1p]=0
mx2=max(Awomax)
ans = [mx1]*N
ans[mx1p] = mx2
for i in range(N):
    print(ans[i])

Measured memory_bytes: 14140
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>


#include <map>

using namespace std;

typedef long long LL;

int n, tt = 1919, c, t, cc = 1919;



int main() {
    cin >> n >> tt;
    
    for (; n; --n) {
        cin >> c >> t;
        if (t <= tt && c < cc) cc = c;
    }

    if (cc == 1919) cout << "TLE";
    else cout << cc << endl;
    

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
void mmin(int &a, int b) {
	a = min(a, b);
}
void mmax(int &a, int b) {
	a = max(a, b);
}
void sor(vel &v) {
	sort(v.begin(), v.end());
}
int nibl(vel &v, int tan) {
	int up = v.size() - 1;
	int lo = 0;
	if (v[up] <= tan) return up;
	while (up - lo > 1) {
		int mi = (up + lo) / 2;
		if (v[mi] <= tan) lo = mi;
		if (tan < v[mi]) up = mi;
	}
	return lo;
}
int vmax(vel &v) {
	int ans = v[0];
	for (int i = 1; i < v.size(); i++) mmax(ans, v[i]);
	return ans;
}
int vmin(vel &v) {
	int ans = v[0];
	for (int i = 1; i < v.size(); i++) mmin(ans, v[i]);
	return ans;
}
signed main() {
	int n;
	cin >> n;
	vel t(n);
	for (int i = 0; i + 1 < n; i++) {
		cin >> t[i];
	}
	t[n - 1] = 0;
	n = n / 2;
	vel stk(1,0);
	vel stm(1,0);
	vel ostk;
	vel ostm;
	for (int su = 1; su < 2 * n; su++) {
		ostk = stk;
		ostm = stm;
		vel x(su+1,0);
		stk = x;
		stm = x;
		for (int ka = 0; ka <=su; ka++) {
			int lo = su - ka;
			int ti = t[su - 1];
			if (lo == 0) {
				stk[ka] = ti;
				stm[lo] = ti;
			}
			else if (ka == 0) {
				stk[ka] = ti;
				stm[lo] = ti;
			}
			else {
				int dp = min(ostk[ka], ostk[lo])+ti;
				stk[ka] = min(ostk[ka], dp);
				stm[lo] = min(ostm[lo], dp);
			}
		}
	}
	cout << min(stk[n], stm[n]) << endl;
	return 0;
}



Measured memory_bytes: 3744
q = int(input())
a_list = [0]*q
pos = 0
for _ in range(q):
    com, *x = map(int, input().split())
    if com == 0:
        a_list[pos] = x[0]
        pos += 1
    elif com == 1:
        print(a_list[x[0]])
    else:
        pos -= 1
        


Measured memory_bytes: 13372
#include <iostream>
#include <map>
using namespace std;
string s;
int n;
map <pair <string,string>,long long> ml,mr;
int main()
{
	cin>>n>>s;
	string l=s.substr(0,n),r=s.substr(n,n);
	for (int i=0;i<1<<n;i++)
	{
		string lr="",lb="",rr="",rb="";
		for (int j=0;j<n;j++)
		{
			if (i&(1<<j))
			{
				lr+=l[j];
				rr+=r[n-1-j];
			}
			else
			{
				lb+=l[j];
				rb+=r[n-1-j];
			}
		}
		ml[make_pair(lr,lb)]++;
		mr[make_pair(rr,rb)]++;
	}
	long long ans=0;
	for (auto x:ml) ans+=x.second*mr[x.first];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 108288
#create date: 2020-07-12 13:28

import sys
stdin = sys.stdin
from collections import Counter

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    lc = list(Counter(s).values())
    if len(lc) == 2 and lc[0] ==lc[1]:
        print("Yes")
    else:
        print("No")
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pqb             	priority_queue<int>
#define pqs             	priority_queue<int,vi,greater<int> >
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)  	type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n,k;cin>>n>>k;
    int a[n+1];
    map<int,int> m;
    fo1(i,n){
    	cin>>a[i];
    	m[i]=a[i];
    }
    vi v;
	v.push_back(1);
	map<int,int> vis;
	vis[1]=true;
	int i=1;
    while(1){
    	if(!vis[m[i]]){
    		v.push_back(m[i]);
    		vis[m[i]]=true;
    		i=m[i];
    	}
    	else{
    		break;
    	}
    }
    // for(auto i: v){
    // 	cout<<i<<" ";
    // }
    // cout<<endl;
    if(k<v.size()){
    	cout<<v[k];
    	return;
    }
    int to_find=v.back();
    // cout<<to_find;
    int pos;
    for(int i=0;i<v.size();i++){
    	if(v[i]==m[to_find]){
    		pos=i;
    		break;
    	}
    }
    // cout<<pos;
    int cycle_len=v.size()-pos+1;


    int to_sub=pos;

    k-=to_sub;
    vi new_v;
    for(int i=pos;i<v.size();i++){
    	new_v.push_back(v[i]);
    }

    cout<<new_v[k%new_v.size()];

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();cerr<<"\nExecution time: "<<(double)(clock()-beg)/1000<<" seconds\n";}
}

Measured memory_bytes: 31620
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, m;
    cin >> n >> m;
    set<int> se;
    se.insert(1);
    vi cou(n, 1);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        cou[x-1]--;
        cou[y-1]++;
        set<int>::iterator itr = se.find(x);
        if(se.end() == itr) continue;
        if(cou[x-1] == 0) {
            se.erase(itr);
        }
        se.insert(y);
    }

    cout << (int)se.size() << endl;
}

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

using namespace std;

typedef long long int lli;

int main() {
    int n, x[100], y[100], h[100];

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

        cin >> x[i] >> y[i] >> h[i];
        /*if (h[i] == 100) {
            cout << x[i] << " " << y[i] << " " << h[i] << endl;

            return 0;
        }*/
    }

    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){
            if (h[a] == h[b]) {return (x[a] == x[b]) ? (y[a] < y[b]) : (x[a] < x[b]);}
            return (h[a] > h[b]);
    });

    /*
    for (int i=0; i<n; i++) {
        cout << ord[i] << " ";
    }
    cout << endl;
    */

    int ansx = x[ord[0]], ansy = y[ord[0]], ansh = h[ord[0]];
    for (int cx=0; cx<=100; cx++) {
        for (int cy=0; cy<=100; cy++) {
            int ch = h[ord[0]] + abs(x[ord[0]]-cx) + abs(y[ord[0]]-cy);
            for (int i=1; i<n; i++) {
                int tmp = abs(x[ord[i]]-cx) + abs(y[ord[i]]-cy);
                if (h[ord[i]] == max(ch-tmp, 0)) {
                    if (i == n-1) {
                        ansx = cx;
                        ansy = cy;
                        ansh = ch;
                    }
                    else continue;
                }
                else break;
            }
        }
    }

    cout << ansx << " " << ansy << " " << ansh << endl;

    return 0;
}



Measured memory_bytes: 768
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#2320
#import numpy as np

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
	n,m=MI()
	e=[]
	for _ in range(m):
		a,b=MI()
		a-=1
		b-=1
		e.append([a,b])
	#print(e)

	UF=UnionFind(n)
	ans=[]
	tmp=n*(n-1)//2

	for li in reversed(e):
		ans.append(tmp)
		a=li[0]
		b=li[1]
		if UF.same(a,b):
			continue
		aa=UF.parents[UF.find(a)]
		bb=UF.parents[UF.find(b)]
		#print(a,b,aa,bb)
		tmp-=aa*bb
		UF.union(a,b)
	print("\n".join(str(i) for i in ans[::-1]))




if __name__ == "__main__":
	main()

Measured memory_bytes: 32648
#include <iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()

using namespace std;



int main() {
    int n,k;
    cin>>n>>k;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    sort(rng(p));
    int ans=0;
    rep(i,k)ans += p[i];
    cout<<ans<<endl;

    return 0;
}

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

struct UnionFind
{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1)
  {
    rep(i,n)
      par[i] = i;
  }

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

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

    if (x == y)
      return;

    if (sizes[x] < sizes[y])
      swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

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

  int size(int x)
  {
    return sizes[find(x)];
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> bridge;
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    bridge.emplace_back(a, b);
  }
  reverse(bridge.begin(), bridge.end());
  UnionFind us(n);
  vector<ll> ans(1);
  ans[0] = (ll)n * (n - 1) / 2;
  rep(i, m - 1)
    if (!us.same(bridge[i].first, bridge[i].second))
    {
      ans.push_back(ans[i] - (ll)us.size(bridge[i].first) * us.size(bridge[i].second));
      us.unite(bridge[i].first, bridge[i].second);
    }
    else
      ans.push_back(ans[i]);
  for (int i=ans.size()-1; i>=0; i--)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3828
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	int m, f, r;

	while (1) {
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 && f == -1 && r == -1) {
			break;
		}

		if (m == -1 || f == -1) {
			printf("F\n");
			continue;
		}

		if (m < 0) {
			m = 0;
		}
		if (f < 0) {
			f = 0;
		}
		if (r < 0) {
			r = 0;
		}

		if (m + f >= 80) {
			printf("A\n");
		}
		else if (m + f >= 65 && m + f < 80) {
			printf("B\n");
		}
		else if (m + f >= 50 && m + f < 65) {
			printf("C\n");
		}
		else if (m + f >= 30 && m + f < 50) {
			if (r >= 50) {
				printf("C\n");
			}
			else {
				printf("D\n");
			}
		}
		else if (m + f < 30) {
			printf("F\n");
		}
	}

	return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<char>> g(n, vector<char>(m));
  int tot = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
      tot += g[i][j] == '#';
    }
  }
  int cnt = 0;
  for (int maska = 0; maska < (1 << n); maska++) {
    for (int maskb = 0; maskb < (1 << m); maskb++) {
      int black = tot;
      set<pair<int, int>> used;
      for (int i = 0; i < n; i++) {
        if ((maska >> i) & 1) {
          for (int j = 0; j < m; j++) {
            if (used.find(make_pair(i, j)) == used.end() and g[i][j] == '#') {
              used.emplace(i, j);
              --black;
            }
          }
        }
      }
      for (int j = 0; j < m; j++) {
        if ((maskb >> j) & 1) {
          for (int i = 0; i < n; i++) {
            if (used.find(make_pair(i, j)) == used.end() and g[i][j] == '#') {
              used.emplace(i, j);
              --black;
            }
          }
        }
      }
      cnt += black == k;
    }
  }
  cout << cnt << '\n';
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    vector<ll> plus(n), minus(n);
    for (int i = 0; i < n; i++) {
        plus[i] = x[i] + y[i];
        minus[i] = x[i] - y[i];
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());
    ll ans = max(plus[n-1] - plus[0], minus[n-1] - minus[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9560
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>();
    let s = s.chars().collect::<Vec<_>>();

    let mut prev = '.';
    let mut count = 0;
    for &c in s.iter() {
        if prev != c {
            prev = c;
            count += 1;
        }
    }

    println!("{}", count);
}

Measured memory_bytes: 4352
import java.util.*;
import java.math.BigDecimal;

class Main{
  static int a,b,d,r;
  static BigDecimal aa,bb,f;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    a = sc.nextInt();
    b = sc.nextInt();
    d = a / b;
    r = a % b;
    aa = new BigDecimal(a);
    bb = new BigDecimal(b);
    f = aa.divide(bb, 5, BigDecimal.ROUND_HALF_UP);
    System.out.println(d + " " + r + " " + f);
  }
}



Measured memory_bytes: 26472
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N = ii()
S = input()
T = input()

dupr = N
while(dupr>=0):
  if S[N-dupr:N] == T[0:dupr]:
    break
  else:
    dupr -= 1

print(N*2 - dupr)



Measured memory_bytes: 38512
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    char s[11], t[11];
    scanf("%s %s", s, t);
    int a, b;
    scanf("%d %d", &a, &b);
    char u[11];
    scanf("%s", u);
    if(strcmp(s, u) == 0){
        a--;
    }else if(strcmp(t, u) == 0){
        b--;
    }
    printf("%d %d", a, b);

    return 0;
}

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


int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  
  vector<int> cnt(N, K);
  int A;
  for(int i=0; i<Q; i++){
    cin >> A;
    cnt.at(A-1)++;
  }
  for(int i=0; i<N; i++){
    if(cnt[i]-Q > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
    
  return 0;
  
}

Measured memory_bytes: 1152
#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>;

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

  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  rep(i, N) {
    string x;
    cin >> x;
    if (x == "AC") ac++;
    else if (x == "WA") wa++;
    else if (x == "TLE") tle++;
    else re++;
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

Measured memory_bytes: 3528
N = gets.chomp.to_i

require 'complex'
root = Math.sqrt(N-1).floor
ans = 0

if N == 2
  puts 1
  exit
end

(1..root).each do |i|
  ans += ((N-1) / i)
  if N / i != i
    ans +=( ((N-1)/i) - ((N-1)/(i+1)))*i
  end
end

puts ans

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

using namespace std;

int main() {
    vector<int> vec(3);
    for (int i = 0; i < 3; i++) {
        cin >> vec.at(i);
    }
    cout << vec.at(2) << " "
         << vec.at(0) << " "
         << vec.at(1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> v(N + 1, vector<int>(N + 1, 0));
	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		v[l][r]++;
	}

	vector<int> p(Q);
	vector<int> q(Q);
	for (int i = 0; i < Q; i++) {
		cin >> p[i] >> q[i];
	}

	for (int i = 0; i < v.size(); i++) {
		for (int j = 1; j < v[i].size(); j++) {
			v[i][j] += v[i][j - 1];
		}
	}

	vector<int> res(Q, 0);
	for (int i = 0; i < Q; i++) {
		int sum = 0;
		for (int j = p[i]; j <= q[i]; j++) {
			sum += (v[j][q[i]] - v[j][p[i] - 1]);
		}

		res[i] = sum;
	}

	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
package main
 
import (
    "fmt"
)
 
func main() {
    var r, g, b int
    fmt.Scan(&r, &g, &b)
    if (r * 100 + g * 10 + b) % 4 == 0 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    char x,y;
    cin >> x >> y;
    if(x < y)
        cout << "<" << endl;
    else if(x > y)
        cout << ">" << endl;
    else
        cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	int K;
	cin>>K;
	int even=0,odd=0;
	for(int i=1;i<=K;i++){
		if(i%2==0){
			even++;
		}
		else{
			odd++;
		}
	} 
	int ans=even*odd;
	cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        A[i] -= a;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (0 < A[i]) ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	int a[5];
	for (int i = 0; i < 5; i++)cin >> a[i];
	cin >> K;
	bool flag = 0;
	for (int i = 0; i < 5; i++)for (int j = i; j < 5; j++)if (a[j] - a[i] > K)flag = 1;
	if (flag)cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""076-c"""


import sys

def kmp(T, P):
    n, m = len(T), len(P)
    j = 0
    k = 0
    fail = kmp_fail(P)
    while j < n:
        if T[j] == P[k] or T[j] == '?':
            if k == m - 1:
                return j - m + 1
            j += 1
            k += 1
        elif k > 0:
            k = fail[k-1]
        else:
            j += 1
    return -1

def kmp_fail(P):
    n = len(P)
    fail = [0] * n
    j = 1
    k = 0
    while j < n:
        if P[j] == P[k]:
            fail[j] = k + 1
            j += 1
            k += 1
        elif k > 0:
            k = fail[k - 1]
        else:
            j += 1
    return fail


def main():
    """Main function."""
    S_p = input()
    T = input()

    pos = kmp(S_p, T)

    if pos < 0:
        print('UNRESTORABLE')
        sys.exit(0)

    total = pos

    pos_ = 0
    while pos_ >= 0:
        pos_ = kmp(S_p[pos+1:], T)
        if pos_ >= 0:
            pos = pos + pos_ + 1

    S_cand = S_p[:pos] + T + S_p[pos+len(T):]

    S = S_cand.replace('?', 'a')
    print(S)

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 3064
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lst[int(input())-1])

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

int main(){
  int64_t N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  int64_t m=min(A, min(B, min(C, min(D, E))));
  int64_t Ans=0;
  if(N%m==0){
    Ans=N/m;
  }
  else{
    Ans=N/m+1;
  }
  cout << Ans+4 << endl;
}

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

int main() {
	string n;
	cin >> n;
	char a = n.at(0), b = n.at(1), c = n.at(2), d = n.at(3);
	if (a == b && b == c ) cout << "Yes" << endl;
	else if (b == c && c == d) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
  string s; cin >> s;
  int length = s.size();
  cout << s[0] << to_string(length - 2) << s[length-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9 + 5

using namespace std;

int N,height[100005];
int dp[100005];

int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        dp[i] = INF;
    }
    dp[1] = 0;

    for(int i=1;i<=N;i++){
        scanf("%d",&height[i]);
    }

    for(int i=1;i<=N;i++){
        if(i+1<=N){
            dp[i+1] = min(dp[i+1],dp[i]+abs(height[i]-height[i+1]));
        }
        if(i+2<=N){
            dp[i+2] = min(dp[i+2],dp[i]+abs(height[i]-height[i+2]));
        }
    }


    printf("%d\n",dp[N]);

    return 0;
}


Measured memory_bytes: 4588
#include<stdio.h>
#include<string.h>

int main()
{
    char s[1010],s1[100],s2[1000],s3[1010];
    int n,a,b,i,k,j;
    scanf("%s", s);

    scanf("%d",&n);
    while(n--){
             strcpy(s3,s);
        scanf("%s", s1);
        if(s1[2]=='p'){
            scanf("%d %d",&a,&b);
            scanf("%s",s2);
            k=0;
            for(i=a;i<=b;i++){
               s[i]=s2[k];
               k++;
            }
        }
        else if(s1[2]=='v'){
            scanf("%d %d",&a,&b);
            for(i=a,j=b;i<=b;i++,j--)
                s[i]=s3[j];

        }
       else if(s1[0]='p'){
            scanf("%d %d",&a,&b);
            for(i=a;i<b;i++)
                printf("%c",s[i]);
                printf("%c\n",s[b]);
        }
    }
    return 0;

}



Measured memory_bytes: 2140
#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>>;

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;
	ll n   = s.size();
	ll tmp = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '1') {
			if (i == n - 1)
				tmp = 3;
			else {
				tmp = (2 * tmp + powm(3, n - i - 1, MOD)) % MOD;
			}
		} else {
			if (i == n - 1) tmp = 1;
		}
	}
	dump(tmp);
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MOD (1000000007)
#define MAXN (100005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

ll S[MAXN];
int A[MAXN];
int N, M;
ll Ans;

ll f() {
	ll ret = 0;
	for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
	for(int i = 1; i <= N; i++) S[i] = S[i-1] + A[i];
	for(int i = 2; i <= N; i++) ret = (ret + (ll)A[i] * (i-1) - S[i-1]) % MOD;
	return ret;
}
int main() {
	scanf("%d%d", &N, &M);
	Ans = f(); N = M; Ans *= f();
	printf("%lld\n", Ans%MOD);
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

int k = 3;
int N = 1 << k;

// void p_id(int id) {
//   std::string s = "";
//   for (size_t i = 0; i < N; i++) {
//     s = std::to_string(id & (N - 1)) + s;
//     id >>= k;
//   }
//   std::cout << s << std::endl;
// }

int swap(int i, int j, int id){
  int sft_i = i * k;
  int sft_j = j * k;
  int x = id & ((N - 1) << sft_i);
  int y = id & ((N - 1) << sft_j);
  id = id ^ x;
  id = id ^ y;
  id = id | ((x >> sft_i) << sft_j);
  id = id | ((y >> sft_j) << sft_i);
  return id;
}

int get_id(int b[]) {
  int id = 0;
  for (size_t i = 0; i < N; i++) id = (id << k) | b[i];
  return id;
}

int get_pos0(int id) {
  for (size_t i = 0; i < N; i++) {
    int d = id & (N - 1);
    if (d == 0) return i;
    id >>= k;
  }
  return -1;
}

void next_ids(int id, std::vector<int> *v){
  int pos0 = get_pos0(id);
  int No2 = N >> 1;
  v->clear();
  if (pos0 < No2) {
    v->push_back(swap(pos0, pos0 + No2, id));
    if (pos0 != 0)       v->push_back(swap(pos0, pos0 - 1, id));
    if (pos0 != No2 - 1) v->push_back(swap(pos0, pos0 + 1, id));
  } else {
    v->push_back(swap(pos0, pos0 - No2, id));
    if (pos0 != No2)     v->push_back(swap(pos0, pos0 - 1, id));
    if (pos0 != N - 1)   v->push_back(swap(pos0, pos0 + 1, id));
  }
}

std::map<int, int> tbl;
std::queue<int> q;

int main() {
  int board[N];
  for (size_t i = 0; i < N; i++) board[i] = i;
  int id = get_id(board);

  q.push(id);
  tbl[id] = 0;
  while (!q.empty()) {
    id = q.front(); q.pop();
    int step = tbl[id];
    std::vector<int> v;
    next_ids(id, &v);
    for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
      if (tbl.find(*it) == tbl.end()) {
        q.push(*it);
        tbl[*it] = step + 1;
      }
    }
  }

  while(1){
      for(int i = 0; i < N; ++i){
          if(scanf("%d", &board[i]) == EOF){
              return 0;
          }
      }
      printf("%d\n", tbl[get_id(board)]);
  }
}

Measured memory_bytes: 4208
#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>;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = b - a + 1;
    ll cd = lcm(c, d);
    ll cnt = b / c + b / d - ((a - 1) / c + (a - 1) / d) - (b / cd - (a - 1) / cd);
    cout << ans - cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3632