akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
long long M = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    long long N, K;
    cin >> N >> K;
    long long sum = 0;
    vector<long long> mo(K + 1);
    rep(i, 0, K) {
        long long t = K - i;
        long long a = K / t;
        mo[t] = modpow(K / t, N, M);
        rep(j, 2, a + 1) {
            mo[t] -= mo[j * t];
            mo[t] %= M;
        }
    }
    rep(i, 1, K + 1) {
        // cout << mo[i] << endl;
        long long p = mo[i] * i % M;
        sum = (sum + p) % M;
    }
    cout << sum << endl;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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; }

ll dp[410][410];

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	rep(i,n+1) rep(j, n+1) dp[i][j] = 1e18;
	for(int i=1; i<=n; i++) {
		for(int j=0; i+j <= n; j++) {
			// [j, j+i)
			ll mini = 1e18;
			if(i==1) {
				//cout << "i=1, j=" << j << endl;
				dp[j][j+i] = 0;
				continue;
			}
			ll sum = 0;
			for(int k=j+1; k<j+i; k++) {
				chmin(mini, dp[j][k] + dp[k][j+i]);
			}
			for(int k=j; k<j+i; k++) {
				sum += a[k];
			}
			dp[j][j+i] = mini + sum;
			//cout << j << " " << j+i << " " << dp[j][j+i] << endl;
		}
	}
	/*rep(i,n+1) {
		rep(j,n+1) {
			if (dp[i][j] >= 1e18) cout << setw(4) << "na";
			else cout << setw(4) << dp[i][j];
			cout << " ";
		}
		cout << endl;
	}*/
	cout << dp[0][n] << endl;

  return 0;
}


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

int main(){
	string s;

	cin >> s;

	while(s!="0"){
		int i[s.size()];
		int x=0;

		for(int k=0;k<s.size();k++){
			i[k] = s[k] - '0';
		}

		for(int j=0;j<s.size();j++){
			x += i[j];
		}

               cout << x << endl;

		cin >> s;
	}
	return 0;
}

Measured memory_bytes: 1188
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAXN 3008
int N;
char S[MAXN];

const int MOD = 1e9 + 7;

int DP[MAXN][MAXN];  // DP[n][last] = number of valid length-n permutations that
                     // ends with value last

