akhauriyash/Code-Regression huggingface dataset:
for i in range(input()):
    s=raw_input()
    cur=0
    for j in range(input()):
        cmd=raw_input()
        if cmd=="forward char":
            cur=min(cur+1,len(s))
        elif cmd=="forward word":
            while cur<len(s) and s[cur]==" ":
                cur+=1
            while cur<len(s) and s[cur]!=" ":
                cur+=1
        elif cmd=="backward char":
            cur=max(cur-1,0)
        elif cmd=="backward word":
            while cur>0 and s[cur-1]==" ":
                cur-=1
            while cur>0 and s[cur-1]!=" ":
                cur-=1
        elif cmd=="delete char":
            if cur!=len(s):
                s=s[:cur]+s[cur+1:]
        elif cmd=="delete word":
            temp=cur
            if temp>=len(s):
                continue
            while temp<len(s) and s[temp]==" ":
                temp+=1
            if temp>=len(s):
                continue
            while temp<len(s) and s[temp]!=" ":
                temp+=1
            s=s[:cur]+s[temp:]
        elif "insert" in cmd:
            idx1=cmd.find('"')
            idx2=cmd.find('"',idx1+1)
            s=s[:cur]+cmd[idx1+1:-1]+s[cur:]
            cur+=idx2-idx1-1
    print s[:cur]+"^"+s[cur:]

Measured memory_bytes: 4324
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	long long int n,a[10000000],some=0,ans=0,spe=0,t=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]%4==0){
			ans++;
		}
		if(a[i]%2==0 && a[i]%4!=0){
			some++;
		}
	}
	if(n/2<=ans || ans*2+some>=n){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x>a.x;
        return y<a.y;
    }
};


vector<P> v[1];
vector<int> v1;
//bitset<4001000> b;
int i,n,m,k,a,d,b,c;
int e;
int o[211111];
int l[211111];
int j[1];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q[2];
queue<int> q;
string r,r1;

//char r[211111];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    //if(a.x!=b.x)
    return a.x<b.x;

}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();


int main()
{
    cin>>r;
    for(int t=0;t<r.size();t++)
    if(r[t]=='A')
    {
        n++;
    }
    else if(r[t]=='B'&&t+1<r.size()&&r[t+1]=='C')
    {
        x+=n;
        t++;
    }
    else
    {
        n=0;
    }
    printf("%lld",x);
}




Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
	string s, t;
	cin >> s >> t;
	int a, b; 
	cin >> a >> b;
	string u;
	cin >> u;
	if(u == s) {
		a -= 1;
	}else {
		b -= 1;
	}
	cout << a << " " << b << "\n";
	return 0;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===


using Tup = tuple<int, int, int>;



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

	string S;
	cin >> S;
	int N = (int)S.size() + 1;

	vector<Tup> lanv;
	bool is_l = true;
	int cnt = 0;
	for (int i = 0; i < N - 1; ++i) {
		if (is_l) {
			if (S[i] == '<') ++cnt;
			else {
				lanv.emplace_back(cnt, i, 1);
				cnt = 1;
				is_l ^= true;
			}
		}
		else {
			if (S[i] == '>') ++cnt;
			else {
				lanv.emplace_back(cnt, i, 0);
				cnt = 1;
				is_l ^= true;
			}
		}
	}


	if (cnt > 0) {
		if (S[N - 2] == '<') lanv.emplace_back(cnt, N - 1, 1);
		else lanv.emplace_back(cnt, N - 1, 0);
	}


	sort(lanv.begin(), lanv.end(), greater<Tup>());

	Vi ans(N, -1);

	for (const auto& tu : lanv) {
		int cnt, pos, less;
		tie(cnt, pos, less) = tu;
		if (less == 1) {
			pos -= cnt;
			for (int i = 0; i < cnt + 1; ++i) {
				if (ans[i + pos] == -1) {
					ans[i + pos] = i;
				}
			}
		}
		else {
			for (int i = 0; i < cnt + 1; ++i) {
				if (ans[pos - i] == -1) {
					ans[pos - i] = i;
				}
			}
		}
	}


	ll sum = 0;
	for (const auto& ai : ans) sum += ai;

	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 6032
#!/usr/bin/env python3
import sys

def f(n):
    if n % 2  == 0:
        return int(n/2)
    else:
        return int((3 * n) + 1)


