akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	vi v(4);
	rep(i,0,4){
		int a; string t;
		t.push_back(s[i]);
		v[i]=stoi(t);
	}
	rep(i,0,1<<3){
		int ans=v[0];
		vector<char> c(3);
		rep(j,0,3){
			if(i>>j&1){
				ans+=v[j+1];
				c[j]='+';
			}
			else{
				ans-=v[j+1];
				c[j]='-';
			}
		}
		if(ans==7){
			cout<<v[0];
			rep(k,0,3){
				cout<<c[k]<<v[k+1];
			}
			cout<<"=7"<<endl;
			return 0;
		}
	}
	
	
	
	return 0;
}

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

short l[2010][2010];
short r[2010][2010];
short u[2010][2010];
short d[2010][2010];

int main(){
    int H, W;
    char lst[2010][2010];
    cin >> H >> W;
    for(int i=0;i<2010;i++){
        for(int j=0;j<2010;j++){
            lst[i][j] = 0;
        }
    }

    string S;
    for(int i=0;i<H;i++){
        cin >> S;
        for(int j=0;j<W;j++){
            if(S[j] == '#') lst[i][j] = 1;
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            l[i][j] = r[i][j] = u[i][j] = d[i][j] = 0;
        }
    }
    

    for(int i=0;i<H;i++){
        for(int j=1;j<W;j++){
            if(lst[i][j] != 1 && lst[i][j-1] != 1){
                l[i][j] = l[i][j-1] + 1;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=W-2;j>=0;j--){
            if(lst[i][j] != 1 && lst[i][j+1] != 1){
                r[i][j] = r[i][j+1] + 1;
            }
        }
    }
    for(int j=0;j<W;j++){
        for(int i=1;i<H;i++){
            if(lst[i][j] != 1 && lst[i-1][j] != 1){
                u[i][j] = u[i-1][j] + 1;
            }
        }
    }
    for(int j=0;j<W;j++){
        for(int i=H-2;i>=0;i--){
            if(lst[i][j] != 1  && lst[i+1][j] != 1){
                d[i][j] = d[i+1][j] + 1;
            }
        }
    }
    int nlst_max = 0;
    int nlst;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            nlst = l[i][j] + r[i][j] + u[i][j] + d[i][j];
            if(lst[i][j] == 1){
                nlst = 0;
            }else{
                nlst++;
            }
            nlst_max = max(nlst_max, nlst);
        }
    }
    cout << nlst_max;
    return 0;
}

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> state(n, k - q);
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
        --a[i];
        state[a[i]]++;
    }
    for (int i = 0; i < n; ++i) {
        if (state[i] > 0) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
}

Measured memory_bytes: 1408
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<int> A(in());
	for (int &x :A)
		x = in();
	auto s = A.begin();
	for (int q = in(); q; q--) {
		int o = in(), b = in();
		if (o)
			outl(*max_element(s + b, s + in()));
		else
			outl(*min_element(s + b, s + in()));
	}
}


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


long N,A,B,H,N2;
long X[200000];
long S[20];

void sub(long P1,long P2){
  if (P1+1==P2) return;
  long Q1,Q2;
  Q1=(P1+P2-1)/2;
  Q2=(P1+P2+1)/2;
  X[Q1]=X[P1];
  X[Q2]=X[P1];

  long R1,R2;
  R1=X[P1];R2=X[P2];
  int fix=-1;
  int modify=-1;
  for (int i=0;i<N;i++){
    if ((R1%2!=R2%2)&&(fix==-1)&&(S[i]==0)){
      fix=i;
      X[Q2]=X[Q2]^(1<<fix);

    }else if ((modify==-1)&&(S[i]==0)){
      modify=i;
      X[Q1]=X[Q1]^(1<<modify);
      X[Q2]=X[Q2]^(1<<modify);
    }
    R1>>=1;R2>>=1;
  }
  S[fix]=1;
  sub(P1,Q1);
  sub(Q2,P2);
  S[fix]=0;
  //cout << "TEST" <<fix <<modify <<endl;
}


