akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int isPrime( int );

int main( void ) {
	int a, d, n, fig;

	for ( ; scanf( "%d %d %d", &a, &d, &n ), a; printf( "%d\n", fig - d ) )
		for ( fig = a; n; fig += d )
			if ( isPrime( fig ) )
				n--;

	return 0;
}

int isPrime( int n ) {
	int i;

	if ( n == 2 )
		return 1;
	if ( !( n & 1 ) )
		return 0;

	for ( i = 3; i * i <= n; i += 2 )
		if ( n % i == 0 )
			return 0;

	return n != 1;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int start = max(A,C);
    if(B < start || D < start)
    {
        cout << "0\n";
        return 0;
    }
    int end = min(B,D);
    cout << end - start << '\n';
}



Measured memory_bytes: 256
import collections
n=int(input())
a=list(map(int,input().split()))
l=[]
r=[]
for i in range(n):
  l.append(i+a[i]+1)
  r.append(i-a[i]+1)
cl=collections.Counter(l)
cr=collections.Counter(r)
ans=0
for k,v in cl.items():
  ans+=v*cr[k]
print(ans)  

Measured memory_bytes: 63248
#include<stdio.h>

int sosu(int x){
	int i=3;
	
	
	
		if(x==2){
		return 1;
		}
		if(x<2||x%2==0){
		return 0;
		}
	
		while(i*i<=x){
		
		if(x%i==0)
		return 0;
		i=i+2;
		
		}
		
		return 1;
	}

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

Measured memory_bytes: 1856
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b = f()
    s = input()

    for i in range(a+b+1):
        if i == a:
            if s[i] != '-':
                print('No')
                return
        else:
            if s[i] not in [str(k) for k in range(10)]:
                print('No')
                return

    
    print('Yes')


solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100000
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define sd(n) scanf("%lld",&n)
ll b[lim+1];
ll cnt[lim+1];
int main()
{
	ll n,m,x,y;
	cin>>n>>m;
	for(ll i=1;i<=n;i++)
	{
		cnt[i]=1;
		b[i]=0;
	}
	b[1]=1;
	while(m--)
	{
		sd(x);
		sd(y);
		cnt[x]--;
		if(b[x])
		b[y]=1;
		cnt[y]++;
		if(cnt[x]==0)
		b[x]=0;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	if(b[i])
	ans++;
	cout<<ans;
}

Measured memory_bytes: 1792
import math

N, H = map(int, input().split())
kiri = []
nage = []
for n in range(N):
    tmps = list(map(int, input().split()))
    kiri.append(tmps[0])
    nage.append(tmps[1])

kiri_max = max(kiri)
nage.sort(reverse=True)
nage = list(filter(lambda x: x >= kiri_max, nage))

count = 0
while (H > 0):
    if (len(nage) != 0):
        H -= nage[0]
        nage.pop(0)
        count += 1
    else:
        if ( H % kiri_max == 0):
            count += H // kiri_max
        else:
            count += H // kiri_max + 1
        break

print(count)


Measured memory_bytes: 12024
#include<stdio.h>

char s[2010][2010];
char t[2010][2010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%s",s[i]);
	for(int i=0;i<n;i++)scanf("%s",t[i]);
	int ans=0;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)ans+=s[i][j]!=t[i][j];
	printf("%d\n",ans);
}


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

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

  if(N==1 && M==1){
    cout<<1<<endl;
    return 0;
  }
  
  if(N==1){
    cout<<M-2<<endl;
  }else if(M==1){
    cout<<N-2<<endl;
  }else{
    cout<< (N-2)*(M-2) <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n; int a, d;
	while (cin >> n) {
		if (n == 0)break;
		int minx = 0; int miny = 0; int maxx = 0; int maxy = 0;
		P p[200]; p[0] = make_pair(0, 0);
		for (int i = 1; i < n; i++) {
			cin >> a >> d;
			if (d == 0) {
				p[i].first = p[a].first - 1;
				p[i].second = p[a].second;
				minx = min(minx, p[i].first);
			}
			else if (d == 1) {
				p[i].first = p[a].first;
				p[i].second = p[a].second - 1;
				miny = min(miny, p[i].second);
			}
			else if (d == 2) {
				p[i].first = p[a].first + 1;
				p[i].second = p[a].second;
				maxx = max(maxx, p[i].first);
			}
			else if (d == 3) {
				p[i].first = p[a].first;
				p[i].second = p[a].second + 1;
				maxy = max(maxy, p[i].second);
			}
		}
		cout << maxx - minx+1 << " " << maxy - miny+1 << endl;
	}
	return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

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

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}

