akhauriyash/Code-Regression huggingface dataset:
<?php
  $n = trim(fgets(STDIN));
  $s = trim(fgets(STDIN));
  $cnt=[];
  for($i=0; $i<strlen($s); $i++){
      $cnt[$s[$i]]++;
  }
//   print_r($cnt);
  
  for($i=1; $i<$n; $i++){
      $ans = [];
      $s = trim(fgets(STDIN));
      $cnt2 = [];
      for($j=0; $j<strlen($s); $j++){
          $cnt2[$s[$j]]++;
      }
      
      foreach($cnt2 as $key => $num){
          if(isset($cnt[$key])){
              $ans[$key] = min($num, $cnt[$key]);
          }
      }
      $cnt = $ans;
  }
  if($n == 1){
      $ans = $cnt;
  }
  if(count($ans) == 0){
      echo "";
      exit;
  }
  ksort($ans);
//   print_r($ans);
  foreach($ans as $k => $d){
      for($i=0; $i<$d; $i++){
          echo $k;
      }
  }

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

int main(){
    ll k, a, b; cin >> k >> a >> b;
    if(b-a<=2){
        cout << k+1 << endl;
        return 0;
    }

    if(k<a){
        cout << k+1 << endl;
    }else{
        ll num = k - (a-1);
        ll tmp = num/2;
        if(num%2==0){
            cout << a + (b-a)*tmp << endl;
        }else{
            cout << a + (b-a)*tmp + 1 << endl;
        }
    }
}

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

using namespace std;

int main()
{
    int n, a[25];
    scanf("%d", &n);
    for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
    int cnt =0;
    for(int i = 1; i < n - 1; i ++)
    {
        if(a[i] > a[i - 1] && a[i] < a[i + 1] || a[i] < a[i - 1] && a[i] > a[i + 1]) cnt ++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int main()
{
	char s[10000]={};

	while(cin>>s){
	int c1=0,c2=0;
	rep(i,strlen(s)-2)if(s[i]=='J' && s[i+1]=='O' && s[i+2]=='I')c1++;
	rep(i,strlen(s)-2)if(s[i]=='I' && s[i+1]=='O' && s[i+2]=='I')c2++;

	cout<<c1<<endl;
	cout<<c2<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N,M,K;
int main(){
    cin >> N >> M >> K;
    COMinit();
    ll com = COM(N*M-2,K-2);
    ll ans = 0;
    rep(d,N) ans += d*(N-d)*M*M, ans %= MOD;
    rep(d,M) ans += d*(M-d)*N*N, ans %= MOD;
    cout << (ans*com)%MOD << '\n';
}

Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

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


//void dfs(int x, int y)
//{
    //int nx,ny;
    //O[x][y] = 0; //今いるところをゼロに
    //REP(i,4)
    //{
        //nx = x + dx[i];
        //ny = y + dy[i];
        //if(0 <= nx && nx <= H && 0 <= ny && ny <= W)
        //{
            //dfs(nx, ny);
        //}
    //}
//}

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int H,W;
    cin >> H >> W;

    int O[H][W];

    REP(i,H)
    {
        string s;
        cin >> s;
        REP(j,W)
        {
            if(s[j] == '.') O[i][j] = 0;
            else O[i][j] =1;
        }
    }
    bool ok = 1;

    REP(i,H)
    {
        REP(j,W)
        {
            if(O[i][j] == 1)
            {
                bool check = 0;
                REP(k,4)
                {
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    if(0 <= nx && nx < H && 0 <= ny && ny < W)
                    {
                        if(O[nx][ny] == 1) check = 1;
                    }
                }
                if(check == 0) ok = 0;
            }
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;





}


Measured memory_bytes: 256
//ALLAH bachiye naw plz,amr 1400+ rating tulai daw plzz
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int x,y,c,t;
  cin>>x>>y;
  if(y&1) { cout<<"No\n"; }
  else {
    c=x+x-(y/2);
    t=x-c;
    if(t>=0 && c>=0) { cout<<"Yes\n"; }
    else { cout<<"No\n"; }
  }
  return 0;
} 

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

int main(){
    int N, D, count = 0;
    double dist;
    std::cin >> N >> D;
    vector<vector<double>> points(N);
    vector<double> a_point(D);
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < D; j++){
            std::cin >> a_point[j];
        }
        points[i] = a_point;
    }
    //input終了
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            dist = 0.0;
            for(int d = 0; d < D; d++){
                dist = dist + (points[i][d] - points[j][d])*(points[i][d] - points[j][d]);
            } 
            dist = sqrtf(dist);

            //std::cout << dist << " " << floorf(dist) << "\n";
            if(dist == floorf(dist)){
                count++;
            }
        }
    }

    std::cout << count;

}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int a[3][N], dp[3][N];

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[j][i];
        }
    } 

    dp[0][0] = a[0][0];
    dp[1][0] = a[1][0];
    dp[2][0] = a[2][0];
    for (int i = 1; i < n; i++) {
        dp[0][i] = a[0][i] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = a[1][i] + max(dp[0][i - 1], dp[2][i - 1]);
        dp[2][i] = a[2][i] + max(dp[0][i - 1], dp[1][i - 1]);
    }

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        ans = max(ans, dp[i][n - 1]);
    }

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


