akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
bool map[100][100];
int main() {
  int a, b, h, w;
  cin >> a >> b;
  a--;
  b--;
  h = 100;
  w = 100;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i < 50)
        map[i][j] = true;
      else
        map[i][j] = false;
    }
  }
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < w; j++) {
      if (i % 2 == 1 && j % 2 == 1) {
        if (a != 0) {
          map[i][j] = false;
          a--;
        }
      }
    }
  }
  for (int i = 50; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i % 2 == 1 && j % 2 == 1) {
        if (b != 0) {
          map[i][j] = true;
          b--;
        }
      }
    }
  }
  cout << h << " " << w << endl;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (map[i][j])
        cout << "#";
      else
        cout << ".";
    }
    cout << endl;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
s, t = input(), input()
n = max(len(s), len(t))
a = sorted(map(ord, s))+[0]*(n-len(s))
b = sorted(map(ord, t), reverse=True)+[0]*(n-len(t))
for k, l in zip(a, b):
    if k < l:
        print("Yes")
        break
    if k > l:
        print("No")
        break
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vpll = vector<pll>;

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

#define SIZE(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));

#define PB push_back
#define MP make_pair
#define F first
#define S second

#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll k; cin >> k;
    string s; cin >> s;
    if (s.length() > k) {
        s = s.substr(0, k);
        s = s +  "...";
    }
    cout << s << endl;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<string>
#include<iostream> 
using namespace std;

int ans,flag;
string a;

int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar())
	if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar())
	x = x * 10 + ch - '0';
	return x * f;
}

