akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int maxn = (int) 2e5 + 20;

#define LL long long

string s, t;

LL gao(int l, int r)
{
    LL res = 0, cnt = 0;
    for(int i = l; i <= r; i++)
    {
        if(t[i] == 'A') cnt++;
        if(t[i] == 'D') res += cnt;
    }
    return res;
}

void work()
{
    cin >>s;
    for(int i = 0; i < s.size(); i++)
    {
        t += s[i];

        if(t.size() > 1)
        {
            if(t[t.size() - 2] == 'B' && t[t.size() - 1] == 'C')
            {
                t.pop_back();
                t.pop_back();
                t += 'D';
            }
        }
    }

    LL ans = 0;
    for(int l = 0, r; l < t.size(); l = r)
    {
        r = l;
        while(r < t.size() && (t[r] == 'A' || t[r] == 'D'))
            r++;
        if(t[l] == 'A' || t[l] == 'D')
            ans += gao(l, r);
        else
            r++;
    }

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 776
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<LL> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-9;
const LL INF = 1e9;
const LL mod = 1000000007;
const LL LINF = 1e18 + 10;
const LL MAX = 1e5 + 1;

int n;
int m;
VI g[MAX];
int ye = 0;
int path[MAX];
char used[MAX];

void dfs(int v)
{
	used[v] = 1;
	path[ye++] = v;
	for (auto i : g[v])
		if (used[i] == 0)
		{
			dfs(i);
			return;
		}
}

bool solve(int v)
{
	ye = 0;
	memset(used, 0, sizeof(used));
	used[v] = 1;
	if (SZ(g[v]) == 1)
	{
		path[ye++] = v;
		dfs(g[v][0]);
		return 1;
	}

	path[ye++] = v;
	dfs(g[v][0]);
	for (auto i : g[v])
		if (used[i] == 0)
			return 0;

	return 1;
}

int cmp(int x, int y)
{
	return SZ(g[x]) < SZ(g[y]);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> m;
	int u, v;
	FOR(i, 0, m)
	{
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	if (n == 2)
	{
		cout << 2 << endl << 1 << " " << 2;
		return 0;
	}

	bool x;
	VI all;
	FOR(i, 0, n)
		all.push_back(i);

	sort(ALL(all), cmp);
	srand(time(NULL));
	int best = 0;
	while (best < 25)
	{
		x = solve(all[best]);
		if (x)
			break;

		best++;
	}

	cout << ye << endl;
	FOR(i, 0, ye)
		cout << path[i] + 1 << " ";
	cin >> n;
	return 0;
}

Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<long long int> 
#define pb push_back
#define f(i,x,n) for (i=x;i<n;i++)


bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
void solve(){
    ll x,k,d;
    cin >> x >> k >> d;
     if(x==0)
    {
        if(k%2==0)
            cout<<"0"<<endl;
        else
            cout<<d<<endl;
            return;
    }
    if(x<0){
    x=(-1)*x;}
    
    ll a=x%d;
    ll y=abs(x-a);
    if((x/d)==k){
    cout << a;
    return;
    }
    if((y/d)>k)
    {
        cout << x-(d*k);
        return;
    }
    k=k-(x/d);
    if(k%2==0){
        cout << a ;
        return;
    }
    else
    {
        cout << d-a;
        return ;
        
    }
    
    
}

int main(){
	ios_base::sync_with_stdio(false); 
     	cin.tie(NULL);
	int t=1;
	
	while(t--)
	solve();	
	
}

Measured memory_bytes: 3628
x = int(input())
sign = ((1,1),(1,-1),(-1,1),(-1,-1))
isloop=True
for a in range(10**3):
    if(isloop==False):
        break
    for b in range(10**3):
        if(isloop==False):
            break
        for s1,s2 in sign:
            if(isloop==False):
                break
            a1 = s1*a
            b1 = s2*b
            if((a1**5)==(x+b1**5)):
                print(a1,b1)
                isloop=False
                break
            
        

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


ll X,Y,Z,K;
vector<ll> AB;
vector<ll> C;

bool solve(ll P){
    int count = 0;
    REP(i,X*Y){
        REP(j,Z){
            if(AB[i] + C[j] >= P){
                count ++;
                if(count >= K){
                    return true;
                }
            }else{
                break;
            }
        }
    }
    return false;
}

ll binary_search(ll M){
    ll ng = -1;
    ll ok = M;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        //cout << ng << ", " << mid << ", " << ok << endl;
        if(solve(mid)){//ここに条件をかく
            ng = mid;
        }else{
            ok = mid;
        }
    }
    return ng;
}

int main() {
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X);
    vector<ll> B(Y);
    C.assign(Z,0);
    REP(i,X){
        cin >> A[i];
    }
    REP(i,Y){
        cin >> B[i];
    }
    REP(i,Z){
        cin >> C[i];
    }
    AB.assign(X*Y, 0);
    REP(i,X){
        REP(j,Y){
            AB[i*Y + j] = A[i]+B[j];
        }
    }
    sort(ALL(AB), greater<ll>());
    sort(ALL(C), greater<ll>());

    vector<ll> ABC;
    if(AB.size() > K){
        REP(i,K){
            REP(j,C.size()){
                ABC.push_back(AB[i] + C[j]);
            }
        }
    }else{
        REP(i,AB.size()){
            REP(j,C.size()){
                ABC.push_back(AB[i] + C[j]);
            }
        }
    }

    sort(ALL(ABC), greater<ll>());

    
    REP(i,K){
        cout << ABC[i] << endl;
    }

    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }

  ll sum=0;
  ll ans=0;
  for(int i=0;i<N;i++){
    if(A.at(i)==0){
      ans+=sum/2;
      sum=0;
    }else{
      sum+=A.at(i);
    }
  }
  ans+=sum/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import itertools

