akhauriyash/Code-Regression huggingface dataset:
N = list(input())
K = int(input())

N.reverse()
n = [0]*100
for i in range(100):
    if 99-i < len(N):
        n[i] = int(N[99-i])

dp2 = [[0]*100 for _ in range(4)]
if n[0] == 0:
    dp2[0][0] = 1
else:
    dp2[1][0] = 1
for i in range(1,100):
    if n[i] == 0:
        for j in range(4):
            dp2[j][i] = dp2[j][i-1]
    else:
        for j in range(1,4):
            dp2[j][i] = dp2[j-1][i-1]

dp1 = [[0]*100 for _ in range(4)]
if n[0] != 0:
    dp1[0][0] = 1
    dp1[1][0] = n[0]-1
for i in range(4):
    for j in range(1,100):
        if i != 0:
            if n[j] != 0:
                dp1[i][j] = dp1[i-1][j-1]*9 + dp1[i][j-1]*1 + dp2[i-1][j-1]*max(0,n[j]-1) + dp2[i][j-1]*1
            else:
                dp1[i][j] = dp1[i-1][j-1]*9 + dp1[i][j-1]*1

        else:
            if n[j] != 0:
                dp1[i][j] = dp1[i][j-1]*1 + dp2[i][j-1]*1
            else:
                dp1[i][j] = dp1[i][j-1]*1

print(dp1[K][-1] + dp2[K][-1])

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Console.ReadLine().ToInt();
		Console.WriteLine(p * 2.0 * Math.PI );
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27612
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define inf 1e18
#define all(v) (v).begin(),(v).end()
using namespace std;

vector <int> dx = {-1,1,0,0};
vector <int> dy = {0,0,-1,1};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll ans = max(a*c,a*d);
	ans = max(ans,b*c);
	ans = max(ans,b*d);
	cout << ans<<"\n";
	return 0;
}

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

#define INF 100000