def solve(s: int):
    
    m_set = set()
    pn = s
    m_set.add(s)
    for m in range(1,100000000):
        nn = f(pn)
        if nn in m_set:
            print(m+1)
            return
        else:
            m_set.add(nn)
            pn = nn


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n, p = map(int, input().split())
s = list(map(int, list(input())))[::-1]

sum = 0
cnt = [0] * p
cnt[0] = 1
n = len(s)
for i in range(n):
    d = s[i] * pow(10, i, p)
    sum = (sum + d) % p
    cnt[sum] += 1

ans = 0
if p in [2, 5]:
    if p == 2:
        ok_list = [0, 2, 4, 6, 8]
    if p == 5:
        ok_list = [0, 5]

    for i in range(n):
        d = s[i]
        if d in ok_list:
            ans += n - i
           
else:
    for i in range(p):
        ans += cnt[i] * (cnt[i]-1) // 2


print(ans)


Measured memory_bytes: 6560
n=gets.to_i
for i in 0...n do
  rui = [0,0,0,0]
  outc=0
  while true do
    break if outc==3
    str = gets.chop
    if str=="HIT" then
      rui[3]+=rui[2]
      rui[2]=rui[1]
      rui[1]=rui[0]
      rui[0]=1
    elsif str=="HOMERUN" then
      rui[3]+=rui[2]+rui[1]+rui[0]+1
      for i in 0..2 do
        rui[i]=0
      end
    else
      outc+=1
    end      
 #   print rui[3]," ",outc,"\n"
  end
  print(rui[3],"\n")
end

Measured memory_bytes: 5024
package main

import "fmt"