import numpy as np


# 入力読み込み
n, k = map(int, input().split())
a = list(map(int, input().split()))

min_cost = 15000000001
for i in itertools.product([True, False], repeat=n):
    key = np.array(i, dtype=bool)
    if np.count_nonzero(key) != k:
        continue
    
    # コスト計算
    cost = 0
    max_height = 0
    for is_look, ai in zip(key, a):
        if not is_look:
            max_height = max(max_height, ai)
        elif ai > max_height:
            max_height = ai
        else:
            max_height += 1
            cost += max_height - ai
    
    min_cost = min(min_cost, cost)

print(min_cost)


Measured memory_bytes: 26940
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
char ch[505][505];
int vis[505][505];
int love[8][8]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
int h[8][8]={{0,1},{1,0},{-1,0},{0,-1}};
int n,m;
int a,b,c,d;
int arr[123];
int main()
{
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&arr[i]);
	if(n<3)
	printf("0\n");
	else
	{
		for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(arr[i]!=arr[j]&&arr[i]!=arr[k]&&arr[k]!=arr[j]&&(arr[i]+arr[j]>arr[k]&&arr[i]+arr[k]>arr[j]&&arr[j]+arr[k]>arr[i]))
				sum++;
			}
		}
	}
	printf("%d\n",sum);
	}
	
} 
       

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H1,M1,H2,M2;
ll K;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H1>>M1>>H2>>M2>>K;
ll time1=60*H1+M1;
ll time2=60*H2+M2;
ll time3=time2-time1;
cout<<time3-K<<endl;
}
    


Measured memory_bytes: 3652
#include<stdio.h>
#define N 100001
int p[N];int r[N];int f(int x){if(p[x]==x){return x;}else return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);if(x==y)return 0;if(r[x]<r[y]){p[x]=y;r[y]+=r[x];}else {p[y]=x;r[x]+=r[y];}}int s(int x,int y){if(f(x)==f(y))return 1;else return 0;}int main(){long n,m,i,b[N],a[N][2];scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",&a[i][0],&a[i][1]);b[m]=(long long)n*(n-1)/2;for(i=0;i<N;i++){p[i]=i;r[i]=1;};for(i=m-1;i>=0;i--){if(f(a[i][0])==f(a[i][1]))b[i]=b[i+1];else{b[i]=b[i+1]-(long)r[f(a[i][0])]*r[f(a[i][1])];u(a[i][0],a[i][1]);}}for(i=1;i<=m;i++)printf("%ld\n",b[i]);return 0;}

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


const long long INF = 1LL << 60;
#define MOD 1000000007;

typedef long long ll;

#define writeln(n) cout<<n<<endl;

typedef pair<int, int> P;

ll dp[100];

int main() {


	int n;

	int dp[50] ={0};
	dp[0] =1;
	dp[1] =2;
	dp[2] =4;

	for(int i=3; i<31; i++){
		dp[i] = dp[i-1]+dp[i-2]+dp[i-3];

	}

	while(1){
		cin>>n;
		if(n ==0){
			break;
		}


		int ans = dp[n-1]/3650;

		if(dp[n-1]%3650 >0 )ans++;

		writeln(ans);


	}




}




Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<ll, ll>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<< "\n";
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n, a);
    if((n%500) <= a){
        Yes;
    } else {
        No;
    }
