akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<sstream>     
#include<map>
#include<iomanip>
#include<cctype>
#include<vector>
#include<set>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	string s;
	while (cin>>s)
	{
		int flag = 1;
		int count = 0;
		if (s[0] != 'A')
			flag = 0;
		for (int i = 2;i <= s.length() - 2;i++)
		{
			if (s[i] == 'C')
			{
				count++;
				s[i] = 'c';
			}
		}
		if (count != 1)
			flag = 0;
		if (flag == 1)
		{
			for (int j = 1;j < s.length();j++)
			{
				if (s[j] >= 'a'&&s[j] <= 'z')
					flag = 1;
				else
				{
					flag = 0;
					break;
				}
				
			}
		}
		if (flag)
			cout << "AC" << endl;
		else
			cout << "WA" << endl;
	}
	return 0;
}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

int ans;
vector<int> a, b, c, d, A;
int n, m, q;

void dfs(int k) {
  if (k - 1 == n) {
    int sum = 0;
    for (int i = 0; i < q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    ans = max(ans, sum);
    return;
  }
  for (int i = A[k - 1]; i < m; i++) {
    A[k] = i;
    dfs(k + 1);
  }
}

void solve() {
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  A.resize(n + 1);  // 1 based

  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  A[0] = 0;
  dfs(1);
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int q = getInt();
  vector<int> s(n);
  vector<int> t(n);
  vector<int> x(n);

  vector<pair<pair<int, int>, int> > v(n);

  REP(i,n){
    s[i] = getInt();
    t[i] = getInt();
    x[i] = getInt();
    // s <= d + x <= t - 1
    // s - x <= d <= t - x - 1
    v[i].first.first = s[i] - x[i];
    v[i].first.second = t[i] - x[i] - 1;
    v[i].second = x[i];
  }
  sort(v.begin(), v.end());
  int idx = 0;

  typedef pair<int, int> data;
  priority_queue<data, vector<data>, greater<data> > pq;
  multiset<int> xx;

  REP(i,q){
    const int d = getInt();

    while(idx < n){
      if(v[idx].first.first <= d){
	pq.push(data(v[idx].first.second, v[idx].second));
	xx.insert(v[idx].second);
	++idx;
      }else {
	break;
      }
    }

    while(pq.size()){
      const data dt = pq.top();
      if(dt.first < d){
	xx.erase(xx.find(dt.second));
	pq.pop();
      }else{
	break;
      }
    }

    if(xx.size()){
      printf("%d\n", *xx.begin());
    }else{
      printf("%d\n", -1);
    }
  }

  return 0;
}

Measured memory_bytes: 16880
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		String str = sc.nextLine();
		
		sc.close();
		
		StringBuilder sb = new StringBuilder();
		
		for(char c : str.toCharArray()){
			if(c != 'B') sb.append(c);
			else{
				if(sb.length() != 0 ) sb.deleteCharAt(sb.length()-1);
			}
		}
		
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 9936
"use strict";

const main = arg => {
    const A = parseInt(arg.split("\n")[0].split(" ")[0]);
    const B = parseInt(arg.split("\n")[0].split(" ")[1]);
    const K = parseInt(arg.split("\n")[0].split(" ")[2]);
    const list = [];
    
    for(let i=1; i<=Math.min(A,B); i++) {
        if(A % i == 0 && B % i == 0) {
            list.push(i);
        }
    }
    
    console.log(list[list.length - K]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n, l;
        n = sc.nextInt();
        l = sc.nextInt();
       
        int[] aji = new int[n];
        int minIndex = 0;
        for(int i=0; i<n;i++)
        {
            aji[i] = l+i;
            if(i > 0){
                if(Math.abs(aji[i]) < Math.abs(aji[minIndex]))
                {
                    minIndex = i;
                }
            }
        }

        int sum = 0;
        for(int i=0; i<n;i++){
            if(i != minIndex)
            {
                sum += aji[i];
            }
        }
        System.out.println(sum);
        
        
    }
}



Measured memory_bytes: 22096
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    int cnt=0;
    cin>>s;
    int n=s.size();
    rep(i,n)cnt+=(i+s[i])%2;//0101…にするのに必要な手数
    cout<<min(cnt,n-cnt)<<endl;//0101…と1010…の手数少ないほう出力
}