int main(){
    int N,Ma,Mb;
    cin >> N >> Ma >> Mb;
    int a[41],b[41],c[41];
    for(int i=1;i<=N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<vector<vector<int>>> dp;
    dp.resize(41);
    for(int i=0;i<=N;i++){
        dp[i].resize(401);
        for(int j=0;j<=400;j++) dp[i][j].resize(401);
    }
    for(int i=0;i<=400;i++){
        for(int j=0;j<=400;j++){
            dp[0][i][j]=INF;
        }
    }
    dp[0][0][0]=0;

    for(int i=1;i<=N;i++){
        for(int x=0;x<=400;x++){
            for(int y=0;y<=400;y++){
                if(x<a[i] || y<b[i]) dp[i][x][y]=dp[i-1][x][y];
                else if(dp[i-1][x-a[i]][y-b[i]]+c[i]<dp[i-1][x][y]) dp[i][x][y]=dp[i-1][x-a[i]][y-b[i]]+c[i];
                else dp[i][x][y]=dp[i-1][x][y];
            }
        }
    }

    int min=INF;
    for(int i=1;Ma*i<=400 && Mb*i<=400;i++){
        if(dp[N][Ma*i][Mb*i]<min) min=dp[N][Ma*i][Mb*i];
    }

    cout << ((min<INF)?min:-1) << endl;

    return 0;
}

Measured memory_bytes: 26624
import std.stdio, std.string, std.array, std.conv;

struct Dice6 {
    int[string] dice6;
    int[] _dice6 = new int[](6);

    this(int[] _dice6) {
        dice6["top"] = _dice6[0];
        dice6["front"] = _dice6[1];
        dice6["right"] = _dice6[2];
        dice6["left"] = _dice6[3];
        dice6["back"] = _dice6[4];
        dice6["bottom"] = _dice6[5];
    }

    void roll(char c) {
        int tmp = dice6["top"];
        if (c == 'E') {
            dice6["top"] = dice6["left"];
            dice6["left"] = dice6["bottom"];
            dice6["bottom"] = dice6["right"];
            dice6["right"] = tmp;
        } else if (c == 'N') {
            dice6["top"] = dice6["front"];
            dice6["front"] = dice6["bottom"];
            dice6["bottom"] = dice6["back"];
            dice6["back"] = tmp;
        } else if (c == 'S') {
            dice6["top"] = dice6["back"];
            dice6["back"] = dice6["bottom"];
            dice6["bottom"] = dice6["front"];
            dice6["front"] = tmp;
        } else {
            dice6["top"] = dice6["right"];
            dice6["right"] = dice6["bottom"];
            dice6["bottom"] = dice6["left"];
            dice6["left"] = tmp;
        }
    }

    int surface(string dir) {
        int result;
        if (dir == "top") {
            result = dice6["top"];
        } else if (dir == "front") {
            result = dice6["front"];
        } else if (dir == "right") {
            result = dice6["right"];
        } else if (dir == "left") {
            result = dice6["left"];
        } else if (dir == "back") {
            result = dice6["back"];
        } else {
            result = dice6["bottom"];
        }
        return result;
    }
}

void main() {
    int[] _dice = readln.chomp.split.to!(int[]);
    Dice6 dice = Dice6(_dice);
    string str = readln.chomp;
    foreach (x; str) {
        dice.roll(x);
    }
    dice.surface("top").writeln;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
bool check(int n,vector<int>a)
{
      while(n>0)
    {
        int temp=n%10;
        if(a[temp])
        {
            return false;
        }
        n=n/10;
    }
    return true;
}

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(10);
    for(int i=0;i<k;i++)
    {
        int f;
        cin>>f;
        a[f]=1;
    }
    for(int i=n;i<=1000000000;i++)
    {
        if(check(i,a))
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;

   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();
	
	int a, b; cin >> a >> b;
	if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0)cout << "Possible" << "\n";
	else cout << "Impossible" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
	int n; cin>>n;
	int a[200000],b[200000];
	FOR(i,0,n){
		cin>>a[i];
		b[a[i]-1]=i;
	}
	set<int> s1,s2;
	s1.insert(-1);
	s1.insert(n);
	s2.insert(1);
	s2.insert(-n);
	ll ans=0;
	FOR(i,0,n){
		set<int>::const_iterator st=s1.lower_bound(b[i]);
		set<int>::const_iterator en=s2.lower_bound(-b[i]);
		
		ans+=(ll)(i+1)*(*st-b[i])*(b[i]+*en);
		s1.insert(b[i]);
		s2.insert(-b[i]);
	}
	co(ans);
}


Measured memory_bytes: 20608
import math
import sys
from collections import Counter
readline = sys.stdin.readline


def main():
    n, k = map(int, readline().rstrip().split())
    a = list(map(int, readline().rstrip().split()))
    c = Counter(a)
    print(sum(sorted(c.values(), reverse=True)[k: len(c)]))


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  string S; cin >> S;
  set<char> s;
  for (int i=0; i < S.size(); i++) {
    s.insert(S.at(i));
  }

  string ans = s.size() == 2 ? "Yes":"No";

  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
const static int N = 100005;
int n;
int a[N], b[N], c[N];
ll bb[N], rsbb[N];
int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &c[i]);
	}
	
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	for (int i = 0; i < n; i++){
		bb[i] = upper_bound(a, a + n, b[i] - 1) - a;
		if (i == 0){
			rsbb[i] = bb[i];
		} else {
			rsbb[i] = bb[i] + rsbb[i - 1];
		}
	}
	ll answer = 0;
	for (int i = 0; i < n; i++){
		int x = upper_bound(b, b + n, c[i] - 1) - b;
		if (x == 0) continue;
		answer += rsbb[x - 1];
	}
	printf("%lld\n", answer);
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//int n=sc.I;
		int[] s=sc.Ia;
		int ans=0;
		if(s[0]>=13){ans=s[1];}
		else if(s[0]>=6){ans=s[1]>>1;}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return ("# "+Console.ReadLine()).Split();}}
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,m;
	t = 1;
	while(t--) {
	 cin >> n >> m;
	 if(n < m)
	  cout << 0 << endl;
	 else
	  cout << 10 << endl;
	}
	return 0;
}


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

void change( int* a, int x, int y )
{
    int temp = a[x];
    a[x] = a[y];
    a[y] = temp;
}

int partition( int* a, int p, int r )
{
    int x = a[r];
    int i = p - 1;

    for( int j = p; j <= r - 1; j++ )
    {
        if( a[j] <= x )
        {
            i = i + 1;
            change( a, i, j );
        }
    }
    change( a, i + 1, r );

    return i + 1;
}