Measured memory_bytes: 4992
n = int(input())
a = list(map(int,input().split()))

even =[]
for i in range(n):
    if a[i]%2 == 0:
        even.append(a[i])
        
ans =[]
for i in range(len(even)):
    if even[i]%3 == 0:
        ans.append(even[i])
        
for i in range(len(even)):
    if even[i]%5 == 0:
        ans.append(even[i])
        
print((set(even)==set(ans))*"APPROVED" or "DENIED")

Measured memory_bytes: 3064
// Problem : B - Count ABC
// Contest : AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_b
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <cmath>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

int n;
string s;

void input() {
  cin >> n >> s;
}

void solve1() {
  int ans = 0;

  for (int i = 0; i < n - 2; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ++ans;
  }
  
  cout << ans;
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;
  
  input();
  solve1();
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b,c; cin >> a >> b >> c;
  int del = a-b;
  
  int ans = c>=del ? c-del:0;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int Nmax = 100010;
const int Tmax = 200010;

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

    vector<int> s(Nmax), t(Nmax), c(Nmax), cnt(Tmax);
    rep(i, n) {
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
    }

    rep(i, C) {

        vector<int> v(Tmax);

        rep(j, n) {
            if(c[j] == i) {
                v[2*s[j]-1]++;
                v[2*t[j]]--;
            }
        }

        rep(j, Tmax-1) {
            v[j+1] += v[j];
        }

        rep(j, Tmax) {
            if(v[j] > 0) {
                cnt[j]++;
            }
        }
    }

    int ans = 0;
    rep(i, Tmax) {
        if(ans < cnt[i]) {
            ans = cnt[i];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };
int p[5005];
vector<P>V;
int dp[5005][5005];
int rmin[5005];
signed main() {
	int n, a, b; cin >> n >> a >> b;
	rep(i, n)cin >> p[i];
	rep(i, n)V.push_back(P(p[i], i));
	sort(V.begin(), V.end());
	rep(i, 5005)rep(j, 5005)dp[i][j] = inf;
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		int pos = V[i - 1].second;
		rep(j, n + 1)rmin[j] = dp[i - 1][j];
		rep(j, n)rmin[j + 1] = min(rmin[j], rmin[j + 1]);
		rep(j, n + 1) {
			if (j == pos)dp[i][j] = rmin[j];
		else if (j < pos) {
			dp[i][j] = rmin[j] + b;
		}
		else {
			dp[i][j] = rmin[j] + a;
		}
		}
	}
	int ans = inf;
	rep(i, n + 1)ans = min(ans, dp[n][i]);
	cout << ans << endl;
}

Measured memory_bytes: 196224
/////////////////////////////////TEST CASES////////////////////////////////////
/*
4
C D C D
C C D C
D D D D
C D D D
7
C D D C D D D
C D D C D D D
D D D D D D C
D C D C D D D
D D D C D C D
C D D C D C C
C D C D C C C
5
D C D C C
D D C C D
D D C C D
D D D C C
C D C C D
5
D C D C D
C C C D D
D D C C D
C D D D C
D C D C C
*/
/////////////////////////////////////CODE/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 1000000000;
ll MOD = 1000000007;
void solve()
{
	string s;
	cin >> s;
	ll ans = 0, cnt = 0;
	FOR(i, 0, s.length())
	{
		if (s[i] == 'R')
			cnt++;
		else
		{
			ans = max(cnt, ans);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans;
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 3648
#![allow(unused_macros)]

macro_rules! line {
    () => {{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf
    }};
}
macro_rules! line_as_vec {
    ( $t:ty ) => {
        line!()
            .trim()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<$t>>()
    };
}
macro_rules! input {
    { $( $i:ident : $t:ty ),* } => {
        let ( $( $i ),* ) = match &line!().split_whitespace().collect::<Vec<_>>()[..] {
            &[ $( $i ),* ] => ( $( $i.parse::<$t>().unwrap() ),* ),
            _ => panic!(),
        };
    };
}

fn main() {
    input!(_n: u64, k: u64);
    let a = line_as_vec!(usize);

    let mut ft = vec![true; a.len()];
    let mut seq = vec![];
    let mut cur = 0;

    while ft[cur] {
        seq.push(cur + 1);

        ft[cur] = false;
        cur = a[cur] - 1;
    }

    let plp = (&seq).into_iter().position(|x| x == &(cur + 1)).unwrap();
    let pre_seq = &seq[0..plp];
    let lp_seq = &seq[plp..seq.len()];

    //println!("{:?} {:?} {:?}", seq, pre_seq, lp_seq);

    println!(
        "{}",
        if k < pre_seq.len() as u64 {
            pre_seq[k as usize]
        } else {
            lp_seq[(k - pre_seq.len() as u64) as usize % lp_seq.len()]
        }
    )
}


Measured memory_bytes: 6224
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<vector>
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
const ll mod=1000000007,MAX=10001;
int n,A[10001];ll ans;
int prime[1000001],primesize,bak[1000001];
bool isprime[1000001];
int PRM;
inline void getlist(const int listsize)
{
    memset(isprime,1,sizeof(isprime));
    isprime[1]=0;
    for(rg int i=2;i<=listsize;i++)
    {
        if(isprime[i]==1)prime[++primesize]=i,bak[i]=primesize;//print(i),putchar(' '),print(primesize),putchar('\n');
        for(int j=1;j<=primesize&&(ll)i*(ll)prime[j]<=(ll)listsize;j++)
        {
           isprime[i*prime[j]]=0;
           if(i%prime[j]==0)break;
        }
    	if(i==1000)PRM=primesize;
    }
}
#define LL long long
inline LL pow(LL x,LL y)
{
	LL res=1;
	for(;y!=0;y>>=1,x=x*x%mod)if(y&1)res=(res*x)%mod;
	return res;
}
int sum[10001][501],extra[10001];
int all[1000001];
ll fac[1000001],inv[1000001];
int main()
{
	fac[0]=1;
	for(int i=1;i<=1000000;i++)fac[i]=(fac[i-1]*i)%mod;
	inv[1000000]=pow(fac[1000000],mod-2);
	for(int i=1000000-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	getlist(1000000);
	read(n);
	for(rg int i=1;i<=n;i++)
	{
		read(A[i]);
		for(rg int j=1;j<=PRM;j++)
		{
			while(A[i]%prime[j]==0)
			{
				A[i]/=prime[j],sum[i][j]++;
				maxd(all[j],sum[i][j]);
			}
		}
		if(A[i]!=1)extra[i]=A[i],all[bak[A[i]]]=1;//print(A[i]),putchar(' ');
	}
	ll qt=1;
	for(rg int i=PRM+1;i<=primesize;i++)if(all[i])qt=qt*prime[i]%mod;
	for(rg int i=1;i<=n;i++)
	{
		ll dq=1;
		for(rg int j=1;j<=PRM;j++)
		{
			int su=all[j]-sum[i][j];
			for(rg int k=1;k<=su;k++)dq=dq*prime[j]%mod;
		}
		dq=dq*qt%mod;
		if(extra[i])dq=dq*(inv[extra[i]]*fac[extra[i]-1]%mod)%mod;
		ans+=dq;
	}
	print(ans%mod);
	return 0;
}

Measured memory_bytes: 43264
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<sstream>
using namespace std;
#define Min(x,y) ((x<y)?x:y)
typedef struct word{
	int n;
	char s[25];
}WORD;
WORD x[30][1000];
int comp(const void *p,const void *q){
	WORD *a=(WORD*)p,*b=(WORD*)q;
	if(a->n==b->n)return strcmp(a->s,b->s);
	else return b->n - a->n;
}

int main(){
	int i,j,n,wn[30],a;
	char sen[1030],str[25],k;
	
	while(1){
		scanf("%d\n",&n);
		if(n==0)break;
		memset(wn,0,sizeof(wn));
		while(n--){
			memset(sen,0,sizeof(sen));
			memset(str,0,sizeof(str));
			fgets(sen,1025,stdin);
			//printf("A:%s",sen);
			istringstream ss(sen);
			while(ss>>str){
				//printf("%s\n",str);
				a=str[0]-'a';
				for(i=0;i<wn[a];i++){
					if(strcmp(str,x[a][i].s)==0){
						x[a][i].n++;
						break;
					}
				}
				if(i==wn[a]){
					x[a][wn[a]].n=1;
					strcpy(x[a][wn[a]++].s,str);
					memset(str,0,sizeof(str));
				}
			}
			/*while(sscanf(sen,"%s",str)!='\0'){
				printf("%s\n",str);
				a=str[0]-'a';
				strcpy(x[a][wn[a]++].s,str);
				memset(str,0,sizeof(str));
			}*/
		}
		scanf("%c\n",&k);
		a=k-'a';
		if(wn[a]==0){
			printf("NA\n");
			continue;
		}
		qsort(x[a],wn[a],sizeof(WORD),comp);
		n=Min(5,wn[a]);
		for(i=0;i<n;i++){
			printf("%s%s",x[a][i].s,(i==n-1)?"\n":" ");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
def search(x, l):
    if L == 0: n = 0
        
    elif x == L[l]: n = p[l]
    elif x == 1: n = 0
    elif 1 < x < L[l-1]: n = search(x-1, l-1)
    elif x == L[l-1]+1: n = p[l-1]
    elif x == L[l-1]+2: n = p[l-1]+1
    else: n = search(x-(2+L[l-1]), l-1) + 1 + p[l-1]
    
    return n
        

N, X = map(int, input().split())

L = [1] * (N+1)
p = [1] * (N+1)

for i in range(1, N+1):
    L[i] = 2 * L[i-1] + 3
    p[i] = 2 * p[i-1] + 1

print(search(X, N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    rep(i,n){
        if(i==a[a[i]])ans++;
    }
    cout << ans/2 << endl;
    return 0;

}



Measured memory_bytes: 4048
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int ar[300005];
int main(){
  cin>>n;
  n*=3;
  REP(i,n) cin>>ar[i];
  sort(ar,ar+n);
  int n3=n/3;
  lint res=0;
  for(int i=n-2;i>=n3;i-=2) res+=ar[i];
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    printf("%.4f\n", sqrt(pow(c-a, 2)+pow(d-b,2)));
    return 0;
}


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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a)a, rreps(i,  0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


int solve(long long N, std::vector<long long> A, std::vector<long long> B) {
	int res = 0;
	rep(i, N) {
		int t = min(A[i], B[i]);
		res += t;
		B[i] -= t;
		t = min(A[i+1], B[i]);
		res += t;
		B[i] -= t;
		A[i+1] -= t;
	}
	return res;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	std::vector<long long> A(N+1);
	for(int i = 0 ; i < N+1 ; i++){
		scanf("%lld",&A[i]);
	}
	std::vector<long long> B(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&B[i]);
	}
	cout << solve(N, std::move(A), std::move(B)) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int K, T;
    cin >> K >>T;
    vector<int> A(T);
    rep(i, T)
        cin >> A[i];

    if(T==1) {
        cout << K-1 << endl;
        return 0;
    }

    sort(A.rbegin(), A.rend());
    int64_t ret = A[0];
    int64_t sum = 0;
    rep(i, A.size()-1) {
        sum += A[i+1];
    }
    if(ret-sum-1 <= 0) {
        ret = 0;
    } else {
        ret = ret-sum-1;
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 3140
#include<iostream>

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

    char start = 'A';
    char anum = 25;
    for(int i = 0; i < s.size(); i++){
	int num = s[i] - start;
	// std::cout << num << std::endl;
	char next;
	if(anum - num < n){
	    next = start;
	    next += n - anum + num - 1;
	    std::cout << next;
	}else{
	    next = s[i];
	    next += n;
	    std::cout << next;
	}
    }
    std::cout << std::endl;
    return 0;
}



Measured memory_bytes: 3644
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >>s;
    if(s == "Sunny")
        cout <<"Cloudy";
    else if(s == "Cloudy")
        cout <<"Rainy";
    else 
        cout <<"Sunny";
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n ;
int a[10];

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> n ;
    int now = 2;
    int i = 1;
    while ( now <= pow(2,7)) {
        a[i] = now;
        now*=2 ;
        i++;
    }
    a[0] = 1 ;
    for (int i =1 ; i <= 10 ; i++) {
        if ( a[i] == n ) {
            cout << n ;
            return 0;
        } else {
            if ( a[i] > n ) {
                cout << a[i-1];
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int n = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '+') {
                n++;
            } else {
                n--;
            }
        }
        System.out.println(n);
    }
}


Measured memory_bytes: 21972
n = int(input())

kousya = [
                [
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                ],
                [
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                ],
                [
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                ],
                [
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                    [0,0,0,0,0,0,0,0,0,0],
                ],
            ]

for _ in range(n):
    b,f,r,v = map(int,input().split())
    tmp = kousya[b-1][f-1][r-1]
    kousya[b-1][f-1][r-1] = tmp + v

for index,tou in enumerate(kousya):
    for kai in tou:
        print(' ' + ' '.join(map(str,kai)))
    if index == len(kousya) - 1:
        continue
    else:
        print('####################')


Measured memory_bytes: 5624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int N, M; cin >> N >> M;

  vector <bool> bridge(N - 1);

  vector < pair <int, int> > BA(M);
  for (int i = 0; i < M; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    BA[i].first = b;
    BA[i].second = a;
  }
  
  sort(BA.begin(), BA.end());

  int ans = 0;
  for (int i = 0; i < M; i++){
    
    bool flag = false;

    int A = BA[i].second, B = BA[i].first;
    for (int j = A; j < B; j++){
      if (bridge[j] == true){
        flag = true;
        break;
      }
    }

    if (flag == false){
      bridge[B - 1] = true;
      ans++;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
N, A, B = [int(x) for x in input().split()]
S = input()

cntA = 0
cntB = 0

for i in range(N):
    if S[i] == 'a':
        if A + B > cntA + cntB:
            cntA += 1
            print('Yes')
        else:
            print('No')
    elif S[i] == 'b':
        if A + B > cntA + cntB and B > cntB:
            cntB += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')



Measured memory_bytes: 4016
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
    
signed main(){
    
    int n;
    cin >> n;
    cout << (n-2)*180<< endl;

    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://m-solutions2019.contest.atcoder.jp/tasks/m_solutions2019_a

Measured memory_bytes: 256
#!/usr/bin/env python
#-*- Coding:utf-8 -*-

n, d = (int(x) for x in input().split())
points = [[int(x) for x in input().split()] for i in range(n)]
sum = 0
for i in range(n):
    a = points[i][0]
    b = points[i][1]
    dist = (a**2 + b**2)**0.5
    if dist <= d:
        sum += 1

print(sum)

Measured memory_bytes: 42664
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**10 for _ in range(n)]
dp[0] = 0

for i in range(1, n):
    mincost = 10 ** 10
    for j in range(1, min(i, k)+1):
        cost = dp[i-j] + abs(h[i] - h[i-j])
        if cost < mincost:
            mincost = cost
    
    dp[i] = mincost

print(dp[-1])


Measured memory_bytes: 56544
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

string N;
int K;
cin >> N >> K;

// cnt [digit][limit][0でない数の個数]
vector<VVI> cnt((int)N.size()+1, VVI(2, VI(N.size()+1, 0)));
cnt[0][0][0] = 1; // 0桁目で0でない数が0個ある数の個数

rep(i, 0, N.size()){
    int digit = N[i] - '0';
    rep(j, 0, 2){
        rep(k, 0, N.size()){
            for(int d = 0; d <= (j ? 9 : digit); ++d){
                cnt[i+1][j || (d < digit)][k + (d > 0)] += cnt[i][j][k];
            }
        }
    }
}

cout << cnt[N.size()][0][K] + cnt[N.size()][1][K] << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String str[] = br.readLine().split(" ");

        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);

        char mat[][] = new char[n][m];
        int start[][] = new int[n][m];
        int end[][] = new int[n][m];

        for(int i = 0; i < n; i++) {
            char c[] = br.readLine().toCharArray();
            for(int j = 0; j < m; ++j) {
                mat[i][j] = c[j];
            }
        }

        Vector<Integer>[] rows = (Vector<Integer>[]) new Vector[n];
        Vector<Integer>[] cols = (Vector<Integer>[]) new Vector[m];

        
        for(int i = 0; i < n; i++) {
            rows[i] = new Vector<Integer>();
        }

        for(int i = 0; i < m; i++) {
            cols[i] = new Vector<Integer>();
        }

        int ans = 0;

        for(int i = 0; i < n; i++) {
            rows[i].add(-1);
            for(int j = 0; j < m; j++) {
                if(mat[i][j] == '#') {
                    rows[i].add(j);
                }
            }
            rows[i].add(m);

            int l = 0, r = 1;

            for(int j = 0; j < m; j++) {
                if(mat[i][j] != '#') {
                    start[i][j] = rows[i].get(r) - rows[i].get(l);
                }
                else {
                    start[i][j] = 0;
                }
                if(j == rows[i].get(r)) {
                    l = r;
                    r += 1;
                }
            }
        }

        for(int i = 0; i < m; i++) {
            cols[i].add(-1);
            for(int j = 0; j < n; j++) {
                if(mat[j][i] == '#') {
                    cols[i].add(j);
                }
            }
            cols[i].add(n);

            int l = 0, r = 1;
            for(int j = 0; j < n; j++) {
                if(mat[j][i] != '#') {
                    end[j][i] = cols[i].get(r) - cols[i].get(l);
                }
                else {
                    end[j][i] = 0;
                }
                if(j == cols[i].get(r))  {
                    l = r;
                    r += 1;
                }
            }
        }

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                ans = Math.max(ans, (start[i][j] + end[i][j]));
            }
        }

        System.out.println(ans - 3);
    }
} 

Measured memory_bytes: 266592
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  ll resr = 0, resl = 0;
  vector<ll> a, b;
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    a.pb(x);
  }
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    b.pb(x);
  }
  for(int i = 0; i < n; i++){
    resr += b[i] - a[i];
    resl += max((ll)0, (b[i] - a[i] + 1) / 2);
  }
  if(resr >= resl)cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            for (var h = N / 4 + 1; h <= 3500; ++h)
            {
                for (var n = h; n <= 3500; ++n)
                {
                    var l = 4 * h * n - N * (h + n);
                    var r = N * h * n;
                    if (0 < l && r % l == 0)
                    {
                        WriteLine($"{h} {n} {r/l}");
                        return;
                    }
                }
            }
            //Out.Flush();
        }
    }
}

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