Measured memory_bytes: 3756
#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;

#define sim template < class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
    sim > typename enable_if< sizeof dud< c >(0) x 1, debug & >::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge< c > range(c i, c j) { return rge< c >{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef XOX
    ~debug()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair< b, c > d)
{
    ris << "" << d.first << " --> " << d.second << "";
}
sim dor(rge< c > d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define imie(...) "" << #__VA_ARGS__ " = " << (__VA_ARGS__) << ", "

#define F first
#define S second
#define endl '\n'
#define pb emplace_back
#define mp make_pair
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define all(v) (v).begin(), (v).end()
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie();                    \
    cout.tie()
#define min3(x, y, z) (x < y ? (x < z ? x : z) : (y < z ? y : z))
#define max3(x, y, z) (x > y ? (x > z ? x : z) : (y > z ? y : z))
#define MAX_N int(1e6 + 7)
#define MAX_M int(1e6 + 7)
#define MAX_V int(1e6 + 7)
#define oo int(1e9 + 217)
#define MOD int(1e9 + 7)
using ll = long long;
using vi = vector< int >;
using vl = vector< ll >;
using vpii = vector< pair< int, int > >;
using pii = pair< int, int >;

typedef tree<
    int,
    null_type,
    less< int >,
    rb_tree_tag,
    tree_order_statistics_node_update >
    oset;

void solve()
{
}

int main()
{
    fast;
    int d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d)
        puts("Yes");
    else
        puts("No");
}


Measured memory_bytes: 3620
#include<stdio.h>
 
int main(){
  int N;
  char S[101],T[101];
  scanf("%d",&N);
  scanf("%s%s",S,T);
  for(int i = 0; i < N; i++){
  	printf("%c%c",S[i],T[i]);
  }
  printf("\n");
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N, M, lim = mi()
A = li()
B = li()

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))
ans = 0
'''
for i in range(N+1):
    if lim < A[i]:
        continue
    #right = 0
    cnt = 0
    wa = 0

    while right < M and wa + B[right] <= lim - A[i]:
        wa += B[right]
        right += 1

    cnt = right - left

    if cnt > 0:
        ans = max(ans, cnt+i)

print(ans)
'''
right = M

for i in range(N+1):
    if A[i] > lim:
        continue

    while True:
        if right < 0 or A[i] + B[right] <= lim:
            break
        right -= 1
    
    #print(i, right)
    ans = max(ans, i + right)
    
print(ans)