const ll MOD=1000000007;

void solve(){
	
	ll s,w;
	cin>>s>>w;

	if(w>=s){
		cout<<"unsafe"<<endl;
	}
	else{
		cout<<"safe"<<endl;
	}
}


int main(){
	
	solve();
	
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.nextLine();
    sc.close();
    
    String start=s.substring(0,1);
    String end=s.substring(s.length()-1,s.length());
    int len=s.length()-2;
    System.out.println(start+len+end);
  }
}

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

int main() {
  int A,B,C,D;
  cin >> A>>B>>C>>D;
  if (A+B>C+D) {
    cout << "Left" << endl;
  }
  else if (A+B<C+D) {
    cout << "Right" << endl;
  }
  else  cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false);}
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector <int> vi;
const int mod = 1e9+7;
const int inf = 1e9+10;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
const int W = 1e9;
#define maxn 100100

PII skal[maxn];
int tab[maxn], n;

int main()
{
	boost;
	cin >> n;
	FOR(i, 1, n) 
	{
		cin >> tab[i];
		skal[i] = mp(tab[i], i);
	}
	sort(skal+1, skal+n+1);
	FOR(i, 1, n) tab[skal[i].e2] = i;
	int res = 0;
	FOR(i, 1, n)
	{
		int r = abs(i - tab[i]) % 2;
		res += r;
	}
	
	assert(res % 2 == 0);
	cout << res / 2;
}


Measured memory_bytes: 1408
// Problem : D - Anything Goes to Zero
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)
#define setbits(x)  __builtin_popcount(x)
int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
int pwrTwo[N];
int getMod(string str, int n, int k) 
{ 

	// pwrTwo[i] will store ((2^i) % k) 
	int pwrTwo[n]; 
	pwrTwo[0] = 1 % k; 
	for (int i = 1; i < n; i++) 
	{ 
		pwrTwo[i] = pwrTwo[i - 1] * (2 % k); 
		pwrTwo[i] %= k; 
	} 

	// To store the result 
	int res = 0; 
	int i = 0, j = n - 1; 
	while (i < n) 
	{ 

		// If current bit is 1 
		if (str[j] == '1') 
		{ 

			// Add the current power of 2 
			res += (pwrTwo[i]); 
			res %= k; 
		} 
		i++; 
		j--; 
	} 
	return res; 
}
int help(int n)
{
	int ct = 0;
	while(n!=0)
	{
		int xxx = setbits(n);
		n = n%xxx;
		++ct;
	}
	return ct;
}		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ct  = 0;
		for(int i=0;i<n;++i)
		{
			if(s[i]=='1')
			++ct;
		}
		int pwrmore[n],pwrless[n];
		pwrmore[0] = 1%(ct+1);
		if(ct!=1)
		pwrless[0] = 1%(ct-1);
		for(int i=1;i<n;++i)
		{
			pwrmore[i] = pwrmore[i-1]*(2%(ct+1));
			pwrmore[i]%=(ct+1);
		}
		if(ct!=1)
		for(int i=1;i<n;++i)
		{
			pwrless[i] = pwrless[i-1]*(2%(ct-1));
			pwrless[i]%=(ct-1);
		}
		int more = getMod(s,n,ct+1);
		int less = 0;
		if(ct!=1)
		 less = getMod(s,n,ct-1);
		//cout<<more<<" "<<less<<"\n";
		for(int i=0;i<n;++i)
		{
			if(s[i]=='1')
			{
				if(ct==1)
				{
					cout<<0<<"\n";
					continue;
				}
				else
				{
					int xxx = (less+ct-1-pwrless[n-1-i])%(ct-1);
					cout<<help(xxx)+1<<"\n";
				}	
			}
			else // '0'
			{
				int xxx = (more+pwrmore[n-1-i])%(ct+1);
				cout<<help(xxx)+1<<"\n";
			}
		}
    }
    return 0;
}


Measured memory_bytes: 8492
N=int(input())
ans = 100000
for i in range(N+1):
    t = i
    count = 0
    while t > 0:
        count += t%6
        t = t//6
    t = N - i
    while t > 0:
        count += t%9
        t = t//9
    if count < ans:
        ans = count
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s;
  t = s;
  reverse(t.begin(), t.end());
  int n = s.size();
  if(s == t and s.substr(0, (n - 1) / 2) == s.substr((n + 3) / 2 - 1, n - 1)){
      cout << "Yes";
  }
  else{
      cout << "No";
  }
}