int main()
{
	cin>>a;
	for (int i=0;a[i]!='\0';i++)
	{
		flag=(flag+1)%2;
		if (flag==1)
		{
			if (a[i]=='p')
			ans--;
		}
		else
		{
			if (a[i]=='g')
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

int main(){
  double R;
  cin>>R;
  cout<<setprecision(1000)<<4*R*M_PI_2f64<<endl;
  return 0;
}

Measured memory_bytes: 3812
X = [0, 0, 0]
N, X[0], X[1], X[2] = map(int, input().split())
Q = []
for _ in range(N):
    s = input()
    if s == 'AB':
        Q.append([0, 1])
    elif s == 'AC':
        Q.append([0, 2])
    else:
        Q.append([1, 2])
ans = True
ret = ''
for i in range(N):
    a = Q[i][0]
    b = Q[i][1]
    if X[a] == X[b] == 0:
        ans = False
        break
    elif X[a] < X[b]:
        ret += chr(ord(str(a)) + 17)
        X[a] += 1
        X[b] -= 1
    elif X[a] > X[b] or i == N - 1:
        ret += chr(ord(str(b)) + 17)
        X[a] -= 1
        X[b] += 1
    else:
        s = Q[i + 1][0]
        t = Q[i + 1][1]
        if a == s or a == t:
            ret += chr(ord(str(a)) + 17)
            X[a] += 1
            X[b] -= 1
        else:
            ret += chr(ord(str(b)) + 17)
            X[a] -= 1
            X[b] += 1
    if X[a] < 0 or X[b] < 0:
        ans = False
        break
if ans:
    print('Yes')
    print('\n'.join(ret))
else:
    print('No')


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

struct Edge {
    int cost, to;
    Edge(int to_, int cost_) : 
        to(to_), cost(cost_) { } 
};

int main(void)
{
    int n, x, t;
    cin >> n >> x >> t;

    cout << t * ((n+x-1)/x) << endl;
    return 0;
} /*atcoder*/


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

long long int a, b, ans;

int main() {
    cin >> a >> b;

    if (a == b)
    {
        ans = a;
    } else {
        if (a%2 == 0)
        {
            if (b%2 == 1)
            {
                ans = ((b-a+1)/2)%2;
            } else {
                ans = b^(((b-a)/2)%2);
            }
        } else {
            if (b%2 == 1)
            {
                ans = a^(((b-a)/2)%2);
            } else {
                ans = a^(((b-a-1)/2)%2)^b;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int M[1000005];
int32_t main()
{
    speed
    string s;
    cin>>s;
    int n=s.size();
    s="#"+s;
    int suma=0,maks=0,mini;
    for(int i=1; i<=n; i++)
    {
        if(s[i]=='1')
            suma++;
        else
            suma--;
        maks=max(maks,suma);
    }
    suma=0;
    for(int i=n; i>=1; i--)
    {
        if(s[i]=='1')
            suma++;
        else
            suma--;
        suma=max(suma,0);
        M[i]=suma;
    }
    int m=maks;
    int wynik=inf;
   //cout<<maks<<endl;
    for(int j=1; j<=2; j++)
    {
        suma=0,maks=0,mini=0;
        for(int i=1; i<=n; i++)
        {
            if(s[i]=='1')
                suma++;
            else if(s[i]=='0')
                suma--;
            else
            {
                if(suma+M[i+1]+1<=m)
                    suma++;
                else
                    suma--;
            }
           // cout<<j<<" "<<i<<" "<<suma<<endl;
            maks=max(maks,suma);
            mini=min(mini,suma);
        }
        wynik=min(wynik,maks-mini);
        m++;
    }

    cout<<wynik;
    return 0;
}


Measured memory_bytes: 8176
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,l,r;
  string s,t="keyence";
  
  cin >> s;
  n=s.size();
  
  i=0;
  l=0;
  while (i<n && s[i]==t[i]){
    i++;
    l++;
  }
  
  i=n-1;
  r=0;
  while (i-n+7>=0 && s[i]==t[i-n+7]){
    i--;
    r++;
  }
  
  if (l+r>=7) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,k;
int main()
{
	cin>>a>>b>>k;
	if(k>a+b) 
	{
		cout<<0<<" "<<0<<endl;
	}
	else if(k<=a)
	{
		cout<<a-k<<" "<<b<<endl;
	}
	else
	{
		cout<<0<<" "<<b-(k-a)<<endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll X;
    cin >> X;
    int ans = 0;
    ll sum = 0;
    int i = 1;
    while (true) {
        if (X <= sum) break;
        sum += i;
        i++;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	int ans=0;
	REP(i,n){
		if(i%2==0&&a[i]%2==1)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

signed main() {
	int n;
	cin >> n;
	vector<int> d;
	int ans = 0;
	rep(i, n) {
		int w;
		cin >> w;
		for(auto j : d) {
			ans = max(ans, abs(w - j));
		}
		d.push_back(w);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int size;
    scanf("%d",&size);
    int arr[size];

    for(int i=0;i<size;i++){
        scanf("%d",&arr[i]);
    }
    int sum=0;
    for(int i=0;i<size;i++){
        sum+=arr[i];
    }
    int average;
    average=sum/size;
    //printf("%d\n",average);
    sum=0;
    for(int i=0;i<size;i++){
        sum+=(arr[i]-average)*(arr[i]-average);
    }
    int min=sum;
    sum=0;
    for(int i=0;i<size;i++){
        sum+=(arr[i]-average+1)*(arr[i]-average+1);
    }
    if(sum<min) min=sum;
    sum=0;

    for(int i=0;i<size;i++){
        sum+=(arr[i]-average-1)*(arr[i]-average-1);
    }
    if(sum<min) min=sum;


    printf("%d",min);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  fix(12);
  int n; cin>>n;
  int a[n],b[n];
  rep(i,0,n) cin>>a[i];
  rep(i,0,n) cin>>b[i];
  
  double aa=0,bb=0,cc=0,m=0;
  rep(i,0,n){
    double x=abs(a[i]-b[i]);
    aa+=x;
    bb+=x*x;
    cc+=x*x*x;
    m=max(m,x);
  }
  co(aa);
  co(pow(bb,0.5));
  co(pow(cc,0.333333333333));
  co(m);
  
  return 0;
}


Measured memory_bytes: 3412
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	int im=m/n;
	int ans1=n*im,ans2=n*(im+1);
	if(ans1>=m&&ans1<=k)
	{
		cout<<"OK";
		return 0;	
	} 
	if(ans2>=m&&ans2<=k)
	{
		cout<<"OK";
		return 0;
	}
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	ll a, b;
	cin >> a >> b;
	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	else if (a < 0 && b < 0) {
		if ((abs(b) - abs(a)) % 2 == 0) {
			cout << "Negative" << endl;
			return 0;
		}
		else {
			cout << "Positive" << endl;
			return 0;
		}
	}
	else {
		cout << "Zero" << endl;
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 256
x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)  # 絶対値を出力することに気をつけてください
print(ans)

Measured memory_bytes: 61856
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	if(s[0]==s[1] || s[2]==s[1] || s[2]==s[3]) cout<<"Bad\n";
	else cout<<"Good\n";
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

#define rep(i, n) for (ll i = 0; i < n; i++)

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P & firstElof, const P & secondElof)
{
	return firstElof.second < secondElof.second;
}

signed main() {
	ll n, k;
	cin >> n >> k;
	vector<double>p(n + 1);
	rep(i, n) {
		ll a;
		cin >> a;
		p[i] = (double)(a + 1) / 2;
	}
	double ans = 0;
	rep(i, k)ans += p[i];
	double tmp = ans;
	for (ll i = 0; i < n - k; i++) {
		tmp = tmp - p[i] + p[i + k];
		if (tmp > ans)ans = tmp;
	}
	printf("%lf", ans);
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int i, n;
	int debt = 100000;
	float interest_rate = 0.05;
	
	while ( scanf("%d", &n) != EOF )
	{
		for (i=1; i<=n; i++)
		{
			//借金 * (1 + 利率)
			debt = (float)debt;		//floatに型変換
			debt *= 1 + interest_rate;
			
			//切り上げ計算
			debt = (int)debt;			//intへ型変換
			if(debt % 1000 != 0)
			{
				debt /= 1000;
				debt++;
				debt *= 1000;
			}
		}
		
		printf("%d\n", debt);
	}
	return 0;
}

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

#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,n)  for(int i=0;i<n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


int main(){
	string s,t;
	cin>>s>>t;
	VI a,b;
	map<char,int>s_map,t_map;
	for(auto &x:s) s_map[x]++;
	for(auto &x:t) t_map[x]++;
	for(auto &x:s_map) a.PB(x.second); 
	for(auto &x:t_map) b.PB(x.second);

	sort(all(a));
	sort(all(b));
	if(a==b)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 776
# seishin.py
from math import sqrt
n, s = map(int, open(0).read().split())

# s = n
if s == n:
    print(n+1)
    exit(0)

def f(b, n):
    res = 0
    while n:
        res += n % b
        n //= b
    return res

# 2 <= b <= sqrt(n)
for b in range(2, int(sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        exit(0)

# sqrt(n) <= b <= n
for p in range(int(sqrt(n)), 0, -1):
    if (n - s) % p > 0:
        continue
    b = (n - s) // p + 1
    if b*b <= n:
        continue
    if f(b, n) == s:
        print(b)
        exit(0)
print(-1)

Measured memory_bytes: 3188
nCk = [[0 for i in range(51)] for j in range(51)]

nCk[1][0] = 1
nCk[1][1] = 1
for i in range(2, 51):
    for j in range(51):
        if j > 0:
            nCk[i][j] = nCk[i-1][j-1] + nCk[i-1][j]
        else:
            nCk[i][j] = nCk[i-1][j]

N, A, B = map(int,input().split())
kouho = []
V = list(map(int,input().split()))
V.sort(reverse = True)
acc = 0
for i in range(B):
    if i < A-1:
        acc += V[i]
    else:
        acc += V[i]
        kouho.append(acc / (i+1))

print(str(kouho[0]))

cnt = 0
for i in range(len(kouho)):
    m = 0
    n = 0
    if kouho[i] != kouho[0]:
        break
    for j in range(N):
        if V[j] == V[A+i-1]:
            if j < A+i:
                m+=1
            n+=1
    cnt += nCk[n][m]
print(str(cnt))

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

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

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int Q;
    cin >> Q;
    Vl A;
    vector<Vi> mat;
    while (Q--) {
        ll N;
        cin >> N;
        A.resize(N);
        for (ll i = 0; i < N; i++) {
            cin >> A[i];
        }
        string S;
        cin >> S;
        reverse(A.begin(), A.end());
        reverse(S.begin(), S.end());

        constexpr ll mx_d = 61;

        mat.assign(mx_d, Vi(202));

        bool is_zero = true;

        for (ll i = 0; i < N; i++) {
            if (S[i] == '0') {
                for (ll j = 0; j < mx_d; j++) {
                    mat[j][i] = (bool)(A[i] & (1ll << j));
                }
            }
            else {
                constexpr ll bk = 201;

                for (ll j = 0; j < mx_d; j++) {
                    mat[j][bk] = (bool)(A[i] & (1ll << j));
                }

                auto mat_cpy = mat;

                int rank = 0;
                for (ll col = 0; col < bk; col++) {
                    int pivot = -1;
                    for (ll row = rank; row < mx_d; ++row) {
                        if (mat[row][col]) {
                            pivot = row;
                            break;
                        }
                    }

                    if (pivot == -1) continue;
                    swap(mat[pivot], mat[rank]);
                    for (ll row = 0; row < mx_d; ++row) {
                        if (row != rank && mat[row][col]) {
                            for (ll c = 0; c <= bk; c++) {
                                mat[row][c] ^= mat[rank][c];
                            }
                        }
                    }
                    ++rank;
                }

                for (ll row = rank; row < mx_d; ++row) {
                    if (mat[row][bk]) {
                        is_zero = false;
                        break;
                    }
                }

                if (!is_zero) {
                    break;
                }

                mat = mat_cpy;
            }
        }

        if (is_zero)
            cout << 0 << "\n";
        else
            cout << 1 << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		String t=scan.nextLine();
		int c=0;
		for (int i=0;i<s.length();i++) {
			if(s.charAt(i)!=t.charAt(i))c++;
		}
		System.out.println(c);
	}

}


Measured memory_bytes: 33904
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

map<ll, ll> m;
int c = 0;

ll sol(ll x) {
    c++;
    if (m[x]) return m[x];
    if (x % 2) return m[x] = (sol(x / 2) * 2 + sol(x / 2 - 1)) % mod;
    else return m[x] = (sol(x / 2) + sol(x / 2 - 1) * 2) % mod;
}

int main() {
    ios::sync_with_stdio(false);
    ll n, z = 0, a[102] = {};
    a[0] = 1; a[1] = 2;
    m[0] = 1; m[1] = 2;
    cin >> n;
    cout << sol(n) << '\n';// << c << ' ' << m.size();
    return 0;
    for (int i = 0; i <= n; i++) {
        //cout << i << ' ';
        int x = 0;
        int l = -1;
        for (int j = 0; j <= i; j++) {
            bool y = 0;
            for (int k = 0; k <= i; k++) if ((k ^ (i - k)) == j) {y = 1; break;}
            if (y) {
                z++;
                x++;
                //cout << j << ' ';
                //if (l != -1) cout << j - l << ' ';
                l = j;
            }
        }
        //cout << x << ' ';
        //cout << __builtin_popcount(i) << ' ';
        //cout << '\n';
    }
    cout << z;
    //1 1 2 1 3 2  3  1  4  3  5  2  5 3 4 1 5 4 7 3 8
    //1 2 4 5 8 10 13 14 18 21 26 28 33
}


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

int main()
{
  int N;
  cin >> N;
  int R = (int)sqrt(double(N));
  cout << R * R << endl;
}

Measured memory_bytes: 256
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b,c=mi()
l=[list(mi()) for i in range(c)]
x=list(itertools.combinations_with_replacement(range(1,b+1),a))
ans=0
for j in x:
  c=0
  for i in l:
    if j[i[1]-1]-j[i[0]-1]==i[2]:
      c+=i[3]
  if c>ans:
    ans=c
print(ans)

Measured memory_bytes: 82144
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000



int main(){
	
	int T;
	cin>>T;
	
	rep(i,T){
		long long N,M,A,B;
		cin>>N>>M>>A>>B;
		
		cout<<floor_sum(N,M,A,B)<<endl;
	}
	
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=1e17;
const ll ms=(1e5)+5;

ll ar[ms]={0};
ll dp[ms][2]={0};

int go(int a,int b,int c)
{

    int r=0;
    if(a)
    {
        r+=c;
        if(b){r++; b--;}
        r+=min(a-1,b);
    }
    else if(c)
    {
        r=c-1;
        if(b)r++;
    }
  //cout<<r<<endl;
    return r;
}

int main()
{
    idfc;
    int n;
    cin>>n;
    int a=0;
    int b=0;
    int c=0;
    int ans=0;
    string s;
    int len;int i;
    while(n--)
    {
        cin>>s;
        len=s.length();
        for(i=1;i<len;i++)
        {
            if(s[i-1]=='A'&&s[i]=='B')ans++;
        }
        if(s[0]=='B'&&s[len-1]=='A')c++;
        else if(s[0]=='B')b++;
        else if(s[len-1]=='A')a++;
    }

    int aa=ans+go(a,b,c);
 //   cout<<a<<" "<<b<<" "<<c<<endl;    
    cout<<aa;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>
 
int main(void) {
 
    int mm = 0;
    int i;
    int ii = 0;
    int iii = 0;
    int s[1000];
    double n = 0;
    double m = 0;
    double aa = 0;
    double a;
    double A[100];
 
    while (1) {
        scanf("%lf", &n);
        if (0 == n) break;
        while (ii != n) {
            scanf("%d", &s[ii]);
            mm += s[ii];
            ii++;
        }
        m = mm / n;
 
        for (i = 0; i < n; i++) {
            aa += (s[i] - m)*(s[i] - m) / n;
        }
        a = sqrt(aa);
        A[iii] = a;
        iii++;
        ii = 0;
        mm = 0;
        aa = 0;
    }
    for (i = 0; i < iii; i++) {
        printf("%f\n", A[i]);
    }
    return 0;
}

Measured memory_bytes: 656
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main()
{
    fast
    int q=1;
    
    while(q--)
    {
      ll d,s,t;
      cin>>d>>s>>t;
      if(s*t>=d)
        cout<<"Yes";
      else
        cout<<"No";

    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];
    if(A == B){
        cout << 0 << endl;
        return 0;
    }
    int64_t mn = 1e9;
    for(int i=0; i<N; i++) if(A[i] > B[i]) mn = min(mn, B[i]);
    int64_t ans = accumulate(A.begin(), A.end(), 0LL) - mn;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define pr(n) printf("%d",n)
#define sc(n) scanf("%d",&n)
#define forr(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=1;i<=n;i++)
#define ll long long
const int N=1*1e5+10;
int a[N][4],n,k,dp[N][4];
int fib(int i, int flag)
{
    //cout<<i<<" "<<flag<<endl;
    if(i==n)return a[n][flag];
    if(dp[i][flag]!=-1)return dp[i][flag];

    int i1,i2;
    if(flag==1)i1=2,i2=3;
    else if(flag==2)i1=1,i2=3;
    else if(flag==3)i1=1,i2=2;
    i1=a[i][flag]+fib((i+1),i1);
    i2=a[i][flag]+fib((i+1),i2);
    return dp[i][flag]=max(i1,i2);

}
signed main()
{
    int tc=1;
    // sc(tc)
    while(tc--)
    {
        sc(n);
        int i;
        fo(i,n)
        {
            sc(a[i][1]);
            sc(a[i][2]);
            sc(a[i][3]);
        }
        memset(dp,-1,sizeof(dp));
       // cout<<"\t"<<fib(1,1)<<" "<<fib(1,2)<<" "<<fib(1,3)<<endl;
        pr(max(fib(1,1),max(fib(1,2),fib(1,3))));
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int 
			 	n,
				m,
				l;
				
		long[][]
				A,
				B,
				C;
				
		String output;
		
		//入力処理
		n = Integer.parseInt(sc.next());
		m = Integer.parseInt(sc.next());
		l = Integer.parseInt(sc.next());
		
		//サイズの指定
		A = new long[n][m];
		B = new long[m][l];
		C = new long[n][l];
		
		//A行列の入力
		for(int i = 0;i < n;i++){
			
			for(int k = 0;k < m;k++){
				
				A[i][k] = Integer.parseInt(sc.next());
			}
		}
		
		//B行列の入力
		for(int k = 0;k < m;k++){
			
			for(int j = 0;j < l;j++){
				
				B[k][j] = Integer.parseInt(sc.next());
			}
		}
		
		//C行列の計算
		for(int k = 0;k < m;k++){
			
			for(int i = 0;i < n;i++){
				
				for(int j = 0;j < l;j++){
					
					C[i][j] += A[i][k] * B[k][j];
				}
			}
		}
		
		//出力処理
		for(int i = 0;i < n;i++){
			
				output = "";
				
				for(int j = 0;j < l;j++){
					
					output += C[i][j];
					//数字の間にスペースを入れる
					if(j < l - 1)output += " ";
				}
				
				System.out.print(output + "\n");
				
		}
		
	}
}



Measured memory_bytes: 79812
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];

//        for (int i=0; i<n; i++) a[i] = sc.nextInt();

        PriorityQueue<Integer> pq = new PriorityQueue<>();

        for (int i=0; i<n; i++){
            pq.add(sc.nextInt()*(-1));
        }

        for (int i=0; i<m; i++){
            int p = pq.poll()/2;
            pq.add(p);
        }

        long ans =0;
        while (!pq.isEmpty()){
            ans += pq.poll()*(-1);
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 63616
K, X = map(int, input().split())

import sys

X_min = X - (K-1)
X_max = X + (K-1)

if (X_max > 1000000):
    X_max = 1000000
if (X_min < -1000000):
    X_min = -1000000

for i in range(X_max - X_min + 1):
    sys.stdout.write(str(X_min) + " ")
    # print(str(X_min)),
    X_min += 1





Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#include <list>
#include <unordered_map>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define SQ 317
#define MAG 33554431
#define RED 0
#define BLUE 1
#define ALP 26
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,k,l,m,r,x,y,K,tot,sz,cur,sum,n,c, maxlvl,q,z,N,ans;
multiset<ll> f;
multiset<ll>::iterator itr;
vector<ll> g[200500], ansvec;
ll fac[200500], invfac[200500];
ll binpow(ll x, ll y)
{
    if (y == 0)
        return 1;
    ll tmp = binpow(x, y/2);
    tmp = tmp*tmp%MOD;
    if (y%2)
        return x*tmp%MOD;
    return tmp;
}
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("input.txt","w",stdout);
 	fac[0] = invfac[0] = 1;
 	for (i = 1; i <= 200000; i++)
    {
        fac[i] = (fac[i-1]*i)%MOD;
        invfac[i] = binpow(fac[i], MOD-2);
    }
    cin >> n >> l >> r;
    for (i = 0; i < n; i++)
    {
        cin >> x >> y;
        g[x].push_back(y);
        f.insert(y);
    }
    for (i = 1; i <= n; i++)
    {
        if (g[i].empty())
            continue;
        sort(g[i].begin(), g[i].end());
        for (j = 0; j < g[i].size(); j++)
        {
            itr = f.find(g[i][j]);
            f.erase(itr);
        }
        ll sz = g[i].size();
        ll min1 = MOD;
        if (!f.empty())
            min1 = (*(f.begin()));
        if (min1 + g[i][0] > r)
            continue;
        for (j = sz-1; j >= 0; j--)
        {
            if (min1 + g[i][j] <= r || g[i][0] + g[i][j] <= l)
                break;
        }
        ansvec.push_back(j+1);

        for (j = 0; j < sz; j++)
            f.insert(g[i][j]);
    }
    ll ans = 1;
    ll sum = 0;
    for (j = 0; j < ansvec.size(); j++)
        sum += ansvec[j];
    ans = ans*fac[sum]%MOD;
    for (j = 0; j < ansvec.size(); j++)
        ans = ans*invfac[ansvec[j]]%MOD;
    cout << ans << endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int x;

    for(int i = 0; i < 10000; i++) {
        cin >> x;
        if(x == 0) {
            return 0;
        } else {
            cout << "Case " << i+1 << ": " << x << endl;
        }
    }
    
    return 0;
}



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

int main()
{

    char s[100] ;
    cin >> s ;
    int i , j , x , rs = 1;
    for (i = 0 ; i <100 ; i++){
        if (s[i] == '\0')
            break;
    }

    x= i;
    for (i=0 , j=x-1  ; i<x && j>0  ; i++ , j--){
        if(s[i] != s[j])
            rs++;
    }


    cout << rs/2 << endl ;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ld long double
#define fi first
#define se second
#define ll long long
#define mp make_pair
using namespace std;
int n;
int t[200005];
const int mod = 1e9 + 7;
int sum[200005];
int dp[200005];
int main()
{	
	scanf("%d", &n);
	for(int i = 1; n >= i; ++i)
		scanf("%d", &t[i]);
	vector < int > v;
	for(int i = 1; n >= i; ++i)
	{
		while(t[i] == t[i + 1])
			i++;
		v.pb(t[i]);
	}
	for(int i = 0; (int)v.size() > i; ++i)
		t[i + 1] = v[i];
	int n = (int)v.size();
	dp[0] = 1;
	for(int i = 1; n >= i; ++i)
	{
		dp[i] = dp[i - 1];
		dp[i] = (dp[i] + sum[t[i]]) % mod;
		sum[t[i]] = (sum[t[i]] + dp[i - 1]) % mod;
	}
	cout << dp[n];
	return 0;
}


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

int main() {
	int score, sum=0;
	for(int i=0; i<5; i++){
		scanf("%d", &score);
		if(score < 40)
			score = 40;
		sum += score;
	}
	
	int ave = sum / 5;
	
	printf("%d\n", ave);
	
	return 0;
}

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

#define _REP(i,a,b) for(int i = (a) ; i >= (int)(b) ; --i )
#define REP(i,a,b) for(int i = (a) ; i <= (int)(b) ; ++i )
#define UREP(i,u) for(int i = p[(u)] ; i + 1 ; i = edge[i].next)
//iterator: for(int u:x),x is container
#define x(p) (p).first
#define y(p) (p).second
#define pii pair<int,int>
#define mp(x,y) make_pair((x), (y))
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x,v) memset((x), (v), sizeof (x))
#define ri1(x) scanf("%d", &(x))
#define ri2(x,y) scanf("%d%d", &(x), &(y))
#define ri3(x,y,z) scanf("%d%d%d", &(x), &(y), &(z))
#define ri4(a,b,c,d) scanf("%d%d%d%d", &(a), &(b), &(c), &(d))
#define pi1(a) printf("%d\n", (a))
#define pi2(a,b) printf("%d%d\n", (a), (b))

#ifdef kinesis
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int maxn = 2e5 + 5;
int a[maxn],n,K;
vector<int> vec;

int main()
{
    ri2(K,n);
    REP(i,1,n) ri1(a[i]);
    REP(i,2,n) vec.push_back(a[i]-a[i-1]);
    vec.push_back(K-a[n]+a[1]);
    sort(vec.begin(),vec.end());
    printf("%d\n",K - vec[(int)vec.size()-1]);
    return 0;
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,t,a,b,n,c,d,y,temp,m,r,sum,count,k,l,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
        string s1,s2;
        cin>>a>>b>>d;
        a-=2*d;
        i=1;
        while(i)
        {
            if(a<(i*b)+(i-1)*d)
            break;
            i++;
        }
        cout<<--i;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
typedef long long ll;

int n;
ll a[maxn],x,sum,ans=1000000000000000000ll;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n-1;i++){
		x+=a[i];
		ans=min(ans,abs(2*x-sum));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    string s;
    cin >> s;
    n = s.size();
    char prev = 'Z';
    i = 0;
    while(i < n)
    {
        if(s[i] == 'A')
        {
            ll j = i;
            while(j < n)
            {
                if(prev == 'A' && s[j] == 'C')
                    break;
                if(prev == 'C' && s[j] == 'C')
                    break;
                if((prev == 'B' && s[j] == 'B') || (prev == 'B' && s[j] == 'A'))
                    break;
                prev = s[j++];
            }
            ll ca = 0;
            while(i < j)
            {
                if(s[i] == 'A')
                    ca++;
                if(s[i] == 'C')
                    ans += ca;
                i++;
            }
        }
        else
            i++;
        prev = 'Z';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<algorithm>

using namespace std;

int table[1050000];

int solve(int x){
    if(table[x] != -2)return table[x];
    if(x < 10)return 0;
    int &res = table[x];
    res = -1;
    int p = 0;
    for(int i = 1;i <= x;i *= 10){
	p = max(p, (x / i) * (x % i));
    }
    res = solve(p);
    if(res >= 0)res++;
    return res;
}

int main(){
    int q, n;
    fill(table, table + 1050000, -2);
    cin >> q;
    while(q--){
	cin >> n;
	cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 5260
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	string s,t,w,c;
	int n,a,b;

	cin >>s >>n;
	for(int i=0;i<n;++i){
		cin >>t;
		if(t=="print"){
			cin >>a >>b;
			w = s.substr(a,b-a+1);
			cout <<w <<endl;
		}else if(t=="reverse"){
			cin >>a >>b;
			w = s.substr(a,b-a+1);
			reverse(w.begin(),w.end());
			s.replace(a,w.size(),w);
		}else{
			cin >>a >>b >>c;
			s = s.replace(a,b-a+1,c);
		}
	}
	return 0;
}

Measured memory_bytes: 3224
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int a,b;
    while(cin>>a>>b){
        if(a<10 && b<10) printf("%d\n",a*b);
        else cout<<-1<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ot(x) cout<<x<<" ";
#define out(x) cout<<x<<"\n";
#define pb push_back
#define in insert
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define yes cout<<"yes\n";
#define no cout<<"no\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define fa(i,a) for(auto i:a)
#define f(i,x,a) for(i=x;i<a;i++)
#define next cout<<"\n";
#define sp(n) cout<<fixed<<setprecision(n);
#define  gcd(a,b)    __gcd(a,b)
#define bs  binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test int t;cin>>t;while(t-->0)
#define mod 1000000007



int main()
{
   fast
  ll n,i,c=0,g=0,x;cin>>n;

  f(i,1,n){
  if(i*i<n){
         x=n/i;
    if(n%i!=0){

        c+=(x-i)*2;
    }
    else{
       c+=(x-i-1)*2;
    }
    g++;
  }
  else{
    break;
  }
  }
 cout<<c+g;
  return 0;
}





Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17

typedef pair<P,P> PP;
int main(){
    int H,W;cin>>H>>W;
    vector<VI> a(H, VI(W,0));
    int odd=0;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        cin>>a[i][j];
        if(a[i][j]&1)++odd;
    }
    vector<PP>res;
    int num=0;
    int x=0,y=0;
    for(int iter=0;iter<W*H;iter++){
        if(a[x][y]%2==1)num++;
        int nx=x,ny=y;
        if(x%2==0){
            if(ny==W-1)nx++;
            else ny++;
        }
        else {
            if(ny==0)nx++;
            else --ny;
        }
        if(num%2==1)if(num<odd)res.push_back(PP(P(x,y),P(nx,ny)));
        x=nx,y=ny;
    }
    cout<<res.size()<<endl;
    for(auto p:res){
        cout<<p.fi.fi+1<<" "<<p.fi.se+1<<" "<<p.se.fi+1<<" "<<p.se.se+1<<endl;
    }
return 0;
}

Measured memory_bytes: 9376
#include <iostream>
#include<bits/stdc++.h>
#define lli long long
#define fin  freopen("input.txt","r",stdin);
#define fout freopen("output.txt","w",stdout);
#define ini(a) scanf("%d",&a);
#define ini2(a,b) scanf("%d%d",&a,&b);
#define inl(a) scanf("%lld",&a);
#define inl2(a,b) scanf("%lld%lld",&a,&b);
#define all(a) a.begin(),a.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SIZE 200010
using namespace std;


int main()
{


    map<int ,string> x;
    x[2]=x[4]=x[5]=x[7]=x[9]="hon";
    x[0]=x[1]=x[6]=x[8]="pon";
    x[3]="bon";

    int now;
    cin>>now;

    cout <<x[now%10];

}



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

int main(){
	int n,N;
	cin>>n;
	N = n%10;
	switch (N){
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout<<"hon"<<endl;
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout<<"pon"<<endl;
			break;
		case 3:
			cout<<"bon"<<endl;
			break;
		default:
			break;
	}
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<deque>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, m; string s; deque<int>ans;
signed main() {
	cin >> n >> m >> s;
	int p = n;
	while (p > 0) {
		if (p <= m) {
			ans.push_front(p);
			break;
		}
		int x = -1;
		for (int i = 1; i <= m; i++)
			if (s[p - i] == '0')x = i;
		if (x == -1) {
			cout << x << endl;
			return 0;
		}
		ans.push_front(x);
		p -= x;
	}
	p = 0;
	for (int i : ans) {
		cout << i;
		p += i;
		if (p != n)cout << ' ';
	}
	cout << endl;
}

Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long sum = 0;
		long result = 0;
		int MOD = 1000000007;
		for(int i = 0; i < n; i++){
		    long a = sc.nextLong();
		    result += sum*a%MOD;
		    result %= MOD;
		    sum += a;
		    sum %= MOD;
		}
		
		// 計算
		//int result = 100000;
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 52904