int n,m;
int l,r;

int main()
{
	
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		if(!i)
		{
			l=x;
			r=y;
		}
		l=max(l,x);
		r=min(r,y);
	}
	if(l>r) cout<<0;
	else cout<<r-l+1;
	
	return 0;
} 


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  vector<bool> chk(26, false);
  string s;
  cin >> s;
  rep(i,(ll)s.size()){
    if(chk[s[i] - 'a']) {
      puts("no");
      return 0;
    }
    chk[s[i] - 'a'] = true;
  }
  puts("yes");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main (){
	ll t1,t2,a1,a2,b1,b2;
	scanf ("%lld%lld%lld%lld%lld%lld",&t1,&t2,&a1,&a2,&b1,&b2);
	if (a1>b1) swap(a1,b1),swap(a2,b2);
	if (a2<b2) {puts("0");return 0;}
	ll l1=a1*t1+a2*t2,l2=b1*t1+b2*t2;
	if (l1<l2) {puts("0");return 0;}
	if (l1==l2) {puts("infinity");return 0;}
	ll d1=t1*b1-t1*a1,d2=t2*a2-t2*b2,dt=l1-l2;
	printf ("%lld",d1/dt*2+(d1%dt!=0));
	return 0;
}

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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,K;
  string S;
  cin>>N>>S>>K;
  char tmp=S[K-1];
  REP(i,N){
    if(S[i]!=tmp){
      S[i]='*';
    }
  }
  cout<<S;


  return 0;
}

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

