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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;
struct segtree{
    static const int SEG=1<<19;
    vint dat;
    segtree():dat(SEG*2,INF){}
    void update(int k,int x){
        k+=SEG-1;
        dat[k]=x;
        while(k){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    int query(int a,int b,int k=0,int l=0,int r=SEG){
        if(r<=a||b<=l)return INF;
        if(a<=l&&r<=b)return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int N,K;
int S[555555];

vint G[555555];
vint X[555555];

int par[20][555555];
int dep[555555];
vint latte;
void dfs(int v){
    sort(all(X[v]));
    for(auto u:X[v]){
        dfs(u);
    }
    latte.pb(v);
}

signed main(){
    scanf("%lld%lld",&N,&K);
    rep(i,N){
        int p;scanf("%lld",&p);p--;S[p]=i+1;
    }
    segtree seg;
    for(int i=N-1;i>=0;i--){
        int tmp=seg.query(S[i]+1,S[i]+K);
        if(tmp<N)G[S[i]].pb(S[tmp]);
        tmp=seg.query(S[i]-K+1,S[i]);
        if(tmp<N)G[S[i]].pb(S[tmp]);
        seg.update(S[i],i);
    }


    for(int i=1;i<=N;i++)G[i].pb(0);
    vint ord;
    vint deg(N+1);
    rep(i,N+1)for(auto u:G[i])deg[u]++;
    rep(i,N+1)if(deg[i]==0)ord.pb(i);
    rep(i,ord.size()){
        int v=ord[i];
        for(auto u:G[v]){
            if(--deg[u]==0)ord.pb(u);
        }
    }
    rep(i,20)par[i][0]=-1;
    reverse(all(ord));

    for(auto v:ord){
        if(v==0)continue;
        vint lis;
        for(auto u:G[v]){
            if(u==0)continue;
            if(u<v){
                lis.pb(u);
                continue;
            }
            for(int i=19;i>=0;i--){
                if(par[i][u]>v)u=par[i][u];
            }
            lis.pb(par[0][u]);
        }
        if(lis.size()==0){
            dep[v]=dep[0]+1;
            par[0][v]=0;
        }
        else if(lis.size()==1){
            dep[v]=dep[lis[0]]+1;
            par[0][v]=lis[0];
        }
        else{
            if(dep[lis[0]]<dep[lis[1]])swap(lis[0],lis[1]);
            int a=lis[0];
            int b=lis[1];
            rep(i,20)if((dep[a]-dep[b])>>i&1)a=par[i][a];
            for(int i=19;i>=0;i--)if(par[i][a]!=par[i][b])a=par[i][a],b=par[i][b];
            if(a<=b){
                par[0][v]=lis[0];
            }
            else{
                par[0][v]=lis[1];
            }
            dep[v]=dep[par[0][v]]+1;
        }

        for(int i=0;i<19;i++){
            if(par[i][v]==-1)par[i+1][v]=-1;
            else par[i+1][v]=par[i][par[i][v]];
        }
    }

    for(int i=1;i<=N;i++)X[par[0][i]].pb(i);
    dfs(0);
    vint ans(N);
    rep(i,N){
        ans[latte[i]-1]=i;
    }
    rep(i,N)printf("%lld\n",ans[i]+1);
    return 0;
}


Measured memory_bytes: 203248
program example

	implicit none

	character(6) S
    
    read(*,*) S
    
    if(S(3:3)==S(4:4) .and. S(5:5)==S(6:6)) then
    	write(*,*) "Yes"
    else
    	write(*,*) "No"
        
    end if

end program example

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int N, ai, stamina; 
int max_range = - 1;
int min_range = INF;
int min_stamina = INF;
vector<int> X;

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

	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> ai;
		X.pb(ai);
		max_range = max(max_range, ai);
		min_range = min(min_range, ai);
	}


	for(int i = min_range; i <= max_range; i++){
		stamina = 0;
		for(int j = 0; j < N; j++){
			stamina += (X[j]-i)*(X[j]-i);
		}
		min_stamina = min(stamina, min_stamina);
	}

	cout << min_stamina << "\n";

	return 0;		
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


vector<vector<bool>> v(100, vector<bool>(100,1));



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s1, s2; cin >> s2 >> s1;
	cout << s1 << s2 << endl;
}

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

int main() {
	int n ;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)cin >> a[i];
	int b[n];
	for(int i=0;i<n;i++)b[i]=a[i];
	sort(b,b+n);
	for(int i=0;i<n;i++){
		if(a[i]<b[n/2])cout<<b[n/2]<<endl;
		else cout<<b[n/2-1]<<endl;
	}
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int n,t;
  cin >> n >> t;
  vector<pair<int,int>> vec(n);
  int i;
  for(i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    vec.at(i)=make_pair(a,b);
  }
  string s="TLE";
  sort(vec.begin(),vec.end());
  for(i=0;i<n;i++){
    if(vec.at(i).second<=t){
      cout << vec.at(i).first;
      break;
    }
  }
  if(i==n){
    cout << s;
  }
}
  


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

using namespace std;
using Graph = vector<vector<int>>;
int main(){

long long k,n,ans = 0,max=0;
cin >> k >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i)
 {
     cin >> a[i];
 } 

sort(a.begin(),a.end());

for (int i = 0; i < n-1; ++i)
{
 ans += a[i+1]-a[i];
 if ( a[i+1]-a[i]>max)
 {
     max =  a[i+1]-a[i];
 }
}
ans += k-a[n-1] + a[0];
if (k-a[n-1] + a[0] >max)
 {
     max = k-a[n-1] + a[0];
 }

ans = ans-max;
cout << ans; 
return 0;
}