int main(){

  cin >> N >> A >> B;
  H=0;
  long A2,B2;
  A2=A;B2=B;
  for (int i=0;i<N;i++){
    if (A2%2!=B2%2) H++;
    A2>>=1;B2>>=1;
  }
  if (H%2==0){
    cout << "NO" << endl;
    return 0;
  }
  N2=1<<N;
  for (int i=0;i<N2;i++) X[i]=0;

  for (int i=0;i<N;i++) S[i]=0;


  //cout << H << endl;
  cout << "YES" << endl;
  X[0]=A;
  X[N2-1]=B;
  sub(0,N2-1);
  for (int i=0;i<N2;i++){
    cout << X[i];
    if (i!=N2-1){
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var insu = new List<long>();
            for (var i = 1; i <= Math.Sqrt(N); i++)
            {
                if (N % i == 0)
                {
                    var len = Math.Max(i.ToString().Length, (N / i).ToString().Length);
                    insu.Add(len);
                }
            }
            Console.WriteLine(insu.Min());
        }
    }
}


Measured memory_bytes: 13268
import copy
h,w,k = map(int, input().split())
lc = []
for _ in range(h):
  ch = [1 if c == "#" else 0 for c in input()]
  lc.append(ch)

ans = 0

for i1 in range(2**h):
  for j1 in range(2**w):
    lc_tmp = copy.deepcopy(lc) 
    for i2 in range(h):
      if (i1 >> i2) &1 == 1:
        for j in range(w):
          lc_tmp[i2][j] = 0

    for j2 in range(w):
      if (j1 >> j2) &1 == 1:
        for i in range(h):
          lc_tmp[i][j2] = 0

    cnt = 0
    for i in range(h):
      cnt += sum(lc_tmp[i])
    ans += 1 if cnt == k else 0
print(ans)

Measured memory_bytes: 9324
n = int(input())
a = list(map(int,input().split()))
s = 1000
i = 0
j = 1
while True:
  if i+1 < n and a[i] < a[i+1]:
    if j+1 < n and a[j] < a[j+1]:
      j += 1
    elif j+1 < n and a[j] >= a[j+1]:
      s = (s//a[i])*a[j]+s%a[i]
      if j+2 == n:
        break
      else:
        i = j+1
        j += 2
    else:
      if a[i] < a[j]:
        s = (s//a[i])*a[j]+s%a[i]
        break
  elif i+1 < n and a[i] >= a[i+1]:
    i += 1
    j += 1
  else:
    break
print(s)

Measured memory_bytes: 80400
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  string s; cin >> s;

  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    outl(-1);
    return;
  }

  if (s.size() < 26) {
    vector<ll> nums(26, 0);
    for (char si : s) nums[si-'a']++;

    for (int i = 0; i < 26; i++) {
      if (nums[i] == 0) {
        outl(s + ctos((char)'a' + i));
        return;
      }
    }
  }

  string ans = "";
  string t = s;
  next_permutation(all(t));
  for (int i = 0; i < s.size(); i++) {
    ans += t[i];
    if (s[i] != t[i]) break;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N; cin >> N;

	if(N%10 == 9 || N/10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int main() {
    int N;
    cin >> N;
    vector<pii> A(N);
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A[i] = make_pair(a, i + 1);
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < N; ++i)
        cout << A[i].second << " ";
    cout << endl;
    return 0;
}


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

const int MAXN = 100010;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int dfs(int u, int fa = 0) {
	int tc = 0;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa)
			tc ^= dfs(to[i], u) + 1;
	return tc;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int n; std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	std::cout << (dfs(1) ? "Alice" : "Bob") << std::endl;
	return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

template<ll mod>
struct RollingHash{
  vector<ll> hash,p;
  ll base;
  RollingHash(string s, ll b){
    ll n = (ll)s.size();
    base = b;
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*base+s[i])%mod;
      p[i+1]=(p[i]*base)%mod;
    }
  }
  ll get(ll l, ll r){
    ll ret=hash[r+1]-(hash[l]*p[r-l+1])%mod;
    if(ret<0)ret+=mod;
    return ret;
  }
};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  const ll tmp_mod=608396398;
  //const ll tmp_mod=979418779;
  //const ll tmp_mod=775791517;
  using RH = RollingHash<tmp_mod>;
  ll base=0;while(base<100000)base=(rand()*rand()*998244353)%tmp_mod;
  ll n;cin>>n;
  string s;cin>>s;
  RH rh(s,base);
  /*auto v=vec(n,n,0LL);
  rep(i,0,n)rep(j,0,n){
    if(i+j<n)v[i][j]=rh.get(i,i+j);
  }*/
  rep(i,0,n-1)rep(j,i+1,n){
    if(s[i]!=s[j])continue;
    ll l=i,r=j;
    while(r-l>=2){
      ll mid=(l+r)/2;
      if(j+mid-i>=n||rh.get(i,mid)!=rh.get(j,j+mid-i)){
        r=mid;
      }
      else l=mid;
    }
    chmax(res,l-i+1);
  }
  cout<<res<<endl;
  return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long

