akhauriyash/Code-Regression huggingface dataset:
/*
#    # #   # #    #      ##   #    #    #  ####  # 
#    #  # #  #    #     #  #  #   #     # #    # # 
######   #   ######    #    # ####      # #    # # 
#    #   #   #    #    ###### #  #      # #    # # 
#    #   #   #    #    #    # #   #     # #    # # 
#    #   #   #    #    #    # #    #    #  ####  #
*/
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

int n, K;
int tot;
char s[1000005];
int len[2005], ps[2005];
bool can[2005][10005];
bitset <1000005> seg[70], st;

char fnd() {
	int i = 1;
	while (i < 32) {
		if ((seg[i + i] & st).any()) i = i + i;
		else i = i + i + 1;
	}
	return 'a' + i - 32;
}

int main() {
	n = read(), K = read();
	rep(i, n) {
		scanf("%s", s + tot);
		len[i] = strlen(s + tot);
		tot += len[i], ps[i + 1] = tot;
	}
	can[n][0] = 1;
	for (int i = n - 1; ~i; -- i) rep(j, K + 1) if (can[i + 1][j]) {
		if (j + len[i] <= K) can[i][j + len[i]] = 1;
		can[i][j] = 1;
	}
	rep(i, 26) rep(j, tot) if (s[j] == i + 'a') seg[i + 32].set(j);
	for (int i = 31; i; -- i) seg[i] = seg[i + i] | seg[i + i + 1];
	st.set(0);
	rep(i, K) {
		rep(j, n) if (st.test(ps[j])) st.set(ps[j + 1]);
		rep(j, n) if (K - i - len[j] < 0 || !can[j + 1][K - i - len[j]]) st.reset(ps[j]);
//		rep(j, tot) if (st.test(j)) printf("%d ", j); puts("");
		char c = fnd(); putchar(c);
		st &= seg[c - 'a' + 32]; st <<= 1;
	}
	puts("");
	return 0;
}