func main() {
	var (
		s     string = "vvvvvv"
		count int
	)
	fmt.Scan(&s)

	sLen := len(s)
	for i := 0; i < sLen/2; i++ {
		lead := s[i : i+1]
		back := s[sLen-i-1 : sLen-i]
		if lead != back {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
n = gets.to_i
p = []
sum = 0
n.times do
  p << gets.to_i
end

p.sort!.reverse!

(1..n).each do |i|
  if i == 1 then 
    sum += p[i-1]/2
  else
    sum += p[i-1]
  end
end

puts sum

Measured memory_bytes: 3836
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

#define MOD 1000000007
#define inf 2000000000

set<int> edg[101000];

int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int L;
	cin >> L;

	vector<int> bits;
	vector<int> pwrs;
	int LL = L;
	int pw = 1;
	while (LL > 0)
	{
		bits.push_back(LL % 2);
		LL /= 2;
		pwrs.push_back(pw);
		pw *= 2;
	}
	reverse(bits.begin(), bits.end());
	reverse(pwrs.begin(), pwrs.end());

	bool compress = false;
	

	vector<vector<pair<int,int>>> edges(bits.size() + 1);
	if (bits.size() == 20)
	{
		compress = true;
	}
	
	for (int i = 1; i < edges.size(); i++)
		edges[i - 1].push_back({ i,0 });

	int acc = pwrs[0];
	for (int i = 1; i + 1 < edges.size(); i++)
	{
		if (bits[i])
		{
			edges[0].push_back({ i + 1, acc });
			acc += pwrs[i];
		}
	}
	//edges[0].push_back({ edges.size() - 1, acc });

	for (int i = 1; i + 1 < edges.size(); i++)
	{
		edges[i].push_back({ i + 1, pwrs[i] });
	}

	if (compress)
	{
		for (int i = 0; i + 1 < edges.size(); i++)
		{
			auto new_vec = edges[i];
			new_vec.clear();
			for (auto x : edges[i])
			{
				if (x.first == 19)
				{
					new_vec.push_back(x);
					new_vec.push_back({ x.first, x.second + 1 });
				}
				else
				{
					if (x.first == 20)
						x.first = 19;
					new_vec.push_back(x);
				}
			}

			edges[i] = new_vec;
		}


		edges.pop_back();
		edges.back().clear();
	}


	int total = 0;
	for (auto x : edges)
		total += x.size();

	cout << edges.size() << " " << total << "\n";
	for (int i = 0; i < edges.size(); i++)
	{
		for (auto y: edges[i])
		{
			cout << i + 1 << " " << y.first + 1 << " " << y.second << "\n";
		}
	}

	return 0;
}


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

int main() {
    long long n, k;
    cin >> n >> k;
    pair <long long, long long> a[n];
    rep (i, n) cin >> a[i].first >> a[i].second;
    sort(a, a + n);

    for(long long sum = 0, i = 0;;i++) {
        sum += a[i].second;
        if (sum >= k) {
            cout << a[i].first << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
/*input
4
0 1 2 3
1 0 3 2
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 100005

int n;
int a[N], b[N];
multiset<int> st;
map<int, int> enc;
vector<vector<int> > e(N);
bool visited[N];

struct dsu {
	int par[N], sz[N];
	dsu() {
		for (int i = 1; i <= N - 4; i++) par[i] = i, sz[i] = 0;
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	int size(int x) {
		return sz[find(x)];
	}
	void uni(int x, int y) {
		x = find(x); y = find(y); sz[y]++;
		if (x != y) {
			sz[y] += sz[x]; sz[x] = 0;
			par[x] = y;
		}
	}
} d;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef UncleGrandpa
	freopen("1test.inp", "r", stdin);
#endif
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i], a[n + 1] ^= a[i], st.insert(a[i]), enc[a[i]];
	st.insert(a[n + 1]); enc[a[n + 1]];
	for (int i = 1; i <= n; i++) {
		cin >> b[i], b[n + 1] ^= b[i];
		if (st.find(b[i]) != st.end()) st.erase(st.find(b[i]));
	}
	if (st.find(b[n + 1]) != st.end()) st.erase(st.find(b[n + 1]));
	if (st.size()) {
		cout << "-1" << endl;
		return 0;
	}
	int cur = 0;
	for (auto it = enc.begin(); it != enc.end(); it++) {
		it->se = ++cur;
	}
	for (int i = 1; i <= n + 1; i++) a[i] = enc[a[i]];
	for (int i = 1; i <= n + 1; i++) b[i] = enc[b[i]];
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] != b[i]) {
			d.uni(a[i], b[i]);
		}
	}
	int ans = 0;
	if (d.size(a[n + 1])) {
		if (a[n + 1] == b[n + 1]) ans += d.size(a[n + 1]);
		else ans += d.size(a[n + 1]) - 1;
		visited[d.find(a[n + 1])] = true;
	}
	for (int i = 1; i <= n; i++) {
		if (!visited[d.find(a[i])] && d.size(a[i]) > 0) {
			ans += d.size(a[i]) + 1;
			visited[d.find(a[i])] = true;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 17664
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
 
using namespace std;
 
int main(){
	int n;
  	cin >> n;
  	if(n<100){
      cout << 111 << endl;
      return 0;
    } else {
      if(n%100 > (n/100)*11){
      	cout << (n/100+1)*111;
        return 0;
      } else{
        cout << (n/100)*111;
        return 0;
      }
    }
}

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

int N;
int change;
int money;

int main() {
	cin>>N;
	money = 1000;
	
	while (money<N){
		money = money + 1000;
	}
	
	change = money - N;
	cout<<change<<endl;
	return 0;
}

Measured memory_bytes: 3544
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, K, A[105];
bool DP[100005], visited[100005];

bool Calc(int turn){
  if (visited[turn] == true) return DP[turn];
  visited[turn] = true;
  if (turn == 0) return DP[0] = false;

  bool ans = false;
  for (int i = 0; i < N; i++){
    if (turn - A[i] < 0) continue;
    if (!Calc(turn - A[i])) ans = true;
  }
  return DP[turn] = ans;
}

int main(){
  scanf("%d%d",&N,&K);
  for (int i=0;i<N;i++)scanf("%d",&A[i]);

  Calc(K);
  if (DP[K]) printf("First\n");
  else printf("Second\n");

  return 0;
}


Measured memory_bytes: 6656
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=101101;
ll pw[22];
ll n;
int len;
int main(){
	scanf("%lld",&n);
	pw[0]=1;
	n--;
	for (int i=1; i<=11; i++)
		pw[i]=pw[i-1]*26;
	for (int i=1; i<=11; i++){
		if (n>=pw[i])	n-=pw[i];
		else{
			len=i;
			break;	
		}
	}
	for (int i=len; i>=1; i--){
		printf("%c",(int)(n/pw[i-1])+'a');
		n=n%pw[i-1];
	}
    return 0;
}

Measured memory_bytes: 1660
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    int n, w;
    cin >> n >> w;

    vector<vector<int>> item(4);

    int w0, v0;
    cin >> w0 >> v0;

    item[0].push_back(v0);
    for (int i = 1; i < n; i++) {
        int w, v;
        cin >> w >> v;
        item[w - w0].push_back(v);
    }


    for(int i = 0; i < 4; i++){
        sort(item[i].begin(), item[i].end(), std::greater<int>());
        item[i].insert(item[i].begin(), 0);
    }

    long best_v = 0;

    long sum_v0 = 0;
    for (size_t i0 = 0; i0 < item[0].size(); i0++) {
        sum_v0 += item[0][i0];

        long sum_v1 = 0;
        for (size_t i1 = 0; i1 < item[1].size(); i1++) {
            sum_v1 += item[1][i1];

            long sum_v2 = 0;
            for (size_t i2 = 0; i2 < item[2].size(); i2++) {
                sum_v2 += item[2][i2];

                long sum_v3 = 0;
                for (size_t i3 = 0; i3 < item[3].size(); i3++) {
                    sum_v3 += item[3][i3];

                    long sum_w = w0 * i0 + (w0 + 1) * i1 + (w0 + 2) * i2 + (w0 + 3) * i3;
                    long sum_v = sum_v0 + sum_v1 + sum_v2 + sum_v3;
                    if(sum_w <= w){
                        /*
                        cout << "solution" << endl;
                        cout << "sum_w  " << sum_w << endl;
                        cout << "sum_v  " << sum_w << endl;
                        cout << "sum_v0 " << sum_v0 << endl;
                        cout << "sum_v1 " << sum_v1 << endl;
                        cout << "sum_v2 " << sum_v2 << endl;
                        cout << "sum_v3 " << sum_v3 << endl;
                        */
                        best_v = max(best_v, sum_v);
                    }
                }
            }
        }
    }

    cout << best_v << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007LL
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll arr[50];
int main()
{
    string s;
    cin>>s;
    ll ans=0,total=0;
    for(int i=s.size()-1;i>=0;i--)
    {
        int c=s[i]-'a';
        ans+=(total-arr[c]);
        arr[c]++;
        total++;
    }
    cout<<ans+1LL<<endl;
}