Measured memory_bytes: 41056
import java.util.Scanner;
import java.util.Arrays;

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

        int n = Integer.parseInt(sc.next());
        String s = sc.next();

        int[] w = new int[n + 1];
        int[] r = new int[n + 1];

        w[0] = 0;
        r[n] = 0;
        for(int i = 0; i < n; i++){
            w[1 + i] = w[i];
            if(s.charAt(i) == 'W'){
                w[1 + i]++;
            }
            r[n - i - 1] = r[n - i];
            if(s.charAt(n - i - 1) == 'R'){
                r[n - i - 1]++;
            }
        }

        int min = -1;
        for(int i = 0; i < n + 1; i++){
            int temp = Math.abs(r[i] - w[i]) + Math.min(r[i], w[i]);
            if(min == -1 || temp < min){
                min = temp;
            }
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 42448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000000000000000;//15
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

ll l=0,r=0;

ll BS(ll t,ll a){
  ll ng=0,ok=(INF+max(t,a))/(max(t,a));
  ll mid;

  while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    if(t*mid>=l && a*mid>=r){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  
  return ok;
}

signed main(){
  ll n,bai,t,a;cin>>n;

  for(int i=0;i < n;i++)
  {
    cin>>t>>a;
    bai=BS(t,a);
    l=bai*t;r=bai*a;
  }

  cout<<l+r<<endl;

}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<stack>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define rrep(f,i,n) for(int (i)=0;(i) < (f); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define mset(a,x) memset(a,x,sizeof(a))

#define MAX 101
#define MAX_V 15

int main()
{
	int i[3],k;
	rep(j, 3) {
		cin >> k;
		i[j] = k;
	}
	sort(i,i+ 3);
	cout << i[0] + i[1] << 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;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n,a,b;
    string s;
    cin >> n >> a >> b >> s;
    int th=0;
    int bb=0;
    rep(i,n){
        if(s.at(i)=='a'){
            if(th<a+b){
                th++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        if(s.at(i)=='b'){
            if(th<a+b&&bb<b){
                th++;
                bb++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        if(s.at(i)=='c') cout << "No" << endl;
    }

}


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

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

  ll N; cin >> N;  
  ll Z; cin >> Z;
  ll W; cin >> W;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll ans = abs(W - A[N - 1]);
  if (N > 1) ans = max(ans, abs(A[N - 1] - A[N - 2]));
  cout << ans << '\n';
  return 0;
}

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

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1);
    map<ll,ll> m;
    ll sum = 0;
    rep(i,0,N){
        cin >> A[i];
        m[A[i]]++;
    }
    for(auto s : m){
        sum += (s.first * s.second);
    }

    ll Q; cin >> Q;
    vector<ll> ans(Q);
    rep(i,0,Q){
        ll b,c; cin >> b >> c;
        ll x = m[b];
        sum -= b * x;
        m[b] = 0;
        m[c] += x;
        sum += c * x;
        ans[i] = sum;
    }
    for(auto &a : ans){
        cout << a << endl;
    }
}

Measured memory_bytes: 10864
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll dp[2][110][20];
int main() {
  ll n,k,ans=0;
  string s;
  cin>>s;
  cin>>k;
  n=s.length();
  dp[1][0][0]=1;
  rep(i,0,n){
    rep(kn,0,k+1){
      ll x=s[i]-'0';
      dp[0][i+1][kn+1]+=dp[0][i][kn]*9;
      dp[0][i+1][kn]+=dp[0][i][kn];
      if(x!=0){
        dp[0][i+1][kn+1]+=dp[1][i][kn]*(x-1);
        dp[0][i+1][kn]+=dp[1][i][kn];
        dp[1][i+1][kn+1]=dp[1][i][kn];
      }
      if(x==0)dp[1][i+1][kn]=dp[1][i][kn];
    
    }
  }

  cout << dp[0][n][k] + dp[1][n][k] << endl;
}



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

int main() {
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;

	if(x - r >= 0 && x + r <= W && y + r <= H && y - r >= 0){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

class FC{
	public:
		int p[31];
		int n;
		bool is_over(){
			return p[1]==p[2] && p[2]==p[3] && p[3]==p[4] && p[4]==p[5] &&  p[5]==p[6] && p[6]==p[7]
					&& p[7]==p[8] && p[8]==p[9]
					&& p[10]==p[11] && p[11]==p[12]
					&& p[13]==p[14] && p[14]==p[15]
					&& p[16]==p[17] && p[17]==p[18]
					&& p[19]==p[20] && p[20]==p[21];
			}
		void rot1(){
			swap(p[7],p[22]);
			swap(p[8],p[23]);
			swap(p[9],p[24]);
			swap(p[13],p[18]);
			swap(p[10],p[12]);
		}
		void rot2(){
			swap(p[1],p[28]);
			swap(p[2],p[29]);
			swap(p[3],p[30]);
			swap(p[16],p[15]);
			swap(p[21],p[19]);
		}
		void rot3(){
			swap(p[1],p[24]);
			swap(p[4],p[27]);
			swap(p[7],p[30]);
			swap(p[16],p[18]);
			swap(p[10],p[21]);
		}
		void rot4(){
			swap(p[3],p[22]);
			swap(p[6],p[25]);
			swap(p[9],p[28]);
			swap(p[13],p[15]);
			swap(p[12],p[19]);
		}
};

int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		FC now;
		for(int j=1;j<=30;j++){
			cin>>now.p[j];
		}
		now.n=0;
		queue<FC> que;
		que.push(now);
		while(!que.empty()){
			now=que.front();
			que.pop();
			if(now.is_over()){
				cout<<now.n<<endl;
				break;
			}
			FC nex1=now;
			nex1.rot1();
			nex1.n++;
			que.push(nex1);
			FC nex2=now;
			nex2.rot2();
			nex2.n++;
			que.push(nex2);
			FC nex3=now;
			nex3.rot3();
			nex3.n++;
			que.push(nex3);
			FC nex4=now;
			nex4.rot4();
			nex4.n++;
			que.push(nex4);
		}
	}
	
	return 0;
}

Measured memory_bytes: 13856
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main() {
	int n, t, m = INF, k = 0;
	cin >> n >> t;
	vector<int> v(n);
	map<int, int> mp;
	rep(i, 0, n) {
		cin >> v[i];
		m = min(m, v[i]);
		mp[v[i] - m]++;
		k = max(k, v[i] - m);
	}
	printf("%d\n", mp[k]);
	return 0;
}


Measured memory_bytes: 8404
#                         author:  kagemeka 
#                         created: 2019-11-06 14:53:37(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, a, b = (x for x in sys.stdin.readlines())
    n = int(n.rstrip())
    a = [int(x) for x in a.split()]
    b = [int(x) for x in b.split()]

    total = a[0] + b[-1]
    sa, sb = sum(a[1:]), sum(b[:-1])
    for i in range(n-1):
        if sa >= sb:
            total += a[i+1]
            sa -= a[i+1]
            sb -= b[i]
        else:
            for j in range(i+1, n-1):
                if sum(a[i+1:j+1]) - sum(b[i:j]) >= 0:
                    total += a[i+1]
                    sa -= a[i+1]
                    sb -= b[i]
                    break
                else:
                    continue
            else:
                total += sb
                break
    print(total)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int r[200000];
int X, K;

int main()
{
  int Q, T, A, minA, maxA, k = 0, t = 0, x = 0, sign = -1;

  cin >> X >> K;
  for(int i = 0; i < K; i++) {
    cin >> r[i];
  }
  r[K] = 2e9;

  minA = 0;
  maxA = X;
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    cin >> T >> A;
    for(; T >= r[k]; ) {
      int diff = sign * (r[k] - t);
      x += diff;
      minA = min(X, max(0, minA + diff));
      maxA = min(X, max(0, maxA + diff));
      t = r[k];
      k++;
      sign *= -1;
    }
    T -= t;
    A = min(maxA, max(minA, A + x));
    A = min(X, max(0, A + sign * T));
    cout << A << endl;

    //cout << minA << " " << maxA << " " << x << " " << t << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
int N,Y;
bool flag = false;
int main(void) {
	cin >> N>>Y;
	for (int i = 0; i <= N ;i++) {
		for (int k = 0; i + k <= N ; k++) {
			int s = N - i - k;
			int sum = 10000 * i + 5000* k + 1000 * s;
			
			if (sum == Y) {
				flag = true;
				cout << i << " " << k << " " << s << endl;
				break;
			}
		}
		if (flag)break;
	}
	if (!flag)cout << "-1 -1 -1" << endl;

	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while( x->right != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ){
      u = u->left;
    }

    else{
      u = u->right;
    }
  }

  return u;

}

Node treeSuccessor(Node x){
  if ( x->right != NIL ){
    return treeMinimum(x->right);
  }
  
  Node y = x->parent;

  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){
  Node x,y; 
  
  if ( z->left == NIL || z->right == NIL ){
    y = z;
  }

  else{
    y = treeSuccessor(z);
  }

  if ( y->left != NIL ){
    x = y->left;
  }

  else{
    x = y->right;
  }

  if ( x != NIL ){
    x->parent = y->parent;
  }
  

  if ( y->parent == NIL ){
    root = x;
  }
  else {
    if (y == y->parent->left){
      y->parent->left = x;
    }

    else{
      y->parent->right = x;
    }

  }

  if ( y != z ){
    z->key = y->key;
  }

  free(y);

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    }

    else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  }

  else {

    if (z->key < y->key) {
      y->left = z;
    }

    else {
      y->right = z;
    }

  }

}

void inorder(Node u){
  if ( u == NIL ){
    return;
  }

  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if ( u == NIL ){
    return;
  }
  
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);

}


int main(){

  int n, i, x;
  char com[20];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){

    scanf("%s", com);
    if ( strcmp(com, "find") == 0 ){

      scanf("%d", &x);

      Node t = treeSearch(root, x);

      if ( strcmp(com, "findMin") == 0 ){

        Node minn = treeMinimum(t);
        printf("%d\n", minn->key);
      }

      else if ( strcmp(com, "findMax") == 0 ){
        Node maxn = treeMaximum(t);
        printf("%d\n", maxn->key);
      }

      else {

        if ( t != NIL ){
          printf("yes\n");
        }

        else {
          printf("no\n");
        }
        
      }
    }
    else if ( com[0] == 'i' ){

      scanf("%d", &x);

      insert(x);
    }
    else if ( strcmp(com, "print") == 0 ){


      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");
    }
    else if ( strcmp(com, "delete") == 0 ){

      scanf("%d", &x);

      treeDelete(treeSearch(root, x));
    }
  }


  return 0;

}


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