Measured memory_bytes: 1920
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include<string.h>
#include<math.h>
#define M 1000000000000
using namespace std;
typedef unsigned long long ull;
int main()
{
    ull a,b,c,x,y;
    while(scanf("%llu %llu %llu %llu %llu",&a,&b,&c,&x,&y)!=EOF)
    {
        ull Min=M;
        ull sum=0;
        sum=sum+x*a+y*b;
        Min=min(Min,sum);
        //printf("%d*\n",sum);
        sum=0;

        ull B=max(x,y);
        sum=sum+2*B*c;
        Min=min(Min,sum);
        //printf("%d*\n",sum);
        sum=0;


        if(x>y)
        {
            sum=sum+2*y*c+(x-y)*a;
            //printf("%d*\n",sum);
        }
         else
        {

            sum=sum+2*x*c+(y-x)*b;

        }

        Min=min(Min,sum);
        sum=0;
        printf("%llu\n",Min);

    }
    return 0;

}



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

int main() {
  int n;
  cin>>n;
  int west[n]={},east[n]={};
  string s;
  cin>>s;
  if(s[0]=='W')
    west[0]++;
  else east[0]++;
  
  
  for(int i=1;i<n;i++){
    if(s[i]=='W'){
      west[i]=west[i-1]+1;
      east[i]=east[i-1];
    }
    else {
      west[i]=west[i-1];
      east[i]=east[i-1]+1;
    }
  }
  
  int ans=min(east[n-1]-east[0],west[n-2]);
  
  for(int i=1;i<n-1;i++)
    ans=min(ans,west[i-1]+east[n-1]-east[i]);
  cout<<ans;

  
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll dp[55][55][2555];

void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll n, score;cin >> n >> score;
	dp[0][0][0] = 1;
	ll nj, x;
	REP(i, n){
		REP(j, i+1)REP(k, score + 1){
			nj = j;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j + 1;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j;x = 2 * j;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
			nj = j - 1;x = j * j;if(j)mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
		}
	}
	cout << dp[n][0][score] << endl;
	return 0;
}


Measured memory_bytes: 55680
#include <iostream>
using namespace std;
#define FOR(i,to) for(i=0;i<(to);i++)