Measured memory_bytes: 640
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	ll a,b,k,i;
	cin>>k>>a>>b;
	for(i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;
			break;
		}
	}
	if(i==b+1){
		cout<<"NG"<<endl;
	}
	


	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;
int num[4];

int main() {
    while (cin >> str) {
	  memset(num, 0, sizeof(num));
	  for (int i = 0; i < str.size(); ++i) {
		num[ (int)(str[i] - 'a') ]++;
	  }

	  sort(num, num + 3, greater<int>());
	  if (num[0] - num[2] >= 2) puts("NO");
	  else puts("YES");
	  
    }
}














Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();

template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<int>(0,N,"");

template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);
// outarr<ll>(0,V.size(),V);

//GCD: 最大公約数（再帰）
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

// #define NMAX 1000000000
ll a,b,c;

string solve(){
	ll d = c-a-b;
	string ans;
	if(d<=0){
		ans =  "No";
	}
	else if(4*a*b<d*d){
		ans = "Yes";
	}
	else{
		ans = "No";
	}
	return ans;
}

int main(){
	cin>>a>>b>>c;
	cout<< solve() <<endl;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

string S, T;

int main(void) {

    cin >> S >> T;

    if (T.substr(0, S.size()) != S) {
        cout << "No" << endl;
        return 0;
    }

    if (T.size() == S.size() + 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int n,m,t;
    scanf("%d %d",&n,&m);
    int a[n][m], b[m], ans[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
       }
    }
    for(int i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<n;i++){
        t=0;
        for(int j=0;j<m;j++){
            t+=(a[i][j]*b[j]);
        }
        ans[i]=t;
    }
    for(int i=0;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

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

struct edge{int s,t,n;}e[100010];
int n,a[100010],h[100010],f[100010];
vector <int> V;

void dfs(int x)
{
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)  dfs(y);
	V.clear();
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)  V.push_back(f[y]);
	sort(V.begin(),V.end()),reverse(V.begin(),V.end());
	for (int i=0; i<V.size(); i++)  f[x]=max(f[x],V[i]+i+1);
}

void work()
{
	scanf("%d",&n);
	for (int i=2; i<=n; i++)
		scanf("%d",&a[i]),e[i]=(edge){a[i],i,h[a[i]]},h[a[i]]=i;
	dfs(1);
	printf("%d",f[1]);
}

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


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ri register int
#define ptf printf
using namespace std;
typedef double db;
typedef long double ld;
typedef long long ll;
typedef vector <int> poly;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef unsigned long long ulll;
typedef unsigned int uii;
typedef string strr;
#define fi first
#define se second
#define pb push_back
#define ppp pop_back
#define rez resize
const ll Inf = 2e18;
const int rlen = 1 << 20, inf = 0x3f3f3f3f;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() getchar()//(((ib == ob) && (ob = (ib =  buf) + fread(buf, 1, rlen, stdin)), ib == ob) ? -1 : *ib++)
inline int read() {
  static int ans, f;
  static char ch;
  ans = 0, ch = gc(), f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans: -ans;
}
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  top = 0, ch = gc();
  while (!isalpha(ch) && !isdigit(ch)) ch = gc();
  while (isalpha(ch) || isdigit(ch)) s[++top] = ch, ch = gc();
  return top;
}
namespace modular {
  const int mod = 998244353;//= 1e9 + 7;
  //int mod;
  int ret;
  inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }
  inline void Dec(int &a, int b) { a = a < b? a - b + mod : a - b; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) {
    for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1);
    return ret;
  }
  inline int Inv(int a) { return ksm(a, mod - 2); }
  inline int sqr(int a) { return (ll) a * a % mod; }
  inline int cub(int a) { return (ll) a * a % mod * a % mod; }
} using namespace modular;
template <typename T> inline void ckmax(T &a, T b) { a < b ? a = b : 0; }
template <typename T> inline void ckmin(T &a, T b) { a > b ? a = b : 0; }
template <typename T> inline T Abs(T a) { return a < 0 ? -a : a; }
template <typename T> inline T gcd(T a, T b) {
  T t;
  while (b) t = a, a = b, b = t - t / a * a;
  return a;
}
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a - a / b * b, y, x);
  y -= a / b * x;
}
const int N = 105;
char s[N];
int n;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = Read(s);
  for (ri i = 1; i <= 3; ++i) cout << s[i];
  return 0;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

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

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