Measured memory_bytes: 29568
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
int main() {
	long long a, b;
	cin >> a >> b;
	long long c = b;
	int cnt = 1;
	while (a >= c){
		c *= b;
		cnt++;
	}

	cout << cnt << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int main()
{
	int n;
	cin>>n;
	char s[20000];
	cin>>s;
	for(int i=0;i<strlen(s);i++)
	{
		int a=s[i];
		a+=n;
		if(a>90)
			a-=26;
		s[i]=a;
	}
	cout<<s;

	return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
  	FASTIO
	long long n, x, ans = 0;
	cin >> n;
	map<long long,long long> freq;
	for(int i=0; i<n; i++)
	{
		cin >> x;
		ans += freq[i-x];
		freq[i+x]++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

/////////////////////////


//Answer


int main() {

int N;
string S;
cin>>N>>S;
for(long i=0;i<S.size();i++){
    int code=S.at(i);
    printf("%c",(((code+N)-65)%26)+65);
}
cout<<endl;
}

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

int main() {
  int a, b, q;
  cin >> a >> b >> q;
  vector<vector<ll>> s = {vector<ll>(a), vector<ll>(b)};
  for (auto& e : s[0]) cin >> e;
  for (auto& e : s[1]) cin >> e;
  for (; q > 0; q--) {
    ll x;
    cin >> x;
    vector<vector<ll>::iterator> it = {lower_bound(begin(s[0]), end(s[0]), x), lower_bound(begin(s[1]), end(s[1]), x)};
    vector<vector<ll>> v(2);
    for (int i = 0; i < 2; i++) {
      if (it[i] != begin(s[i])) {
        v[i].push_back(*(it[i] - 1));
      }
      if (it[i] != end(s[i])) {
        v[i].push_back(*it[i]);
      }
    }
    ll r = 1e18;
    for (auto e0 : v[0]) {
      for (auto e1 : v[1]) {
        r = min(r, min(abs(e0 - x), abs(e1 - x)) + abs(e0 - e1));
      }
    }
    cout << r << endl;
  }
}


Measured memory_bytes: 3328
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc108_a.cpp
 * time   : Thu Apr 30 22:25:55 2020
 * quest  : A - Pair
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  cout << ((k % 2) ? (k / 2 * (k / 2 + 1)) : (k / 2 * k / 2)) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=100005;
int n;
struct BIT
{
	int bit[MAX_N*2];
	void init()
	{
		memset(bit,0,sizeof(bit));
	}
	int sum(int i)
	{
		int s=0;
		while(i>0)
		{
			s+=bit[i];
			i-=lowbit(i);
		}
		return s;
	}
	void add(int i,int x)
	{
		while(i<=2*n)
		{
			bit[i]+=x;
			i+=lowbit(i);
		}
	}
}rec;
int a[MAX_N],cnt[MAX_N];
bool check(int v)
{
	rec.init();
	For(i,1,n)cnt[i]=cnt[i-1]+((a[i]>=v)?1:-1);
	LL tot=0;
	For(i,0,n)
	{
		tot+=rec.sum(cnt[i]+n);
		rec.add(cnt[i]+n,1);
	}
	return tot>=(LL)n*(n+1)/4;
}
int main()
{
	cin>>n;
	int lb=0,ub=0;
	For(i,1,n)
	{
		cin>>a[i];
		ub=max(ub,a[i]+1);
	}
	while(lb<ub)
	{
		int mid=(lb+ub)/2;
		if(check(mid))lb=mid+1;
		else ub=mid;
	}
	cout<<lb-1<<endl;
	return 0;
}



Measured memory_bytes: 1792
#!/usr/bin/env python3

import sys
import pprint
from math import gcd


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	k = int(sys.stdin.readline())
	s = 0
	for a in range(1, k+1):
		for b in range(a, k+1):
			for c in range(b, k+1):
				if len(set([a, b, c])) == 3:
					s += gcd(gcd(a, b), c) * 6
				elif len(set([a, b, c])) == 2:
					s += gcd(gcd(a, b), c) * 3
				elif len(set([a, b, c])) == 1:
					s += gcd(gcd(a, b), c)
	print(s)
	


main()

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

int red[100005],col[100005],blu[100005];
priority_queue<int,vector<int>,greater<int>> p,q;

int main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=1;i<=a;i++)
        cin>>red[i];
    for(int i=1;i<=b;i++)
        cin>>blu[i];
    for(int i=1;i<=c;i++)
        cin>>col[i];

    
    for(int i=1;i<=a;i++)
    {
        if(p.size()<x)
        {
            p.push(red[i]);
        }
        else
        {
            p.push(red[i]);
            p.pop();
        }
    }  
    for(int i=1;i<=b;i++)
    {
        if(q.size()<y)
        {
            q.push(blu[i]);
        }else
        {
            q.push(blu[i]);
            q.pop();
        }
    }  

    sort(col+1,col+c+1);
    for(int i=1;i<=c;i++)
    {
        int pmi=p.top();
        int qmi=q.top();
        if(col[i]<=min(pmi,qmi))
            continue;
        if(pmi<=qmi)
        {
            p.push(col[i]);
            p.pop();
        }else
        {
            q.push(col[i]);
            q.pop();
        }
    }

    long long ans=0;
    while(p.size())
    {
        ans+=1ll*p.top();
        p.pop();
    }
    while(q.size())
    {
        ans+=1ll*q.top();
        q.pop();
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 2552
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    cout << (a + b + c > 21? "bust" : "win") << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    sum = 0
    for i in range(1, N + 1):
        if i <= K:
            sum += X
        else:
            sum += Y
    print(sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
using System;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (N % 2 > 0)
            {
                Console.WriteLine("No");
                return;
            }

            var l = S.Substring(0, N / 2);
            var r = S.Substring(N / 2, N / 2);
            Console.WriteLine(l == r ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int a[MAX];

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    int n,k;
    cin>>n>>k;
    ll ans = 0;
    for(int i = k;i>0;--i){
        ll tot = power(k/i,n);
        for(int j = i+i;j<=k;j+=i){
            tot=(tot-a[j]+MOD)%MOD;
        }
        a[i] = tot;
        ans = (ans + tot*i)%MOD;
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

typedef long long ll;


const int N=1000000+5;

int n;
string s;
int q;

ll D;
ll DM;
ll cnt_M;

inline void add(int p)
{
    if(s[p]=='D') D++;
    if(s[p]=='M')
    {
        DM+=D;
        cnt_M++;
    }
}

inline void del(int p)
{
    if(s[p]=='D')
    {
        D--;
        DM-=cnt_M;
    }
    if(s[p]=='M')
    {
        cnt_M--;
    }
}

inline ll slove(ll l)
{
    ll ans=0LL;
    D=0LL;
    DM=0LL;
    cnt_M=0LL;

    for(int i=1;i<=n;i++)
    {
        add(i);
        if(i>l)
        {
            del(i-l);
        }
        if(s[i]=='C')
        {
            ans+=DM;
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>s;
    s="."+s;
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        int l;
        cin>>l;
        cout<<slove(l)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 2332
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ABC118C
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var A = ss.Next(long.Parse, N);

            var ret = A[0];

            foreach (var a in A)
            {
                ret = MathX.Gcd(ret, a);
            }

            sw.WriteLine(ret);
            //---------------------------------
        }
    }

    public static partial class MathX
    {
        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long Lcm(long a, long b)
        {
            return a * (b / Gcd(a, b));
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = { ' ' };
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public bool EndOfStream { get { return streamReader.EndOfStream && index >= line.Length; } }

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (EndOfStream) throw new EndOfStreamException();
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 18912
s = int(input())
i = 2
al = set()
al.add(s)

while(True):
    if s%2 == 0:
        s /= 2
    else:
        s = s*3 + 1
    
    if s in al: 
        break
    else:
        i += 1
        al.add(s)


print(i)


Measured memory_bytes: 38384
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int N,i,ans=0;cin >> N;
bool a=true;
vector<int> d(N);
for(i=0;i<N;i++){cin >> d[i];}
sort(d.begin(),d.end());
if(d.at(N/2-1)!=d.at(N/2))ans=d.at(N/2)-d.at(N/2-1);
cout << ans;
}

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

int main(void){
	int w, n;
	int val[31];
	cin >> w >> n;
	for(int i=0; i<=w; i++) val[i]=i;
	for(int i=0; i<n; i++){
		int a, b;
		char c;
		cin >> a >> c >> b;
		swap(val[a],val[b]);
	}
	for(int i=1; i<=w; i++)
		cout << val[i] << endl;
	return 0;

}

Measured memory_bytes: 0
n,m = map(int,input().split())
 
min,max  = map(int,input().split())
for i in range(m-1):
    l,r = map(int,input().split())

    if l > max:
        print(0)
        exit(0)

    if r < min:
        print(0)
        exit(0)
 
    if l > min:
        min = l
    
    if r < max:
        max = r
  
 
print(max-min+1)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC174
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var p = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var ND = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var N = ND[0]; var D = ND[1];
            var ans = 0;
            for (int i = 0; i < N; i++)
            {
                var XY = Console.ReadLine().Split().Select(double.Parse).ToArray();
                var dis = Math.Sqrt(Math.Pow(XY[0], 2) + Math.Pow(XY[1], 2));
                if (dis <= D) ans++;
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 41404
#include<stdio.h>

long n,m;
int main() {
	scanf("%ld %ld", &n, &m);
	if (n == 1 ){
		if (m == 1) {
			printf("1");
		}
		else {
			printf("%ld", m - 2);
		}
	}
	else if (m == 1) {
		if (n == 1) {
			printf("1");
		}
		else {
			printf("%ld", n - 2);
		}
	}
	else {
		printf("%ld", (n - 2)*(m - 2));
	}
}

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

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

int w, h;
//vector< vector<int> > field( h, vector<int>(w) );
int field[90][90];

int saiki( int x, int y, int d ){
    int res = d;
    for( int i = 0; i < 4; i++ ){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if( 1 <= nx && nx <= w && 1 <= ny && ny <= h && field[nx][ny] ){
            field[nx][ny] = 0;
            res = max( res, saiki( nx, ny, d + 1 ) );
            field[nx][ny] = 1;
        }
    }
    return res;
}
int main(){
    while( cin >> w >> h && w ){
        for( int i = 1; i <= h; i++ ){
            for( int j = 1; j <= w; j++ ){
                cin >> field[i][j];
            }
        }
        int result = 0;
        for( int i = 1; i <= h; i++ ){
            for( int j = 1; j <= w; j++ ){
                if( field[i][j] ){
                    field[i][j] = 0;
                    result = max( result, saiki( i, j, 1 ) );
                    field[i][j] = 1;
                }
            }
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 3084
#include <iostream>
#include <math.h>
using namespace std;

bool IsEqual(double a, double b)
{
	if (fabs(a - b) < 0.0000001) return true;
	return false;
}

int main()
{
	int n;
	double x[4];
	double y[4];

	cin >> n;
	while (n--)
	{
		for (int i = 0; i < 4; i++)
		{
			cin >> x[i] >> y[i];
		}

		double dx1 = x[1] - x[0];
		double dy1 = y[1] - y[0];
		double dx2 = x[3] - x[2];
		double dy2 = y[3] - y[2];

		if (IsEqual(dx1, 0) && IsEqual(dx2, 0)) cout << "YES" << endl;
		else if (IsEqual(dx1, 0) || IsEqual(dx2, 0)) cout << "NO" << endl;
		else if (IsEqual(dy1 / dx1, dy2 / dx2)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

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

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var n = Console.ReadLine().ToLong();
            var his = Console.ReadLine().ToLongArray();

            for (var i = n - 1; i > 0; i--)
            {
                if (his[i] < his[i - 1])
                {
                    his[i - 1]--;
                    if (his[i - 1] > his[i])
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }

            Console.WriteLine("Yes");
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        private static long ToLong(this double ddd) => (long) ddd;
        private static long ToLong(this string str) => long.Parse(str);
        private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        private static long Sign(this long iii) => Math.Sign(iii);
        private static bool IsEven(this long iii) => iii % 2 == 0;
        private static readonly int[] Dx = {0, -1, 0, 1};
        private static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string alphabet = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        public static string JoinToStr(this IEnumerable<int> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}

Measured memory_bytes: 31196
from collections import defaultdict

def main():
	N,M = map(int,input().split())
	submit = defaultdict(lambda : [0,0])
	for _ in range(M):
		p,s = input().split()
		p = int(p)
		if(s == "AC"):
			submit[p][0] = 1
		else:
			if(submit[p][0] == 0):
				submit[p][1] +=1
	num_AC = 0
	num_WA = 0
	for _,value in submit.items():
		if(value[0] == 1):
			num_AC += 1
			num_WA += value[1]
	print(num_AC,num_WA)

if __name__ == "__main__":
	main()

Measured memory_bytes: 23500
from math import floor

def prime(n):
    sup = floor(pow(n,1/2))
    for d in range(2,sup+1):
        if n % d == 0:
            return False
    return True

ans_list = []

def solve():
    n = int(input())
    if n == 0:
        return "end"
    cnt = 0
    for k in range(n+1,2*n+1):
        if prime(k):
            cnt += 1
    return cnt

while True:
    ans = solve()
    if ans == "end":
        break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e16;
int main()
{
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<vector<P>> e_yen(n+1);
    vector<vector<P>> e_snu(n+1);
    for(int i = 0; i < m; i++)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        e_yen[u].push_back(P(a, v));
        e_yen[v].push_back(P(a, u));
        e_snu[u].push_back(P(b, v));
        e_snu[v].push_back(P(b, u));
    }

    vector<ll> yen(n+1);
    vector<ll> snu(n+1);
    for(int i = 0; i <= n; i++)
    {
        yen[i] = INF;
        snu[i] = INF;
    }
    yen[s] = 0;
    snu[t] = 0;

    priority_queue<P, vector<P>, greater<P>> yenq;
    yenq.push(P(0, s));
    while(!yenq.empty())
    {
        P p = yenq.top();
        yenq.pop();
        if(yen[p.second] < p.first) continue;
        for(auto nx : e_yen[p.second])
        {
            if(yen[nx.second] > yen[p.second] + nx.first)
            {
                yen[nx.second] = yen[p.second] + nx.first;
                yenq.push(P(yen[nx.second], nx.second));
            }
        }
    }
    priority_queue<P, vector<P>, greater<P>> snuq;
    snuq.push(P(0, t));
    while(!snuq.empty())
    {
        P p = snuq.top();
        snuq.pop();
        if(snu[p.second] < p.first) continue;
        for(auto nx : e_snu[p.second])
        {
            if(snu[nx.second] > snu[p.second] + nx.first)
            {
                snu[nx.second] = snu[p.second] + nx.first;
                snuq.push(P(snu[nx.second], nx.second));
            }
        }
    }

    vector<ll> ac(n+1);
    ac[n] = INF;
    for(int i = n-1; i >= 0; i--)
    {
        ac[i] = min(ac[i+1], yen[i+1]+snu[i+1]);
    }

    for(int i = 0; i < n; i++)
    {
      ll ans = 1e15 - ac[i];
      cout << ans << endl;
    }
}


Measured memory_bytes: 20216
/*
文字列の配列の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int free=0;
        int[] cnt=new int[8];
        for (int i = 0; i < n; i++) {
            int a=sc.nextInt();
            if(a<400)cnt[0]++;
            else if(a<800)cnt[1]++;
            else if(a<1200)cnt[2]++;
            else if(a<1600)cnt[3]++;
            else if(a<2000)cnt[4]++;
            else if(a<2400)cnt[5]++;
            else if(a<2800)cnt[6]++;
            else if(a<3200)cnt[7]++;
            else free++;
        }
        int minimum=0,maximum=0;
        for (int i = 0; i < 8; i++) {
            if(cnt[i]>0)minimum++;
        }
        if(minimum==0){
            minimum=1;
            maximum=free;
        }
        else maximum=minimum+free;
        out.println(minimum+" "+maximum);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using Edge = struct{
  int to;
  int dis;
};
vector<Edge> edge[100000];
int x[100000];
bool used[100000];

void dfs(int n, int p, int d) {
  if (used[n])
    return ;
  x[n] = d;
  used[n] = true;
  for (auto &e: edge[n]) {
    if (e.to == p)
      continue;
    dfs(e.to, n, d+e.dis);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  int L[M], R[M], D[M], l, r, d;
  for (int i=0; i<M; i++) {
    cin >> l >> r >> d;
    l--; r--;
    L[i] = l;
    R[i] = r;
    D[i] = d;
    edge[l].push_back({r, d});
    edge[r].push_back({l, -d});
  }
  for (int i=0; i<N; i++)
    dfs(i, -1, 0);
  for (int i=0; i<M; i++) {
    int xl = x[L[i]], xr = x[R[i]];
    if (xr-xl != D[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 14464
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
d = [0]*25
n = int(input())
if n < 10:
    print(0)
    exit()
for i in range(2,n+1):
    x = i
    for j in range(25):
        while x%p[j]==0:
            d[j] += 1
            x //= p[j]
d.sort(reverse=True)
four = 0
for i in range(25):
    if d[i] >= 4:
        four += 1
two = 0
for i in range(25):
    if d[i] >= 2:
        two += 1
tw_four = 0
for i in range(25):
    if d[i] >= 24:
        tw_four += 1
one_four = 0
for i in range(25):
    if d[i] >= 14:
        one_four += 1
seven_four = 0
for i in range(25):
    if d[i] >= 74:
        seven_four += 1
if (four < 2 or two < 3):
    print(0)
    exit()
ans = (four*(four-1)//2)*(two-2)
if one_four > 0:
    ans += one_four*(four-1)
if tw_four > 0:
    ans += tw_four*(two-1)
if seven_four > 0:
    ans += seven_four
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.00000001
using namespace std;

struct Info{
	double r;
};

double*** dp;

void func(char buf[300]){

	double length;
	int tmp;

	int index;

	tmp = 0;
	for(index = 0;buf[index] != ' ' && buf[index] != '\0'; index++){
		tmp = 10*tmp + buf[index] - '0';
	}

	length = (double)tmp;

	Info info[15];
	int info_index = 0;

	while(buf[index] != '\0'){

		tmp = 0;
		for(++index;buf[index] != ' ' && buf[index] != '\0';index++){
			tmp = 10*tmp + buf[index] - '0';
		}
		info[info_index].r = (double)tmp;
		info_index++;
	}

	double sum = 0;

	for(int i = 0; i < info_index; i++){
		sum += info[i].r;
	}

	if(length > 2*sum+EPS){
		printf("OK\n");
		return;
	}

	double distance[info_index][info_index];

	for(int i = 0; i < info_index;i++){
		for(int k = 0; k < info_index; k++){
			if(i != k){
				distance[i][k] = sqrt((info[i].r+info[k].r)*(info[i].r+info[k].r)-(info[i].r-info[k].r)*(info[i].r-info[k].r)); //i??????k???
			}
		}
	}

	int limit = pow(2,info_index);


	double minimum = 4000.0;

	for(int start_town = 0; start_town < info_index;start_town++){

		for(int i = 0; i <= info_index; i++){
			for(int k = 0; k < info_index;k++){
				for(int p = 0; p < limit; p++)dp[i][k][p] = 3000.0;
			}
		}

		int next_state;

		next_state = pow(2,start_town);

		dp[0][start_town][next_state] = info[start_town].r;

		for(int i = 1; i <= info_index; i++){
			for(int k = 0; k < info_index; k++){
				for(int state = 0; state < limit; state++){
					if(dp[i-1][k][state] < 2000.0){
						for(int a = 0; a < info_index; a++){
							if(state & (1 << a)){
								if(i == info_index && a == start_town && state == limit-1){
									dp[i][start_town][limit-1] = min(dp[i][start_town][limit-1],dp[i-1][k][state]+info[k].r);
								}
							}else{
								next_state = state + pow(2,a);
								dp[i][a][next_state] = min(dp[i][a][next_state],dp[i-1][k][state]+distance[k][a]);
							}
						}
					}
				}
			}
		}

		minimum = min(minimum,dp[info_index][start_town][limit-1]);

	}

	if(minimum < length || fabs(minimum-length) < EPS){
		printf("OK\n");
	}else{
		printf("NA\n");
	}

}

int main(){

	dp = new double**[13];

	for(int i = 0; i < 13; i++){
		dp[i] = new double*[12];
		for(int k = 0; k < 12; k++){
			dp[i][k] = new double[4096];
		}
	}


	char buf[300];
	int index;
	char ch;

	while(true){
		index = 0;
		ch = getchar();

		if(ch == '\n' || ch == '\0' || ch == EOF)break;

		while(ch != '\n' && ch != '\0' && ch != EOF){
			buf[index++] = ch;
			ch = getchar();
		}
		buf[index] = '\0';
		func(buf);
	}

	return 0;
}

Measured memory_bytes: 8244
function Main(input) {
  var tmp = input.split('\n');
  var n = tmp[0];
  var arr = tmp[1].split(' ');
  var count = 0;

  for(var i = 0; i < arr.length; i++) {
    arr[i] = parseInt(arr[i]);
  }

  for ( var i = 1; i < (n - 1); i++) {
    if ((arr[i] > arr[i - 1]) && (arr[i] < arr[i + 1])){
      count++;
    } else if ((arr[i] < arr[i - 1]) && (arr[i] > arr[i + 1])) {
      count++;
    }
  }

  console.log(count);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>

void type1(int H, int W)
{
	int i, j;

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

		for (j = 0; j < W; j++) {


			putchar('#');

		}

		putchar('\n');

	}

	putchar('\n');

	return;
}

void type2(int H,int W)
{
	int i, j;

	for (i = 0; i < W; i++) {
		putchar('#');
	}

	putchar('\n');

	for (i = 1; i < H - 1; i++) {
		putchar('#');

		for (j = 0; j < W - 2; j++) {
			printf(".");
		}
		printf("#\n");
	}

	for (i = 0; i < W; i++) {
		putchar('#');
	}

	printf("\n\n");

	return;
}

int main(void)
{
	int H, W;

	while (1) {
		
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) {
			break;
		}
		else if (W <= 2) {
			type1(H, W);
		}
		else {
			type2(H, W);
		}

	}

	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
struct state{
  int x,y,z,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};


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

int sx,sy,gx,gy,lx,ly;
int n;

bool t[500][500];
int d[500][500][6];

int main(){
  cin>>sx>>sy>>gx>>gy;
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    t[a+250][b+250]=true;
  }
  cin>>lx>>ly;
  priority_queue<state> Q;

  for(int i=0;i<500;i++)
    for(int j=0;j<500;j++)
      for(int k=0;k<6;k++)
        d[i][j][k]=1e9;
  
  d[250+sx][250+sy][0]=0;
  Q.push((state){250+sx,250+sy,0,0});
  

  while(!Q.empty()){
    state s=Q.top();Q.pop();
    
    if(s.cost>d[s.x][s.y][s.z])continue;

    //cout<<s.x<<' '<<s.y<<' '<<s.z<<' '<<s.cost<<endl;
    
    int a=abs((250-s.x)*(250-s.y)*s.z)%6;

    for(int i=0;i<7;i++){

      int nx=s.x+dx[i];
      int ny=s.y+dy[s.x%2][i];
      int nz=(s.z+1)%6;
      
      if(nx<250-lx||ny<250-ly)continue;
      if(nx>250+lx||ny>250+ly)continue;
      if(t[nx][ny])continue;

      
      if(i==a){
        if(d[nx][ny][nz]>s.cost){
          d[nx][ny][nz]=s.cost;
          Q.push((state){nx,ny,nz,s.cost});
        }
      }else{
        if(d[nx][ny][nz]>s.cost+1){
          d[nx][ny][nz]=s.cost+1;
          Q.push((state){nx,ny,nz,s.cost+1});
        }
      }
    }
  }

  int ans=1e9;
  for(int i=0;i<6;i++)
    ans=min(ans,d[gx+250][gy+250][i]);
  if(ans==1e9)ans=-1;
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 7280
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

int dirx[] = {1, -1, 0, 0};
int diry[] = {0, 0, 1, -1};

class agcC {
private:
    int H, W, K;
    bool isvalid(int x, int y) {
        return (x >= 0 && x < H && y >= 0 && y < W);
    }
public:
    void solve(istream& in, ostream& out) {
        in >> H >> W >> K;
        vector<vector<int>> A(H, vector<int>(W));
        int sx = -1, sy = -1;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                char c;
                in >> c;
                A[i][j] = (c == '#' ? 1 : 0);
                if (c == 'S') {
                    sx = i;
                    sy = j;
                }
            }
        }
        assert(sx != -1 && sy != -1);
        
        queue<tuple<int, int, int>> q, tq;
        vector<vector<int>> vis(H, vector<int>(W, 0));
        tq.emplace(sx, sy, K);
        while (!tq.empty()) {
            int cx, cy, ck;
            tie(cx, cy, ck) = tq.front();
            tq.pop();
            q.emplace(cx, cy, 1);
            if (cx == 0 || cx == H-1 || cy == 0 || cy == W-1) {
                out << "1\n";
                return;
            }
            vis[cx][cy] = 1;
            if (ck > 0) {
                for (int i = 0; i < 4; ++i) {
                    int xx = cx + dirx[i], yy = cy + diry[i];
                    if (isvalid(xx, yy) && !A[xx][yy] && !vis[xx][yy]) {
                        tq.emplace(xx, yy, ck-1);
                        vis[xx][yy] = 1;
                    }
                }
            }
            
        }
        
        int res = 1000 * 1000 * 1000;
        while (!q.empty()) {
            int cx, cy, cc;
            tie(cx, cy, cc) = q.front();
            q.pop();
            
            int dist1 = (H-1 - cx) / K + ((H-1 - cx) % K > 0 ? 1 : 0);
            int dist2 = (cx) / K + ((cx) % K > 0 ? 1 : 0);
            int dist3 = (W-1 - cy) / K + ((W-1 - cy) % K > 0 ? 1 : 0);
            int dist4 = (cy) / K + ((cy) % K > 0 ? 1 : 0);
            res = min(res, min(dist1 + 1, min(dist2 + 1, min(dist3 + 1, dist4 + 1))));
        }
        out << res << "\n";
    }
};


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

	agcC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

class Main {

	void solve() {

		int a = inint(), b = inint(), c = inint();
		out.println(c>=a&&c<=b ? "Yes" : "No");

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    set<string> s;
    while(n--){
        string t;
        cin>>t;
        s.insert(t);
    }
    cout<<s.size()<<endl;
}

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

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  if((n == 1 && a != b)|| a > b){
    cout << 0 << endl;
    return 0;
  }
  cout << a+b*(n-1)-a*(n-1)-b+1 << endl;
}

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

int main(){
    int n, m, x;

    cin >> n >> m >> x;

    vector<int> a(m);

    int num = 0;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        if(a[i] < x){
            num = i;
        }
    }

    //cout << num << endl;

    //cout << m - num - 1 << endl;
    //cout << num + 1 << endl;
    if(num == 0){
        cout << num << endl;
    } else {
        if(m - num - 1 > num + 1){
            cout << num + 1 << endl;
        } else {
            cout << m - num - 1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;string ans="No";cin>>a>>b;
  if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)a=0;
  else if(a==4||a==6||a==9||a==11)a=1;
  else if(a==2)a=2;
  if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)b=0;
  else if(b==4||b==6||b==9||b==11)b=1;
  else if(b==2)b=2;
  if(a==b)ans="Yes";
  cout <<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1<<26;
string s;
int dp[N + 10];
int main(){
	//freopen("readin.txt","r",stdin);
	cin >> s;
	int have = 0;
	for(int i = 0;i < (1<<26);i++)dp[i] = 1e6;
	for(auto i : s){
		have^=1<<(i - 'a');
		if(!(have&(have - 1)))dp[have] = 1;
		for(int j = 0;j < 26;j++)dp[have] = min(dp[have],1 + dp[have^(1<<j)]);
	}
	cout << dp[have] << endl;
}

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

/** Problem0044 : Prime Number II **/
#define MAX 110000
int main()
{
	bool prime[MAX];
	int  input;
	unsigned sum, num;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		if (input == 0) break;
		sum=0; num=0;
		for (int i=2; num<input; i++) {
			if (prime[i]) {
				sum += i;
				num++;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

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

int main(){

    char b;
    cin>>b;

    if(b=='A') cout<<'T'<<endl;
    if(b=='T') cout<<"A"<<endl;
    if(b=='G') cout<<"C"<<endl;
    if(b=='C') cout<<"G"<<endl;






    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>

#define MAX 100
//#define NIL -1

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;
int n;

void insert(int val) {
    Node *y = NIL;
    Node *x = root;
    Node *z = new Node();
    
    z->key = val;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if (z->key > x->key) {
            x = x->right;
        } else {
            x = x->left;
        }
    }
    z->parent = y;
    
    if ( y == NIL ) {
        root = z;
    } else if ( y->key > z->key ) {
        y->left = z;
    } else {
        y->right = z;
    }
//    delete z;
}

Node * find(Node *x, int val) {
    while ( x != NIL) {
        if (x->key == val) break;
        if (x->key > val) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return x;
}


Node * getSuccessor(Node *u) {
    while (u->left != NIL) {
        u = u->left;
    }
    return u;
}


void delete_node(Node *u) {
    Node *y;
    Node *x;
    if (u->left != NIL && u->right != NIL) {
        y = getSuccessor(u->right);
    } else {
        y = u;
    }
    
    // search child
    if (y->left != NIL) {
        x = y->left;
    } else {
        x = y->right;
    }
    
    // set the parent to the child if it exists
    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 ( u != y ) {
        u->key = y->key;
    }
    
    delete y;
}

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

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

void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int main() {
    int val;
    char moji[10];
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", moji);
        if (moji[0] == 'i') {
            scanf("%d", &val);
            insert(val);
        } else if (moji[0] == 'f') {
            scanf("%d", &val);
            Node *t = find(root, val);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if (moji[0] == 'd') {
            scanf("%d", &val);
            Node *t = find(root, val);
            delete_node(t);
        } else {
            print();
        }
    }
    
    return 0;
}

Measured memory_bytes: 21860
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;int flag=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
      if(!(a[i]%3==0 || a[i]%5==0))
        flag=1;
    }
  }
  if(flag==1)
    cout<<"DENIED"<<endl;
  else
    cout<<"APPROVED"<<endl;
    
}


Measured memory_bytes: 256
import numpy as np
n, g = map(int, input().split())
inps = []
for i in range(1, n + 1):
    inp = list(map(int, input().split()))
    inp.append(inp[0] * i * 100 + inp[1])
    inp.append(i)
    inps.append(inp)

def at(items, goal):
    if goal <= 0:
        return 0

    # while goal > 0:
    result = 0
    for t, c, a, i in reversed(items):
        tn = i * 100
        cnt = min(t - 1, (goal + tn - 1) // tn)
        result += cnt
        goal -= cnt * tn
        if goal <= 0:
            return result
    return float("inf")

#%%
result = []
for i in range(2 ** n):
    items = []
    other = []
    for item in inps:
        (items if i & 1 else other).append(item)
        i >>= 1

    # ncnt
    tcnt = sum(map(lambda x: x[0], items))
    acnt = sum(map(lambda x: x[2], items))
    ncnt = at(other, g - acnt)
    result.append(tcnt + ncnt)
print(min(result))


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  deque<char> d;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == 'B'){
      if(d.size())
        d.pop_back();
    }
    else{
      d.push_back(s[i]);
    }
  }
  for (auto&& n : d) {
    std::cout << n ;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256