int main() {
	int i, j, k, l;
	int N; cin >> N;
	int t = 0, x = 0, y = 0;
	FOR(i, N) {
		int tt, xx, yy;
		cin >> tt >> xx >> yy;
		int dt = tt - t;
		int dx = xx - x;
		int dy = yy - y;
		if (dx < 0) dx *= -1;
		if (dy < 0) dy *= -1;
		int dist = dx + dy;

		if (dt < dist || dt % 2 != dist % 2) {
			cout << "No" << endl;
			return 0;
		}
		t = tt;
		x = xx;
		y = yy;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;




int main() {
	ll n, k1, k2;
	cin >> n >> k1;
	rep(_, 4) {
		cin >> k2;
		k1 = min(k1, k2);
	}
	ll ans = 0;
	ans = n / k1 + 4;
	if (n % k1 != 0) {
		ans += 1;
	}
	cout << ans << endl;
}

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

int main(){
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> p(n,k-q);
  rep(i,q){
    int a;
    cin >> a;
    a--;
    p[a]++;
  }
  rep(i,n){
    if(p[i]>0) puts("Yes");
    else puts("No");
  }
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  /*for(o=1;o<=n;o++)
    {
      if(o == n){printf("%d\n",A[o]);}
      else printf("%d ",A[o]);
    }
  */
  for(j=1;j<=n;j++)
    {   
	      key = A[j];		
	      i = j-1;
	      while(i>0 && A[i]>key)
		{
		  A[i+1]=A[i];  
		  i = i-1;
		}
	      A[i+1] = key;
	      for(k=1;k<=n;k++){
		if(k == n)printf("%d\n",A[k]);
		else printf("%d ",A[k]);
	      }
    }
  
  return 0;
}


Measured memory_bytes: 2112
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <deque>
#include <cmath>
#include <stack>
#include <ctime>
#include <queue>
#include <set>
#include <map>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
#define X first
#define Y second
#define MP make_pair
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
 
const int ppr[] = {257, 263};
const ll INF = 2e18;
const int inf = 2e9;
const int mod[] = {int(1e9 + 7), int(1e9 + 9)};
const int N = 1e6 + 123;
const ld pi = 3.141592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int n;
pii p[N];

main() {             	
//  freopen(".in", "r", stdin);                          
//  freopen(".out", "w", stdout);
 
//	srand(time(NULL));
	
	speed;
	     
	cin >> n;

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

	sort(p + 1, p + n + 1);

	for(int i = 1; i <= n; i++)
		cout << p[i].s << ' ';

    return 0;                                        
}  

Measured memory_bytes: 1664
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define continue continue
#define break break
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

double check(int a, int b, double mid){
	if(mid > M_PI / 2.0) {
		return 0.0;
	}
	long double ret;
	if(a * tan(mid) <= b) {
		ret = a * a * b - a * a * a * tan(mid) / 2.0;
	} else {
		ret = b * b / tan(mid) * a / 2.0;
	}
	return ret;
}


int main(void){
	int a, b, x; cin >> a >> b >> x;
	double ng = 0;
	double ok = M_PI / 2;
	rep(i, 100000){
		double mid = (ng + ok) / 2;
		if(check(a, b, mid) < x) ok = mid;
		else ng = mid;
	}
	printf("%.10lf\n", ok / M_PI * 180);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll a,b;
    cin >> a >> b;
    rep(i,max(a,b)){
        cout << min(a,b);
    }
    cout << endl;
}


Measured memory_bytes: 256
import itertools
n = int(input())
l = [int(each) for each in input().split()]
if len(l) < 3:
    print(0)
else:
    result = 0

    l2 = sorted(l)

    for pair in itertools.combinations(l, 3):
        if len(set(pair)) < 3:
            continue
        l2 = sorted(list(pair))
        if l2[0]+l2[1] > l2[2]:
            result += 1
    print(result)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n;
signed main(){
	n=read();
	if(n==2){puts("1");return 0;}
	int cnt=2;
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			int tmp=n/i;
			int m=n/i;
			while(m%i==0){
				m=m/i;
			}
			m=m%i;
			if(m==1)cnt++;
			if(tmp!=i){
				m=n/tmp;
				while(m%tmp==0){m=m/tmp;}
				m=m%tmp;
				if(m==1)cnt++;
			}
		}
	}
	n--;
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			int tmp=n/i;
			if(tmp!=i)cnt+=2;
			else cnt++;
		}
	}
	printf("%lld\n",cnt);
	return 0;
}


Measured memory_bytes: 256
a, b, k = map(int, input().split())
l = []
for i in range(a, min(a+k, b+1)):
    l.append(i)
for i in range(max(a, b-k+1), b+1):
    l.append(i)
l = sorted(set(l))
for i in l:
    print(i)


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