string s;
int d;
LL dpT[10000][2][100];
LL dp(int pos, int rivne, int ostacha)
{
	if(pos==SZ(s))
		return ostacha==0;
	if(dpT[pos][rivne][ostacha]!=-1)
		return dpT[pos][rivne][ostacha];
	if(rivne)
	{
		LL ans=0;
		FOR(i,0,(s[pos]-'0'))
		{
			ans=(ans+dp(pos+1,0,(ostacha+i)%d))%mod;
		}
		ans=(ans+dp(pos+1,1,(ostacha+s[pos]-'0')%d))%mod;
		return dpT[pos][rivne][ostacha]=ans;
	}
	else
	{
		LL ans=0;
		FOR(i,0,10)
		{
			ans=(ans+dp(pos+1,0,(ostacha+i)%d))%mod;
		}
		return dpT[pos][rivne][ostacha]=ans;
	}
}


int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
	FILL(dpT,-1);
	cin >> s >> d;
	cout<<(dp(0,1,0)+mod-1)%mod;
	return 0;
}


Measured memory_bytes: 16640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        long countW = s.replaceAll("[^W]", "").length() - 1;

        long result = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'W') {
                result += i - countW;
                countW--;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 45932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

bool has_divisor(int N, int i) {
    if(i==N)return false;
    if(N%i==0)return true;
    return has_divisor(N,i+1);
}

bool is_prime(int N) {
    if(N==1)return false;
    else if(N==2)return true;
    else return !has_divisor(N,2);//約数見つからなかったらfalseなのでその逆
}
 
int main(){
    int X;
    cin >> X;
    for(int i=X;i<100004;i++){
        if(is_prime(i)==true){
        cout << i << endl;
        break;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct proces{
  char name[10];
  int count;
  int time;
  }def;

int head,n,tail;
def c[100000];


void enq(def s){
  c[tail]=s;
  
  tail=(tail+1)%100000;

}


def deq(){
  def sd=c[head];
  head=(head+1)%100000;
  
  return sd;
}


int min(int k,int l){
  if(k>l) return l;
  else return k;
}


int main(){
  int tasu,i,q,b,sum=0;
  def type;
  scanf("%d %d",&b,&q);
  for(i=1;i<=b;i++){
    scanf("%s",c[i].name);
    scanf("%d",&c[i].time);
    c[i].count=1;
  }
  head=1;
  tail=b+1;
  while(tail != head){
    type=deq();
    tasu=min(q,type.time);
    type.time=type.time-tasu;
    sum=sum+tasu;
    if(type.time>0){
      enq(type);
    }
    else if(type.count==1){
      
      printf("%s %d\n",type.name,sum);
      type.count=0;
    }
    
  }
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const ll MX=20, MY=20;
bool map2d[MX][MY]; //行けるならtrue
ll depth[MX][MY];
ll dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};

ll bfs(ll sx, ll sy) {
    if(!map2d[sx][sy]) return 0;
    rep(i,MX) rep(j,MY) depth[i][j]=0; //初期化する
    if(depth[sx][sy]) return 0;
    deque<P> dq;
    dq.emplace_back(sx,sy);
    depth[sx][sy]=1; // departure: depth=1
    while(!dq.empty()) {
        ll vx = dq.front().first, vy = dq.front().second;
        dq.pop_front();
        rep(i,4){
            ll x=vx+dx[i], y=vy+dy[i];
            if(x<0 or x>=MX or y<0 or y>=MY) continue;
            if(!map2d[x][y]) continue;
            if(depth[x][y]!=0) continue;
            depth[x][y]=depth[vx][vy]+1;
            dq.emplace_back(x,y);
        }
    }
    ll ct=0;
    rep(i,MX) rep(j,MY) maxi(ct,depth[i][j]); 
    return ct-1; //行けたノード数を返す、深さなどでも可 
}
//--MAIN-----------------------------------
void Main() {
    ll H,W; cin>>H>>W;
    rep(i,H){
        rep(j,W){
            char c; cin>>c;
            if(c=='.') map2d[i][j]=1;
        }
    }
    ll ans=0;
    rep(i,MX) rep(j,MY) maxi(ans,bfs(i,j));
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> counter(m);

    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            counter[a - 1]++;
        }
    }
    int ans = 0;
    for (auto& c : counter)
    {
        if (c == n)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };
template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {
	RPQ<pair<Cost, int>> q;
	dist[start] = 0;
	q.emplace(dist[start], start);
	while(! q.empty()) {
		auto cp = q.top(); q.pop();
		int  p = cp.SE;
		Cost c = cp.FI;
		if(dist[p] != c) { continue; }
		for(auto && e : g[p]) {
			int  ep = e.FI;
			Cost ec = e.SE;
			if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }
		}
	}
	return;
}

// ----

int n, q, k;
vector<pair<int, LL>> v[100000];
LL dist[100000];
LL INF = 1e16;

int main() {
	cin >> n;
	inc(i, n - 1) {
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		v[a].EB(b, c);
		v[b].EB(a, c);
	}
	cin >> q >> k;
	k--;
	inc(i, n) { dist[i] = INF; }
	dijkstra(k, v, dist);
	inc(i, q) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << dist[x] + dist[y] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 11120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	hh := make([]int, n)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		hh[i] = getNextInt(scanner)
	}

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	seg := Segment{}

	seg.init(n + 1)

	for i := 0; i < n; i++ {
		mx := seg.max(0, hh[i])
		seg.maximize(hh[i], mx+aa[i])
	}

	fmt.Fprintln(writer, seg.bucket[seg.h-1][0])
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int64
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int64, 1)
	seg.bucket[0] = make([]int64, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int64, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index int, value int64) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		parent := index / seg.chunk
		if seg.bucket[seg.i+1][parent] < value {
			seg.bucket[seg.i+1][parent] = value
		}
		index /= seg.chunk
	}
}