int sum(const VI& PS, int L, int R) {
   if (L > R) return 0;
   int res = PS[R] - PS[L-1];
   if (res < 0)
      res += MOD;
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N;
   cin >> (S+2);

   DP[1][1] = 1;
   FOR(n, 2, N) {
      // compute prefix sum of previous DP row
      VI PS(n);
      FOR(i, 1, n-1) {
         PS[i] = (PS[i-1] + DP[n-1][i]) % MOD;
      }

      if (S[n] == '<') {
         FOR(nxt, 1, n) {
            DP[n][nxt] = sum(PS, 1, nxt-1);
         }
      }
      else {
         FOR(nxt, 1, n) {
            DP[n][nxt] = sum(PS, nxt, n-1);
         }
      }

   }

   int res = 0;
   FOR(last, 1, N) {
      res += DP[N][last];
      if (res >= MOD)
         res -= MOD;
   }
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 34304
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct NODE {
	int id, l;
	inline int operator<(const NODE &n2) const {
		return l < n2.l;
	}
} no[100005];
int n;
int main() {
	cin >> n;
	for(int i= 1; i <= n; i++) no[i].id= i, cin >> no[i].l;
	sort(no + 1, no + n + 1);
	for(int i= 1; i <= n; i++) cout << no[i].id << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

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

	int t = 1;
	// cin >> t;

	while (t--) {
                int n, x, t;
                cin >> n >> x >> t;
                if (n % x == 0) cout << (n / x) * t << endl;
                else cout << ((n / x) + 1) * t << endl;
	}
	return 0;
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

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


int main(){
	int n, k; cin>> n >> k;
	int ans = 0, x;
	for(int i = 1 ; i <= n; i++){
		cin>>x;
		if(x >= k)
			ans++;
	}
	cout<<ans;
	return 0;
}


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

int main() {
  string S,T,U;
  int A,B;
  cin >> S >> T >> A >> B >> U;
  if (S == U)
    cout << A-1 << " " << B << endl;
  else
    cout << A << " " << B-1 << endl;
      
      
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

int n,k;
int a[105];
int dp[100007];
int solve(int stone)
{
	//if(stone<a[0])return 0;
	if(dp[stone])return dp[stone];
	
	for(int i=0;i<n;i++){
		if(stone>=a[i]){
			int ret = solve(stone-a[i]);
			if(ret==2){
				return dp[stone]=1;

			}
		}
	}
	return dp[stone]=2;
}
int main()
{
	fast_io
	cin >>n>>k;
	for(int i=0;i<n;i++)cin >>a[i];

	int ans=solve(k);
	dp[0]=2;
	if(ans==1)puts("First");
	else puts("Second");
	return 0;	
}


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

using namespace std;

int n,k,m;
int pan [1000001] ;
int dp [100001];
int ans =0 ;
void init ()
{
    pan[0]=1;
    k=1;
    for (int i=6;i<=100001;i*=6)
        pan[k++]=i;
    for (int i=9;i<=100001;i*=9)
        pan[k++]=i;
    sort (pan , pan+k) ;
}
void dfs (int depth , int left)
{

    if (ans < depth )return ;
    if (left ==0 ) {  ans = min (ans,depth ) ; return ; }

    for (int i=m;i>=0;i--)
    {
    if (left < pan[i] ) continue ;
    else if ( (ans-depth )*pan [i] < left )  continue ;
    else dfs (depth+1 , left-pan[i]) ;
    }

}
int main ()
{
    ios::sync_with_stdio (false ) ;
    init () ;
    while (cin>>n )
    {
        ans=1001;
        m=k;
        while (pan[--m] > n) ;
       // cout<<pan[m]<<endl;
        dfs (0,n);
        cout<<ans<<endl ;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
using  ll = long long;
using namespace std;

int main(){
  int h, w; cin >> h >> w;
  string s[100];
  for(int i = 0; i < h; i++){
    cin >> s[i];
  }
  for(int i = 0; i < h; i++){
    cout << s[i] << endl;
    cout << s[i] << endl;
  }

  return 0;
}


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

int main(){
  int k;
  cin >> k;
  int ans[33]={0};
  ans[1] = 1; ans[17] = 1;
  ans[2] = 1; ans[18] = 5;
  ans[3] = 1; ans[19] = 1;
  ans[4] = 2; ans[20] = 5;
  ans[5] = 1; ans[21] = 2;
  ans[6] = 2; ans[22] = 2;
  ans[7] = 1; ans[23] = 1;
  ans[8] = 5; ans[24] = 15;
  ans[9] = 2; ans[25] = 2;
  ans[10] = 2; ans[26] = 2;
  ans[11] = 1; ans[27] = 5;
  ans[12] = 5; ans[28] = 4;
  ans[13] = 1; ans[29] = 1;
  ans[14] = 2; ans[30] = 4;
  ans[15] = 1; ans[31] = 1;
  ans[16] = 14; ans[32] = 51;
  cout << ans[k] << endl;
  return 0;
}

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

const int N = 2e5 + 10;
typedef long long ll;
ll n, K, a[N], b[5];
ll x[N], tx, y[N], ty;

ll calc(ll lim) {
    ll num = 0;
    if (lim < 0) {
        lim *= -1;
        rep(i, 1, tx) {
            int j = upper_bound(y + 1, y + ty + 1, lim / x[i]) - y - 1;
            num += j;
        }
        num = tx * ty - num;
    } else if (!lim) {
        num += tx * ty;
    } else {
        num += tx * ty + (n - tx - ty) * (tx + ty) + (n - tx - ty) * (n - tx - ty - 1) / 2;
        rep(i, 1, tx) {
            int j = lower_bound(x + 1, x + i, lim / x[i] + 1) - x - 1;
            if (x[i] * x[j] >= lim) --j;
            num += j;
        }
        rep(i, 1, ty) {
            int j = lower_bound(y + 1, y + i, lim / y[i] + 1) - y - 1;
            if (y[i] * y[j] >= lim) --j;
            num += j;
        }
    }
    return num;
}

bool chk(ll lim) {
    ll num = 0;
    num = calc(lim);
    // printf("%lld %lld !!!\n", lim, num);
    return num <= K - 1;
}

int main() {
    cin >> n >> K;
    rep(i, 1, n) {
        cin >> a[i];
        b[a[i] < 0 ? 0 : (!a[i] ? 1 : 2)]++;
    }

    // rep(i, 1, n) rep(j, i + 1, n) if (a[i] * a[j] == 448283280358331064) { printf("%lld %lld ????????????\n", a[i], a[j]); break; }

    sort(a + 1, a + n + 1);
    rep(i, 1, n)
        if (a[i] < 0) x[++tx] = -a[i];
    reverse(x + 1, x + tx + 1);
    rep(i, 1, n)
        if (a[i] > 0) y[++ty] = a[i];
    // chk(448283280358331064);
    // chk(448283280358331103);

    ll ans = 0, l = -1e18, r = 1e18;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (chk(mid)) {
            ans = mid, l = mid + 1;
        }
        else r = mid - 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n,max_height = -1;
  int a[200005] = {0};
  long long ans = 0;
  cin >> n;
  cin >> a[0];
  max_height = a[0];
  for(int i=1;i<n;i++){
    cin >> a[i];
    if(a[i] < max_height) {
      ans += max_height - a[i];
    }
    else {
      max_height = a[i];
    }
  }
  cout << ans;
  return 0;
}


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

int main()
{
  long n;
  int p[1000];
  string s="abcdefghijklmnopqrstuvwxyz";
  cin >> n;
  int i=0;
  while(n>0){
  p[i]=n%26;
  if(p[i]==0)p[i]=26;
  n=(n-p[i])/26;
  i++;
  }

  for(int j=i-1; j>=0; j--){
    cout << s[p[j]-1];
  }
  cout <<'\n';
  return 0;
}

Measured memory_bytes: 3632
import itertools

n = int(input())
p = int(input().replace(' ', ''))
q = int(input().replace(' ', ''))

t = [num for num in range(1, n+1)]
a = []
per_c = 0

for per in itertools.permutations(t):
  s = ''
  for i in range(n):
    s += str(per[i])
  a.append(int(s))
a.sort()
#print(n, p, q)
#print(a)

p_i = 0
q_i = 0
for i in range(len(a)):
  b = a[i]
  if b == p:
    p_i = i+1
  if b == q:
    q_i = i+1
#print(p_i, q_i)
print(abs(p_i - q_i))
  

Measured memory_bytes: 42716
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

LL dp[15][2];
int N,A[15];

LL dfs(const int i, const bool iseven)
{
    if (i == N)
        return iseven;
    LL& ans = dp[i][iseven];
    if (ans == -1) {
        ans = 0;
        const int dx[] = {-1,0,-1};
        FOR(d,0,3) {
            const int x = A[i]+dx[d];
            ans += dfs(i+1, iseven | (x%2 == 0));
        }
    }
    return ans;
}

int main()
{
    while (cin >> N) {
        FOR(i,0,N)
            cin >> A[i];
        memset(dp,-1,sizeof(dp));
        const LL ans = dfs(0,0);
        cout << ans << endl;
    }
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
    rep(i,X){
        rep(j,X){
            if((i+j) == X &&  2*i + 4*j == Y ){
                cout << YES << endl;
                return;
            }

        }
    }


    cout << NO << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define all(x) (x.begin(),x.end())
#define pii pair<int,int> 
#define vi vector<int> 
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define fi first
#define se second
using namespace std;
void solve()
{
int d,s,t;
cin>>d>>s>>t;
if((double)d/s>t)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;	
}
int32_t main()
{
	int t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
// Problem : A - Don't be late
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<pair<int, int>> XL(n);
    rep(i, n) cin >> XL[i].first >> XL[i].second;
    sort(all(XL));
    vector<bool> removed(n, false);
    int idx      = 0;
    int look_idx = 1;
    while (idx < n - 1 and look_idx < n) {
        int cl = XL[idx].first - XL[idx].second,
            cr = XL[idx].first + XL[idx].second;
        int nl = XL[look_idx].first - XL[look_idx].second,
            nr = XL[look_idx].first + XL[look_idx].second;

        if (cr > nl) {
            if (cr > nr) {
                removed[idx] = true;
                idx          = look_idx;
                look_idx     = idx + 1;
            } else {
                removed[look_idx] = true;
                idx               = idx;
                look_idx          = look_idx + 1;
            }
        } else {
            idx      = look_idx;
            look_idx = idx + 1;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!removed[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int start=max(a,c);
  int end=min(b,d);
  if(end-start>0) {
    cout << end-start << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#define MAX 10000
#define NIL -1

struct Node
{
	int p, left, right;
};

Node T[MAX];
int  D[MAX];
int  H[MAX];

void setDepth(int u, int d)
{
	D[u] = d;
	if (T[u].left != NIL) setDepth(T[u].left, d + 1);
	if (T[u].right != NIL) setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
	int h1 = 0, h2 = 0;
	if (T[u].left != NIL)h1 = setHeight(T[u].left) + 1;
	if (T[u].right != NIL)h2 = setHeight(T[u].right) + 1;
	return H[u] = h1 > h2 ? h1 : h2;
}

// 節点uの兄弟を返す
int getSibling(int u)
{
	if (T[u].p == NIL) return NIL;
	if (T[T[u].p].left == u && T[T[u].p].right != NIL)return T[T[u].p].right;
	if (T[T[u].p].right == u && T[T[u].p].left != NIL)return T[T[u].p].left;
	return NIL;
}

void print(int u)
{
	std::cout << "node " << u << ": ";
	std::cout << "parent = " << T[u].p << ", ";
	std::cout << "sibling = " << getSibling(u) << ", ";

	int deg = 0;
	if (T[u].left != NIL) deg++;
	if (T[u].right != NIL) deg++;
	std::cout << "degree = " << deg << ", ";

	std::cout << "depth = " << D[u] << ", ";
	std::cout << "height = " << H[u] << ", ";

	if (T[u].p == NIL)
	{
		std::cout << "root\n";
	}
	else if (T[u].left == NIL && T[u].right == NIL)
	{
		std::cout << "leaf\n";
	}
	else
	{
		std::cout << "internal node\n";
	}
}

int main()
{
	int n;
	std::cin >> n;


	for (int i = 0; i < n; i++)
	{
		T[i].p = NIL;
	}

	int p, l, r;
	for (int i = 0; i < n; i++)
	{
		std::cin >> p >> l >> r;
		T[p].left = l;
		T[p].right = r;
		if (l != NIL) T[l].p = p;
		if (r != NIL) T[r].p = p;
	}

	int root;
	for (int i = 0; i < n; i++)
	{
		if (T[i].p == NIL)
		{
			root = i;
			break;
		}
	}

	setDepth(root, 0);
	setHeight(root);

	for (int i = 0; i < n; i++)
	{
		print(i);
	}
}


Measured memory_bytes: 3080
package main

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

// 成績
func main() {
	sc := bufio.NewScanner(os.Stdin)
	s := ""
	for i := 0; i < 50; i++ {
		sc.Scan()
		ary := strings.Split(sc.Text(), " ")
		m, _ := strconv.Atoi(ary[0])
		f, _ := strconv.Atoi(ary[1])
		r, _ := strconv.Atoi(ary[2])
		if m == -1 && f == -1 && r == -1 {
			break
		}
		if m == -1 || f == -1 {
			s += "F\n"
		} else if 80 <= m+f {
			s += "A\n"
		} else if 65 <= m+f && m+f < 80 {
			s += "B\n"
		} else if 50 <= m+f && m+f < 65 {
			s += "C\n"
		} else if m+f < 30 {
			s += "F\n"
		} else {
			if 50 <= r {
				s += "C\n"
			} else {
				s += "D\n"
			}
		}
	}
	fmt.Print(s)
}



Measured memory_bytes: 1132
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        string order,S;
        cin >> order >> S;
        reverse(order.begin(),order.end());
        for(int j=0; j<order.size(); j++){
            char now = order[j];
            if(now == 'J'){
                S = S.back() + S;
                S.pop_back();
            }else if(now == 'C'){
                S += S[0];
                S.erase(S.begin());
            }else if(now == 'E'){
                if(S.size()%2){
                    S = S.substr(S.size()/2+1) + S[S.size()/2] + S.substr(0,S.size()/2);
                }else{
                    S = S.substr(S.size()/2) + S.substr(0,S.size()/2);
                }
            }else if(now == 'A'){
                reverse(S.begin(),S.end());
            }else if(now == 'M'){
                for(int k=0; k<S.size(); k++){
                    if('0'<=S[k] and S[k]<='9'){
                        S[k] = (S[k]-'0'+1)%10 + '0';
                    }
                }
            }else{
                for(int k=0; k<S.size(); k++){
                    if('0'<=S[k] and S[k]<='9'){
                        S[k] = (S[k]-'0'-1+10)%10 + '0';
                    }
                }
            }
        }
        cout << S << endl;
    }
    return 0;
}


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

int main() {
    map<string,int> p;
  int n;
  cin >> n;
  
  rep(i,n) {
      string s;
      cin >> s;

      p[s] ++;
  }
  int m;
  cin >> m;
  

  rep(i,m){
      string t;
      cin >> t;

      p[t]--;
  }

  int ma=0;
  

  for(auto q:p)ma=max(ma,q.second);

  cout << ma << endl;

}

Measured memory_bytes: 256
# ContestName
# URL
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    if N <= 999:
        print('ABC')
    else:
        print('ABD')

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long

using namespace std;

int mod = 1e9 + 7;

int po(int a, int x){
    if(a == 1){
        return x;
    }
    if(a % 2){
        return po(a / 2, x * x % mod) * x % mod;
    }
    return po(a / 2, x * x % mod);
}

void solve(){
    int x, y;
    cin >> x>> y;
    int a = (2 * x - y), b = (2 * y - x);
    if(a < 0 || b < 0 || a % 3 || b % 3){
        cout << 0;
        return;
    }
    a /= 3; b /= 3;
    int t = 1, t1 = 1, t2 = 1;
    for(int i = 1; i <= a + b; i++){
        t = t * i % mod;
    }
    for(int i = 1; i <= a; i++){
        t1 = t1 * i % mod;
    }
    for(int i = 1; i <= b; i++){
        t2 = t2 * i % mod;
    }
    //cout << t << ' ' << t1 << ' ' << t2 << endl;
    cout << t * po(mod - 2, t1) % mod * po(mod - 2, t2) % mod;
}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int test = 1;
    //freopen("output.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //cin >> test;
    while(test--){
        solve();
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		String answer = "NO";

		if(a == 5){
			if (b==5 && c==7) {
				answer = "YES";
			} else if (b==7 && c==5) {
				answer = "YES";
			}
		}else if(a==7) {
			if (b==5) {
				if (c==5) {
					answer = "YES";
				}
			}
		}

		System.out.println(answer);;


	}

}


Measured memory_bytes: 9940
#include <iostream>
using namespace std;
 
int dp[11][46] = {0};
 
int main()
{
    dp[0][0]=1;
    for(int k=0; k<10; k++)
    {
        for(int i=k; i>=0; i--)
        for(int j=0; j<46-k; j++)
        {
            dp[i+1][j+k] += dp[i][j];
        }
    }
 
    int N,S;
    while(cin>>N>>S, N||S)
    {
        if(0<=N && N<11 && 0<=S && S<46)
        {
            cout << dp[N][S] << endl;
        }
        else
        {
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 2944
import qualified Data.Vector                   as V
import           Control.Applicative
import           Control.Monad


main :: IO ()
main = do
  [n, m, c] <- map read . words <$> getLine
  bs        <- map read . words <$> getLine
  as        <- replicateM n $ map read . words <$> getLine

  print $ length $ filter (> 0) $ map (+ c) $ f as bs [0 .. m - 1]

f []       bs is = []
f (a : as) bs is = f as bs is ++ [g a bs is 0]

g as bs []       ans = ans
g as bs (i : is) ans = g as bs is $ ans + (as !! i) * (bs !! i)


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

int main(void) {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; i++) {
        string first = s.substr(0, i), second = s.substr(i);
        bool fc[26] = {}, sc[26] = {};
        int cnt = 0;
        for (auto c : first)
            fc[c - 'a'] = true;
        for (auto c : second)
            sc[c - 'a'] = true;
        for (int i = 0; i < 26; i++)
            if(fc[i] && sc[i])
                cnt++;
        if (cnt > ans)
            ans = cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,aa[1000];
signed main(){
	cin>>a;
	rep(i,a){
		cin>>aa[i];
	}
	sort(aa,aa+a);
	cout<<aa[a-1]-aa[0];
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int g[4][2001][2001];

signed main() {
  int h, w;
  cin >> h >> w;
  string s[2001];
  rep(i, 0, h) cin >> s[i];

  rep(i, 0, h) {
    int sum = 0;
    rep(j, 0, w) {
      if(s[i][j] == '#') sum = 0;
      else {
        sum++;
      }
      g[0][i][j] = sum;
    }
  }

  rep(i, 0, h) {
    int sum = 0;
    dep(j, w - 1, 0) {
      if(s[i][j] == '#') sum = 0;
      else {
        sum++;
      }
      g[1][i][j] = sum;
    }
  }

  rep(i, 0, w) {
    int sum = 0;
    rep(j, 0, h) {
      if(s[j][i] == '#') sum = 0;
      else {
        sum++;
      }
      g[2][j][i] = sum;
    }
  }

  rep(i, 0, w) {
    int sum = 0;
    dep(j, h - 1, 0) {
      if(s[j][i] == '#') sum = 0;
      else {
        sum++;
      }
      g[3][j][i] = sum;
    }
  }

  int ans = 0;
  rep(i, 0, h) {
    rep(j, 0, w) {
      if(s[i][j] == '.') {
        ans = max(ans, g[0][i][j] + g[1][i][j] + g[2][i][j] + g[3][i][j] - 3);
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 129664
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    ll c=0;
    cin>>s;
    
    rep(i,s.size()-1){
        if(s[i]!=s[i+1]) c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }
ll modadd(ll a, ll b) { return ((a += b) < mod) ? a : (a - mod); }
ll modmult(ll a, ll b) { return (ll)((a * b) % mod); }

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

ll dp[2010][2010];

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        dp[i][0] = 1;
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = modadd(dp[i - 1][j], dp[i - 1][j - 1]);
        }
    }

    //cout << dp[10][5];

    /*
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < 20; j++)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */

    if(n == 1 && k == 1){
      cout << 1;
      return 0;
    }

    for (int i = 1; i <= k; i++)
    {
        cout << modmult(dp[n - k + 1][i], dp[k - 1][i - 1]) << "\n";
    }
}

Measured memory_bytes: 30208
use std::cmp::*;
use std::collections::HashSet;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let n = int();

    let mut divisor = HashSet::new();

    let mut l = 1;
    while l * l <= n {
        if n % l == 0 {
            divisor.insert(l);
            divisor.insert(n / l);
        }
        l += 1;
    }

    let mut mdivisor = HashSet::new();
    let m = n - 1;
    let mut l = 1;
    while l * l <= m {
        if m % l == 0 {
            mdivisor.insert(l);
            mdivisor.insert(m / l);
        }
        l += 1;
    }

    divisor.remove(&1);
    //println!("{:?}", divisor);

    mdivisor.remove(&1);
    //println!("{:?}", mdivisor);

    for d in divisor {
        let mut k = n;
        while k % d == 0 {
            k = k / d;
        }
        if k == 1 || k % d == 1 {
            mdivisor.insert(d);
        }
    }
    //println!("{:?}", mdivisor);
    println!("{}", mdivisor.len())
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

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

  ll r = 0;
  ll g = 0;
  ll b = 0;
  rep(i,n){
    if(s[i] == 'R')r++;
    else if (s[i]=='G')g++;
    else if (s[i]=='B')b++;
  }
  ll sum=0;
  rep(i,n-2) FOR(j,1,(n+1)/2){
    if(i+2*j>=n)break;
    if(s[i]==s[i+j] || s[i]==s[i+j+j] || s[i+j]==s[i+2*j])continue;
    sum++;
  }
  ll ans = r*g*b - sum;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
N, K = map(int, input().split())


def sub_sum(l, r):
    return (l + r) * (r - l + 1) / 2


ans = 0

for i in range(K, N+2):
    l = sub_sum(0, i-1)
    r = sub_sum(N-i+1, N)
    ans += r - l + 1

ans = ans % (10**9+7)

print(int(ans))


Measured memory_bytes: 9124
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n;
    cin >> n;
    Int x = 0, y = 0, t = 0;
    REP(n,i){
        Int pt, px, py;
        cin >> pt >> px >> py;
        if (abs(pt - t) >= abs(px-x) + abs(py-y) && (((pt  - t)- abs(px-x) + abs(py-y)) )% 2 == 0) {
        }else{
            cout << "No" << endl;
            return 0;
        }
        t = pt;
        x = px;
        y = py;
    }
    cout << "Yes" << endl;
    return 0;
}




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

using namespace std;

class segtree {
  struct node {
    node() {}
    node(char c) { mask |= (1 << (c - 'a')); }
    node(int x) : mask(x) {}
    int mask = 0;
    void apply(int l, int r, char c) {
      mask = 1 << (c - 'a');
    }
  };

  node merge(const node& a, const node& b) const {
    return node(a.mask | b.mask);
  }

  int n;
  vector<node> t;

  void push(int v, int l, int r) {
    int m = l + r >> 1;
    //t[v << 1].apply(l, m);
    //t[v << 1 | 1].apply(m + 1, r);
  }

  template<typename... M> void modify(int v, int tl, int tr, int l, int r, const M&... m) {
    if (l <= tl and tr <= r) {
      t[v].apply(tl, tr, m...);
      return;
    }
    if (tl > r or l > tr) {
      return;
    }
    push(v, tl, tr);
    int tm = tl + tr >> 1;
    modify(v << 1, tl, tm, l, r, m...), modify(v << 1 | 1, tm + 1, tr, l, r, m...);
    t[v] = merge(t[v << 1], t[v << 1 | 1]);
  }

  node get(int v, int tl, int tr, int l, int r) {
    if (l <= tl and tr <= r) {
      return t[v];
    }
    if (tl > r or l > tr) {
      return node();
    }
    push(v, tl, tr);
    int tm = tl + tr >> 1;
    return merge(get(v << 1, tl, tm, l, r), get(v << 1 | 1, tm + 1, tr, l, r));
  }

  node getElem(int v, int tl, int tr, int k) {
    if (tl == tr) {
      return t[v];
    }
    push(v, tl, tr);
    int tm = tl + tr >> 1;
    if (k <= tm) {
      return getElem(v << 1, tl, tm, k);
    } else {
      return getElem(v << 1 | 1, tm + 1, tr, k);
    }
  }

public:
  segtree(int _n) {
    int p = 1;
    while ((1 << p) < _n) {
      ++p;
    }
    n = 1 << p;
    t.resize(n << 1);
    for (int i = n - 1; i >= 1; --i) {
      t[i] = merge(t[i << 1], t[i << 1 | 1]);
    }
  }

  template<class T> segtree(const T& a) {
    int p = 1;
    while ((1 << p) < a.size()) {
      ++p;
    }
    n = 1 << p;
    t.resize(n << 1);
    for (int i = 0; i < a.size(); ++i) {
      t[i + n] = a[i];
    }
    for (int i = n - 1; i >= 1; --i) {
      t[i] = merge(t[i << 1], t[i << 1 | 1]);
    }
  }

  template<typename... M> void modify(int l, int r, const M&... m) {
    modify(1, 0, n - 1, l, r, m...);
  }

  node get(int l, int r) {
    return get(1, 0, n - 1, l, r);
  }

  node getElem(int k) {
    return getElem(1, 0, n - 1, k);
  }
};

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

  int n;
  string s;
  cin >> n >> s;
  segtree tr(s);
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      tr.modify(i, i, c);
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      cout << __builtin_popcount(tr.get(l, r).mask) << '\n';
    }
  }

  return 0;
}

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

using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

int main() {
  int a;
  cin >> a;
  int sum = 0;
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= a; j++) {
      for (int k = 1; k <= a; k++) {
        sum += gcd(i, gcd(j, k));
      }
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3560
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

int main(){
  long long N;
  cin >> N;
  long long mini = 10000000000;
  long long maxi = 0;
  long long A;
  for(int i = 0; i < N; i++){
    cin >> A;
    mini = min(mini,A);
    maxi = max(maxi,A);
  }

  printf("%lld\n",maxi - mini );
  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 205, mod = 1e9+7;

ll n, k, a[205], ans;

struct cand {
	vector<ll> x;
	ll c;
	cand(vector<ll> &T, ll C) {
		x = T; c = C;
	}
	bool operator == (cand &T) {
		for(ll i=1;i<n;i++) {
			if(x[i]-x[i-1] != T.x[i]-T.x[i-1]) return false;
		}
		return true;
	}
	bool operator < (cand &T) {
		for(ll i=1;i<n;i++) {
			ll A = x[i]-x[i-1], B = T.x[i]-T.x[i-1];
			if(A < B) return true;
			if(A > B) return false;
		}
		return (x[0] > T.x[0]);
	}
};

vector<cand> c;

ll mincnt (ll A, ll B) {
	ll R = 0;
	for(ll i=60;i--;) {
		ll X = A&(1ll<<i), Y = B&(1ll<<i);
		if(X == Y) R += !!X;
		else return R + 1;
	}
	return -1;
}

void solve (ll I) {
	if(I > k) return;
	vector<pll> V;
	for(ll i=1;i<=n;i++) {
		V.push_back({a[i]%(1ll<<I), a[i]/(1ll<<I)});
	}
	sort(V.begin(), V.end());
	{
		vector<ll> T;
		for(ll j=0;j<n;j++) {
			T.push_back(V[j].Y);
		}
		sort(T.begin(), T.end());
		c.push_back(cand(T, k-I));
	}
	for(ll i=0;i<n-1;i++) {
		if(V[i].X == V[i+1].X) continue;
		ll C = I + mincnt(V[i].X, V[i+1].X);
		if(C > k) continue;
		vector<ll> T;
		for(ll j=0;j<=i;j++) {
			if(!V[j].Y) return;
			T.push_back(V[j].Y-1);
		}
		for(ll j=i+1;j<n;j++) {
			T.push_back(V[j].Y);
		}
		sort(T.begin(), T.end());
		c.push_back(cand(T, k-C));
	}
}

int main()
{
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	sort(a+1, a+1+n);
	for(ll i=0;i<=60;i++) {
		solve(i);
	}
	sort(c.begin(), c.end());
	for(ll i=0,S=0;i<c.size();i++) {
		if(i+1 < c.size() && c[i] == c[i+1]) continue;
		for(ll j=S;j<=i;j++) {
			ll A = c[j].x[0];
			if(j == i) {
				ans = (ans + min(A, c[j].c) + 1) % mod;
				continue;
			}
			ll B = c[j+1].x[0];
			if(A - B <= c[j].c) {
				c[j+1].c = max(c[j+1].c, c[j].c - A + B);
				c[j].c = A - B -1;
			}
			ans = (ans + c[j].c + 1) % mod;
		}
		S = i+1;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 15608
#include <stdio.h>
#include <ctype.h>
int main(void){
  int c;
  while((c=getchar())!=EOF){
      if(isupper(c)){
          putchar(tolower(c));
      }
      else if(islower(c)){
          putchar(toupper(c));
      }
      else{
          putchar(c);
      }
  }
  return 0;  
}


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



int main(){
    int N;
    cin>>N;
    int kisu=0,gusu=0;
    vector<long> data(N);
    for(int i=0;i<N;i++){
        cin>>data[i];
        if(data[i]%2==0)gusu++;
        else kisu++;
    }

    bool ans=true;

    if(kisu%2!=0)ans=false;

    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    }

    



Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B; cin >> A >> B;
	if(A == 1) A = 14;
	if(B == 1) B = 14;

	if(A > B) cout << "Alice" << endl;
	else if(A < B) cout << "Bob" << endl;
	else cout << "Draw" << endl;


	return 0;

}


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

int main()
{
  int N, M;
  cin >> N;
  vector<string> s(N);
  rep(i,N) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  rep(i,M) cin >> t[i];

  int max = 0;
  rep(i, N) {
    int ans = count(s.begin(), s.end(), s[i]);
    ans -= count(t.begin(), t.end(), s[i]);
    if(ans > max) max = ans;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
//#include <bits/stdc++.h>

using namespace std;
typedef long long unsigned int ll;	//10^18
typedef unsigned long ul;

typedef map<ll, ll> m;
typedef multimap<ll, ll> mm;
typedef set<ll> s;
typedef multiset<ll> ms;
typedef priority_queue<ll> pq;
typedef queue<ll> q;
typedef deque<ll> dq;
typedef list<ll> lst;
typedef pair<ll, ll> p;

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

//#define and &&
//#define or ||
//#define not !
//#define neq !=
//#define eq ==

#define REP(i, n) for(int i=0;i<n;i++)	// from 0 to n
#define REPR(i, n) for(int i = n;i >= 0;i--)	// from n to 0
#define FOR(i, m, n) for(int i = m;i < n;i++)	// from m to n
#define DBG(a) cout << #a << " : " << a << "\n";
#define MSG(a) cout << a << "\n";
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

#define pb push_back	//配列などの最後に要素を追加
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

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; }

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

//swap(a, b);
//sort(arr, arr + n);	//昇順
//sort(arr, arr+n, greater<int>());	//降順
//max(a, b);
//min(a, b);

//upper_bound(a, a+n, k)	//配列aの中で、kより大きい値が初めて現れる位置へのポインタ
//upper_bound(ALL(v), k)	//STLvの中で、kより大きい値が初めて現れる位置へのポインタ
//lower_bound(a, a+n, k)
//lower_bound(ALL(v), k)	//STLvの中で、kの以上値が初めて現れる位置へのポインタ
//lower_bound(ALL(v),k) - upper_bound(ALL(v),k)	//二分探索を用いて、ある列aに含まれる数kの個数を求める


// index が条件を満たすかどうか
bool isOK(vector<ll>& v, int index, int key) {
	if (v[index] >= key) return true;
	else return false;
}

// 汎用的な二分探索	
int bs(vector<ll>& v, int key) {
	int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int ok = (int)v.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOK(v, mid, key)) ok = mid;
		else ng = mid;
	}
	return ok;
}

// 最大公約数
ll gcd(ll a, ll b) {
	if (a < b)	swap(a, b);
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;

}

// 素因数分解
vector<ll> prime_factorization(ll n) {
	vector<ll> cnt_pf(ceil(sqrt(n)), 0);
	FOR(i, 1, SZ(cnt_pf)) {
		while (n % (i+1) == 0) {
			cnt_pf[i]++;
			n /= (i+1);
		}
		if (n == 1)	break;
	}
	if (n != 1) {
		cnt_pf[0]++;
	}
	return cnt_pf;
}

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

	//string s;
	//cin >> s;
	
	ll n, m;
	int ans = 1;
	cin >> n >> m;

	n = gcd(n, m);

	vector<ll> a(ceil(sqrt(n)));
	a = prime_factorization(n);
	REP(i, SZ(a)) {
		if (a[i] != 0) {
			ans++;
		}
	}


	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 15872