int main(void){
  int N;
  cin >> N;
  int d[110];
  for(int i=0;i<N;i++) cin >> d[i];
  int a[100];
  
  for(int i=0;i<100;i++){
    a[i]=0;
  }
  for(int i=0;i<N;i++){
    a[d[i]-1]++;
  }
  int count = 0;
  for(int i=0;i<100;i++){
    if(a[i] >= 1) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>

using ll = long long;

int main() {
    int N, M;
    std::cin >> N >> M;

    std::vector<int>A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    std::vector<std::pair<int, int>> BC(M);
    for (int i = 0; i < M; i++) {
        int b, c;
        std::cin >> b >> c;
        BC[i].first = b;
        BC[i].second = c;
    }

    std::sort(A.begin(), A.end());
    std::sort(BC.begin(), BC.end(), [](auto p1, auto p2)->bool {return p1.second > p2.second; });
    int index = 0;
    for (int i = 0; i < N;) {
        if (A[i] >= BC[index].second)break;
        bool flag = false;
        for (int j = 0; j < BC[index].first; j++) {
            if (A[i] >= BC[index].second) {
                flag = true; break;
            }
            A[i] = BC[index].second;
            i++;
            if (i >= N)break;
        }
        if (flag)break;
        index++;
        if (index >= M)break;
    }

    std::cout << std::accumulate(A.begin(), A.end(), (ll)0) << std::endl;


    return 0;
}


Measured memory_bytes: 1408
n,h = map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
maxA = A[0]
cnt=0
for i in range(n):
    if B[i]>=maxA:
        h-=B[i]
        cnt+=1
        if h<=0:
            print(cnt)
            break
    else:
        cnt+=-(-h//maxA)
        print(cnt)
        break
else:
    cnt+=-(-h//maxA)
    print(cnt)
            

Measured memory_bytes: 11296
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n, dp[maxn];
void solve(){
	scanf("%d", &n);
	int res = 0;
	forn(i, 1, n){
		int x;
		scanf("%d", &x);
		dp[x] = max(1, dp[x - 1] + 1);
		res = max(res, dp[x]);
	}
	printf("%d", n - res);
}
main () {
	int t = 1;
	//scanf("%d", &t);
	while(t--)
		solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

string s;
int dp[510][510];

bool rec(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(l > r) return dp[l][r] = true;
    bool res = false;
    if(s[l] != 'm' || s[r] != 'w') return dp[l][r] = false;
    rep(i, l + 1, r){
        if(s[i] == 'e'){
            res |= (rec(l + 1, i - 1) & rec(i + 1, r - 1));
        }
    }
    return dp[l][r] = res;
}

signed main(){
    cin >> s;
    memset(dp, -1, sizeof(dp));
    cout << (rec(0, s.size() - 1) ? "Cat" : "Rabbit") << endl;
}

Measured memory_bytes: 5216
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int read(){
	int f=1,x=0; char c=getchar();
	while (c>'9' || c<'0') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
	return f*x;
}
const int MAXN=55555;
int b,c=0,B[10000],n,d,C[10][100],f,D[10];
bool A[MAXN]; 
bool check(int e){
	int a=sqrt(e);
	int i=2;
	while((i<=a)&&(e%i!=0))i++;
	if(i<=a)return 0;
	return 1;
}
int main(){
	for(int i=2;i<=MAXN;i++)A[i]=1;
//	b=sqrt(MAXN);
	for(int i=2;i<=MAXN;i++)
		if(A[i]){
//			B[++c]=i;
			f=i;
//			if(i>=100) C[f%100][++D[f%100]]=f;
			D[f%10]++;
			C[f%10][D[f%10]]=f;
//			else C[f][++D[f]]=f;
			int a=i+i;
			while(a<=MAXN){
				A[a]=0;
				a+=i;
			}
		}
	cin>>n;
//	cout<<D[0]<<endl;
//	for(int i=0;i<10;i++)cout<<D[i]<<" ";
	for(int i=1;i<10;i++)
		if(i%2!=0&&D[i]>=n){
			for(int j=1;j<=n;j++)printf("%d ",C[i][j]);
			break;
		}
	return 0;
}

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


P_n = [i for i in range(105) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Measured memory_bytes: 9092
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
vector<pair<int, int>> edge[100000];
bool visit[100000];
int ans[100000];


void dfs(int u, int parity) {
	if (visit[u])return;
	visit[u] = true;

	if (parity)ans[u] = 1;

	for (auto e: edge[u]) {
		dfs(e.first, parity ^ e.second);
	}
}


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

	cin >> n;
	rep(i, n-1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		c &= 1;
		edge[a].emplace_back(b, c);
		edge[b].emplace_back(a, c);
	}

	dfs(0, 0);

	rep(i,n) {
		cout << ans[i] << endl;
	}




	return 0;
}

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

int main(){
  string S;
  cin>>S;
  int i;
  for(i=2; i<S.size(); i+=2){
  if(S.substr(0,(S.size()-i)/2)
     ==S.substr((S.size()-i)/2, (S.size()-i)/2)){break;}
  }
  cout<<S.size()-i<<endl;
}

Measured memory_bytes: 256
def main():
    r, d, x = map(int, input().split())
    a = d/(1-r)
    ans = [x]
    for i in range(10):
        ans.append(r*(ans[-1])-d)
    # print(ans[1:])
    for i in range(1, 11):
        print(ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll N, C;
	cin >> N >> C;
	vector<vll> D(C, vll(C)), c(N, vll(N));
	rep(i, C) rep(j, C) cin >> D[i][j];
	rep(i, N) rep(j, N) {
		cin >> c[i][j];
		--c[i][j];
	}

	vll dif0(C), dif1(C), dif2(C);
	rep(loop, C) {
		ll t0 = 0, t1 = 0, t2 = 0;
		rep(i, N) rep(j, N) {
			if ((i + j) % 3 == 0) t0 += D[c[i][j]][loop];
			if ((i + j) % 3 == 1) t1 += D[c[i][j]][loop];
			if ((i + j) % 3 == 2) t2 += D[c[i][j]][loop];
		}
		dif0[loop] = t0, dif1[loop] = t1, dif2[loop] = t2;
	}
	

	ll ans = INF;
	rep(i, C) rep(j, C) rep(k, C) {
		if (i != j && j != k && k != i) {
			ans = min(ans, dif0[i] + dif1[j] + dif2[k]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176
n,l,t =  map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
las = [0]*n
for i in range(n):
  las[i] = (x[i][0]+(t if x[i][1]==1 else -t))%l
han = []
for i in range(1,n):
  if x[i][1] != x[0][1]:
    if x[0][1] ==1:
      han.append(x[i][0]-x[0][0])
    else:
      han.append(l-x[i][0]+x[0][0])
su = 0
t*=2
su += (len(han))*(t//l)
t%=l
for i in han:
  if t> i:
    su+=1
if x[0][1] == 2:
  su=(-su)%n
else:
  su%=(n)
ii = las[0]
las.sort()
basyo = las.index(ii)
for i in range(basyo+1,n):
  if las[basyo] == las[i]:
    if x[0][1] == 2:
      basyo+=1
  break
las.extend(las)
ans = [0]*n
z = 0
for i in range(basyo,basyo+n):
  ans[(su+z)%n] = las[i]
  z += 1
for i in ans:
  print(i)

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

using namespace std;

int k;
vector<long long> V;

void Generator(long long n)
{
    if (n > 3234566667)
    {
        return;
    }
    V.push_back(n);
    int g = n % 10;
    if (g)
    {
        Generator(n * 10 + g - 1);
    }
    Generator(n * 10 + g);
    if (g < 9)
    {
        Generator(n * 10 + g + 1);
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for (int i = 1; i <= 9; ++i)
    {
        Generator(i);
    }
    sort(V.begin(), V.end());
    cin >> k;
    cout << V[k - 1];
    return 0;
}

Measured memory_bytes: 1400
import heapq

N, M = map(int, input().split())
A = [-int(_) for _ in input().split()]
heapq.heapify(A)

tmp = 0
for m in range(M):
    div = -heapq.heappop(A)
    div = div // 2
    heapq.heappush(A, -div)
print(-sum(A))

Measured memory_bytes: 14180
from functools import reduce

n, k = map(int, input().split())
p = list(map(int, input().split()))

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(max_mean, cur)
print(max_mean)


Measured memory_bytes: 25308
#include <bits/stdc++.h>
#include <random>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;
 
int main() {
	random_device rd;
	mt19937 mt(rd());
	int N, M; cin >> N >> M;
	vector<string> a(N);
	rep(i, N) cin >> a[i];
	rep(t, 100000) {
		vector<vector<bool>> b(M, vector<bool>(M, true));
		rep(j1, M) for (int j2 = j1; j2 < M; j2++)
			rep(i, N) if (a[i][j1] != a[N - 1 - i][j2]) b[j1][j2] = false;
		vector<bool> dp(1<<M);
		dp[0] = true;
		rep(S, 1<<M) if (dp[S])
			rep(j1, M) for (int j2 = j1 + 1; j2 < M; j2++)
				if (!(S>>j1 & 1) && !(S>>j2 & 1) && b[j1][j2])
					dp[S | 1<<j1 | 1<<j2] = true;
		bool ok = false;
		if (M % 2 == 0) ok = dp.back();
		else {
			rep(j, M) if (dp[(1<<M) - 1 - (1<<j)] && b[j][j]) ok = true;
		}
		if (ok) {
			cout << "YES" << endl;
			return 0;
		}
		shuffle(a.begin(), a.end(), mt);
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char s[100010];

int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	//give the fucking vjudge flying fucking
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='p')
		{
			ans--;
		}
	}
	printf("%d\n",ans+n/2);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main
 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[30];
		for (int i = 0; i < 28; i++){
			int n = sc.nextInt();
			x[n - 1]++;
		}
		int i = 0;
		int flag = 2;
		while (flag > 0){
			if (x[i] == 0){
				System.out.println(i + 1);
				flag--;
			}
			i++;
		}
	}

}



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

int main() {
	int N,K;
	cin >> N >> K;
	vector<int> vec(N);
	for(int i=0; i<N; i++){
		cin >> vec.at(i);
	}

	sort(vec.begin(),vec.end());

	int x=0;
	for(int i=0; i<K; i++){
		x = x + vec.at(i);
	}

	cout << x << endl;
}

Measured memory_bytes: 3576
#include <cstdio>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n,m;
	if (!scanf("%d%d", &n, &m)){
		return 1;
	}
	if (n > 9 || m > 9){
		printf("-1\n");
		return 0;
	}
	printf("%d\n", n*m);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
#include <map>
#include <ctype.h>

using namespace std;

#define loop(i,n) for (i = 0; i < n; ++i) 
#define loop2(i,k,n) for (i = k; i <= n; ++i) 
#define loopb(i,k,n) for (i = k; i >= n; --i)
#define remove_space(x) x.erase(remove(x.begin(), x.end(), ' '), x.end())
typedef long long ll;

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

    int n;
    cin >> n;

    int arr[n];

    int i;
    loop(i,n){
    	cin >> arr[i];
    }

    int sum = 0;
    for(int i=0; i<n; i++){
    	for(int j=i+1; j<n; j++){
    		sum += (arr[i]*arr[j]);
    	}
    }

    cout << sum;
	return 0;
}

Measured memory_bytes: 256
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = -1

def solve():
    for a in A:
        if len(set(a)) == 1:
            return True
    for a in zip(*A):
        if len(set(a)) == 1:
            return True

    return len({A[0][0], A[1][1], A[2][2]}) == 1 or len({A[0][2], A[1][1], A[2][0]}) == 1

if solve():
    print("Yes")
else:
    print("No")

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

#define max 100
char map[100][100];
bool visited[100][100];

int main(void){

	while( 1 ) {
		int pos[] = {0, 0};
		int w, h;
		cin >> h >> w;
		if( !(w|h) ) break;

		for(int i = 0; i < max * max; i++)
			visited[ i / max ][ i % max ] = false;
		for(int i = 0; i < h; i++)
			cin >> map[i];

		while( !(visited[ pos[0] ][ pos[1] ] == true || map[ pos[0] ][ pos[1] ] == '.') ) {
			visited[ pos[0] ][ pos[1] ] = true;
			switch( map[ pos[0] ][ pos[1] ] ) {
				case '>':
					pos[1] ++;
					break;
				case '<':
					pos[1] --;
					break;
				case '^':
					pos[0] --;
					break;
				case 'v':
					pos[0] ++;
					break;
			}
		}

		if( visited[ pos[0] ][ pos[1] ] == true )
			cout << "LOOP" << endl;
		else
			cout << pos[1] << " " << pos[0] << endl;

	}

	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
int dp[101][101];
int subsequenceCount(string S, string T)
{
   int i,j;
   for(i=0;i<=100;i++) for(j=0;j<=100;j++) dp[i][j]=(int)(j==0);
    dp[0][1]=(S[0]==T[0]);
   for(i=1;i<S.size();i++)
    for(j=1;j<=T.size();j++)
    {
      dp[i][j]=dp[i-1][j];
      if(S[i]==T[j-1])
        dp[i][j]+=dp[i-1][j-1];
    }

    return dp[S.size()-1][T.size()];
}

int main() {
       ios::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
       string s;
       cin>>s;
       ll ans=0;
       stack<char> st;
       for(auto it:s)
       {
        if(!st.empty() and st.top()!=it)
          {ans++;st.pop();}
        else
          st.push(it);
       }
       cout<<2*ans;
       return 0;

}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] a = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			sum += a[i];
		}
		
		Arrays.sort(a);
		
		if(a[n-m] >= (double)sum/(4*m)) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int x;
	cin>>x;
	int MAX=0;
	for(int i=0;i<=sqrt(x);i++) {
		for(int j=0;j<=sqrt(x);j++) {
			if(pow(i,j)<=x) {
				MAX=max(MAX,(int)pow(i,j));
			}
		}
	}
	cout<<MAX<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

bool f[10];

bool check(int x){
    while(x>0){
        if (f[x%10])
            return 0;
        x /= 10;
    }
    return 1;
}

int main() {
    int n, k;
    cin >> n >> k;
    REP(i,k){
        int a;
        cin >> a;
        f[a] = 1;
    }

    while(1){
        if (check(n)){
            cout << n << endl;
            return 0;
        }
        n++;
    }

    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0; cnt = 0; tmp = float('inf'); flag = False
    for a in A:
        ans += abs(a)
        tmp = min(tmp, abs(a))
        if a < 0:
            cnt += 1
        elif a == 0:
            flag = True
        else:
            continue
    if cnt%2 == 0:
        flag = True
    if flag:
        print(ans)
    else:
        print(ans - 2*tmp)

if __name__ == "__main__":
    main()


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> drink;
	for (int i = 0, a, b; i < n; i++) {
		cin >> a >> b;
		drink.emplace_back(a, b);
	}
	sort(drink.begin(), drink.end(), [](auto &a, auto &b) {
		return a.first < b.first;
	});

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		if (drink[i].second < m) {
			m -= drink[i].second;
			sum += (long long) drink[i].first * drink[i].second;
		} else {
			sum += (long long) drink[i].first * m;
			break;
		}
	}
	cout << sum << endl;
}


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

int main() {
	long long a,b,k;cin>>a>>b>>k;
	if(a>=k){
		a -=k;
	} else {
		b-=k-a;
		a=0;
	}
	cout << a <<" "<<max(b,0LL) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    
    res = max({
        a*c,
        a*d,
        b*c,
        b*d
    });
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int k,s; cin >> k >> s;
	int ans=0;
	rep(i,k+1) {
		rep(j,k+1) {
			int m=s-i-j;
			if(0<=m&&m<=k) ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3580
N = int(input())
S = [input() for x in range(N)]

dic = {
    "AC":0,
    "WA":0,
    "TLE":0,
    "RE":0
}

ac = sum(1 for x in S if x == "AC")
wa = sum(1 for x in S if x == "WA")
tl = sum(1 for x in S if x == "TLE")
re = sum(1 for x in S if x == "RE")

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tl))
print("RE x " + str(re))

Measured memory_bytes: 79564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string S;
int K, dp[310][310][310];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> S >> K;
    for(int i = 0; i < S.length(); i++) dp[i][i][0] = 1;
    for(int i = 0; i + 1 < S.length(); i++) dp[i][i + 1][S[i] != S[i + 1]] = 2;
    for(int k = 0; k <= K; k++){
        for(int len = 0; len < S.length(); len++){
            for(int l = 0; l + len < S.length(); l++){
                if(l == 0 || l + len - 1 == S.length()) continue;
                if(S[l - 1] == S[l + len + 1]) chmax(dp[l - 1][l + len + 1][k], dp[l][l + len][k] + 2);
                else chmax(dp[l - 1][l + len + 1][k + 1], dp[l][l + len][k] + 2);
                chmax(dp[l - 1][l + len][k], dp[l][l + len][k]);
                chmax(dp[l][l + len + 1][k], dp[l][l + len][k]);
            }
        }
    }
    int ans = 0;
    for(int l = 0; l < S.length(); l++){
        for(int r = l; r < S.length(); r++){
            for(int k = 0; k <= K; k++){
                chmax(ans, dp[l][r][k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 112896
#include <bits/stdc++.h>
using namespace std;
 
int main () {
 
    string s;
    cin >> s;
 
    int K;
    cin >> K;
 
    vector<string> strs;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= K; j++) {
 
            if (i + j > s.size()) continue;
            strs.push_back(s.substr(i, j));
        }
    }
 
    sort(strs.begin(), strs.end());
    strs.erase(unique(strs.begin(), strs.end()), strs.end());
 
    cout << strs[K - 1] << endl;
 
    return 0;
}

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

int main(){
	int n;
  	cin >> n;
  
  	int i = 1;
  	int ans = 0;  
  	while(i <= n){
    	int a;
      	cin >> a;
      	
      	if(i % 2 == 1 && a % 2 == 1) ans++;
      	i++;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
                continue;
            }
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
               continue;
            }
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

li a, b, c;

inline bool ok() {
	rep(i, b + 1) {
		if ((a * i) % b == c ) {
			return true;
		}
	}
	return false;
}


int main(void)
{
	cin >> a >> b >> c;

	cout << (ok() ? "YES" : "NO") << endl;

	return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' '

int main() {
    int r;
    cin >> r;
    int d;
    cin >> d;
    int x_2000;
    cin >> x_2000;

    int x_next;
    REP(i, 10){
        x_next = r * x_2000 - d;
        PRINT(x_next)
        x_2000 = x_next;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
const int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };

int cnt = 0;
int w, h;
char tab[101][101];

void dfs(int x, int y, char c){
	tab[y][x] = '.';
	rep(i, 4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx >= 0 && nx < w&&ny >= 0 && ny < h&&tab[ny][nx] == c){
			dfs(nx, ny, c);
		}
	}
}

void solve(){
	rep(i, h){
		rep(j, w){
			cin >> tab[i][j];
		}
	}
	cnt = 0;
	rep(i, h){
		rep(j, w){
			if (tab[i][j] != '.'){
				cnt++;
				dfs(j, i, tab[i][j]);
			}
		}
	}
	cout << cnt << endl;
}

int main(){
	while (1){
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		solve();
	}
}

Measured memory_bytes: 1636
t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    X = list(map(int, input().split()))
    li = []
    for j in range(n-1):
        li.append(X[j+1]-X[j])
    li.sort(reverse=True)
    print(sum(li[(k-1):]))


Measured memory_bytes: 21304
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll p[n];rep(i,0,n)cin>>p[i];
	ll ans=0;
	rep(i,1,n-1){
		vll v;
		v.pb(p[i-1]),v.pb(p[i]),v.pb(p[i+1]);
		sort(all(v));
		if(v[1]==p[i])ans++;
		v.clear();
	}
	cout<<ans;
	
	
	return 0;
}



Measured memory_bytes: 256
def minandmax(bottom,up,mod): #bottom< n < upなるmodで割り切れるnの値の最大値と最小値を返す
    if bottom%mod == 0:
        mnm = bottom
    else:
        mnm = bottom + (mod-bottom%mod)
        if mnm > up:
            mnm = None
    if up%mod == 0:
        mxm = up
    else:
        mxm = up - up%mod
        if mxm < bottom:
            mxm = None
    ans = [mnm,mxm]
    return ans

k = int(input())
a = list(map(int,input().split()))
i = k-1
bottom = 2
up = 2

check = True
if a[-1] != 2:
    check = False
while i >= 1 and check:
    nbottom = minandmax(bottom,up+a[i]-1,a[i-1])[0]
    nup = minandmax(bottom,up+a[i]-1,a[i-1])[1]
    if nbottom == None and nup == None:
        check = False
    elif nbottom == None:
        nbottom = nup
    elif nup == None:
        nup = nbottom
    i += -1
    bottom = nbottom
    up = nup

if check:
    bottom = minandmax(bottom,bottom+a[0]-1,1)[0]
    up = minandmax(up,up+a[0]-1,1)[1]
    print(bottom,up)
else:
    print("-1")

Measured memory_bytes: 14428
#include<bits/stdc++.h>
using namespace std;
int a[200005],c[200005],n,k;
int main(){
	scanf("%d%d",&n,&k);
	register int i,j,t,s,f;
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(j=1;j<=k;j++){
		memset(c,0,sizeof(c));
		for(i=1;i<=n;++i){
			++c[max(1,i-a[i])];
			--c[min(n+1,i+a[i]+1)];
		}
		s=0,f=1;
		for(i=1;i<=n;i++){
			s+=c[i];a[i]=s;
			if(a[i]<n) f=0;
		}
		if(f) break;
	}
	for(i=1;i<=n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}

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

int main(){
  int N;  cin >> N;
  int ans = 1;
  for(int i = 0;i < 7;i++){
    if(ans * 2 <= N)ans = ans*2;
    else{
      cout << ans << endl;
      return 0;
    }
  }
}

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

int main(){
	long N,M;
	cin>>N>>M;
	long ans;
	if(N<M/2){
		ans=N;
		ans+=(M-2*N)/4;
	}
	else{
		ans=M/2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    str = input()

    max_len = 0
    len_acgt = 0
    for i in range(len(str)):
        if str[i] in "ACGT":
            len_acgt += 1
        else:
            len_acgt = 0

        max_len = max(max_len, len_acgt)

    print(max_len)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string n;
  cin >> n;
  
  if(n == "Sunny")
  	cout << "Cloudy" << endl;
  
  if(n == "Cloudy")
  	cout << "Rainy" << endl;
  
  if(n == "Rainy")
  	cout << "Sunny" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N;
long long d[105];
int main(){
	cin >> N;
	rep(i, N) cin >> d[i];
	long long ans = 0;
	for(long long i = 0; i < N; i++) {
		for(long long j = i + 1; j < N; j++) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3544
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

sc = [LIST() for _ in range (M)]

if N == 1 and M == 0:
  print(0)
  exit()
  
ans = [-1]*N

for s, c in sc:
  if s == 1 and c == 0 and N >= 2:     #一桁目が0
    print(-1)
    exit()
  if ans[s-1] != -1 and ans[s-1] != c:     #既に同じ桁に同じ数字。
    print(-1)
    exit()
  if ans[s-1] == -1:
    ans[s-1] = c
    
if ans[0] == -1:
  ans[0] = 1
    
for i in range(N):
  if ans[i] == -1:
    ans[i] = 0
    
for n in ans:
  print(n, end="")
print()

Measured memory_bytes: 5192