func (seg *Segment) max(l, r int) int64 {
	var max int64
	if seg.n < r {
		r = seg.n
	}
	var i int
	for index := l; index < r; index += seg.unit[i] {
		for i < seg.h-1 && index%seg.unit[i+1] == 0 {
			i++
		}
		for i > 0 && index+seg.unit[i] >= r {
			i--
		}
		if max < seg.bucket[i][index/seg.unit[i]] {
			max = seg.bucket[i][index/seg.unit[i]]
		}
	}

	return max
}


Measured memory_bytes: 10496
N = int(input())

count_ab = 0
count_fb = 0
count_ea = 0
count_fbea = 0
for i in range(N):
    s = input()
    count_ab += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        count_fbea += 1
    elif s[0] == "B":
        count_fb += 1
    elif s[-1] == "A":
        count_ea += 1

ans = count_ab
if count_fbea > 0:
    ans += count_fbea - 1
    if count_fb > 0:
        count_fb -= 1
        ans += 1
    if count_ea > 0:
        count_ea -= 1
        ans += 1
ans += min(count_fb, count_ea)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n,m,x;
	cin >> n >> m >> x;
	vector <int> c(n);
	vvint a(n,vector <int>(m));
	for(int i = 0;i < n;++i){
		cin >> c[i];
		for(int j = 0;j < m;++j) cin >> a[i][j];
	}
	int minn = 2e9;
	bool flag = 0;
	for(int i = 0;i < (1 << n);++i){
		int num = i;
		int curr = 0;
		int k = 0;
		vector <int> d(m);
		while(num > 0){
			if(num & 1){
				curr += c[k];
				for(int j = 0;j < m;++j){
					d[j] += a[k][j];
				}
			}
			num >>= 1;
			++k;
		}
		bool flag0 = 1;
		for(int i = 0;i < m;++i){
			if(d[i] < x){
				flag0 = 0;
				break;
			}
		}
		if(flag0){
			flag = 1;
			minn = min(minn,curr);
		}
	}
	if(flag) cout << minn << newl;
	else cout << -1 << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<vector<char>> path(n,vector<char>(n));
    vector<vector<int>> d(n,vector<int>(n,100000));
    for(int i = 0;i < n;i++)d[i][i] = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
        cin >> path[i][j];
        if(path[i][j] == '1')d[i][j] = 1;
        }
    }
    //cout << "OK" << endl;
    for(int k = 0;k < n;k++){     
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(d[i][k] < 100000 && d[k][j] < 100000)d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
    /*for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
          cout << d[i][j] << endl;
        }
    }*/
    bool judge = true;
    int MAX = -1;
    for(int k = 0;k < n;k++){     
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(d[i][j] < 100000 && d[i][k] < 100000 && d[k][j] < 100000 && (d[i][j]%2) != ((d[i][k] + d[k][j])%2)){
                    //cout << d[i][k]+d[k][j] << d[i][j];
                    cout << -1 << endl;
                    judge = false;
                    break;
                }else{
                    if(d[i][j] < 100000)MAX = max(MAX,d[i][j]);
                }
            }
            if(judge == false)break;
        }
        if(judge == false)break;
    }
    if(judge)cout << MAX+1 << endl;
    //cin >> n;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define N 100100