int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  int ans[1010][1010];
  rep(i,h){
    rep(j,w){
      if(i<b){
        if(j<a) cout<<0;
        else cout<<1;
      }else{
        if(j<a) cout<<1;
        else cout<<0;
      }
    }
    cout<<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 2005;
int f[N][N];
int tot[N][N];
int up[N][N];
int lef[N][N];

int tqr(int il, int jl, int ir, int jr){
  if(il > ir || jl > jr) return 0;
  return tot[ir][jr] - tot[ir][jl - 1] - tot[il - 1][jr] + tot[il-1][jl-1];
}

int uqr(int il, int jl, int ir, int jr){
  if(il > ir || jl > jr) return 0;
  return up[ir][jr] - up[ir][jl - 1] - up[il - 1][jr] + up[il-1][jl-1];
}

int lqr(int il, int jl, int ir, int jr){
  if(il > ir || jl > jr) return 0;
  return lef[ir][jr] - lef[ir][jl - 1] - lef[il - 1][jr] + lef[il-1][jl-1];
}

int main(){
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  char k;
  for(int i = 1; i <= n; i ++ ){
    for(int j = 1; j <= m ; j ++ ){
      cin >> k;
      f[i][j] = k - '0';
      tot[i][j] = f[i][j] + tot[i-1][j] + tot[i][j-1] - tot[i-1][j-1];
      up[i][j] = (f[i][j] & f[i-1][j]) + up[i-1][j] + up[i][j-1] - up[i-1][j-1];
      lef[i][j] = (f[i][j] & f[i][j-1]) + lef[i-1][j] + lef[i][j-1] - lef[i-1][j-1];
    }
  }
  int ci, cj, ri, rj;
  for(int i = 0 ; i < q; i ++ ){
    cin >> ci >> cj >> ri >> rj;
    cout << tqr(ci, cj, ri, rj) - uqr(ci + 1, cj, ri, rj) - lqr(ci, cj + 1, ri, rj) << "\n";
  }
  return 0;
}


Measured memory_bytes: 64640
#include<bits/stdc++.h>
#define LL long long
#define MAXN 100005
using namespace std;


int N,M;
int x[MAXN], y[MAXN];

struct Node{
	int id,v;
	Node(int id=0, int v=0):id(id), v(v){}
	
	bool operator < (const Node& n1) const{
		return v < n1.v;
	}
} nx[MAXN], ny[MAXN];


struct edge{
	int u,v,w;
	edge(int u=0, int v=0, int w=0):u(u), v(v), w(w){}
	
	bool operator < (const edge& e1) const{
		return w < e1.w;
	}
} e[2*MAXN];

void addE(int u, int v, int w){
	e[++M] = edge(u,v,w);
	//cout<<"addE: "<<u<<" "<<v<<" "<<w<<endl;
}

int p[MAXN];
int findR(int x){
	if(x==p[x]) return x;
	else return p[x] = findR(p[x]);
}

LL ans = 0;
void kruskal(){
	for(int i=1;i<=N;i++) p[i] = i;
	sort(e+1, e+1+M);
	
	int u,v,w,ru,rv;
	for(int i=1;i<=M;i++){
		u = e[i].u; v = e[i].v;
		ru = findR(u);
		rv = findR(v);
		if(ru==rv) continue;
		
		ans += e[i].w;
		p[ru] = rv;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>x[i]>>y[i];
		nx[i] = Node(i, x[i]);
		ny[i] = Node(i, y[i]);
	}

	sort(nx+1, nx+1+N);
	sort(ny+1, ny+1+N);

	for(int i=1;i<N;i++){
		addE(nx[i].id, nx[i+1].id, nx[i+1].v - nx[i].v);
		addE(ny[i].id, ny[i+1].id, ny[i+1].v - ny[i].v);
	}
	
	kruskal();
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stack>

using namespace std;

int main() 
{
	long int d, sum=0;

	while (cin >> d)
	{
		sum = 0;
		for (int i = 1; i*d <= 600 - d; i++)
		{
			sum += (i * d) * (i * d) * d;
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;;
const int maxn=100000+10;

string s,t;
int ns,nt;
int nextz[maxn][26],first[26];
long long kq;

int main(){
  //freopen("input.txt","r",stdin);
  cin>>s>>t;ns=s.length();nt=t.length();
  s=" "+s;t=" "+t;
  for(int j=0;j<26;j++) first[j]=ns+1;
  for(int i=ns;i>=1;i--)
    for(int j=0;j<26;j++)
      if (s[i]-'a'==j) first[j]=i;
  for(int j=0;j<26;j++) nextz[ns][j]=first[j];
  for(int i=ns-1;i>=0;i--)
    for(int j=0;j<26;j++){
      nextz[i][j]=nextz[i+1][j];
      if (s[i+1]-'a'==j) nextz[i][j]=i+1;
    }
  long long kq=0;int ii=0;
  for(int i=1;i<=nt;i++){
    int prev=ii;
    ii=nextz[ii][t[i]-'a'];
    if (ii==ns+1){
      cout<<-1;return 0;
    }
    if (prev<ii) kq=kq+ii-prev;
    else kq=kq+ii-prev+ns;
  }
  cout<<kq;
}


Measured memory_bytes: 10724
/* Tuan Kkura */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 200005

int a[MAXN];

int main()
{
    _io
    int n; cin >> n;
    int cnt = 0;
    int res = 0;
    FOR(i, 1, n)
    {
        cin >> a[i];
        if(a[i] <= a[i-1])
            cnt++;
        else cnt = 0;
        res = max(res, cnt);
    }
    cout << res;
}


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

int main(int argc, const char * argv[]) {
    int N;
    int L[20] = {0};
    int max = 0;
    int maxIndex = 0;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        if (L[i] > max) {
            max = L[i];
            maxIndex = i;
        }
    }
    
    int total = 0;
    for (int i = 0; i < N; i++) {
        if (i != maxIndex) {
            total += L[i];
        }
    }
    
    if (max < total) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, a = map(int, input().split())
    xl = list(map(int, input().split()))
    dp = [[[0] * 2501 for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n):
            for k in range(2501):
                if dp[i][j][k] > 0:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + xl[i]] += dp[i][j][k]
    ans = 0
    for i in range(1,n+1):
        ans += dp[n][i][i*a]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91740