akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MOD = 1000000000 + 7;
// constexpr int MAXA = 1000800;
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<int> makePrimes(int n)
{
    vector<int> res, pr(n + 1, 1);
    pr[0] = pr[1] = 0;
    for (int p = 2; p < sqrt(n) + 2; p++)
        if (pr[p])
            for (int x = p * 2; x <= n; x += p)
                pr[x] = 0;
    for (int p = 2; p < n + 1; p++)
        if (pr[p])
            res.push_back(p);
    return res;
}
vector<int> vp;
int vp_size;

constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}
constexpr int modinv(int a) { return modpow(a, MOD - 2); }
constexpr int countFactor(int &a, int f)
{
    if (a <= 0)
        return 0;
    int count = 0;
    while (a % f == 0)
    {
        a /= f;
        count++;
    }
    return count;
}

// LCMの素因数の数を更新する
void updateLCM(int a, vector<int> &pf_lcm)
{
    // 試し割り法 sqrt(a) 未満の素数で割った回数を数えて、素因数の数を数える
    for (int j = 0; j < vp_size; j++)
    {
        int p = vp[j];

        if (p > sqrt(a))
            break;

        // 因数pの数を数える
        int count = countFactor(a, p);

        pf_lcm[j] = max(count, pf_lcm[j]);
    }

    // aが素数の場合 素数aを数える
    if (a < 2)
        return;
    int count = 1;
    int j = lower_bound(vp.begin(), vp.end(), a) - vp.begin();
    pf_lcm[j] = max(count, pf_lcm[j]);
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    // 素数の集合
    vp = makePrimes(*max_element(a.begin(), a.end()));
    vp_size = vp.size();

    vector<int> pf_lcm(vp_size, 0);
    for (int i = 0; i < n; i++)
    {
        updateLCM(a[i], pf_lcm);
    }

    // LCM modulo を求める
    int lcm_modulo = 1;
    for (int i = 0; i < vp_size; i++)
    {
        (lcm_modulo *= modpow(vp[i], pf_lcm[i])) %= MOD;
    }

    int ans = 0;

    // b[i] = lcm / a[i] である
    // 答え Sum(b[i]) を求める
    for (int i = 0; i < n; i++)
    {
        (ans += lcm_modulo * modinv(a[i])) %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9336
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        num = num + 10000;
        String ans = "Good";
        List<Integer> list = new ArrayList<>();
        while (num > 0) {
            list.add(num % 10);
            num /= 10;
        }
        for(int i =0; i<3; i++){
            if(list.get(i) == list.get(i+1)){
                ans = "Bad";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
int main(){
    long N,M;
    scanf("%ld %ld",&N,&M);

    if (N == 1 && M == 1){
        printf("%d\n",1);
    }else if (N == 2 || M == 2){
        printf("%d\n",0);
    }else if (N >= 3 && M == 1){
        printf("%ld\n",N-2);
    }else if (N == 1 && M >= 3){
        printf("%ld\n",M-2);
    }else{
        printf("%ld\n",N*M-2*(N+M-2));
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	long long int x;
	cin >> x;
	long long int ans = 2 * (x / 11);
	if(x % 11 <= 6 && x % 11 >= 1) ans++;
	else if(x % 11 > 6) ans += 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N,K;
vector<ll> di;
map<ll,  int> moebius(ll n){
    map<ll,int> res;
    vector<ll> primes;
    for (ll i=1; i*i<=n; i++){
        if (n%i==0){
            di.push_back(i);
            if (i!=n/i) di.push_back(n/i);
        }
    }
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            primes.pb(i);
            while(n%i==0) n/=i;
        }
    }
    if(n!=1) primes.pb(n);
    int m=sz(primes);
    rep(i,0,1<<m){
        ll mu=1, d=1;
        rep(j,0,m){
            if(i>>j&1){
                mu*=-1;
                d*=primes[j];
            }
        }
        res[d]=mu;
    }
    return res;
}
ll mod_pow(ll x, ll n, ll mod=MOD){
    if (n==0) return 1;
    ll res=mod_pow(x*x%mod, n/2, mod);
    if (n%2==1) res=res*x%mod;
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    ll ans=0;
    map<ll, int> m=moebius(N);
    for(ll d : di){
        ll res=0;
        for(ll D: di){
            if(d%D==0){
                res+=m[d/D]*mod_pow(K, (D+1)/2);
                res%=MOD;
            }
        }
        res*=(d%2?d:d/2);
        res%=MOD;
        ans+=res;
        ans%=MOD;
    }
    cout <<(ans+MOD)%MOD<<"\n";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
typedef short int si;
typedef long long int ll;
typedef long int li;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<li,li> pli;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define linf LONG_MAX 
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define mkp make_pair
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define endl '\n'
const ll N=11;
ll mod=1e9+7;
signed main()
{
    fast;
    ll pro=1,temp,n,m,k,t,i,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=0,i1=-1,i2=-1;
    cin>>n>>k;
    k=2*k+1;
    ans=ceil((ld)n/(ld)k);
    cout<<ans;
    return 0;
} 
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    if (k == 0) ans = n*n;
    else FOR(i,k+1,n+1) ans += n/i * (i-k) + max(0LL,n-n/i*i-k+1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, 1, n + 1)
    {
        string num = to_string(i);
        if (num.length() % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
}


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

using namespace std;

int main() {
	cin.tie(0);
	cout.tie(0);
	iostream::sync_with_stdio(0);
	int n;
	cin>>n;
	for (int i = 1; i <= n; i++) {
		if ((n % i) == 0 && i < 10 && (n / i) < 10) {
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

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

int n, a[101010];

int main() {
  cin >> n;
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }
  int pos = 0, res = 0;
  rep(i, n + 1){
    pos = a[pos];
    if(pos == 1){
      res = i + 1;
      break;
    }
    if(i == n) res = -1;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
n,a,b=map(int, input().split())

def digitSum(n):
	s = str(n)
	array = list(map(int, s))
	return sum(array)
count = 0
for i in range(n):
	temp = digitSum(i+1)
	if (temp >= a) and (temp <= b):
		count = count + i+1


print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int h,w,m;cin>>h>>w>>m;
    v row(h,0),col(w,0);
    vv coll(w);
    f(i,m)
    {
    	int h1,w1;cin>>h1>>w1;
    	h1--;
    	w1--;
    	row[h1]++;
    	col[w1]++;
    	coll[w1].pb(h1);
    }
    set<pi>rows;
    for(int i=0;i<h;i++)
    {
    	rows.insert({row[i],i});
    }
    int ans=0;
    for(int i=0;i<w;i++)
    {
    	int ans1=0;
    	for(auto it:coll[i])
    	{
    		ans1=max(ans1,col[i]+row[it]-1);
    		rows.erase({row[it],it});
    	}
    	if(!rows.empty())
    	{
    		auto it=rows.end();
    		it--;
    		ans1=max(ans1,col[i]+it->first);
    	}
    	for(auto it:coll[i])
    		rows.insert({row[it],it});
    	ans=max(ans,ans1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 43068
n=int(input())
list1=list(map(int,input().split()))

ans=0
for i in range(n):
    if list1[i]%2==0:
        if list1[i]%3==0 or list1[i]%5==0:
            pass
        else:
            ans=1
            break
if ans==0:
    print('APPROVED')
else:
    print('DENIED')

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

int main()
{
    ll i,j,k,l,m,n,o,p,q,r,a[300001],b[300001];
    cin>>n>>m>>k;
    a[0]=0;b[0]=0;
    for(i=1;i<=n;i++)
    {
     cin>>a[i];
     a[i]+=a[i-1];
    }
    for(i=1;i<=m;i++)
    {
        
        cin>>b[i];
        b[i]+=b[i-1];
    }
    i=0;
    j=0;
    ll ans=0;
    for(i=0;i<=n;i++)
    {
          if(a[i]<=k)
          {
            ll val=k-a[i];
            ll start=0,end=m,mid,index=0;
             while(start<=end)
             {
                 mid=(start+end)/2;
                 if(b[mid]<=val)
                 {
                     index=mid;
                     start=mid+1;
                 }
                 else 
                 {
                     end=mid-1;
                 }
             }
             ans=max(ans,index+i);
          }
    }

    for(i=0;i<=m;i++)
    {
          if(b[i]<=k)
          {
            ll val=k-b[i];
            ll start=0,end=n,mid,index=0;
             while(start<=end)
             {
                 mid=(start+end)/2;
                 if(a[mid]<=val)
                 {
                     index=mid;
                     start=mid+1;
                 }
                 else 
                 {
                     end=mid-1;
                 }
             }
             ans=max(ans,index+i);
          }
    }

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

Measured memory_bytes: 6732
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

vector< vector<int> > Gra;
vector< bool > visit;
vector<int> path;
//0からN-1のパスを知りたい
bool dfs(int v,int ter){
	visit[v] = true;
	if( v == ter ){
		path.push_back(v);
		return true;
	}
	int size = Gra[v].size();
	for(int i=0;i<size;++i){
		int to = Gra[v][i];
		if( visit[to] ) continue;
		bool res = dfs(to,ter);
		if( res ){
			path.push_back(v);
			return true;
		}
	}
	visit[v] = false;
	return false;
}

const int BB = 0;
const int WW = 1;
vector<int> color;
void paint(int v,int col){//今の頂点、塗る色
	if( color[v] == -1 || color[v] == col ){
		color[v] = col;
		visit[v] = true;
		int size = Gra[v].size();
		for(int i=0;i<size;++i){
			int to = Gra[v][i];
			if( visit[to] ) continue;
			paint( to, col );
		}
	}
	return;
}
void solve(){
	int N;
	cin >> N;
	Gra = vector< vector<int> >(N);
	visit = vector<bool>(N,false);
	for(int i=0;i<N-1;++i){
		int a,b;
		cin >> a >> b;
		--a;--b;
		Gra[a].push_back(b);
		Gra[b].push_back(a);
	}
	
	dfs(0,N-1);
	color = vector<int>(N,-1);
	int size = path.size();//0は白、size-1は黒
	int W,B;
	W = 0;
	B = size-1;
	while(1){//黒からはじめる
		if( color[ path[B] ] == -1 ){
			color[ path[B] ] = BB;
			--B;
		}else{
			break;
		}
		if( color[ path[W] ] == -1 ){
			color[ path[W] ] = WW;
			++W;
		}else{
			break;
		}
	}
	visit.assign(N,false);
	paint(0,BB);//黒BBで塗る
	paint(N-1,WW);//白WWで塗る

	int Bnum = 0;
	int Wnum = 0;
	for(int i=0;i<N;++i){
		if( color[i] == BB ){
			++Bnum;
		}else{
			++Wnum;
		}
	}

	if( Bnum > Wnum ){
		cout << "Fennec" << endl;
	}else{
		cout << "Snuke" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 12920
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
using namespace std;

vector<int> a;

int main()	
{
	int n;
	cin >> n;
	a.resize(n);
	for(int i=0; i<n; i++)	cin >> a[i];
	sort(a.begin(),a.end());
	int ans=0;
	for(int i=0; i<n-1; i++)	{
		for(int j=i+1; j<n; j++)	{
			int x=a[i]+a[j];
			auto it=lower_bound(a.begin()+j+1,a.end(),x);
			--it;
			int d=it-(a.begin()+j);
			ans+=d;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
MOD = 998244353

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

N, M, K = map(int, input().split())
comb = Combination(N + K)

ans = 0
for k in range(K + 1):
    L = N - k
    ans += M * pow(M - 1, L - 1, MOD) * comb.nhr(L, k)
    ans %= MOD
print(ans)

Measured memory_bytes: 59544
N =int(input())
D = [int(x) for x in input().split()]
cnt = [0]*(N)
if D[0]!=0:
  print(0)
  exit()
for i in range(N):
  cnt[D[i]]+=1
ans = 1
if cnt[0]!=1:
  print(0)
  exit()
a = 0
b = 0
for i in range(1,N-1):
  if cnt[i]==0 and a==0:
    a=i
    b+=1
  if a!=0 and cnt[i]!=0:
    print(0)
    exit()
  elif a!=0 and cnt[i]==0:
    b+=1
  ans*=cnt[i-1]**cnt[i]
  ans%=998244353
#print(cnt,a,b)
if N-a==b or a==b==0:
  print(ans)
else:
  print(0)

Measured memory_bytes: 53548
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		
		sc.close();
		
		long snack = lcm(a, b);
		System.out.println(snack);

	}
	
	static long gcd(long a, long b) 
    { 
		if (a == 0)
		{
			return b;
		}
			  
		return gcd(b % a, a);  
    } 
	
	static long lcm(long a, long b) 
    { 
        return (a*b)/gcd(a, b); 
    } 
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
void input(){
    fast_io();
    cin >> S;
}

int solve(){
    int N = S.length();
    int ans = N;
    for (int i = 0; i < N-1; i++)
    {
        if(S[i]!=S[i+1]){
            ans = min(ans,max(i+1,N-(i+1)));
        }
    }
    cout << ans << endl;    
    return 0;
}   

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

Measured memory_bytes: 3760
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
m = int(input())
t = []
for _ in range(m):
    t.append(input())
s_ = collections.Counter(s)
t_ = collections.Counter(t)
a = []
for key in s_.keys():
    num = s_[key] - t_[key]
    a.append(num)
print(max(max(a),0))

Measured memory_bytes: 3316
program A081
    implicit none
    character(3) :: s
    integer(4) :: i, sum

    read(5,*) s
    sum = 0
    do i = 1, 3
        if (s(i:i) == "1") then
            sum = sum + 1
        end if
    



    end do

    write(6,*) sum


end program A081

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

int main(){
  int n;cin >> n;
  int a[n];for(int i=0;i<n;i++)cin >> a[i];
  for(int i=n-1;i >= 0;--i){
    if(i == 0)cout << a[i] << endl;
    else cout << a[i] << " ";
  }
  return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int) (x.size())
#define fi first
#define se second
#define pii pair<int, int>

const int N = 1e5 + 100;
int p[N];
vector<int> par(N, -1);
pii xy[N];
int root(int v) {
    return (par[v] < 0 ? v : (par[v] = root(par[v])));
}
void merge(int a, int b) {
    if ((a = root(a)) == (b = root(b))) 
        return;
    if (par[b] < par[a]) 
        swap(a, b);
    par[a] += par[b];
    par[b] = a;
}

int n, m;
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> xy[i].fi >> xy[i].se;
        merge(xy[i].fi, xy[i].se);
    }
    map<int, vector<int>> mp;
    for (int i = 1; i <= n; i++) {
        mp[root(i)].push_back(i);
    }
    vector<vector<int>> comp_ind, comp_p;
    int ans = 0;
    for (auto &el : mp) {
        comp_ind.push_back(el.se);
        comp_p.push_back({});
        for (auto &ind : comp_ind.back()) {
            comp_p.back().push_back(p[ind]);
        }
        sort(comp_p.back().begin(), comp_p.back().end());
        for (auto &ind : comp_ind.back()) {
            if (binary_search(comp_p.back().begin(), 
                comp_p.back().end(), ind)) {
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

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

#define reint register int
#define coint const int

using namespace std;

coint SIZE = 1000 + 5;

int li[SIZE][SIZE];
int ind[SIZE], mk[SIZE];
queue<int> que;
int stk[SIZE], scnt;

int main(void) {
    int n;
    scanf("%d", &n);
    for (reint i = 1; i <= n; ++i)
        for (reint j = 1; j < n; ++j)
            scanf("%d", &li[i][j]);

    int ans = 0, cnt = 0;
    coint tot = n * (n - 1) / 2;
    for (reint i = 1; i <= n; ++i) ind[i] = 1;
    for (reint i = 1; i <= n; ++i) que.push((int)i);
    while (cnt < tot) {
        scnt = 0;
        while (!que.empty()) {
            coint x = que.front();
            //printf("x = %d\n", x);
            que.pop();
            if (mk[x]) continue;
            if (ind[x] >= n) continue;
            coint v = li[x][ind[x]];
            //printf("v = %d\n", v);
            if (li[v][ind[v]] != x || mk[v]) continue;
            mk[x] = mk[v] = 1, stk[++scnt] = x, stk[++scnt] = v;
            ++ind[li[x][ind[x]++]], ++cnt;
        }
        if (!scnt) { ans = -1; break; }
        ++ans;
        //printf("ans = %d, cnt = %d\n", ans, cnt);
        for (reint i = 1; i <= scnt; ++i)
            mk[stk[i]] = 0, que.push(stk[i]);
        if (cnt < tot && que.empty()) { ans = -1; break; }
    }
    printf("%d\n", ans);

    return 0;
}


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

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    int A[100][100];
    int B[100][100];
    long long C[100][100];

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

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> B[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            C[i][j] = 0;
            for (int k = 0; k < m; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            cout << C[i][j];
            if (j != l-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    string s;
    cin>>s;
    ll q;
    cin>>q;
    ll c1=0;
    ll t;
    ll f;
    char c;
    string s1,s2;
    for(ll i=0;i<q;i++)
    {
        cin>>t;
        if(t==1)
        {
            c1+=1;
        }
        else
        {
            cin>>f>>c;
            if(c1%2==0)
            {
                if(f==1)
                {
                    s1=c+s1;
                }
                else
                {
                    s2=s2+c;
                }
            }
            else
            {
                if(f==1)
                {
                    s2=s2+c;
                }
                else
                {
                    s1=c+s1;
                }
            }
        }
    }
    s=s1+s+s2;
    if(c1%2==0)
    {
        cout<<s;
    }
    else
    {
        for(ll i=0;i<s.length();i++)
            cout<<s[s.length()-1-i];
    }
}

Measured memory_bytes: 1512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 1000003;
const int K = 20;
pair < int, int > a[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, dmg, d;
    cin >> n >> d >> dmg;
    for (int i = 1; i <= n; i++){
        cin >> a[i].F >> a[i].S;
    }
    sort(a + 1, a + n + 1);
    int ans = 0;
    vector < pair < int, pair < int, int > > > s;
    int cnt = 0;
    int x = 0;
    for (int i = 1; i <= n; i++){
        while(cnt < s.size() && s[cnt].F <= a[i].F){
            x += s[cnt].S.F * s[cnt].S.S;
            cnt++;
        }
        a[i].S -= x;
        if (a[i].S <= 0) continue;
        int p, y;
        if (a[i].S % dmg == 0){
            y = a[i].S / dmg;
            p = a[i].F + 2 * d + 1;
        } else{
            y = a[i].S / dmg + 1;
            p = a[i].F + 2 * d + 1;
        }
        x += y * dmg;
        ans += y;
        s.pb({p, {dmg, -y}});
    }
    cout << ans;
}


Measured memory_bytes: 11504
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c,c5,c10,c50,c100,c500;
  cin>>c>>c5>>c10>>c50>>c100>>c500;
  if(c + c5*5 + c10*10 + c50*50 + c100*100 + c500*500 < 1000){
    cout<<0<<endl;
  }else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 1164
package main

import (
	"fmt"
)

func main() {
	var n, d, dd int

	fmt.Scanf("%d", &n)
	slice1 := make([]int, 100, 100)
	slice2 := make([]int, 100, 100)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &d, &dd)
		slice1[i] = d
		slice2[i] = dd
	}
	total := 0
	for i := 0; i < n; i++ {
		if total >= 3 {
			break
		}
		if slice1[i] == slice2[i] {
			total++
		} else {
			total = 0
		}
	}
	if total >= 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1936
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll X[1010],Y[1010],Z[1010];
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		cin >> X[i] >> Y[i] >> Z[i];
	}
	ll d[2] = {1,-1};
	vector<ll> v;
	ll ans = 0;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				ll sem = 0;
				for(int l=0;l<N;l++){
					v.push_back(d[i]*X[l]+d[j]*Y[l]+d[k]*Z[l]);
				}
				sort(v.begin(),v.end());
				reverse(v.begin(),v.end());
				for(int l=0;l<M;l++){
					sem += v[l];
				}
				ans = max(ans,sem);
				v.clear();
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<vector>

void print(std::vector<bool>v){
    for(auto p:v){
        std::cout<<p<<",";
    }
    std::cout<<std::endl;
}

int main(){
    int N;
    std::string s;
    std::cin>>N;
    std::cin>>s;
    std::vector<bool> v(N);
    for(int i=0;i<N;++i){
        if(s[i]=='R')
            v[i]=1;
        else
            v[i]=0;
    }
    int seekL,seekR;
    int cnt=0;
    for(seekL=0,seekR=N-1;seekL<seekR;){
        // print(v);
        // std::cout<<seekL<<","<<seekR<<std::endl;
        if(v[seekL]==0 && v[seekR]==1){
            v[seekL]=1;
            v[seekR]=0;
            cnt++;
        }
        if(v[seekL]==1){
            seekL++;
        }
        if(v[seekR]==0){
            seekR--;
        }
    }
    std::cout<<cnt;
}

Measured memory_bytes: 3760
s=list(map(str,input()))
A=int(input())
V=[]
S=[]
ct=0
for i in range(1,A+1):
  for j in range((len(s)-(i-1))):
    V.append("".join(s[j:j+i]))
S=sorted(set(V))
#print(S)
print(S[A-1])


Measured memory_bytes: 5084
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
  var line = chunk.toString().split('\n');
  var seconds = Number(line[0]);
  var hour_sec = 60 * 60;
  var minute_sec = 60;
 
  var h = Math.floor(seconds / hour_sec);
  var m = Math.floor((seconds % hour_sec) / minute_sec);
  var s = seconds % hour_sec % minute_sec;
 
  console.log(h + ':' + m + ':' + s);
});

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

int main(){
 map<char , int >mp;
 string s;
 cin >> s;
 for(int i=0;i<s.size();i++){
    mp[s[i]]++;
 }
 map<char , int > :: iterator it;
 for(it=mp.begin();it!=mp.end();it++){
    int n;
    n=it->second ;
    if(n%2!=0){
        cout << "No" <<endl;
        return 0;
    }
 }
  cout << "Yes" <<endl;
 return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Map<Integer, Integer> map = new HashMap<>();
    int prevSumMod = 0;
    for (int i = 1; i <= N; i++) {
      int A = sc.nextInt();
      int sumMod = (A+prevSumMod)%M;
      map.put(sumMod, map.getOrDefault(sumMod, 0)+1);
      prevSumMod = sumMod;
    }
    
    long ans = 0;
    for (Map.Entry<Integer, Integer> ent : map.entrySet()) {
      int k = ent.getKey();
      int v = ent.getValue();
      if (k == 0 || v > 1) {
        ans += (long)v*(v+1)/2 - (k != 0 ? v : 0);
      }
    }
    
    System.out.println(ans);
  }
}


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

int main() {

  int N;
  string S;
  cin >> N >> S;
  int st, sum,i;
  sum = 0;
  st = 0;
  i = 0;
  while(i<N){
    if(S.at(i) == 'A'){
      st = 1;
    }
    else if(st == 1 && S.at(i) == 'B'){
      st = 2;
    }else if(st == 1 && S.at(i) != 'B'){
      st = 0;
    }
    else if(st == 2 && S.at(i) == 'C'){
      sum++;
      st = 0;
    }else if(st == 2 && S.at(i) != 'C'){
      st = 0;
    }
    
    i++;
  }
  cout << sum << endl;
  

}


Measured memory_bytes: 256
num = list(map(int, input().split()))

A = num[0]
B = num[1]
C = num[2]
D = num[3]
E = num[4]
F = num[5]

watA_max = F // (100 * A)
sugar = 0
water = 0
beaker = F
ans = []
for i in range(1, watA_max+1):
    water = 100 * A * i
    beaker = F - (100 * A * i)
    watB_max = beaker // (100 * B)
    for j in range(watB_max+1):
        water = 100 * (A * i + B * j)
        beaker = F - (100 * (A * i + B * j))
        sugC_max = beaker // C
        for k in range(sugC_max+1):
            sugar = C * k
            beaker = F - (100 * (A * i + B * j)) - C * k
            if sugar * 100 > water * E:
                break
            sugD_max = beaker // D
            for l in range(sugD_max+1):
                sugar = C * k + D * l
                beaker = F - (100 * (A * i + B * j)) - C * k - D * l
                if sugar * 100 > water * E:
                    break
                if ans == [] or sugar / water >= ans[-1][-1]:
                    ans.append([sugar + water, sugar, sugar / water])
                
print(ans[-1][0], ans[-1][1])

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 5e5 + 1, mod = 1e9 + 7;

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    int n, cnt[26];
    cin >> n >> s;
    for (int i = 0; i < 26; i++)
        cnt[i] = 1;
    for (int i = 0; i < n; i++)
        ++cnt[s[i] - 'a'];
    int ans = 1;
    for (int i = 0; i < 26; i++)
        ans = (ans * cnt[i]) % mod;
    cout << (ans - 1 + mod) % mod;
    return 0;
}


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

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

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

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

    int ans = A[n / 2] - A[n / 2 - 1];
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(void) {
    int N, Y;
    cin >> N >> Y;
    int x = -1;
    int y = -1;
    int z = -1;

    for(int i = 0; i < N+1; i++) {
        for (int j = 0; j < N+1; j++) {
            if (N < (i + j)) {
                break;
            }
            int k = N - (i + j);
            unsigned long sum = (10000 * i) + (5000 * j) + (1000 * k);
            if (sum == Y) {
                x = i;
                y = j;
                z = k;
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }

    cout << -1 << ' ' << -1 << ' ' << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = ["M", "A", "R", "C", "H"]
b = [0] * 5
for _ in range(n):
    s = list(input())
    for i in a:
        if i == s[0]:
            b[a.index(i)] += 1
ans = 0
for i in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            ans += b[i] * b[j] * b[k]
print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            // 写経
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var res = new int[n];

            for (var i = a.Length; i >= 1; i--)
            {
                var sum = 0;
                for (var j = i; j <= n; j += i)
                    sum += res[j - 1];

                res[i - 1] = sum % 2 != a[i - 1] ? 1 : 0;
            }

            var balls = res.Select((elem, count) => new { elem, count })
                           .Where(x => x.elem == 1)
                           .Select(x => x.count + 1)
                           .ToArray();

            Console.WriteLine(balls.Length);
            if (balls.Length != 0) Console.WriteLine(string.Join(" ", balls));
        }
    }
}


Measured memory_bytes: 32596
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li m;
    cin >> m;
    li digitsum = 0;
    li digits = 0;
    for (int i = 0; i < m; ++i) {
        li d, c;
        cin >> d >> c;
        digitsum += d * c;
        digits += c;
    }
    
    li ans = digits - 1 + (digitsum - 1) / 9;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	int i;
	long ans=0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		ans += a[i]-1;
	}
	printf("%ld",ans);
	return 0;
}

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

typedef long long i64;


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

	int n;
	cin >> n;
	if (n == 2) {
		int a, b;
		cin >> a >> b;
		if (a < b)
			swap(a, b);
		cout << a - b << '\n' << a << ' ' << b << '\n';
		return 0;
	}

	vector <int> v(n);
	vector <pair <int, int>> op;

	for (auto& i : v)
		cin >> i;

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

	if (v[0] > 0) {
		/// imi trebuie un negativ
		swap(v[0], v[n - 2]);
		op.push_back({ v[n - 2], v[n - 1] });
		v[n - 2] -= v[n - 1];
		v.pop_back();
	}
	else if (v[n - 1] < 0) {
		/// imi trb ceva pozitiv
		op.push_back({ v.back(), v[0] });
		v[0] = v.back() - v[0];
		v.pop_back();
	}

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

	int neg = v[0], poz = v.back();

	for (int i = 1; i + 1 < v.size(); i++) {
		if (v[i] < 0) {
			op.push_back({ poz, v[i] });
			poz -= v[i];
		}
		else {
			op.push_back({ neg, v[i] });
			neg -= v[i];
		}
	}

	op.push_back({ poz, neg });
	poz -= neg;

	cout << poz << '\n';
	

	for (auto i : op)
		cout << i.first << ' ' << i.second << '\n';

	return 0;
}

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; cin >> x; return x; }
double fin() { double x; cin >> x; return x; }
Int lin() { Int x; cin >> x; return x; }

Int X[100050];

int main() {
	int X= in();

	string res;
	
	if (X <= 999) {
		res = "ABC";
	}
	else {
		res = "ABD";
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w, k) = (v[0], v[1], v[2]);
    let v = read_vec::<usize>();
    let (sy, sx, gy, gx) = (v[0] - 1, v[1] - 1, v[2] - 1, v[3] - 1);

    let mut grid = vec![vec![]; h];
    for i in 0..h {
        let s = read::<String>().chars().collect::<Vec<_>>();
        grid[i] = s;
    }

    let mut que = VecDeque::new();
    que.push_back((sx, sy, 0, 0));
    let mut checked = vec![vec![false; w]; h];
    checked[sy][sx] = true;
    let mut count_grid = vec![vec![-1i64; w]; h];

    while let Some((cur_x, cur_y, count, dir)) = que.pop_front() {
        count_grid[cur_y][cur_x] = count;
        if cur_x == gx && cur_y == gy {
            println!("{}", count);
            return;
        }

        if dir != -1 {
            for i in 1..k + 1 {
                if cur_x + i > w - 1 || grid[cur_y][cur_x + i] == '@' {
                    break;
                }
                if checked[cur_y][cur_x + i] {
                    continue;
                }
                que.push_back((cur_x + i, cur_y, count + 1, 1));
                checked[cur_y][cur_x + i] = true;
            }
        }

        if dir != -2 {
            for i in 1..k + 1 {
                if cur_y + i > h - 1 || grid[cur_y + i][cur_x] == '@' {
                    break;
                }
                if checked[cur_y + i][cur_x] {
                    continue;
                }
                que.push_back((cur_x, cur_y + i, count + 1, 2));
                checked[cur_y + i][cur_x] = true;
            }
        }

        if dir != 1 {
            for i in 1..k + 1 {
                if cur_x < i || grid[cur_y][cur_x - i] == '@' {
                    break;
                }
                if checked[cur_y][cur_x - i] {
                    continue;
                }
                que.push_back((cur_x - i, cur_y, count + 1, -1));
                checked[cur_y][cur_x - i] = true;
            }
        }

        if dir != 2 {
            for i in 1..k + 1 {
                if cur_y < i || grid[cur_y - i][cur_x] == '@' {
                    break;
                }
                if checked[cur_y - i][cur_x] {
                    continue;
                }
                que.push_back((cur_x, cur_y - i, count + 1, -2));
                checked[cur_y - i][cur_x] = true;
            }
        }
    }
    println!("-1");
    // debug!(count_grid);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 18852
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


class Node{
	public:
		bool used;
		int prenum; //DFSの訪問の順番
		int parent; //DFS Treeにおける親
		int lowest; //min(自分のprenum, 逆辺がある場合の親のprenum, すべての子のlowest)
		Node() : used(0) { }
};

class articulationPoints {
	private:
		int v, cnt;
		vector<Node> node;
		void dfs(int current, int prev){
			node[current].prenum = node[current].lowest = cnt;
			cnt++;

			node[current].used = true;

			int next;
			rep(i,edge[current].size()){
				next = edge[current][i];
				if(not node[next].used){
					node[next].parent = current;
					dfs(next, current);
					node[current].lowest = min(node[current].lowest, node[next].lowest);
					if(node[current].prenum < node[next].lowest){
						bridge.emplace_back(make_pair(min(current, next), max(current, next)));
					}
				}else if(next != prev){
					node[current].lowest = min(node[current].lowest, node[next].prenum);
				}
			}
		}
	public:
		vector<vector<int>> edge;
		vector<pair<int, int>> bridge;
		set<int> ap; // 関節店
		articulationPoints(int n) : v(n), cnt(1), node(n), edge(n) { }
		void addEdge(int a, int b){
			edge[a].emplace_back(b);
			edge[b].emplace_back(a);
		}
		void run(){
			dfs(0, -1); // 0 == root

			int np = 0;
			range(i,1,v){
				int p = node[i].parent;
				if(p == 0) np++;
				else if(node[p].prenum <= node[i].lowest) ap.emplace(p);
			}
			if(np > 1) ap.emplace(0);
			//for(auto it:ap){ cout << it << endl; } //関節点の全列挙
			sort(all(bridge));
			//for(auto it:bridge){ cout << it.first << ' ' << it.second << endl; } //橋の全列挙

		}
};

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

	articulationPoints ap(n);
	rep(i,m){
		int s, t;
		cin >> s >> t;
		ap.addEdge(s,t);
	}
	ap.run();
	for(auto i : ap.bridge){
		cout << i.first << ' ' << i.second << endl;
	}
}



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

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

int N,Q;
LL x[112345];
LL L;
LL y[20][112345];
void doubling(){
    FOR(k,1,20){
        REP(i,N){
            y[k][i]=y[k-1][y[k-1][i]];
        }
    }
}
int f(int a,int b,int k){
    //cout<<a<<" "<<b<<" "<<k<<endl;
    while(k>0){
        if(y[k-1][a]<b)return (1<<(k-1))+f(y[k-1][a],b,k-1);
        k--;
    }
    return 1;
}
int main(){
    cin>>N;
    REP(i,N)cin>>x[i];
    cin>>L>>Q;
    REP(i,N){
        int ok=i;
        int ng=N;
        while(ng-ok>1){
            const int mid=(ok+ng)/2;
            if(x[mid]-x[i]<=L)ok=mid;
            else ng=mid;
        }
        y[0][i]=ok;
    }
    doubling();
    REP(i,Q){
        int a,b;
        cin>>a>>b;
        tie(a,b)=minmax({a,b});
        cout<<f(a-1,b-1,19)<<endl;
    }

    
   
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin>>s;

	bool x1=false, x2=false, x3=true;
	x1 = s.front() == 'A';

	int ccnt=0, cpos=-1;
	for(int i=2; i<=s.size()-2; i++){
		if (s[i] == 'C'){
			ccnt++;
			cpos = i;
		}
	}
	if (ccnt == 1) x2 = true;

	for(int i=1; i<s.size(); i++){
		if (!('a'<=s[i] && s[i]<='z') && i != cpos){
			x3 = false;
			break;
		}
	}

	if (x1 && x2 && x3)
		cout << "AC\n";
	else
		cout << "WA\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll burger_len[51] = {1};

ll rec(ll N, ll X) {
    if (X == 1) {
        return N ? 0 : 1;
    } else if (1 < X && X <= burger_len[N-1] + 1) {
        return rec(N-1, X-1);
    } else if (X == burger_len[N-1] + 2) {
        return rec(N-1, burger_len[N-1]) + 1;
    } else if (burger_len[N-1] + 2 < X && X < burger_len[N]) {
        return rec(N-1, burger_len[N-1]) + 1 + rec(N-1, X - burger_len[N-1] - 2);
    } else if (X == burger_len[N]) {
        return rec(N-1, burger_len[N-1]) * 2 + 1;
    }
}

int main() {
    ll N, X;
    for (int i = 1; i <= 50; i++) {
        burger_len[i] = burger_len[i-1] * 2 + 3;
    }

    cin >> N >> X;
    cout << rec(N, X) << endl;

    return 0;
}

Measured memory_bytes: 256