Measured memory_bytes: 256
#include<iostream>*
        #include<bits/stdc++.h>
        using namespace std;
        #define PB push_back
        #define MK make_pair
        #define F first
        #define S second
        #define REB(i,a,b) for(ll i=a;i<b;i++)
        #define LP(k,a,b) for(ll k=a;i>=b;k--)
        typedef long long ll;
        typedef pair<int,int> pi;
        ll diagonal1[15],diagonal2[15],column[15],N, ans[15];
        ll c=0;
        void search(int y) {
            if (y == N) {
                    c++;return;
            }
            if(ans[y]!=-1){
                search(y+1);
            }else{
                for (int x = 0; x < N; x++) {
                     if (column[x] || diagonal1[x+y] || diagonal2[x-y+N-1]) continue;
                     column[x] = diagonal1[x+y] = diagonal2[x-y+N-1] = 1;
                     ans[y]=x;
                     search(y+1);
                     if(c>0){
                        return ;
                     }
                     column[x] = diagonal1[x+y] = diagonal2[x-y+N-1] = 0;
                     ans[y]=-1;
                     }

            }
        }
        int main()
        {   ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
            memset(diagonal1,0,sizeof(diagonal1));
            memset(diagonal2,0,sizeof(diagonal2));
            memset(column,0,sizeof(column));
            memset(ans,-1,sizeof(ans));
            N=8;ll arr[N][N];
            int t;cin>>t;
            int a,b;
            while(t--){
               cin>>a>>b;
                ans[a]=b;
                column[b] = diagonal1[a+b] = diagonal2[b-a+N-1] = 1;
            }
            /*  REB(i,0,N){
                     REB(j,0,N){
                     if(ans[i]==j){cout<<'Q';}
                     else{cout<<'.';
                     }
                  }
                  cout<<'\n';
               }
               cout<<'\n'<<'\n';*/
            search(0);
              REB(i,0,N){
                     REB(j,0,N){
                     if(ans[i]==j){cout<<'Q';}
                     else{cout<<'.';
                     }
                  }
                  cout<<'\n';
               }
            return 0;
        }



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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,M;
    cin >> N >> M;
    multiset<int> A;
    rep(i,N) {
        int a;
        cin >> a;
        A.insert(a);
    }
    rep(i,M) {
        int a = *A.rbegin();
        //cout << a << endl;
        A.erase(A.find(a));
        a /= 2;
        A.insert(a);
    }

    //cout << A.size() << endl;
    ll ans = 0;
    for (auto a:A) {
        ll b = a;
        ans += b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8212
from collections import deque

K = int(input())

dq = deque(list(range(1,10)))

for i in range(K):
    now = dq.popleft()
    for i in (-1,0,1):
        add = (now%10)+i
        if 0 <= add<10:
            dq.append(now*10+add)

print(now)

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

typedef long long LL;
typedef long double LD;
typedef string ST;


struct XXX {
  LL A;
  LL B;
  bool operator>(const XXX x) const {
    return A > x.A;
  }
  bool operator<(const XXX x) const {
    return A < x.A;
  }
};



void func()
{
  LL N, M;
  cin >> N >> M;
  priority_queue<XXX,vector<XXX>,greater<XXX>> AB;

  for (LL i = 0; i < N; ++i) {
    XXX x;
    cin >> x.A;
    cin >> x.B;
    AB.push(x);
  }

  LL cost = 0;
  LL m = 0;
  while (!AB.empty()) {
    LL A = AB.top().A;
    LL B = AB.top().B;
    AB.pop();

    LL honsu = min(M - m, B);
    m += honsu;
    cost += honsu * A;
    if (m == M) {
      break;
    }
    

  }
  cout << cost;


}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif


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

int main(){
    vector<int> v(6);
    rep(i,6) cin >> v.at(i);

    for(int i = 0; i < 4; i++){
        for(int j = i + 1; j < 5; j++){
            if(v.at(j) - v.at(i) > v.at(5)){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}

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

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

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

    ll K; cin >> K;

    ll base = K/50 + 49;
    cout << 50 << endl;
    for (int i = 0;i < 50;i++){
        if(i < K%50) cout << base+50-(K%50-1) << " ";
        else cout << base-K%50 << " ";
    }
    cout << endl;
    
    return 0;

}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long K;
	scanf("%lld",&K);
	long long N;
	scanf("%lld",&N);
	std::vector<long long> A(N);
	for(ll i = 0 ; i < N ; i++){
		scanf("%lld",&A[i]);
	}

	vector<ll> diffs(N);
	diffs[0] = K - (A[N - 1] - A[0]);
	for (ll i = 1; i < N; ++i)
	{
		diffs[i] = A[i] - A[i - 1];
	}

	ll start = max_element(diffs.begin(), diffs.end()) - diffs.begin();

	ll sum = 0;
	ll i = (start + 1) % N;
	if (i < 0)		i += N;
	while (i % N != start)
	{
		if (i == 0)
		{
			sum += K - (A[N - 1] - A[0]);
		}
		else
		{
			sum += A[i] - A[i - 1];
		}
		i = (i + 1) % N;
		if (i < 0)	i += N;
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int> a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(), (a).end()

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;
}

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

ll keta(ll n)
{
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind
{
public:
  vi Parent;
  UnionFind(int n)
  {
    Parent = vi(n, -1);
  }

  int root(int a)
  {
    if (Parent[a] < 0)
      return a;
    else
      return Parent[a] = root(Parent[a]);
  }

  int size(int a)
  {
    return -Parent[root(a)];
  }

  bool merge(int a, int b)
  {
    a = root(a);
    b = root(b);
    if (a == b)
      return false;

    if (size(a) < size(b))
      swap(a, b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial
{
public:
  vl Fac;
  Factrial(int MAX)
  {
    Fac = vl(MAX + 1);
    rep(i, MAX)
    {
      if (i == 0)
        Fac[i + 1] = 1;
      else
        Fac[i + 1] = ((i + 1) * Fac[i]) % MOD;
    }
  }
};

int main(){
  int n,k; cin >> n >> k;
  int R,S,P; cin >> R >> S >> P;
  //vi v(3); rep(i,3) cin >> v[i];
  string t; cin >> t;
  
  int ans = 0;

  rep(i,n) {
    if(t[i] == 'r') ans += P;
    if(t[i] == 's') ans += R;
    if(t[i] == 'p') ans += S;
  }

  rep(i,k) {
    bool subst = true;
    for(int j = i; j+k < n; j += k) {
      if(t[j] == t[j+k] && subst){
        subst = false;
        if(t[j] == 'r') ans -= P;
        if(t[j] == 's') ans -= R;
        if(t[j] == 'p') ans -= S;
      }
      else{
        subst = true;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P,int>PP;
int x[200006], v[200006];
vector<PP>v1, v2;
int p1[200006], p2[200006];
int rmin1[200006], rmin2[200006], rmax1[200006], rmax2[200006];

struct RAQ {
	int n;
	vector<int>node, lazy;
	void init(int N) {
		n = 1;
		while (n < N)n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1);
	}
	void eval(int k, int l, int r) {
		if (!lazy[k])return;
		node[k] += lazy[k] * (r - l);
		node[k] %= mod;
		if (k < n - 1) {
			rep(i, 2) {
				lazy[2 * k + i + 1] += lazy[k];
				lazy[2 * k + i + 1] %= mod;
			}
		}
		lazy[k] = 0;
	}
	void update(int a, int b, int x, int k, int l, int r) {
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] += x;
			lazy[k] %= mod;
			eval(k, l, r);
			return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		node[k] = node[k * 2 + 1] + node[k * 2 + 2];
		node[k] %= mod;
	}
	int calc(int a, int b, int k, int l, int r) {
		eval(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b)return node[k];
		int vl = calc(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = calc(a, b, k * 2 + 2, (l + r) / 2, r);
		return (vl + vr) % mod;
	}
	void add(int a, int b, int x) {
		update(a, b, x, 0, 0, n);
	}
	int getsum(int a, int b){
		return calc(a, b, 0, 0, n);
	}
};
RAQ dp;
vector<P>S;

void setmin(int n) {
	rep(i, n)rmin1[i] = rmin2[i] = rmax1[i] = rmax2[i] = p2[i];
	rep(i, n - 1) {
		rmin1[i + 1] = min(rmin1[i], rmin1[i + 1]);
		rmax1[i + 1] = max(rmax1[i], rmax1[i + 1]);
	}
	for (int i = n - 1; i > 0; i--) {
		rmin2[i - 1] = min(rmin2[i - 1], rmin2[i]);
		rmax2[i - 1] = max(rmax2[i - 1], rmax2[i]);
	}
}

signed main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> x[i] >> v[i];
		v1.push_back(PP(P(x[i], v[i]),i));
		v2.push_back(PP(P(v[i], x[i]),i));
	}

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	rep(i, n) {
		p1[i] = v1[i].second;
		p2[v2[i].second] = i;
	}
	rep(i, n)p1[i] = p2[p1[i]];
	//i->p1[i]
	rep(i, n)p2[p1[i]] = i;

	setmin(n);

	rep(i, n) {
		int L, R;
		int lb = i - 1, ub = n;
		while (ub - lb > 1) {
			int mi=(ub + lb) / 2;
			int M = rmin2[mi];
			if (M <= p2[i]) {
				lb = mi;
			}
			else ub = mi;
		}
		R = lb;
		lb = -1, ub = i + 1;
		while (ub - lb > 1) {
			int mi = (ub + lb) / 2;
			int M = rmax1[mi];
			if (M >= p2[i])ub = mi;
			else lb = mi;
		}
		L = ub;
		S.push_back(P(R, L));
	}
	

	sort(S.begin(), S.end());
	dp.init(n + 1);
	dp.add(0, 1, 1);

	rep(i, n) {
		int L = S[i].second, R = S[i].first;
		dp.add(R + 1, R + 2, dp.getsum(L,R+2));
	}
	cout << dp.getsum(n, n + 1)<<endl;

}


Measured memory_bytes: 37020
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function eval(a::Tuple{Int,Int},b::Tuple{Int,Int})
	if a[2]<b[2]
		1
	elseif a[2]==b[2]
		0
	else
		-1
	end
end

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = l>>1
		while eval(x,h[k])==1&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if eval(h[2*k],z)>=0
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if eval(z,h[2*k])>=0&&eval(z,h[2*k+1])>=0
					break
				else
					t = eval(h[2*k],h[2*k+1])>=0 ? 2*k : 2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:n]
	for i in 1:m
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	dis = 10^18*ones(Int, length(e))
	h = Array{Tuple{Int,Int},1}()
	push!(h,(1,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v] = dis[v]<0 ? w : min(dis[v],w)
		for i in 1:length(e[v])
			if dis[e[v][i]]<0　|| dis[e[v][i]]>w+1
				dis[e[v][i]] = w+1
				hpush(h,(e[v][i],w+1))
			end
		end
	end
	println(dis[n]<=2 ? "POSSIBLE" : "IMPOSSIBLE")
end

main()

Measured memory_bytes: 243172
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String op=sc.next();
            int b = sc.nextInt();
            
            if(op.equals("+")){
                System.out.println(a+b);
                
            }else if(op.equals("-")){
                System.out.println(a-b);
                        
            }else if(op.equals("*")){
                System.out.println(a*b);
                                
            }else if(op.equals("/")){
                System.out.println(a/b);
            }
            if(op.equals("?"))
                break;
        }
        sc.close();
    }
}



Measured memory_bytes: 26152
N,K = list(map(int,input().split()))
S = input()
if N == 1:
    print(0)
else:
    lc = max(S.count('L')-1,0)
    rc = max(N-lc-1,0)
    maxc = lc+rc
    nowc = 0
    now = S[0]
    for i in range(1,N):
        if S[i] == now:
            nowc += 1
        else:
            now = S[i]
    print(min(nowc+2*K,maxc))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template <class T> struct Mo{
    int n,q;
    vector<int> l,r,p;
    vector<T> ans,c,v;
    T a;
    Mo(int n,T a,vector<T>&c):n(n),q(),l(),r(),p(),ans(),c(c),v(n),a(a){}
    void add_query(int L,int R){
        l.emplace_back(L);
        r.emplace_back(R);
        p.emplace_back(q++);
    }
    void adv_right(T&A,int R){
        if(!v[c[R]]++) ++A;
    }
    void adv_left(T&A,int L){
        if(!--v[c[L]]) --A;
    }
    void prv_left(T&A,int R){
        if(!v[c[R]]++) ++A;
    }
    void mo(){
        int h=int(n/sqrt(q));
        sort(p.begin(),p.end(),[&](int i,int j){return l[i]/h==l[j]/h?r[i]<r[j]:l[i]<l[j];});
        ans.resize(q);
        T A{a};
        int L=-1,nl=-1,nr=-1;
        for(auto i:p){
            if(l[i]/h!=L){
                A=a;
                v.assign(n,0);
                for(int j=0;j<r[i];++j) adv_right(A,j);
                for(int j=0;j<l[i];++j) adv_left(A,j);
                L=l[i]/h;
            }
            else{
                for(int j=nr;j<r[i];++j) adv_right(A,j);
                if(nl<l[i]) for(int j=nl;j<l[i];++j) adv_left(A,j);
                else for(int j=nl-1;j>=l[i];--j) prv_left(A,j);
            }
            ans[i]=A;
            nl=l[i],nr=r[i];
        }
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    vector<int> c(n);
    for(auto&i:c) cin>>i,--i;
    Mo<int> mo(n,0,c);
    {
        int l,r;
        fr(i,q){
            cin>>l>>r;
            mo.add_query(l-1,r);
        }
    }
    mo.mo();
    for(auto&i:mo.ans) cout<<i<<'\n';
}

Measured memory_bytes: 17620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int x;
  cin >> x;

  int a = x / 100;
  int b = x % 100;

  if (b <= a * 5) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>
#include <math.h>
#include <map>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


// mod. m での a の逆元 a^{-1} を計算する
// a * a^(p−2) ≡ 1(mod p)
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

vector <ll>  get_divisor(ll n)
{
  vector <ll> res;
  for(ll i = 2; i * i <= n; ++i)
  {
    while(n % i == 0)
    {
      res.push_back(i);
      n /= i; 
    }
  }
  if(n != 1)
  {
    res.push_back(n);
  }

  return res;
}

//最小公倍数の約数のリストのほうがいいかな

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector <ll> a(N);
    REP(i, N)cin >> a[i];

    vector<ll> now = a;
    map <ll, ll> m;
    //素因数分解
    for(ll i = 0; i < N; ++i)
    {
        for (ll j = 2; j*j <= now[i]; ++j) {
            ll cnt = 0;
            while(now[i] % j == 0)
            {
                ++cnt;
                now[i] /= j;
            }
            m[j] = max(m[j], cnt);
        }
        m[now[i]] = max(m[now[i]], 1LL);
    }

    ll ans = 1;
    for(auto v: m)
    {
        for(int i = 0; i < v.second; ++i)
        {
            ans *= v.first;
            ans %= MOD;
        }
    }
    ll res = 0;
    for(int i = 0; i < N; ++i)
    {
        ll tmp = ans * modinv(a[i], MOD);
        res += tmp;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int a[1000010];

int main(){
    int s, ans=-1;
    cin >> s;
    a[1] = s;
    for(int i=2; ans==-1; i++){
        if(a[i-1]%2==0){
            a[i] = a[i-1]/2;
        }
        else{
            a[i] = a[i-1]*3+1;
        }
        for(int j=1; j<i; j++){
            if(a[i] == a[j]){
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    lint ret = 0;
    int idx  = 0;
    int curr = 0;
    for (int i = 0; i < n; ++i) {
        while ((curr & a[i]) != 0) {
            curr ^= a[idx];
            idx++;
        }
        ret += i - idx + 1;
        curr ^= a[i];
    }
    cout << ret << "\n";
    return 0;
}

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

using namespace std;

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

  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string t;
    cin >> t;
    mp[t]++;
  }

  cout << "AC x " << mp["AC"] << '\n';
  cout << "WA x " << mp["WA"] << '\n';
  cout << "TLE x " << mp["TLE"] << '\n';
  cout << "RE x " << mp["RE"] << '\n';
  return 0;
}



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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 10;

char s[N];
int n;

void run() {
  scanf("%s", s);
  n = strlen(s);
  int l = n / 2, r = n + 1;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    int rr = mid - 1;
    int ll = n - mid;
    int ok = 1;
    for (int i = ll; i <= rr; ++i) if (s[i] != s[ll]) ok = 0;
    if (ok) {
      l = mid;
    } else {
      r = mid;
    }
  }
  printf("%d\n", l);
}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int w, a, b, t;

	cin >> w >> a >> b;
	if (a > b) swap(a, b);
	t = b - (a + w);
	cout << (t < 0 ? 0 : t) << endl;

	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	int dp[n + 1][27]; // 1, 2
	for (int i = 0; i <= 26; i++)
		for (int j = 0; j <= n; j++) dp[j][i] = 0;
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			if (s[i] == j + 'a') {
				if (i + 1 < n) dp[i + 2][26] = std::max(dp[i + 2][26], dp[i][j] + 1);
			} else {
				dp[i + 1][s[i] - 'a'] = std::max(dp[i + 1][s[i] - 'a'], dp[i][j] + 1);
				if (i + 1 < n) dp[i + 2][26] = std::max(dp[i + 2][26], dp[i][j] + 1);
			}
		}
		dp[i + 1][s[i] - 'a'] = std::max(dp[i + 1][s[i] - 'a'], dp[i][26] + 1);
	}
	int res = 0;
	for (int i = 0; i <= 26; i++) res = std::max(res, dp[n][i]);
	std::cout << std::max(1, res) << std::endl;
	
	
	
	return 0;
}


Measured memory_bytes: 21636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int a, b, c, d;
		if (x > y) {
			a = x;
			b = y;
		} else {
			a = y;
			b = x;
		}
		if (a % 2 == 1 && b % 2 == 0) {
			for (int i = b - 1; i > 0; i -= 2) {
				c = a % i;
				if (c == 0) {
					d = b % i;
					if (d == 0) {
						System.out.println (i);
						break;
					}
				}
			}
		} else {
			for (int i = b; i > 0; i -= 2) {
				c = a % i;
				if (c == 0) {
					d = b % i;
					if (d == 0) {
						System.out.println (i);
						break;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 26332
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] abc = new int[n][3];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 3; j++)
				abc[i][j] = sc.nextInt();
		
		long[][] dp = new long[n][3];
		for (int i = 0; i < 3; i++)
			dp[0][i] = abc[0][i];
		
		for (int i = 1; i < n; i++)
			for (int j = 0; j < 3; j++)
				for (int k = 0; k < 3; k++) {
					if (k == j) continue;
					dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + abc[i][j]);
				}
		
//		for (int i = 0; i < n; i++)
//			System.out.println(Arrays.toString(dp[i]));
		
		long max = 0;
		for (int i = 0; i < 3; i++)
			max = Math.max(max, dp[n - 1][i]);
		
		System.out.println(max);
 		
		sc.close();
	}
}



Measured memory_bytes: 54472
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc126_a.cpp
 * time   : Fri May  1 16:45:31 2020
 * quest  : A - Changing a Character
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    if (i == k - 1)
      cout << char(tolower(s[i]));
    else
      cout << s[i];
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
/*
  AOJ 2198
  Title:Sum of Consecutive Integers
  @kankichi573
*/
#include <stdio.h>

main()
{
  int N,i,ret,c_s;
  
  while(scanf("%d",&N)  && N)
    {
      ret=0;
      for(i=2;;i++)
	{
	  c_s=i*(i-1)/2;
	  if(c_s>=N)
	    break;
	  if(((N - c_s) % i)==0)
	    ret++;
	}
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 600
S = list(input())
if not S[0]==S[1]==S[2]==S[3]:
    a = S[0]
    S.pop(0)
    if a in S:
        S.remove(a)
        if S[0]==S[1]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
    
else:
    print('No')

Measured memory_bytes: 3060
import fractions
n, m = map(int, input().split())
listS = list(input())
listT = list(input())

l = n*m // fractions.gcd(n, m)
a = l//n
b = l//m

if listS[0] != listT[0]:
    print(-1)
else:
    checkI = a*b // fractions.gcd(a, b)
    if checkI > l:
        print(l)
    else:
        index = 0
        flag = 0
        while index < l//min(a, b):
            if index*checkI//a > len(listS)-1 or index*checkI//b > len(listT)-1:
                break
            elif listS[index*checkI//a] != listT[index*checkI//b]:
                print(-1)
                flag = 1
                break
            else:
                index += 1
        if flag == 0:
            print(l)
        

Measured memory_bytes: 6688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,w;
  cin >> w>>a >> b;
  if(b<a) swap(a,b);
  cout << max(0, b-(a+w)) << endl;


  
  return 0;
    

}


Measured memory_bytes: 384
fun main() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    val s = IntArray(m)
    val c = IntArray(m)
    repeat(m) {i ->
        val (r1, r2) = readLine()!!.split(" ").map { it.toInt() }
        s[i] = r1
        c[i] = r2
    }

    var ans = -1
    for (i in 0..Math.pow(10.0, n.toDouble()).toInt()){
        val sa = i.toString().split("").filter { it != "" }
        var flg = true

        for (j in 0..(m - 1)) {
            if (sa.size < s[j]) {
                flg = false
                break
            } else if (sa[s[j] - 1].toInt() != c[j]) {
                flg = false
                break
            }

        }
        if (flg && i.toString().length == n) {
            ans = i
            break
        }
    }

    println(ans)
}

Measured memory_bytes: 41328
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	N, = linput()
	vB = linput()
	
	vC = [b-i-1 for i,b in enum(vB)]
	vC.reverse()
	#print(N)
	res = 0
	vR = []
	
	for _ in "*"*N:
		try:
			x = vC.index(0)
			vR.append(vB[N-x-1])
			vC[x] = -INF
			for j in range(x):
				vC[j] += 1
		except ValueError as e:
			print(-1)
			return
	
	#sT = "No Yes".split()
	#print(sT[res])
	#print(res)
	print(*vR[::-1], sep="\n")

if __name__ == "__main__":
	main()


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


int sum = 0;
vector<string> dat;

void dfs(int now, int n, string s) {
	if (now == n) {
		dat.push_back(s);
		sum++;
		return;
	}
	for (char c = '0'; c <= '9'; c++) {
		if (now == 0 && c == '0') continue;
		if (now == 0 || abs(s[now-1] - c) <= 1) {
			string t = s;
			t += c;
			dfs(now+1, n, t);
		}
	}
}

void Main() {
	int K; cin >> K;

	int pre;
	for (int i = 1; sum < K; i++) {
		pre = sum;
		dat.resize(0);
		dfs(0, i, "");
	}
	sort(begin(dat), end(dat));
	cout << dat[K-pre-1] << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 9460
#include<stdio.h>
#include<stdlib.h>

//static const int MA=100;
#define MA 100
static const int I=(1<<21);
static const int W=0;
static const int G=1;
static const int B=2;

int n,A[MA][MA];

int prim(){
    int u,minv,i,v;
    int d[MA],p[MA],color[MA];
    
    for(i=0;i<n;i++){
        d[i]=I;
        p[i]=-1;
        color[i]=W;
    }
    d[0]=0;
    
    while(1){
        minv=I;
        u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i] && color[i]!=B){
                u=i;
                minv=d[i];
            }
        }
        
        if(u==-1)
            break;
        color[u]=B;
        
        for(v=0;v<n;v++){
            if(color[v]!=B && A[u][v]!=I){
                if(d[v]>A[u][v]){
                    d[v]=A[u][v];
                    p[v]=u;
                    color[v]=G;
                }
            }
        }
    }
    
    int sum=0;
    
    for(i=0;i<n;i++){
        if(p[i]!=-1)
            sum+=A[i][p[i]];
    }
    
    return sum;
}

int main(){
    int i,j,e;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&e);
            A[i][j]=(e==-1)?I:e;
        }
    }
    
    printf("%d\n",prim());
    return 0;
}



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

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

	int len = s.size() - 2;
	while (len > 0) {
		bool ok = true;
		for (int i = 0; i < len / 2; ++i) {
			if (s[i] != s[len / 2 + i]) { ok = false; }
		}
		if (ok) { break; }
		len -= 2;
	}

	cout << len << endl;

	return 0;
}


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct UnionFind {
    int n, cc, *u;
    UnionFind() : n(0), cc(0), u(NULL) {}
    UnionFind(int n_) : n(n_), cc(n_) {
	u = new int[n_];
	memset(u, -1, sizeof (int) * n);
    }
    UnionFind(const UnionFind &y) : n(y.n), cc(y.cc) {
	u = new int[y.n];
	memcpy(u, y.u, sizeof (int) * n);
    }
    ~UnionFind() {
	delete[] u; u = NULL;
	n = cc = 0;
    }
    friend void swap(UnionFind &x, UnionFind &y) {
	swap(x.n, y.n); swap(x.cc, y.cc); swap(x.u, y.u);
    }
    UnionFind& operator=(UnionFind y) { 
	swap(*this, y);
	return *this;
    }
    int root(int x) {
	int y = x, t;
	while (u[y] >= 0) y = u[y];
	while (x != y) { t = u[x]; u[x] = y; x = t; }
	return y;
    }
    bool link(int x, int y) {
	x = root(x); y = root(y);
	if (x == y) return false;
	if (u[y] < u[x]) swap(x, y);
	u[x] += u[y]; u[y] = x; cc--;
	return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -u[root(x)]; }
    int count() { return cc; }
};

int N;
char S[100011];
int A[100011];
int B[100011];

void MAIN() {
    scanf("%s%d", S+1, &N);
    S[0] = 'a';
    int LEN = strlen(S);
    S[LEN] = 'a';
    LEN++;
    REP (i, LEN-1) {
	A[i] = (int)S[i+1] - (int)S[i];
    }
    UnionFind U(LEN-1);
    REP (i, N) {
	int l, r;
	scanf("%d%d", &l, &r);
	U.link(l-1, r);
    }
    REP (i, LEN-1) U.link(i, LEN-2-i);
    REP (i, LEN-1) B[U.root(i)] += A[i];
    bool yes = true;
    REP (i, LEN-1) if (B[i] % 26) yes = false;

    puts(yes? "YES": "NO");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1536
#include<iostream>

using namespace std;
using ll = long long;

ll x;

ll solver(ll n){
  ll dp[n];
  dp[0] = 0;
  for(int i = 1; i <= n; ++i){
    dp[i] =  dp[i - 1] + i;
  }
  return dp[n];
}

int main(){
  cin >> x;
  ll cnt = 0;
  //cout << solver(1) << endl;
  
  while(solver(cnt) < x){
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640