#define NN 500010

int n, q;
int e[N];
string qr[N];
int S[N];
vector<int> qs[N];

int ne[NN][26], L = 1;
int co[NN];
vector<int> ed[NN];

int ans[26][27];

void ff(int x) {
	for (vector<int>::iterator ii = ed[x].begin(); ii != ed[x].end(); ii++) {
		int i = *ii;
		for (vector<int>::iterator qq = qs[i].begin(); qq != qs[i].end(); qq++) {
			int q = *qq;
			string s = qr[q];
			int T = 0;
			for (int j = 0; j < 26; j ++) {
				for (int k = 0; k < j; k ++)
					T += ans[s[j]-'a'][s[k]-'a'];
				T += ans[s[j]-'a'][26];
			}
			S[q] = T;
			//printf ("%d %d\n", q, T);
		}
	}
	
	for (int c = 0; c < 26; c ++) {
		if (!ne[x][c]) continue;
		for (int k = 0; k < 26; k ++)
			if (k != c && ne[x][k])
				ans[c][k] += co[ne[x][k]];
		ans[c][26] += (int) ed[x].size();
		ff(ne[x][c]);
		for (int k = 0; k < 26; k ++)
			if (k != c && ne[x][k])
				ans[c][k] -= co[ne[x][k]];
		ans[c][26] -= (int) ed[x].size();
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) {
		string s; cin >> s;
		int nw = 0;
		int l = (int) s.length();
		for (int j = 0; j < l; j ++) {
			int c = s[j]-'a';
			if (ne[nw][c] == 0) {
				ne[nw][c] = L++;
			}
			nw = ne[nw][c];
		}
		e[i] = nw;
		co[nw] ++;
		ed[nw].pb(i);
	}
	cin >> q;
	for (int i = 0; i < q; i ++) {
		int x;
		cin >> x >> qr[i];
		x --;
		qs[x].pb(i);
	}
	for (int i = L-1; i >= 0; i--) {
		for (int j = 0; j < 26; j ++)
			if (ne[i][j]) {
				co[i] += co[ne[i][j]];
			}
	}
	ff(0);
	for (int i = 0; i < q; i ++) 
		printf ("%d\n", S[i]+1);
	return 0;
}