const int MAXN = 1e5 + 5;


bool used[MAXN];
vector <int> g[MAXN];

vector < vector <int> > comp;


void dfs(int v){
	used[v] = true;

	comp[comp.size() - 1].push_back(v);

	for(int to : g[v]){
		if(!used[to]){
			dfs(to);
		}
	}
}


main(){

	int n, m; cin >> n >> m;


	vector <int> x(m), y(m), z(m);

	for(int i = 0; i < m; i++){
		cin >> x[i] >> y[i] >> z[i];
		x[i]--; y[i]--;
	}


	for(int i = 0; i < m; i++){
		g[x[i]].push_back(y[i]);
		g[y[i]].push_back(x[i]);
	}


	for(int i = 0; i < n; i++){
		if(!used[i]){
			comp.push_back(vector<int>());
			dfs(i);
		}
	}


	cout << comp.size() << endl;

	return 0;
}

Measured memory_bytes: 13812
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int N=1010,M=5010;
int n,x,f[N][2],g[2][M],v[N];
int tot,fi[N],a[N],ne[N];
//0:Choose white   1:Choose black
inline void add(int x,int y){
	a[++tot]=y;ne[tot]=fi[x];fi[x]=tot;
}
inline void update(int v,int wi1,int bl1,int wi2,int bl2){
	int tmp;
	for (int i=v;~i;--i){
		tmp=1e9;
		if (i>=wi1) tmp=min(tmp,g[0][i-wi1]+bl1);
		if (i>=wi2) tmp=min(tmp,g[0][i-wi2]+bl2);
		g[0][i]=tmp;
		tmp=1e9;
		if (i>=bl1) tmp=min(tmp,g[1][i-bl1]+wi1);
		if (i>=bl2) tmp=min(tmp,g[1][i-bl2]+wi2);
		g[1][i]=tmp;
	}
	for (int i=1;i<=v;++i) 
		g[0][i]=min(g[0][i],g[0][i-1]),
		g[1][i]=min(g[1][i],g[1][i-1]);
}
inline void solve(int x){
	for (int i=fi[x];i;i=ne[i]) solve(a[i]);
	for (int i=0;i<=v[x];++i) g[0][i]=g[1][i]=0;
	for (int i=fi[x];i;i=ne[i]) update(v[x],v[a[i]],f[a[i]][0],f[a[i]][1],v[a[i]]);
	f[x][0]=g[0][v[x]];f[x][1]=g[1][v[x]];
}
main(){
	scanf("%d",&n);
	for (int i=2;i<=n;++i) scanf("%d",&x),add(x,i);
	for (int i=1;i<=n;++i) scanf("%d",v+i);
	solve(1);
	puts(f[1][0]!=1e9||f[1][1]!=1e9?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n;
	while(scanf("%d", &n),n){
		int w, h, s, t;
		int ans = 0;
		bool cell[100][100];
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++) cell[i][j] = false;
		}
		scanf("%d%d", &w, &h);
		for(int i = 0; i < n; i++){
			int x, y;
			scanf("%d%d", &x, &y);
			x--; y--;
			cell[x][y] = true;
		}
		scanf("%d%d", &s, &t);
		for(int i = 0; i <= w-s; i++){
			for(int j = 0; j <= h-t; j++){	
				int cnt = 0;
				for(int k = i; k < i+s; k++){
					for(int l = j; l < j+t; l++){
						cnt += cell[k][l];
					}
				}
				if(ans < cnt) ans = cnt;
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1036
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int n;
string a;
string b;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		cin >> a;
		cin >> b;
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());

		if (a.length() > 80 || b.length() > 80) {
			cout << "overflow" << endl;
			continue;
		}

		string ans;
		int alen = a.length();
		int blen = b.length();
		if (alen > blen) {
			for (int i = 0; i < alen - blen; i++) {
				b += '0';
			}
		}
		else {
			for (int i = 0; i < blen - alen; i++) {
				a += '0';
			}
		}

		int k = 0;
		for (int i = 0; i < a.length(); i++) {
			int ai = a[i] - '0';
			int bi = b[i] - '0';
			int ci = ai + bi + k;
			ans += ci % 10 + '0';
			k = ci / 10;
		}
		if (k != 0)ans += k+'0';
	
		if (ans.length() > 80) {
			cout << "overflow" << endl;
			continue;
		}
		reverse(ans.begin(), ans.end());
		for (int i = 0; i < ans.length(); i++) {
			cout << ans[i];
		}
		cout << endl;
	}

	
	return 0;
}