RET;}



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() {
    ll N, tmp;
    cin >> N;
    vector<ll> F(N);
    vector<vector<ll>> P(N, vector<ll>(11));
    rep(i,N) rep(j,10) {
        cin >> tmp;
        if (j == 0) F.at(i) = tmp;
        else {
            F.at(i) *= 2;
            F.at(i) += tmp;
        }
    }
    rep(i,N) rep(j,11) cin >> P.at(i).at(j);
    ll ans = -10e10;
    for (ll bit = 1; bit < (1<<10); ++bit) {
        ll profit = 0;
        for (int i = 0; i < N; ++i) {
            int cnt = __builtin_popcount(bit & F.at(i));
            profit += P.at(i).at(cnt);
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3584
// Shift-JIS（シフトジス）

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

int gcd(int a, int b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    int R;
    cin >> R;
    if (R < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (R < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  K = readint()[1]
  if K%2==0 || K%5 ==0
    println(-1)
    return
  end

  dp = Vector{int}(undef,10^7+1)
  dp[1] = 7%K
  mod = dp[1]

  for  i in 1:10^7
    if mod%K ==0
      println(i)
      return
    end
    dp[i+1] = dp[i]*10%K
    mod += dp[i+1]
    mod %= K
  end
  println(-1)

end

main()

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

int main() {
  int n, a1, a2, a3, a4;
  cin >> n;
  a1 = n/1000;
  a2 = n%1000/100;
  a3 = n%100/10;
  a4 = n%10;
  if ((a2 == a3)&&((a1 == a2)||(a3 == a4))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=200010;
ll lazy[N<<2],tr[N<<2];
ll s[N];
ll sum[N];
void pushup(int l,int mid,int r,int u){
    tr[u]=(tr[u<<1|1]+1ll*s[r-mid]*tr[u<<1]%mod)%mod;
}
void init(int l,int r,int u){
    if(l==r){
        tr[u]=1;
        return ;
    }
    int mid=l+r>>1;
    init(l,mid,u<<1);
    init(mid+1,r,u<<1|1);
    pushup(l,mid,r,u);
}
void pushdown(int l,int r,int u){
    int mid=l+r>>1;
    if(lazy[u]){
        tr[u<<1]=(1ll*sum[mid-l]*lazy[u])%mod;
        tr[u<<1|1]=(1ll*sum[r-mid-1]*lazy[u])%mod;
        lazy[u<<1]=lazy[u<<1|1]=lazy[u];
        lazy[u]=0;
    }
}
void update(int l,int r,int a,int b,int d,int u){
    if(l<=a&&b<=r){
        lazy[u]=d;
        tr[u]=(sum[b-a]*d)%mod;
//        cout<<a<<' '<<b<<' '<<tr[u]<<endl;
        return ;
    }
    pushdown(a,b,u);
    int mid=a+b>>1;
    if(l<=mid)update(l,r,a,mid,d,u<<1);
    if(r>mid) update(l,r,mid+1,b,d,u<<1|1);
    pushup(a,mid,b,u);
}
int main()
{
    s[0]=sum[0]=1;
    int n,q;
    cin>>n>>q;

    for(int i=1;i<=n;++i)s[i]=1ll*s[i-1]*10%mod;
    for(int i=1;i<=n;++i)sum[i]=(sum[i-1]+s[i])%mod;
    init(1,n,1);
    for(int i=1;i<=q;++i){
        int l,r,d;
        cin>>l>>r>>d;
//        cout<<l<<' '<<r<<endl;
        update(l,r,1,n,d,1);
//		cout<<query(1,4,1,n,1)<<endl; 
        cout<<tr[1]<<endl;
    }
}

Measured memory_bytes: 14864
#include <stdio.h>

int main(void)
{
	long int n;
	long sum;
	long int i;

	scanf("%ld", &n);

	sum = 0;

	for (i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		sum += i;
	}

	printf("%ld", sum);

	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
#define N 2001
using namespace std;

int n;
LL f[N];

inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<1)+(x<<3)+(a^48);a=getchar();}
	return x*w;
}

int main()
{
	n=qr();
	f[0]=1;
	for(register int i=3;i<=n;i++)
		for(register int j=3;j<=i;j++)
			f[i]=(f[i]+f[i-j])%mod;
	printf("%lld\n",f[n]);
	return 0;
} 

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

int main(){
	int x,y,z; cin>>x>>y>>z;
	vector<int> v(x);
	int i=0;
	while(i<x){
		for(int j=i; j<i+z; j++){
			v[j]=0;
		}
		i+=z;
		if(i+y+z>x) break;
		for(int k=i; k<i+y; k++){
			v[k]=1;
		}
		i+=y;
	}
	int ans=accumulate(v.begin(),v.end(),0);
	cout<<ans/y<<endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#define N 5

int main(void){
  int i,j,k;
  int input[N];
  int flag = 0;
  
  for(i=0; i<N; i++){
    scanf("%d",&input[i]);
  }
  scanf("%d",&k);
  
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if((input[j]-input[i]) > k){
        flag = 1;
      }
    }
  }
  
  if(flag == 0){
    printf("Yay!\n");
  }else{
    printf(":(\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
num_list = [x for x in range(1, n+1)]
num_list = list(itertools.permutations(num_list))
a = 0
b = 0
for i in range(len(num_list)):
    if p == num_list[i]:
        a = i + 1
    if q == num_list[i]:
        b = i + 1
ans = abs(a - b)

print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n,ans=0;
char arr[1000][1000];
bool kembar(int A,int B,int i,int j){
	return arr[A+i][B+j]==arr[A+j][B+i];
}
void hitung(pii start){
	int A=start.fi;
	int B=start.se;
	int beda=0;
	
	for(int i=0;i<n-1;i++)
	{
		for(int j=i;j<n-1;j++)
		{
			if(!kembar(A,B,i,j))
				beda++;
		}
	}
	while(A<n&&B<n)
	{
		for(int i=0;i<n;i++)
			if(!kembar(A,B,i,n-1))
				beda++;
		if(beda==0)
			ans++;
		for(int i=0;i<n;i++)
			if(!kembar(A,B,0,i))
				beda--;
		A++;B++;
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%s",&arr[i]);
	int batas=2*n-1;
	for(int i=0;i<batas;i++)
		for(int j=0;j<batas;j++)
			arr[i][j]=arr[i%n][j%n];
	for(int i=0;i<n;i++)
		hitung(mp(0,i));
	for(int i=1;i<n;i++)
		hitung(mp(i,0));
	cout<<ans<<endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    REP(i, n)
    {
        int h;
        cin >> h;
        a.push_back(h);
    }
    sort(a.begin(), a.end(), greater<int>());
    long long cnt = 0;
    REP(i, n)
    {
        if (i < k)
            continue;
        cnt += (long long)a[i];
    }
    cout << cnt << endl;
}

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

flg = False
for a in range(N//4 + 1):
  for b in range(N//4 + 1):
    if (N - 4*a - 7*b) == 0:
      print('Yes')
      flg = True
      break
  else:
    continue
  break
  
if flg == False:
  print('No')

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

int main() {
    int D, N, t[205], a[205], b[205], c[205], dp[205][205];  // dp[i][j] = i日目に服jを着た時の最大値
    cin >> D >> N;
    for(int i=0;i<D;i++){
        cin >> t[i];
    }
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0;i<D-1;i++){
        for(int j=0;j<N;j++){
            if(t[i] < a[j] || t[i] > b[j]) continue;
            for(int k=0;k<N;k++){
                if(t[i+1] < a[k] || t[i+1] > b[k])continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(c[k]-c[j]));
            }
        }
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        ans = max(ans, dp[D-1][i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int m;
	cin >> m;
	string S,Sfd,Sbw;
	map<string,int> mp;
	for(int loop=0;loop<m;loop++){
		cin >> S;
		for(int loop2=1;loop2<S.length();loop2++){
			Sfd=S.substr(0,loop2);
			Sbw=S.substr(loop2);
			mp[Sfd+Sbw]=1;	//Sfd+Sbw
			mp[Sbw+Sfd]=1;	//Sbw+Sfd
			reverse(Sbw.begin(),Sbw.end());
			mp[Sfd+Sbw]=1;	//Sfd+wbS
			mp[Sbw+Sfd]=1;	//wbS+Sfd
			reverse(Sfd.begin(),Sfd.end());
			mp[Sfd+Sbw]=1;	//dfS+wbS
			mp[Sbw+Sfd]=1;	//wbS+dfS
			reverse(Sbw.begin(),Sbw.end());
			mp[Sfd+Sbw]=1;	//dfS+Sbw
			mp[Sbw+Sfd]=1;	//Sbw+dfS
		}
		cout << mp.size() << endl;
		mp.clear();
	}
	return 0;
}


Measured memory_bytes: 3220
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#define _for(i,n) for(int i = 0; i < n; i++)

using namespace std;



int main() {
    int n;
    cin >> n;
    int x[n];int y[n];int h[n];
    _for (i,n) cin >> x[i] >> y[i] >> h[i];
    int minh = INT_MAX;
    _for (i,n) minh = min(minh, h[i]);
    int maxh = INT_MIN;
    _for (i,n) maxh = max(maxh, h[i]);
    int ans[3];
    for (int hh = maxh; hh <= minh+200; hh++) {
        _for(hx,101) {
            _for(hy,101) {
                ans[0] = hx; ans[1] = hy; ans[2] = hh;
                _for(i,n) {
                    if (max(hh-abs(hx-x[i])-abs(hy-y[i]),0)!=h[i]) {
                        ans[2] = -1;
                        break;
                    }
                }
                if (ans[2]!=-1) {
                    cout<<ans[0]<<' ' <<ans[1]<<' '<<ans[2]<< endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = input().split(' ')
count = 0

for i in range(0, n):
    minj = i

    for j in range(i, n):
        if int(A[j]) < int(A[minj]):
            minj = j

    if i != minj:
        (A[i], A[minj]) = (A[minj], A[i])
        count += 1

print(" ".join(A))
print(count)

Measured memory_bytes: 7664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int main()
{
	int N,A,B;
	while( scanf(" %d",&N) != EOF ){
		scanf(" %d %d",&A,&B);
		N = N - A;
		N = N % B;
		printf("%d\n",N);
	}
}

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

int N,M;

main()
{
        cin>>N>>M;
        int cnt=0;
        for(int i=0;i<M;i++)
        {
                int a; cin>>a;
                cnt+=a;
        }
        if(cnt>N)cout<<-1<<endl;
        else cout<<N-cnt<<endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def readln(ch):
    _res = list(map(int,str(input()).split(ch)))
    return _res

n = int(input())
a = readln(' ')
ans = 0
for x in a:
    if x % 2 == 1:
        ans = ans + 1
if ans % 2 == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 14112
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a[3]; rep(i, 3) cin >> a[i];
    sort(a, a+3);
    int d1 = a[2] - a[0];
    int d2 = a[2] - a[1];
    ((d1+d2)%2==0) ? cout << (d1+d2)/2 << endl : cout << 1+(d1+d2+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,q,a,b,c;

int sz;
int seg[400010]={};
int get_size(int n);
int unit();
int func(int a,int b);
int build(int n);
int update(int k,int x); //0-indexed
int _get(int a,int b,int k,int l,int r);
int get(int a,int b); //[a,b)

int main(){
	cin >> n >> q; build(n);
	REP(i,0,q){
		cin >> a >> b >> c;
		if(a) cout << get(b,c+1) << endl;
		else update(b,c);
	}
	
	return 0;
}

int get_size(int n){
	int res=0;
	while(n) n=n>>1,res++;

	return (1<<res);
}

int unit(){
	return 0;
}

int func(int a,int b){
	return a+b;
}

int build(int n){
	sz=get_size(n);
	REP(i,0,2*sz) seg[i]=unit();
	return 0;
}

int update(int k,int x){
	k+=sz-1;
	seg[k]+=x;
	while(k){
		k=(k-1)>>1;
		seg[k]=func(seg[k*2+1],seg[k*2+2]);
	}

	return 0;
}

int _get(int a,int b,int k,int l,int r){
	if(b<=l||r<=a) return unit();
	if(a<=l&&r<=b) return seg[k];

	return func(_get(a,b,2*k+1,l,(l+r)>>1), _get(a,b,2*k+2,(l+r)>>1,r));
}

int get(int a,int b){
	return _get(a,b,0,0,sz);
}

Measured memory_bytes: 4108
// #include<iostream>
// using namespace std;
// const int inf(int(1e9));
//
// int main(){
//   int n,T;cin>>n>>T;
//   int ans{inf};
//   for(int i=0;i<=n-1;i++){
//     int c,t;cin>>c>>t;
//     if(t<T&&c<ans){
//       ans=c;
//     }
//   }
//   if(ans==inf){
//     cout<<"TLE"<<endl;
//   }else{
//     cout<<ans<<endl;
//   }
// }
//

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N,T;cin>>N>>T;
  vector<int>c(N),t(N);
  for(int i=0;i<N;i++){
    cin>>c[i]>>t[i];
  }
  vector<int> filtered_c;
  for(int i=0;i<N;i++){
    if(t[i]<=T)filtered_c.push_back(c[i]);
  }
  if(filtered_c.size()==0)cout<<"TLE"<<endl;
  else cout<<*min_element(filtered_c.begin(),filtered_c.end())<<endl;
}


Measured memory_bytes: 256
//defines e includes
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep1(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, a, b) for(int i=(int)a;i<(int)b;i++)
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define p_b pop_back
#define p_f pop_front
#define mp make_pair
#define MAX 100010
#define oo INT_MAX
using namespace std;
//tipagem de pares
typedef pair<int, int> ii;
typedef pair<char, char> cc;
typedef pair<int, char> ic;
typedef pair<char, int> ci;
//tipagem de vetores
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<bool> vb;
//tipagem de outras estruturas
typedef queue<int> qi;
typedef deque<int> dqi;
//tipagem de tipos primitivos
typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
	
	fastio;
	ll h; cin >> h;
	int log = log2(h);
	ll ans =pow(2, log+1)-1; 
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int N, K;
vector<int> MyMonster, Opponent;


bool solve() {
	int myIndex, cnt;

	sort(MyMonster.begin(), MyMonster.end(), greater<int>());
	sort(Opponent.begin(), Opponent.end(), greater<int>());

	myIndex = 0;
	cnt = 0;
	K = 40001;
	for (int i = 0; i < N; ++i) {
		while (myIndex < N - 1) {
			if (Opponent[i] >= MyMonster[myIndex]) {
				++myIndex;
				break;
			}
			++cnt;
			if (cnt >= ((myIndex + 1) / 2 + 1)) {
				K = myIndex + 1;
				return true;
			}
			++myIndex;
		}
		if (myIndex == N - 1) {
			return false;
		}
	}
}

int main() {
	int num;

	while (cin >> N, N) {
		MyMonster.clear();
		Opponent.clear();
		for (int i = 0; i < N; ++i) {
			cin >> num;
			MyMonster.push_back(num);
		}
		for (int i = 0; i < N; ++i) {
			cin >> num;
			Opponent.push_back(num);
		}
		//show();
		if (solve()) {
			cout << K << endl;
			continue;
		}
		cout << "NA" << endl;
	}

	return 0;
}



Measured memory_bytes: 3528
import java.util.*;

public class Main {
    static int MOD = 998244353;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] left = new int[k];
        int[] right = new int[k];
        for (int i = 0; i < k; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }
        
        // ans: マス1からマスNへ行くパターン数
        // (ただし、各マスからは各区間[i]の値進める)
        
        // ex. {[1, 1], [3, 4], [6, 10]}
        // もらうDPで考えると、
        // dp[i]へ dp[i-1]...dp[i-1]とdp[i-4]...dp[i-3]とdp[i-10]...dp[i-6]から遷移できる
        
        // how:
        // dp[L] + dp[L+1] ... + dp[R]をまとめて遷移させたいなら
        // dpの累積和(sdp)を取って、区間和(sdp[R] - sdp[L-1])を求めて遷移させれば良い
        // -> dpの累積和を都度取りながらdpする。
        
        // dp[i]: iマスに到達するパターン数
        int[] dp = new int[n+1];
        dp[1] = 1;
        // sdp[i+1]: dp[0]～dp[i]までの累積和
        // ex.[L, R] = sdp[R+1] - sdp[L]
        int[] sdp = new int[n+2];
        sdp[2] = sdp[1] + dp[1];
        
        for (int i = 2; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                int l = left[j];
                int r = right[j];
                int L = i-r;
                int R = i-l;
                if (L-1 < 0) L = 1;
                if (R < 0) R = 0;
                
                int sum_LR = sdp[R+1] - sdp[L];
                if (sum_LR < 0) sum_LR += MOD;
                dp[i] += sum_LR;
                dp[i] %= MOD;
            }
            
            sdp[i+1] = sdp[i] + dp[i];
            sdp[i+1] %= MOD;
            // System.out.println(Arrays.toString(dp));
        }
        // System.out.println(" " + Arrays.toString(dp));
        // System.out.println(Arrays.toString(sdp));
        
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 38504
use std::ops::{Index, IndexMut};
use std::cmp::{Ordering};
use std::collections::BinaryHeap;
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!();
}

fn main() {
    let s = getline();
    let iv: Vec<_> = split!(s);
    let h: usize = parse!(iv[0]);
    let w: usize = parse!(iv[1]);
    let s = getline();
    let iv: Vec<_> = split!(s);
    let n: usize = parse!(iv[0]);
    let s = getline();
    let iv:Vec<_> = split!(s);
    let a: Vec<i32> = iv.into_iter().map(|x| x.parse().unwrap()).collect(); 
    
    let mut x = 0;
    let mut y = 0;
    let mut ans = vec![vec![0;w];h];
    for i in 0..n {
        for _ in 0..a[i] {
            ans[x][y] = i+1;
            if x%2 == 0 {
                if y == w-1 {
                    x += 1;
                } else {
                    y += 1;
                }
            } else {
                if y == 0 {
                    x += 1;
                } else {
                    y -= 1;
                }
            }
        }
    }
    for e in &ans {
        printvec(e);
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin>>s;
  if (s == "ABC") {
    cout<<"ARC\n";
  } else {
    cout<<"ABC\n";
  }
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

bool d[10];

bool check(int n){
	while(n>0){
		if(!d[n%10]){
			return false;
		}
		n/=10;
	}
	return true;
}

int main(){

	int N, K;
	int tmp;
	int n;

	cin>>N>>K;
	n=N;

	for(int i=0; i<10; i++){
		d[i]=true;
	}

	for(int i=0; i<K; i++){
		cin>>tmp;
		d[tmp]=false;
	}


	while(true){
		if(check(n)){
			break;
		}
		n+=1;
	}

	cout<<n<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <queue>
#define N 101
#define INFTY (1<<21)


int n;
int M[N][N];
int d[N];

void bfs(int u) {
    std::queue<int> Q;
    Q.push(u);
    for (int i = 0; i < n; i++) d[i] = INFTY;
    d[u] = 0;
    while ( ! Q.empty() ) {
        int j = Q.front();
        Q.pop();
        for (int v = 0; v < n; v++) {
            if (M[j][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[j] + 1;
            Q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i+1, d[i] == INFTY ? -1 : d[i]);
    }
}

int main() {
    int u, k, v;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) M[i][j] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        if (k == 0) continue;
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    bfs(0);
    
    return 0;
}



Measured memory_bytes: 3240
n = int(input())
a = list(map(int, input().split()))
import numpy as np

# print(n)
# print(a)
# if n==1:
#     m = 1
#     b = a[0]

h = int(np.floor(n/2))
# print("h={}".format(h))
boxes = np.zeros(n)
boxes[h:] = a[h:]
if n%2==0:       
    for i in range(h):
        d = n-h-i-1
        s = sum(boxes[2*(d+1)-1::d+1])%2
        if s==a[d]:
            boxes[d] = 0
        else:
            boxes[d] = 1
    # print("ans_even={}".format(boxes))
    ans = list(map(int, boxes))
    print(sum(ans))
    for i in range(len(ans)):
        if ans[i]==1:
            print("{} ".format(i+1), end="")
else:
    for i in range(h):
        d = n-h-i-2
        s = sum(boxes[2*(d+1)-1::d+1])%2
        if s==a[d]:
            boxes[d] = 0
        else:
            boxes[d] = 1
    # print("ans_odd={}".format(boxes))
    ans = list(map(int, boxes))
    print(sum(ans))
    for i in range(len(ans)):
        if ans[i]==1:
            print("{} ".format(i+1), end="")

Measured memory_bytes: 18084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
const long mod = 1e9+7;
int main(){
	int N;cin>>N;
	string s,t;cin>>s>>t;
	long res;
	if(s[0]==t[0]) res=3;
	else res=6;
	rep(i,1,N){
		if(s[i-1]==s[i]) continue;
		if(s[i]==t[i]&&s[i-1]==t[i-1]) (res*=2)%=mod;
		if(s[i]!=t[i]&&s[i-1]!=t[i-1]) (res*=3)%=mod;
        if(s[i]!=t[i]&&s[i-1]==t[i-1]) (res*=2)%=mod;
	}cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 101;
int n,m[MAX][MAX],d[MAX];
queue<int> s;

void bfs(int num)
{
	for(int i=1;i<=n;i++) d[i]=INT_MAX;
	s.push(num);
	d[num]=0;
	while(!s.empty())
	{
		int u=s.front();
		s.pop();
		for(int i=1;i<=n;i++)
		{
			if(m[u][i]==0) continue;
			if(d[i]!=INT_MAX) continue;
			s.push(i);
			d[i]=d[u]+1;
		}
	}
	for(int i=1;i<=n;i++) cout<<i<<" "<<( d[i]==INT_MAX ? (-1): d[i] )<<endl;
}
int main()
{
	int u,k,t;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>u>>k;
		for(int j=0;j<k;j++)
		{
			cin>>t;
			m[u][t]=1;
		}
	}
	bfs(1);
	return 0;
}


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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; ++i) std::cin >> v[i];
  std::sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < n; ++i) ans = (ans + v[i]) / 2;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NIL NULL

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

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){
    if(u==NIL || k==u->key) return u;
    return  ((k< u->key) ? treeSearch(u->left,k) : treeSearch(u->right,k));
}

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

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  y = (z->left==NIL || z->right == NIL) ? z : treeSuccessor(z);
  x = (y->left!=NIL) ? y->left : 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;
}

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;
    x = (z->key < x->key) ?  x->left : x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    (z->key < y->key) ? (y->left = z) : (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 ( com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }else if (com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 25208
n,m,l = map(int,input().split())
A = []
for i in range(n):
    a = [int(j) for j in input().split()]
    A.append(a)
B = []
for j in range(m):
    b = [int(k) for k in input().split()]
    B.append(b)
    
for i in range(n):
    c = []
    for k in range(l):
        x = 0
        for j in range(m):
            x += A[i][j]*B[j][k]
        c.append(str(x))
    print(" ".join(c))

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

using namespace std;

int main()
{
    char c;
    while (1)
    {

        scanf("%c",&c);
        if (c == '\n')
            break;
        if (c >= 'a' && c <= 'z'){
            c -= 32;
  
        }
        else if (c >= 'A' && c <= 'Z'){
            c += 32;   
        }
        cout << c;
        
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3160
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


ll a,b,c;
string s;
int main() {
    cin>>a;
    cout << "Christmas";
    REP(i,0,25-a){
        cout << " Eve";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 768
package main

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

const INFINITY = math.MaxInt64/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	k := stdin.ReadInt()
	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += Gcd(a, Gcd(b, c))
			}
		}
	}
	stdout.Println(sum)
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}


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

int main()
{
    int N;
    std::cin >> N;
    int level;
    std::cin >> level;
    long long sum = 0;
    for (int i = 0; i < N - 1; i++)
    {
        int A;
        std::cin >> A;
        if (level > A)
        {
            sum += level - A;
        }
        else
        {
            level = A;
        }
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 3632
S=input()
p=2019
h=0
d=1
t=0
c=[0]*p
c[0]=1
for s in reversed(S):
  m=int(s)*d%p
  h=(h+m)%p
  t+=c[h]
  c[h]+=1
  d=d*10%p
print(t)

Measured memory_bytes: 9212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
S = input()
N = len(S)
child = [0]*N
 
cnt_R = 0
for i in range(N):
	if S[i] == "R":
		cnt_R += 1
	else:
		child[i-1] += cnt_R
		cnt_R = 0
 
cnt_L = 0
for i in range(N-1, -1, -1):
	if S[i] == "L":
		cnt_L += 1
	else:
		child[i+1] += cnt_L
		cnt_L = 0
 
#print(child)
i = 0
while i < N:
	if child[i] == 0:
		i += 1
	else:
		tmp = child[i]+child[i+1]
		if tmp%2 == 0:
			child[i] = tmp//2
			child[i+1] = tmp//2
		else:
			flg = 1
			c_1 = tmp//2 + (child[i] > child[i+1])
			c_2 = tmp - c_1
			if max(child[i], child[i+1])%2:
				child[i] = c_1
				child[i+1] =c_2
			else:
				child[i] = c_2
				child[i+1] = c_1
		i += 2

print(*child)

Measured memory_bytes: 8676
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int arr[upperlimit];
int main() {
	int n,cost=INF,gg=0;
	sd(n);
	for(int i = 1; i <= n; i++) sd(arr[i]);
	for(int i = -100; i <= 100; i++){
		gg=0;
		for(int j = 1; j <= n; j++) gg+=(i-arr[j])*(i-arr[j]);
		cost=min(cost,gg);
	}
	pd(cost);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int a,b,cnt=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        stringstream ss;
        string s,c;
        ss<<i;
        ss>>s;
        c=s;
        reverse(s.begin(),s.end());
        if(s==c)
        {
            cnt++;
        }
    }
    cout<<cnt<<NL;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <ctime>
#include <algorithm>
#define rg register
#define llint long long
using namespace std;
const int N=1008611;
const llint mn=1e9;

struct ios
{
	template <typename _tp>
	inline ios operator >> (_tp &x)
	{
		x = 0;int f = 1;char c = getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c<='9'&&c>='0';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x)
	{
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x) ++dgt,s[dgt] = x%10+'0',x/=10;
		while(dgt) putchar(s[dgt]),--dgt;
		return *this;
	}
	inline ios operator << (char x)
	{
		putchar(x);
		return *this;
	}
}io;

llint n,x,y,X,Y;

inline llint rrand()
{
	return (llint)rand()*rand()%mn+1;
}

int main()
{
	io >> n;
	x = Y = ceil(sqrt(n));
	llint rsl = x*Y-n;
	if(rsl==0) io << 0 << ' ' << 0 << ' ' << x << ' ' << 0 << ' ' << 0 << ' ' << Y << '\n';
	for(rg int i=sqrt(rsl);i>=1;--i)
		if(rsl%i==0)
		{
			io << 0 << ' ' << 0 << ' ' << x << ' ' << rsl/i << ' ' << i << ' ' << Y << '\n';
			break;
		}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int m,n;
  cin>>m>>n;
  cout<<(m+n)*(m+n-1)/2-m*n<<endl;    
return 0;
}


Measured memory_bytes: 256