Measured memory_bytes: 122364
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
//#define MOD 1000000007 //S.size()
using namespace std;
typedef unsigned long long ll;
const long long mod = 1000000007;
int main(void){
	int N;
	cin >> N;
	long long ans = 1;
	for(long long i = 1; i <= N; i++){
		ans *= i;
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }


int main(){
    set<ll> se;
    ll a,b,c;
    cin>>a>>b>>c;
    se.insert(a);
    se.insert(b);
    se.insert(c);
    if(se.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

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

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

    int num = s.size() - 2;
    cout << s[0] << num << s.back() << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

char s[11];

int main() {
    int n, i, j;
    long long ans = 0;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    if (n == 1) {
        printf("%s\n", s);
        
        return 0;
    }
    
    for (i = 0; i < (1 << (n - 1)); i++) {
        long long x = 0;
        
        for (j = 0; j < n; j++) {
            x *= 10;
            x += s[j] - '0';
            
            if ((i >> j) & 1) {
                ans += x;
                x = 0;
            }
        }
        
        ans += x;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    if n % 1000 == 0:
        print('0')
    else:
        print((n // 1000 + 1) * 1000 - n)
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27172
//My_Template

#include<bits/stdc++.h>

#define ll long long int
#define vec vector<long long int>
#define pb(a) push_back(a)
#define myfor(n) for(long long int i = 0; i < n; i++)
#define tc(t) long long int t; cin>>t; while(t--)
#define sortt(a) sort(a.begin(), a.end())
#define summ(a) accumulate(a.begin(), a.end(), 0ll)
#define M 1000000007ll

using namespace std;

int main() {

	//code_goes_here-->

	double n,x,t;

	cin>>n>>x>>t;

	int p = ceil(n/x);

	p = p*t;

	cout<<p;

	return 0;
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < n; i++){
			String str = sc.nextLine();
			System.out.println(str.replaceAll("Hoshino", "Hoshina"));

		}
	sc.close();

	}

}


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


int main(){
  ll A;
  double b;
   cin >> A;
   cin >> b;
  int B=100*b+0.5;
  
  cout << (A*B)/100 << endl;
  
}
  


Measured memory_bytes: 3664
/*
    Problem 14
    https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int MAX = 15;
const ll INF = 1e18;
/* global variables */
/* function */
/* main */
int main(){
    int N, K, upper;
    ll ans, tmp, pre;
    cin >> N >> K;

    vector<ll> building(N);
    for (int i = 0; i < N; i++) cin >> building[i];

    upper = pow(2, N);
    ans = INF;
    for (int b = 0; b < upper; b++) {
        bitset<MAX> bs(b);
        vector<int> v(MAX, 0);
        if (bs.count() != K or !bs[0]) continue;
        for (int i = 0; i < N; i++)
            if ((bs >> i)[0]) v[i] = 1;
        tmp = 0;
        pre = building[0];
        for (int i = 1; i < N; i++) {
            if (v[i]) {
                if (pre >= building[i]) {
                    tmp += pre - building[i] + 1;
                    pre++;
                }
            }
            pre = max(pre, building[i]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
}

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

int main()
{
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); i++) {
	if (ans.empty() && s[i] == 'B') {
	  continue;
	}
	if (s[i] == '0'|| s[i] == '1') {
	  ans.push_back(s[i]);
	}
	else {
	  ans.pop_back();
	}
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256