Measured memory_bytes: 3248
/**
 * Recurring Decimals
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static java.lang.Integer.parseInt;

public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int a = parseInt(line.substring(0, line.indexOf(' ')));
			int L = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((a | L) == 0) break;

			Map<Integer, Integer> diff = new HashMap<Integer, Integer>();
			int count = 0;

			diff.put(a, count);
			while (count <= 20) {
				count++;
				int[] nums = new int[10];
				for (int i = L - 1; i >= 0; i--) {
					nums[a / (int) Math.pow(10, i)]++;
					a %= (int) Math.pow(10, i);
				}

				int[] _nums;
				int max = 0, min = 0, fig;
				// max
				fig = L - 1;
				_nums = Arrays.copyOf(nums, nums.length);
				for (int i = _nums.length - 1; i >= 0; i--) {
					while (_nums[i] != 0) {
						max += i * (int) Math.pow(10, fig);
						_nums[i]--;
						fig--;
					}
				}
				// min
				fig = L - 1;
				_nums = Arrays.copyOf(nums, nums.length);
				for (int i = 0; i < nums.length; i++) {
					while (_nums[i] != 0) {
						min += i * (int) Math.pow(10, fig);
						_nums[i]--;
						fig--;
					}
				}
				a = max - min;
				if (diff.containsKey(a)) {
					break;
				} else {
					diff.put(a, count);
				}
			}
			System.out.print(String.format("%d %d %d\n", diff.get(a), a, count - diff.get(a)));
		} //end while
	} //end main
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int main() {
   ll n;
   cin >> n;
   vec<ll> a(n), b(n);
   for (ll i = 0LL; i < n; i++) {
      cin >> a[i];
   }
   for (ll i = 0LL; i < n; i++) {
      cin >> b[i];
   }

   ll aCnt = 0LL, bCnt = 0LL;
   for (ll i = 0LL; i < n; i++) {
      if (a[i] < b[i]) {
         ll c = b[i] - a[i];
         // ll t = b[i]%2LL ? b[i]/2LL+1LL : b[i]/2LL;
         ll t = c%2LL ? c/2LL+1LL : c/2LL;
         aCnt += t;
         a[i] += 2LL * t;
      }
   }

   // rep (i, 0, n) {
   //    printf("%3d ", a[i]);
   // }
   // puts("");
   // rep (i, 0, n) {
   //    printf("%3d ", b[i]);
   // }
   // puts("");

   for (ll i = 0LL; i < n; i++) {
      if (a[i] > b[i]) {
         bCnt += a[i] - b[i];
         b[i] = a[i];
      }
   }

   // rep (i, 0, n) {
   //    printf("%3d ", a[i]);
   // }
   // puts("");
   // rep (i, 0, n) {
   //    printf("%3d ", b[i]);
   // }
   // puts("");

   // debug2(aCnt, bCnt)
   if (aCnt >= bCnt) {
      puts("Yes");
   } else {
      puts("No");
   }

   // ll A = 1LL, B = 1LL;
   // if (aCnt > bCnt) { // aの回数が多すぎる
   //    B += aCnt - bCnt;
   // } else { // bの回数が多すぎる
   //    A += (bCnt - aCnt)*2LL;
   // }
   // // debug2(A, B)

   // if (A <= B) {
   //    puts("Yes");
   // } else {
   //    puts("No");
   // }

   return 0;
}

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

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    int count = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            count++;
        }
    }

    cout << count;
    return 0;
}

Measured memory_bytes: 3912
import java.util
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  case class Edge(from: Int, to: Int)

  case class RR(representative: Long) extends AnyVal {
    def +(that: RR): RR = RR((this.representative + that.representative) % RR.mod)

    def -(that: RR): RR = RR((this.representative - that.representative + RR.mod) % RR.mod)

    def *(that: RR): RR = RR((this.representative * that.representative) % RR.mod)

    def unary_- : RR = RR((-this.representative + RR.mod) % RR.mod)
  }


  object RR {
    val mod: Long = (1e9+7).toLong

    val _0: RR = RR(0)
    val _1: RR = RR(1)
  }


  def read() = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()
    val edges = IndexedSeq.fill(n - 1) {
      val from = sc.nextInt() - 1
      val to = sc.nextInt() - 1
      Edge(from, to)
    }
    (n, k, edges)
  }

  def solve(n: Int, k: Long, edges: IndexedSeq[Edge]): Long = {
    val nextList = IndexedSeq.fill(n)(ArrayBuffer.empty[Int])
    for (edge <- edges) {
      nextList(edge.from).append(edge.to)
      nextList(edge.to).append(edge.from)
    }
    val numNextVisited = Array.fill(n)(0)
    val visited = Array.fill(n)(false)
    val queue: util.Queue[Int] = new util.ArrayDeque[Int]()
    val score = Array.fill(n)(-123L)


    queue.add(0)
    score(0) = k
    visited(0) = true

    while (!queue.isEmpty) {
      val current = queue.remove()
      for (next <- nextList(current)) {
        if (!visited(next)) {
          score(next) = k- (1 + numNextVisited(current))
          queue.add(next)
          visited(next) = true

          numNextVisited(next) += 1
          numNextVisited(current) += 1
        }
      }
    }
    score.map(RR(_)).foldLeft(RR(1))(_*_).representative
  }

  def main(args: Array[String]): Unit = {
    val (n, k, edges) = read()
    println(solve(n,k,edges))
  }
}

Measured memory_bytes: 87480
using System;

namespace CSsample
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            var x = input.Split();
            int A = int.Parse(x[0]);
            int B = int.Parse(x[1]);
            int sum = 0;
            if (A > B)
            {
                sum = A*2-1;
            }
            else if (A < B)
            {
                sum = B*2-1;
            }
            else
            {
                sum = A * 2;
            }
            Console.WriteLine(sum);
        }
    }
}



Measured memory_bytes: 11092
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[A];
    int[] b = new int[B];
    int[] m = new int[3*M];
    int amin = 100001;
    int bmin = 100001;
    int cmin = 200002;
    int ci = 0;
    //String str = sc.next();
    for(int i=0; i<A; i++){
        a[i] = sc.nextInt();
        if(amin > a[i]){
            amin = a[i];
        }
    }
    for(int i=0; i<B; i++){
        b[i] = sc.nextInt();
        if(bmin > b[i]){
            bmin = b[i];
        }
    }
    for(int i=0; i<M; i++){
        m[3*i] = sc.nextInt();
        m[3*i+1] = sc.nextInt();
        m[3*i+2] = sc.nextInt();
        ci = a[m[3*i]-1] + b[m[3*i+1]-1] - m[3*i+2];
        if(cmin > ci){
            cmin = ci;
        }
    }
    //if(str[0].equals("H"));
    if(amin+bmin >= cmin){
        System.out.println(cmin);
    }else{
        System.out.println(amin+bmin);
    }
  }
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int K; cin >> K;
    ll ans = 0;
    REP(i,K)REP(j,K)REP(k,K){
        ans += gcd(i+1, gcd(j+1, k+1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int x[3];
	int max = 0;
	int a, b;
	for (int i = 0; i < 3; i++) {
		scanf("%d", &x[i]);
	}
	if (x[0] < x[1]) swap(x[0], x[1]);
	if (x[1] < x[2]) swap(x[1], x[2]);
	if (x[0] < x[1]) swap(x[0], x[1]);
	printf("%d", 10 * x[0] + x[1] + x[2]);
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
}

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

int main() {

    int n;
    cin >> n;
    int a, b, c, d;
    a =n/1000; b=n/100 - a*10; c=n/10-(a*100+b*10); d =n%10;
    if(a==b||(b==c||(c==d))){
        cout <<"Bad" << endl;}
            else{cout << "Good"<<endl;
}
}

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

int main(void) {
  int a, b, k, ans[1000], i = 1, j = 0;

  if(scanf("%d %d %d", &a, &b, &k) == 1);

  while(i <= a) {

    if(a % i == 0 && b % i == 0) {
      ans[j] = i;
      j++;
    }
    i++;
  }

  printf("%d", ans[j - k]);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int anntena[5], k;
    for (int i = 0;i < 5; i++){
        cin >> anntena[i];
    }
    cin >> k;
    for (int j = 0; j < 5; j++){
        for(int l = j + 1; l < 5; l++){
            if(anntena[l] - anntena[j] > k){
                goto endloop;
            }
        }
    }
    cout << "Yay!";
    goto finish;
endloop:
    cout << ":(";
finish:
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
//constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,M;
ll A[100007];
vector<vector<ll>> E(100007);

// void dfs(ll key){
//   rep(i,E[key].size()){
//     if(C[E[key][i]]==0){
//       A[E[key][i]]=key;
//       C[E[key][i]]=1;
//       dfs(E[key][i]);
//     }
//   }
// }

int main(){
  cin >> N >> M;
  rep(i,M){
    ll X,Y;
    cin >> X >> Y;
    E[X].pb(Y);
    E[Y].pb(X);
  }
  cYes;
  // C[1]=1;
  // dfs(1);
  // Rep(i,2,N+1){
  //   cout << A[i] << endl;
  // }
  vector<ll> C;
  C = vector<ll>(N+1,0);
  queue<ll> Q;
  Q.push(1);
  C[1]=1;
  while(!Q.empty()){
    auto X = Q.front();
    Q.pop();
    rep(i,E[X].size()){
      if(C[E[X][i]]==0){
        Q.push(E[X][i]);
        C[E[X][i]]=1;
        A[E[X][i]]=X;
      }
    } 
  }
  Rep(i,2,N+1){
  cout << A[i] << endl;
  }
}

Measured memory_bytes: 13688
#define Z(V) for(v=360,m=g();--m;V+=sin(x*z))v-=x=g();V+=sin(v*z)
a;g(){scanf("%d",&a);a?a:exit(0);}main(m,v,x){for(;;){double s=0,t=0,z=.01745329,e=.000001;Z(s);Z(t);puts(s>t+e?"1":s+e<t?"2":"0");}}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{  int n;
  ll w;
   ll wi,vi;
  cin >> n >> w;
   vector<vector<ll>>dp(n+1,vector<ll>(100004,1000000009));
   dp[0][0]=0;
   for(int i=1;i<n+1;i++){
     cin>>wi>>vi;
     for(int j=100003; j>=0; j--){
      if(j-vi>=0) dp[i][j] = min(dp[i-1][j-vi]+wi, dp[i-1][j]);
      else dp[i][j] = dp[i-1][j];
    }
   }
   int ans=0;
   for(int i=0;i<100004;i++){
    if(dp[n][i]<=w){
        ans=max(ans,i);
    }
   }
     cout<<ans;
     return 0;
}


Measured memory_bytes: 83200
#include<iostream>
using namespace std;
int main(){int n;while(cin>>n){int counter=0;for(int a=0;a<10;a++){for(int b=0;b<10;b++){for(int c=0;c<10;c++){if(0<=n-a-b-c && n-a-b-c<=9){counter++;}}}}cout<<counter<<endl;}return 0;}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)


set<string> tree;

int main(){
    int n;

    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        string a,b,op = "insert";

        cin>>a>>b;

        if(a == op){
            tree.insert(b);
        }else{
            set<string>::iterator itr;
            itr = tree.find(b);
            if(itr != tree.end())
                printf("yes\n");
            else
                printf("no\n");
        }
    }
}

Measured memory_bytes: 32272
#include<bits/stdc++.h>
using namespace std;
#define int long long int

signed main(){
    int t = 1; //cin >> t;
    while(t--){
        int a,b,c,d; cin >> a >> b >> c >> d;
        int ans = -1e18;
        ans = b*d;
        ans = max(ans,b*c);
        ans = max(ans,a*c);
        ans = max(ans,a*d);
        cout << ans;
    }    
}

Measured memory_bytes: 3632
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$s = $input[0];
$t = $input[1];

$input = explode(' ', trim(fgets(STDIN)));
$a = (int)$input[0];
$b = (int)$input[1];
$u = trim(fgets(STDIN));


if ($u === $s) {
	$a -= 1;
} elseif ($u === $t) {
	$b -= 1;
}
echo $a . " " . $b;

Measured memory_bytes: 4728
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for k in range(a+1):
    for l in range(b+1):
        for m in range(c+1):
            if 500*k+100*l+50*m == x: 
                count += 1
print(count)


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<String>();
    if a == "Sunny" {
        println!("Cloudy")
    } else if a == "Cloudy" {
        println!("Rainy")
    } else {
        println!("Sunny")
    }
    
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    sort(All(a)); reverse(All(a));
    int ans = 0;
    REP(i, N){
        if(i%2 == 0) ans += a[i];
        else ans -= a[i];
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <atcoder/all>
#define mp make_pair
#define fi first
#define se second
#define INF 10000000000000000LL
#define ll  long long 
const long long  inf =1e18+44;
const int MAX=3e5+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=1e6+9;
const int MAX_A=71;
const int LN=20;
const double eps=1e-1;
using namespace std;
using namespace atcoder;
vector<int>adj[MAX];
int vis[MAX];
void dfs(int u){
    vis[u]=1;
    for(auto v: adj[u]){
        if(!vis[v])
            dfs(v);
    }
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n , m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x, y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            cnt = cnt+1;
        }
    }
    cout<<cnt-1;
}


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

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return (0);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        // https://atcoder.jp/contests/abc159/tasks/abc159_c
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            double l = double.Parse(Console.ReadLine());

            double a;
            a = l / 3;

            Console.WriteLine(a * a * a);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e5+5

void solve(){
    string s, t;
    cin>>s>>t;
    ll n = s.len();
    vl v[26];
    loop(i,0,s.len()){
        v[s[i]-'a'].pb(i);
    }
    ll a[n+1][26];
    loop(i,0,26){
        a[n][i] = inf;
    }
    loop(i,0,s.len()){
        loop(j,0,26){
            auto it = lb(v[j].begin(), v[j].end(), i);
            if(it == v[j].end()) a[i][j] = inf;
            else a[i][j] = *it;
        }
    }
    ll ans = 0;
    ll str = 1;
    ll ptr = 0;
    ll i=0;
    while(i < t.len()){
        ll x = a[ptr][t[i]-'a'];
        if(x == inf && ptr == 0){
            print(-1);
            ret;
        }
        else if(x == inf && ptr != 0){
            str++;
            ptr = 0;
        }
        else if(x != inf){
            ptr = x+1;
            i++;
        }
    }
    ans = str*(s.len()) + (ptr+1);
    ans = ans - (s.len()+1);
    print(ans);
}

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

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
  
}



Measured memory_bytes: 21836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        String P = null;
        
        for(int i=0;i<N;i++){
            H -= sc.nextInt();
        }
        
        if(H <= 0){
            P = "Yes";
        } else {
            P = "No";
        }
        System.out.println(P);
    }
}


Measured memory_bytes: 58708
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, M;
  string S;
  cin >> N >> M >> S;
  vector<int> next(N+1, -1);
  set<pair<int, int> > se, se2;
  se.insert(make_pair(0, N));
  se2.insert(make_pair(N, 0));
  rrep(i, N+1) {
    if(S[i] == '1') continue;
    auto begin = se2.lower_bound(make_pair(i+M+1, -1));
    for(auto itr=begin; itr!=se2.end(); itr++) {
      se.erase(make_pair(itr->second, itr->first));
    }
    se2.erase(begin, se2.end());
    int x = se.begin()->first;
    next[i] = se.begin()->second;
    se.insert(make_pair(x+1, i));
    se2.insert(make_pair(i, x+1));
  }
  int tmp = 0;
  vector<int> ans;
  int cnt = 0;
  while(tmp != N) {
    if(next[tmp] == -1 || next[tmp] == tmp || cnt > N) break;
    ans.push_back(next[tmp] - tmp);
    tmp = next[tmp];
    cnt++;
  }
  if(tmp != N) cout << -1 << endl;
  else {
    for(int a: ans) cout << a << ' ';
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 6016
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

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

    // input
    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    FOR(i, 0, H){
        string s;
        cin >> s;
        S[i] = s;
    }

    // for(auto s : S){
    //     p(s);
    // }

    FOR(i, 0, H){
        FOR(j, 0, W){
            char c = S[i][j];
            if(c == '.'){
                int bomb_count = 0;
                FOR(k, 0, 8){
                    int next_i = i + dx[k];
                    int next_j = j + dy[k];
                    if(0 <=next_i && next_i < H && 0<= next_j && next_j < W){
                        if(S[next_i][next_j]=='#'){
                            bomb_count++;
                        }
                    }
                }
                S[i][j] = to_string(bomb_count)[0];
            }
        }
    }
    
    FOR(i, 0, H){
        p(S[i]);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10][10];
int flag = 0;

int main()
{
	for(int i = 1; i <= 3; i++)
	{
		for(int j = 1; j <= 3; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 1; i <= 3; i++)
	{
		for(int j = 1; j <= 3; j++)
		{
			if((a[1][1]-a[1][2]!=a[2][1]-a[2][2])||(a[1][1]-a[1][2]!=a[3][1]-a[3][2])||(a[2][1]-a[2][2]!=a[3][1]-a[3][2]))
			{
				flag = 1;
				break;
			}
			if((a[1][3]-a[1][2]!=a[2][3]-a[2][2])||(a[1][3]-a[1][2]!=a[3][3]-a[3][2])||(a[2][3]-a[2][2]!=a[3][3]-a[3][2]))
			{
				flag = 1;
				break;
			}
			if((a[1][1]-a[1][3]!=a[2][1]-a[2][3])||(a[1][1]-a[1][3]!=a[3][1]-a[3][3])||(a[2][1]-a[2][3]!=a[3][1]-a[3][3]))
			{
				flag = 1;
				break;
			}
			if((a[1][1]-a[2][1]!=a[1][2]-a[2][2])||(a[1][1]-a[2][1]!=a[1][3]-a[2][3])||(a[1][2]-a[2][2]!=a[1][3]-a[2][3]))
			{
				flag = 1;
				break;
			}
			if((a[3][1]-a[2][1]!=a[3][2]-a[2][2])||(a[3][1]-a[2][1]!=a[3][3]-a[2][3])||(a[3][2]-a[2][2]!=a[3][3]-a[2][3]))
			{
				flag = 1;
				break;
			}
			if((a[1][1]-a[3][1]!=a[1][2]-a[3][2])||(a[1][1]-a[3][1]!=a[1][3]-a[3][3])||(a[1][2]-a[3][2]!=a[1][3]-a[3][3]))
			{
				flag = 1;
				break;
			}
		}
	}
	if(flag == 1) printf("No\n");
	if(flag == 0) printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
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>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

vector<ll> b, p;
ll solve(int level, ll x) {
    if(level == 0) {
        return x > 0;
    }
    if(x < b[level - 1] + 2) {
        return solve(level - 1, x - 1);
    } else if(x == b[level - 1] + 2){
        return solve(level - 1, x - 1) + 1;
    } else {
        return p[level - 1] + 1 + solve(level - 1, x - b[level - 1] - 2);
    }
}

signed main(void) {
    int n; ll x; cin >> n >> x;
    
    b.resize(n + 1); p.resize(n + 1);
    b[0] = 1; p[0] = 1;
    rep(i, n) {
        b[i + 1] = b[i] * 2 + 3;
        p[i + 1] = p[i] * 2 + 1;
    }

    cout << solve(n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int c[101010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		c[a]++;
		c[b]++;
	}
	for (int i=1;i<=n;i++){
		if (c[i]%2==1){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int a,b,x;
	scanf("%d %d ",&a,&b);
	x=b/a;
	if(a==1){
		printf("%d\n",b);
	}
	else if(a>b||a==b){
		printf("%d\n",1);
	}
	else if(b%a!=0){
		printf("%d\n",x+1);
	}
	else {
		printf("%d\n",b/a);
	}
	return 0;
}
	
		
		
	


Measured memory_bytes: 2048
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

print(ans)

Measured memory_bytes: 3060