int main()
{
    int n;

    cin >> n;

    int a[n+1];

    for( int i = 1; i <= n; i++ )
        cin >> a[i];
    
    int q = partition( a, 1, n );

    for( int i = 1; i <= n; i++ )
    {
        if( i == q && i != n )                          //presentation error処理その他
            cout << "[" << a[i] << "]" << " ";
        else if( i == q && i == n )
            cout << "[" << a[i] << "]" << endl;
        else if( i != n )
            cout << a[i] << " ";
        else
            cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3368
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
char s[maxn];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans1=n,ans2=n;
	REP(i,1,n){
		if(s[i]=='1') ans1=min(ans1,max(n-i,i-1));
		else if(s[i]=='0') ans2=min(ans2,max(n-i,i-1));
	}
	printf("%d\n",max(ans1,ans2));
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;

vector<long long> dijk(long long s, long long v, vector<vector<pair<long long, long long> > > adjlist){
    
    priority_queue <pair<long long, long long> > wait;
    vector<long long> result(v, INF);

    //スタート地点を追加
    result[s] = 0;
    wait.push(make_pair(0, s));

    //ダイクストラ本体
    while(!wait.empty()){    //waitが空になるまで

        long long nowpoint = wait.top().second;
        long long nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;

        //今いる頂点と隣接しているすべての頂点をなめる
        for(long long i = 0; i < adjlist[nowpoint].size(); i++){

            long long nextpoint = adjlist[nowpoint][i].second;
            long long nextcost = nowcost + adjlist[nowpoint][i].first;
            //現時点より安く到達できそうであれば、結果を更新して優先度付きキューに格納
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    
    return result;         //結果列を返す
}

signed main(){

    long long n, m, s, g; cin >> n >> m >> s >> g;
    s--;
    g--;
    vector<vector<pair<long long, long long> > > adj_from_s(n);          //first := コスト　second := 行先
    vector<vector<pair<long long, long long> > > adj_from_g(n);          //first := コスト　second := 行先    

    for(long long i = 0; i < m; i++){
        long long u, v, a, b; cin >> u >> v >> a >> b;
        u--;
        v--;
        adj_from_s[u].push_back({a, v});
        adj_from_s[v].push_back({a, u});
        adj_from_g[u].push_back({b, v});
        adj_from_g[v].push_back({b, u});
    }

    vector<long long> result_from_s(n);
    result_from_s = dijk(s, n, adj_from_s);

    vector<long long> result_from_g(n);
    result_from_g = dijk(g, n, adj_from_g);

    vector<pair<long long, long long> > cost(n);                          //first := cost   second := i番目で両替
    for(long long i = 0; i < n; i++){
        cost[i] = {result_from_s[i] + result_from_g[i], i + 1};
    }

    sort(cost.begin(), cost.end());
    
    /*for(long long i = 0; i < n; i++){
        cout << cost[i].first << " " << cost[i].second << endl;
    }*/

    long long idx = 0;

    for(long long i = 0; i < n; i++){
        while(cost[idx].second <= i){
            idx++;
        }

        cout << 1000000000000000 - (long long)cost[idx].first << endl;
    }

    return 0;
}

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

const int MAX_V = 50;
const int MAX_S = 2505;
const ll INF = 1e18;

struct Edge {
    int to, a, b;
    Edge(int to, int a, int b):to(to), a(a), b(b){}
};

struct Data {
    int v,s;
    ll x;
    Data(int v, int s, ll x):v(v),s(s), x(x){}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};

vector<Edge> G[MAX_V];
ll dist[MAX_V][MAX_S+5];

int main() {
    int N,M,S;
    cin >> N >> M >> S;
    S = min(S, MAX_S);
    rep(i,M) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        --u; --v;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }
    vector<int> c(N), d(N);
    rep(i,N) cin >> c[i] >> d[i];

    rep(i,N) rep(j,MAX_S+5) dist[i][j] = INF;
    priority_queue<Data> que;
    auto push =[&](int v, int s, ll x) {
        if(s < 0) return;
        if(dist[v][s] <= x) return;
        dist[v][s] = x;
        que.emplace(v, s, x);
    };
    push(0, S, 0);

    while(que.size()) {
        Data hoge = que.top(); que.pop();
        int v = hoge.v, s = hoge.s;
        ll x = hoge.x;
        if(dist[v][s] < x) continue;
        {
            int ns = min(s + c[v], MAX_S);
            push(v, ns, x + d[v]);
        }
        for(auto e : G[v]) {
            push(e.to, s-e.a, x+e.b);
        }
    }

    for(int i = 1; i < N; ++i) {
        ll res = INF;
        rep(j,MAX_S+5) {
            res = min(res, dist[i][j]);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 6344
// CONTEST

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

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#ifndef DEBUG
#define DEBUG 0
#endif
#define dbg(X) do { if (DEBUG) { cout << #X ": " << (X) << endl << flush; } } while (0)
#define dbg2(X) do { if (DEBUG) { cout << #X ":" << endl; for (auto& __x : (X)) { cout << __x << endl << flush; } } } while (0)
#define dbgv(...) do { if (DEBUG) { cout << "(" #__VA_ARGS__ "): " << make_tuple(__VA_ARGS__) << endl << flush; } } while (0)
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Modulo op
constexpr ll modulo = 1000000000 + 7;
ll madd(ll x, ll y) { return (x + y) % modulo; }
ll msub(ll x, ll y) { return (x - y) % modulo; }
ll mmul(ll x, ll y) { return (x * y) % modulo; }
ll mexp(ll x, ll e) {
  ll res = 1;
  while (e > 0) {
    if (e & 1) { res = mmul(res, x); }
    x = mmul(x, x); e >>= 1;
  }
  return res;
}
ll minv(ll x) { return mexp(x, modulo - 2); }
ll mdiv(ll x, ll y) { return mmul(x, minv(y)); }

// Main
void mainCase() {
  ll n;
  cin >> n;
  vector<ll> ls(n, 0);
  cin >> ls;

  ll s = 0;
  FOR(i, 0, n) {
    s = madd(s, ls[i]);
  }

  ll res = 0;
  FOR(i, 0, n) {
    s = msub(s, ls[i]);
    res = madd(res, mmul(ls[i], s));
  }
  res = madd(res, modulo);
  cout << res << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  // [ Single case ]
  mainCase();
  return 0;
  // [ Multiple cases ]
  // int t;
  // cin >> t;
  // FOR(i, 0, t) { mainCase(); }
  // return 0;
}

/*
python misc/run.py atcoder/abc177/c/main.cpp --check

%%%% begin
3
1 2 3
%%%%
11
%%%% end
*/


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

typedef struct node {
    int key;
    struct node *parent, *left, *right;
} Node;

Node *root;

void Search(int key) {
    Node *x = root;
    while (x != NULL) {
        if (key == x->key) {
            cout << "yes" << endl;
            return;
        }
        if (key < x->key) x = x->left;
        else x = x->right;
    }
    cout << "no" << endl;
}

void Insert(int key) {
    Node *x = root, *y = NULL, *z;    
    z = (Node *)malloc(sizeof(Node));
    z->left = NULL;
    z->right = NULL;
    z->parent = NULL;
    z->key = key;
    //cout << root << endl;
    while (x != NULL) {
        //cout << x << endl;
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    //cout << "ok" << endl;
    z->parent = y;
    //cout << y << endl;

    if (y == NULL) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
}

Node *nxt(Node *x){
  if (x->left != NULL) return nxt(x->left);
  return x;
}

void Delete(Node *x) {
    Node *y = x->parent;
    if (x->left == NULL && x->right == NULL) {
        if (y != NULL && y->left == x) y->left = NULL;
        if (y != NULL && y->right == x) y->right = NULL;
        free(x);
        return;
    }
    if (x->left == NULL && x->right != NULL) {
        if (y != NULL && y->left == x) y->left = x->right;
        if (y != NULL && y->right == x) y->right = x->right;
        (x->right)->parent = y;
        free(x);
        return;
    }
    if (x->left != NULL && x->right == NULL) {
        if (y != NULL && y->left == x) y->left = x->left;
        if (y != NULL && y->right == x) y->right = x->left;
        (x->left)->parent = y;
        free(x);
        return;
    }
    Node *z = nxt(x->right);
    x->key = z->key;
    Delete(z);
}

void delete_(int key) {
    Node *x = root;

    while (x != NULL && key != x->key) {
        if (key < x->key) x = x->left;
        else x = x->right;
    }
    /*
    if (x == NULL) {
        printf("(not found)\n");
        return;
    }*/
    Delete(x);
}

void mid_dfs(Node *x) {
    if (x->left != NULL) mid_dfs(x->left);
    cout << " " << x->key;
    if (x->right != NULL) mid_dfs(x->right);
}

void pre_dfs(Node *x) {
    cout << " " << x->key;
    if (x->left != NULL) pre_dfs(x->left);
    if (x->right != NULL) pre_dfs(x->right);
}

void print() {
    mid_dfs(root);
    cout << endl;
    pre_dfs(root);
    cout << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string ope;
        cin >> ope;

        if (ope == "insert") {
            int k;
            cin >> k;
            Insert(k);
        }
        else if (ope == "find") {
            int k;
            cin >> k;
            Search(k);
        }
        else if (ope == "delete") {
            int k;
            cin >> k;
            delete_(k);
        }
        else {
            print();
        }
    }
}



Measured memory_bytes: 21916
S = gets.chomp

cubes = S.dup
t = 0

while cubes.size > 0 && t < cubes.size
  if cubes[t...t + 2].match(/01|10/)
    cubes.slice!(t, 2)
    t = t - 2
  end
  t = t + 1
end

puts S.size - cubes.size


Measured memory_bytes: 68604
#include <stdio.h>
int main(){
  int n,i,tmp;
  int *a;
  
  scanf("%d",&n);
  a=(int*)calloc(n,sizeof(int));
  
  for(i=0;i<n;i++){
    scanf("%d",&tmp);
    a[tmp]++;
    if(a[tmp]>2 || a[0]>1){
      printf("0");
      return 0;
    }
  }
  
  tmp=1;
  for(i=0;i<n/2;i++){
    tmp*=2;
    tmp=tmp%1000000007;
  }
  printf("%d",tmp);
  free(a);
}

Measured memory_bytes: 512
// AOJ Volume 0 Problem 0043

#include <stdio.h>
#include <string.h>



void puzzle1(int no, int *n, int comb, int *answer)
{
	int i;
	int ret;
	int sum = 0;

	for (i = 1; i <= 7; i++){
		if (n[i] > 0  && n[i + 1] > 0 && n[i + 2] > 0){
// printf("[123:%d]", i);

			n[i    ]--;
			n[i + 1]--;
			n[i + 2]--;
			
			puzzle1(no, n, comb++, answer);
			
			n[i    ]++;
			n[i + 1]++;
			n[i + 2]++;
			
//			return;
		}
	}
	
	for (i = 1; i <= 9; i++){
		if (n[i] == 3){
// printf("[333:%d]", i);
			n[i] -= 3;
			puzzle1(no, n, comb++, answer);
			n[i] += 3;
			
//			return;
		}
	}
	
	for (i = 1; i <= 9; i++){
		sum += n[i];
	}
	
	
	if (sum == 2){
		for (i = 1; i <= 9; i++){
//			printf("<%d>", sum);
			if (n[i] == 2){
				answer[no] = 1;
//				printf("[%d]", no);
				return;
			}
			else if (n[i] > 0){
				break;
			}
		}
	}
	return;
}


int main(void)
{
	char in[14];
	int n[11];
	int answer[11];
	int i;
	int flg_first;
	
	while (scanf("%s", in) != EOF){
		
		memset(n, 0, sizeof(n));
		memset(answer, 0, sizeof(answer));
		for (i = 0; i < 13; i++){
			n[in[i] - '0']++;
		}

		flg_first = 0;
		for (i = 1; i <= 9; i++){
			if (n[i] < 4){
				n[i]++;

				puzzle1(i, n, 0, answer);

				n[i]--;
			}
		}
		for (i = 1; i <= 9; i++){
			if (answer[i] != 0){
				if (flg_first == 1){
					printf(" ");
				}
				flg_first = 1;
				printf("%d", i);
			}
		}
		if (flg_first == 0){
			printf("0");
		}
		printf("\n");
	}
	return (0);
}

Measured memory_bytes: 0
$queen_poss = [nil] * 8

def valid?(new_i, new_j)

  if $queen_poss[new_i] != nil
    return false
  end

  # Check column
  $queen_poss.each{|j|
    if j == new_j
      return false
    end
  }

  i = new_i
  j = new_j
  while 0 <= i-1 && 0 <= j-1
    i -= 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while i+1 < 8 && j+1 < 8
    i += 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while 0 <= i-1 && j+1 < 8
    i -= 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  i = new_i
  j = new_j
  while i+1 < 8 && 0 <= j-1
    i += 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  return true
end

def print_queens()
  $queen_poss.each{|j|
    row = ['.'] * 8
    row[j] = 'Q'
    puts(row.join)
  }
end


$fixed_ijs = []

# Input values
_ = gets
while line = gets
  i, j = line.split(' ').map(&:to_i)
  $queen_poss[i] = j
  $fixed_ijs.push([i, j])
end


def solve(i)

  if i == 8
    print_queens()
    return true
  end

  (0...8).each{|j|
    if $fixed_ijs.include?([i,j])
      solve(i+1)
    end
    if valid?(i, j)
      $queen_poss[i] = j
      solve(i+1)
      $queen_poss[i] = nil
    end
  }

  return false
end


solve(0)



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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

ll dp[105][5][2];

ll solve(int idx,int nz,bool ls){
	if (idx>=n){
		return nz==k;
	}
	ll &r=dp[idx][nz][ls];
	if (r!=-1)
		return r;
	r=0;
	for(int i=0;i<10;i++){
		x= s[idx]-'0';
		if ((!ls && i>x) || (nz>=k && i))
			break;
		r+=solve(idx+1,nz+(i!=0),ls|(i<x));
	}
	return r;
}

int main(){
	//IO();
	memset(dp,-1,sizeof dp);
	scanf("%s",s);
	scanf("%d",&k);
	n=strlen(s);
	printf("%lld\n",solve(0,0,0));
}


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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

#define ALL(x) x.begin(),x.end()

#define P pair<ll,ll>

#define F first

#define S second

signed main(){

  ll A,B,C,K,ans;cin>>A>>B>>C>>K;
  if(K<=A+B)ans=min(A,K);
  else ans=2*A+B-K;
  printf("%lld\n",ans);

  return 0;

}

Measured memory_bytes: 3764
s[1<<17],t[1<<17];a,b,c;main(d){for(;d=getchar()/11;a++)s[a+1]=s[a]+d-4;for(;d=getchar()/11;b++)t[b+1]=t[b]+d-4;for(gets(&a);~scanf("%d%d%d%d",&a,&b,&c,&d);)puts((s[b]-s[a-1]-t[d]+t[c-1])%3?"NO":"YES");}

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


struct misaka{
	int x,y;
	int cnt;
}e;

int n,m;
int sx,sy;
int ex,ey;
char g[2000][2000];
bool st[2000][2000];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int ans = 10e8;

void bfs(){
	deque<misaka> q;
	q.push_back({sx,sy,0});
	
	while(!q.empty()){
		auto tmp = q.front();
		q.pop_front();
		
		int x = tmp.x;
		int y = tmp.y;
		int cnt = tmp.cnt;
		
		if(x == ex && y == ey){
			ans = cnt;
			return;
		}
		
		if(st[x][y]) 
			continue;
		st[x][y] = true;
		
		for(int i = 0;i < 4;++i){
			int tx = x + dx[i];
			int ty = y + dy[i];
			
			if(tx < 1 || tx > n || ty < 1 || ty > m || g[tx][ty] == '#')
				continue;
			
			q.push_front({tx,ty,cnt});
		}
		
		for(int i = x - 2;i <= x + 2;++i){
			for(int j = y - 2;j <= y + 2;++j){
				if(i < 1 || i > n || j < 1 || j > m || g[i][j] == '#')
					continue;
				
				q.push_back({i,j,cnt+1});
			}
		}
		
	}
}
int main(){
	scanf("%d %d %d %d %d %d",&n,&m,&sx,&sy,&ex,&ey);
	
	for(int i = 1;i <= n;++i)
		scanf("%s",g[i]+1);
		
		
	bfs();
	
	if(ans == 10e8) 
		printf("-1\n");
	else
		printf("%d\n",ans);
		
	return 0;
} 

Measured memory_bytes: 9280
# B - 105
N = int(input())

def make_divisours(n):
    return_list = []
    for i in range(1,int(n**0.5) + 1):
        if n%i == 0:
            return_list.append(i)
            if i != n//i:
                return_list.append(n//i)
    return return_list

cnt = 0
for i in range(1,N+1,2):
    divisours = make_divisours(i)
    if len(divisours) == 8:
        cnt += 1
print(cnt)

Measured memory_bytes: 62264
from collections import deque

a=deque(list(input()))
b=deque(list(input()))
c=deque(list(input()))
n=len(a)+len(b)+len(c)

t=a.popleft()
if len(a)==0:
    print('A')
    exit()

for i in range(n-1):
    if t=='a':
        if len(a)==0:
            print('A')
            exit()
        t=a.popleft()
    elif t=='b':
        if len(b)==0:
            print('B')
            exit()
        t=b.popleft()
    elif t=='c':
        if len(c)==0:
            print('C')
            exit()
        t=c.popleft()

Measured memory_bytes: 3316
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

max_a = max(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(min(dp[h:]))


Measured memory_bytes: 3832
X = int(input())


import math
def get_sieve_of_eratosthenes(n):
    if n==1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

result = get_sieve_of_eratosthenes(200000)
ans = [i for i in result if (i>=X  and i <= X*3)]
print(min(ans))

Measured memory_bytes: 11800
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    if l[i] != l[j]:
      for k in range(j+1,n):
        if l[j] != l[k]:
          if l[i] < l[j]+l[k]:
            c += 1
print(c)

Measured memory_bytes: 67676
#include<bits/stdc++.h>
using namespace std;
int main(){

	int n;
	cin >> n;
	long long sum =0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{	int x = __gcd(i,j);
			for(int k = 1; k <= n; k++)
			{
				sum += __gcd(k,x);
			}
		}
	}
	cout << sum << endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  print(min(b, a * n));
}


Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int a,b;
    cin >> a >> b;
    
    int c = __gcd(a,b);
    
    cout << (a*b)/c ;
    
	return 0;
    
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k=0,ans=0,x[2]={0};
        cin>>n;
        
      vector<ll>A(n);
      map<ll,ll> B;
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
            B[A[i]]++;
          
        }
        // sort(A,A+n);
        sort(A.begin(),A.end());
      	 
        for(ll i=n-1;i>=0;i--)
        {
          
            if(B[A[i]]>=2)
            {
              
                if((B[A[i]]>=4 && k==0))
                {
                    ans=A[i]*A[i];
                    break;
                }
                x[k]=A[i];
              
                k++;
                if(k==2)
            	{
            		ans=x[0]*x[1];  
            		cout<<ans;
            		return 0;
            	}
            	i=max(0ll,i-B[A[i]]+1);
            }
            
        }
        cout<<ans;
    } 
    return 0;
}

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

 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 1e5 + 1;//                                                             |
//----------------------------------------------------------------------------------




void solve()
{
    ll n;cin>>n;
    ll ans=1;
    ll res=0;
    int f=0;
    for(ll i=0;i<n;i++){
        res=(res*10+7)%n;
        if(res==0) {f=1;break;}
        else ans++;
    }
    if(f ) cout<<ans<<"\n";
    else cout<<-1<<"\n";
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N + 1, 0);
    vector<ll> B(N + 1, 0);
    for (int i = 1; i <= N; ++i)
    {
        cin >> A[i];
        B[i] = B[i - 1] + A[i];
    }

    map<ll, ll> sameModMap;
    REP(i, N + 1)
    {
        ll res = B[i] % M;
        auto iter = sameModMap.find(res);
        if (iter == sameModMap.end())
        {
            sameModMap[res] = 1;
        }
        else
        {
            sameModMap[res]++;
        }
    }

    ll ans = 0;
    for(auto iter = sameModMap.begin(); iter != sameModMap.end(); ++iter)
    {
        ll num = iter->second;
        ans += num * (num - 1) / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5760
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    ll n, m;
    cin >> n >> m;
    vl v;
    if(n > m/2){
        cout << m/2;
        return 0;
    }
    v.pb((2*n+m)/4);
    v.pb((n+m/2)/2);
    sort(all(v));
    cout << v[0];


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <numeric>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	string s1;
	for (int j = 0; j < s.size(); ++j) {
		if (s[j] == 'B' && j < s.size() - 1 && s[j + 1] == 'C')
		{
			s1 += 'D'; 
			++j;
		}
		else s1 += s[j];
	}
	long long res = 0;
	int i = s1.size() - 1;
	int seq = 0;
	while (i >= 0) {
		if (s1[i] == 'A') {
			res += seq;
		}
		if (s1[i] == 'D')
			++seq;
		if (s1[i] == 'B' || s1[i] == 'C') {
			seq = 0;
		}
		--i;
	}
	cout << res << endl;
	return 0;
}


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

int main(){
    int a,b;
    cin>>a>>b;
    int ak=a;
    long sum=0;
    vector<int> v;
    while(a--){
        int c;
        cin>>c;
        v.push_back(c);
        sum+=c;
    }
    long val=b-sum;
    if(val==0) cout<<ak<<endl;
    else{
        long al=val/sum;
        long app=val/(*min_element(v.begin(),v.end()));
        cout<<max(al,app)+ak<<endl;
    }
    return 0;
}

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

int main() {
      string s;
      int ans = 0;

      cin >> s;
      if(s[0] == '1'){
            ans++;
      }
      if(s[1] == '1'){
            ans++;
      }
      if(s[2] == '1'){
            ans++;
      }
      cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MX 5000000
ll fact[MX+8];
ll rfact[MX+8];
ll i,j,k,l,a,b;
ll mod = 1000000007ll;

ll rui(ll a,ll b){
	if(b == 0){
		return 1;
	}else if(b == 1){
		return a;
	}else{
		if(b % 2 == 1){
			ll ans = a * rui(a,b-1);
			ans %= mod;
			return ans;
		}else{
			ll ans = rui(a,b/2);
			ans *= ans;
			ans %= mod;
			return ans;
		}
	}
}


void c3_init(){
	fact[0] = 1;
	for(int i=1;i<=MX;i++){
		fact[i] = fact[i-1] * i;
		fact[i] %= mod;
	}
	rfact[MX] = rui(fact[MX],mod-2);
	for(i=MX-1;i>=0;i--){
		rfact[i] = rfact[i+1] * (i+1);
		rfact[i] %= mod;
	}
}



ll suma[MX+100],sumb[MX+100];

ll c3(ll n,ll r){
	//nCrwomotomeru
	if(n == 0){
		return 1;
	}
	if(r > n || n < 0 || r < 0){
		if(r > n)cout << "r > n" << endl;
		if(n < 0)cout << "n < 0" << endl;
		if(r < 0)cout << "r < 0" << endl;
		//cout << " !!! " << endl;
	}
	if(r == 0){
		return 1;
	}
	return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

bool solve(){
	ll a,b,c,sx,sy;
	cin >> a >> b >> c >> sx >> sy;
	if(a + b + c == 0)return false;
	if(sx < sy){
		swap(a,b);
		swap(sx,sy);
	}
	//sx > sy 
	for(int i=0;i<=sx;i++){
		if(a == 0){
			if(i == 0){
				suma[i] = 1;
			}else{
				suma[i] = 0;
			}
		}else{
			if(i == 0){
				suma[i] = 0;
			}else{
				if(i < a){
					suma[i] = 0;
				}else{
					suma[i] = c3(i-1,a-1);
				}
			}
		}
	}
	for(int i=0;i<=sy;i++){
		if(b == 0){
			if(i == 0){
				sumb[i] = 1;
			}else{
				sumb[i] = 0;
			}
		}else{
			if(i == 0){
				sumb[i] = 0;
			}else{
				if(i < b){
					sumb[i] = 0;
				}else{
					sumb[i] = c3(i-1,b-1);
				}				
			}
		}
	}
	ll ans = 1;
	ll sum = 0;
	for(int i=0;i<=sy;i++){
		//cout << suma[i + sx - sy] * sumb[i] << endl;
		sum += (((suma[i + sx - sy] * sumb[i]) % mod) * c3(a+b+c-1+sy - i,sy - i) % mod);
		sum %= mod;
	}
	//cout << suma[29] << " " << sumb[0] << endl;
	ans = c3(a+b+c,a) * c3(b+c,b);
	ans %= mod;
	ans *= sum;
	ans %= mod;
	//ans *= c3(a+b+c-1+sy,sy);
	ans %= mod;
	cout << ans << endl;
	return true;
}

int main(){
	
	c3_init();
	while(solve()){}
	
}



Measured memory_bytes: 96840
N = int(input())
H = list(map(int, input().split()))

if N == 1:
    print(0)
else:
    ans = 0
    H1 = H[0]
    H2 = H[1]
    count = 1
    move = 0
    while count != N:
        count += 1
        if H2 <= H1:
            move += 1
            ans = max(ans, move)
        else:
            move = 0
        if count != N:
            H1 = H2
            H2 = H[count]

    print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<vector<int>> fld(30,vi(30));
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
int h, w, ans;

bool check(int x, int y)
{
	if (x >= 0 && x < h && y >= 0 && y < w) return true;
	return false;
}

void solve(int x,int y, int n)
{
	if (n == 10) return;
	REP(i, 4)
	{
		int nx = x; int ny = y;
		if (!check(nx+dx[i],ny+dy[i])||fld[nx + dx[i]][ny + dy[i]] == 1) continue;
		while (1)
		{
			nx += dx[i]; ny += dy[i];
			if (!check(nx, ny)) break;
			if (fld[nx][ny] == 1) break;
			if (fld[nx][ny] == 3)
			{
				ans = min(ans, n + 1);
				return;
			}
		}
		if (!check(nx, ny)) continue;
		fld[nx][ny] = 0;
		solve(nx - dx[i], ny - dy[i], n + 1);
		fld[nx][ny] = 1;
	}
}

int main()
{
	while (cin >> w >> h, w)
	{
		ans = 100;
		int x, y;
		REP(i, h)REP(j, w)
		{
			cin >> fld[i][j];
			if (fld[i][j] == 2)
			{
				x = i; y = j;
				fld[i][j] = 0;
			}
		}
		solve(x, y, 0);
		cout << (ans==100?-1:ans) << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
A = []

N, M, C = (int(x) for x in input().split())

B_before = input().split()
B = ([int(x) for x in B_before])

for i in range(N):
    A_before = input().split()
    A.append([int(x) for x in A_before])

count = 0

for i in range(N):
    answer = 0
    for j in range(M):
        answer += A[i][j] * B[j]
        if j == M - 1:
            answer += C
            if answer > 0:
                count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int B, A, N;
vector<int> P;

int main() {
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++)
	{
		int tmpP;
		cin >> tmpP;
		P.push_back(tmpP);
	}

	vector<int> n(3);
	for (const auto &tmpP : P)
	{
		if (tmpP <= A) {
			n[0]++;
		}
		else if (tmpP <= B) {
			n[1]++;
		}
		else {
			n[2]++;
		}
	}

	int ans = min(min(n[0],n[1]),n[2]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256