int main() {
	int count = 0;
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < s1.size(); i++) {
		if (s1[i] != s2[i]) {
			++count;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 3864
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,d = gets.split.map(&:to_i)
array = n.times.map { gets.split.map(&:to_i) }

count = 0
array.each do |x,y|
  if d*d >= x*x + y*y
    count += 1
  end
end

puts count 
  

Measured memory_bytes: 28420
#include<iostream>

using namespace std;

int a[200000];

int main()
{
	int N;

	cin >> N;

	for (int i = 0; i < N; i++)
		cin >> a[i];
	
	int min = a[0],ans=1;
	
		for (int j = 1; j < N; j++)
			if (min > a[j]) {
				++ans;
				min = a[j];
			}
		cout << ans;
}


Measured memory_bytes: 4416
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int n;cin>>n;
if(n<1200) cout<<"ABC";
else if(n<2800) cout<<"ARC";
else cout<<"AGC";




return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int min(int x,int y){
	if(x<y)return x;
	return y;
}

int main(){
	int N,A,B;
	scanf("%d%d%d",&N,&A,&B);
	int P[N];
	int c[3]={0,0,0};
	for(int i=0;i<N;i++){
		scanf("%d",&P[i]);
		if(P[i]<=A)c[0]++;
		else if(P[i]<=B)c[1]++;
		else c[2]++;
	}
	int ans=N;
	ans=min(ans,c[0]);
	ans=min(ans,c[1]);
	ans=min(ans,c[2]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
S = int(input())
if S <= 1000000000:
    X2 = 1
    Y3 = S
    print(0,0,X2,0,0,Y3)
elif S == 10 ** 18:
    print(0,0,0,1000000000,1000000000,0)
else:
    X2 = 1000000000
    S_mod = S % X2
    X3 = X2 - S_mod
    Skiriage = S + X3
    Y3 = Skiriage / X2
    print(0,0,X2,1,X3,int(Y3))

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

#define MAX 100000
vector <int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;
    int next;
    for(int i=0;i<G[current].size();i++){
        next = G[current][i];
        if (!visited[next]){
            parent[next] = current;
            dfs(next, current);
            lowest[current] = min(lowest[current], lowest[next]);
        }else if(next != prev){
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void art_points(){
    for (int i=0;i<N;i++){
        visited[i] = false;
    }
    timer = 1;
    dfs(0,-1);

    set<int> ap;
    int np = 0;
    for (int i=1;i<N;i++) {
        int p = parent[i];
        if (p == 0) {
            np++;
        } else if (prenum[p] <= lowest[i]) {
            ap.insert(p);
        }
    }
        if(np>1){
            ap.insert(0);
        }
        for (set<int>::iterator it = ap.begin();it!=ap.end();it++){
            cout << *it << endl;
        }

}

int main() {
   
    int m;
    cin >> N >> m;
    for (int i=0;i<m;i++){
        int s,t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();

}


Measured memory_bytes: 6936
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int a,b,ans,now;
int main()
{
	cin>>a>>b;
	if(b==1) {printf("0");return 0;}
	if(b<=a) {
		cout<<"1";return 0;
	}
	now=a;
	while(1){
		now+=(a-1);
		ans++;
		if(now>=b) break;
	}
	printf("%d",ans+1);
	return 0; 
 } 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a[] = new int[n];
		int b[] = new int[n-1];
		int ans = 0;
		
		for (int i = 0 ; i < n -1 ; i++ ) {
			b[i] = Integer.parseInt(sc.next());
		}
		
		a[n-1] = b[n-2];
		a[0] = b[0];
		for (int i = n - 2 ; 0 < i ; i-- ) {
			a[i] = Math.min(b[i],b[i-1]);
		}
		

		
		for (int i : a) {
			ans += i;
		}
		
		
		
		
		System.out.println(ans);
		
			}
	
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,k,ans;
signed main(){
	cin>>n>>k;
	for(int i=k;i<=n+1;i++){
		int mn=i*(0+i-1)/2;
		int mx=i*(n+(n-i+1))/2;
		int sum=(mx-mn+1)%MOD;
		//cout<<sum<<endl;
		ans+=sum;
		ans%=MOD;
	}
	cout<<ans<<endl;
	
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		int h;
		cin >> h;
		if(h >= k) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(void) {

	int N;
	cin >> N;
	int A[200010]{};
	for (int i = 0; i < N; i++) cin >> A[i];

	pair<int, int> max;
	max.first = 0;
	max.second = 0;
	int second = 0;
	for (int i = 0; i < N; i++)
	{
		if (max.second < A[i])
		{
			max.first = i;
			max.second = A[i];
		}
		else if(second < A[i]) second = A[i];
	}

	for (int i = 0; i < N; i++)
	{
		if (i == max.first) cout << second << endl;
		else cout << max.second << endl;
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int numofbits(unsigned long long bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> k;
    int N = pow(2, n);
    rep(i, N) {
        if(numofbits(i) == k) {
            cout << i << ":";
            m = i;
            for(int j = 0; m > 0; j++) {
                if(m & 1) cout << " " << j;
                m /= 2;
            }
            cout << "\n";
        }
    }
}



Measured memory_bytes: 3344
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
 
    // Your code here!
   int N,A;
   cin >> N >> A;
   N = N % 500;
   if(A>=N){
       cout  << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N;
ll A[Nmax];

int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A, A+N);

	int n = N-1;
	while(n > 0 && A[n]!=A[n-1]) n--;
	if(n<=0){
		cout << 0 << endl;
		return 0;
	}
	ll ans = A[n];
	n -= 2;
	while(n > 0 && A[n]!=A[n-1]) n--;
	if(n<=0){
		cout << 0 << endl;
		return 0;
	}
	ans *= A[n];
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int F[50];
    F[0] = 1, F[1] = 1;
    for(int i=2; i<=n; i++)
        F[i] = F[i-1]+F[i-2];
    cout << F[n] << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int a = INF;
	rep(i,n){
		sum += l+i;
		if(abs(l+i) < abs(a)) a = l+i;
	}
	cout << sum - a << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
          int upperBase = sc.nextInt();
          int lowerBase = sc.nextInt();
          int height = sc.nextInt();

          int area = (upperBase + lowerBase) * height / 2;

          System.out.println(area);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


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

int main(){
    ll x,a;
  	int n;
    scanf("%lld",&x);

    a=100;
    for(int i=1; i<=4000; i++){
        a=a*1.01;
        if(a>=x){
            printf("%d",i);
            return 0;
        }
    }
  	printf("%d",-1);
}

Measured memory_bytes: 3832
package main

import "fmt"

func main(){
	var s,t string
	var ans int
	fmt.Scan(&s)
	fmt.Scan(&t)
	for i:=0 ; i<len(s) ; i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4492
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


class BIT():
    def __init__(self,init_value):
        self.n = len(init_value)
        self.tree = [0]*(self.n+1)
        for i in range(1,self.n+1):
            x = init_value[i-1]
            while i <= self.n:
                self.tree[i] += x
                i += i & (-i)
    def update(self,i,x):  # i(1-index)番目の値を+x
        while i <= self.n:
            self.tree[i] += x
            i += i & (-i)
        return
    def query(self,i):  # 1番目からi(1-index)番目までの和を返す
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & (-i)
        return res


N,Q = MI()
A = LI()
BIT = BIT(A)
for _ in range(Q):
    p,q,r = MI()
    if p == 0:
        BIT.update(q+1,r)
    else:
        print(BIT.query(r)-BIT.query(q))


Measured memory_bytes: 132600
#include <iostream>
using namespace std;
 
class card {
	public:
	bool ex;
	string rank;
	int number;
	card();
	void set(bool i, string j, int k);
	string getr(int t);
};

card::card() {
	ex = 0;
	rank = "S";
	number = 1;
}
void card::set(bool i, string j, int k) {
	ex = i;
	rank = j;
	number = k;
}

string card::getr(int t) {
	if((t-1)/13 == 0) {
		return "S";
	} else if ((t-1)/13 == 1) {
		return "H";
	} else if ((t-1)/13 == 2) {
		return "C";
	} else {
		return "D";
	}
}
 
int main() {
	card c[52];
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		int k, l, m;
		string r;
 		cin >> r >> l;
 		if(r == "S") {
 			k =0;
 		} else if(r == "H") {
 			k = 1;
 		} else if(r == "C") {
 			k = 2;
 		} else {
 			k = 3;
 		}
 		m = k*13 + l - 1;
 		c[m].set(1, r, l);
	}
	for(int i=0;i<52;i++) {
		if(!c[i].ex) {
			if((i+1)%13 == 0) {
				cout << c[i].getr(i+1) << " " << 13 << endl;
			} else {
				cout << c[i].getr(i+1) << " " << (i+1)%13 << endl;
			}
		}
	}
	return 0;
}

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

int main()
{
    long long x;
    cin>>x;
    long long ans =0;
    ans+=(x/500) * 1000;
    if(x%500!=0)
    {
        x = x%500;
        ans+= (x/5) * 5;

    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    // vector<string> ss1(1 << n), ss2(1 << n);
    vector<pair<int, string>> ss1(1 << n), ss2(1 << n);
    for(int i = 0; i < (1 << n); i++){
        string s1, s2, t1, t2;
        for(int j = 0; j < n; j++){
            (i >> j & 1 ? s1 : s2) += s[j];
            (i >> j & 1 ? t1 : t2) += s[2 * n - 1 - j];
        }
        reverse(s2.begin(), s2.end());
        reverse(t2.begin(), t2.end());
        ss1[i] = {s1.size(), s1 + s2};
        ss2[i] = {t1.size(), t1 + t2};
        // prints(ss2[i], i);
    }
    sort(ss2.begin(), ss2.end());
    // prints(ss1, ss2);
    ll ans = 0;
    for(int i = 0; i < (1 << n); i++){
        auto beg = lower_bound(ss2.begin(), ss2.end(), ss1[i]),
             end = upper_bound(ss2.begin(), ss2.end(), ss1[i]);
        ans += end - beg;
        // prints(ans, ss1[i], *beg, *end);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 46080
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long N = sc.nextLong();

		for (int h = 1; h <= 3500; h++) {
			for (int n = 1; n <= 3500; n++) {
				long tmp = N * h * n;
				long tmp2 = 4L * h * n - N * (n + h);

				if (tmp2 > 0 && tmp % tmp2 == 0) {
					pr.printf("%d %d %d\n", h, n, tmp / tmp2);
					return;
				}
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,vector<int>>;

int a[12][12];

int main(void) 
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int>c (n);
    rep(i,n) {
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    int ans = INF;
    //全探索　ビットを使う
    //買う = 1 買わない = 0 
    rep(i,1 << n){
        int cost = 0;
        vector<int> d (m);
        rep(j,n){
            if(i >> j & 1){
                //買う
                cost += c[j];
                rep(k,m) d[k] += a[j][k];
            }
        }

        bool ok = true;
        rep(k,m) if(d[k] < x) ok =false;
        if(ok) ans = min(ans,cost);
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}



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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  string s,t;
  cin >> s >> t;
  string aux = t.substr(0,t.size()-1);

  if(s == aux)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    int n,k,d,sum=0;
    in(n,k);
    vector<int> vec(n);
    in(vec);
    sort(all(vec));
    int l=0,r=vec[n-1],m=(l+r)/2;
    while(m!=l){
        sum=0;
        rep(i,n)sum+=(vec[i]-1)/m;
        if(sum<=k)r=m;
        else l=m;
        m=(l+r)/2;
    }
    out(m+1);
}

Measured memory_bytes: 3968
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

signed main() {
  int n;
  while (cin >> n, n) {
    int m = in();
    string p = "I", s; REP(_, n) p += "OI";
    cin >> s;
    int ans = 0;
    REP(i, m) {
      if (s[i] == 'O') continue;
      if (2 * n + 1 + i > m) break;
      if (p == s.substr(i, 2 * n + 1)) ++ans;
    }
    print(ans);
  }
  
  return 0;
}

Measured memory_bytes: 4608