akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

string dp[70][70];

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int W, H;
	vector<string> C;
	while(1){
		C.clear();
		cin >> W >> H;
		if(W == 0 && H  == 0) break;
		rep(i,H){
			string a;
			cin >> a;
			rep(j, a.size()){
				dp[i][j] = "";
			}
			C.pb(a);
		}
		rep(i, H){
			rep(j, W){
				if(!isdigit(C[i][j])) continue;
				string s1(1, C[i][j]), s2(1, C[i][j]);
				if(i != 0) s1 = dp[i - 1][j] + s1;
				if(j != 0) s2 = dp[i][j - 1] + s2;
				if(s1 == "0") s1 = "";
				if(s2 == "0") s2 = "";
				if(s1.size() == s2.size()){
					dp[i][j] = max(s1, s2);
				}
				else{
					dp[i][j] = (s1.size() > s2.size())? s1 : s2;
				}
			}	
		}

		string ans = "";
		rep(i,H){
			rep(j,W){
				if(ans.size() == dp[i][j].size()){
					ans = max(ans, dp[i][j]);
				}
				else{
					ans = (ans.size() > dp[i][j].size())? ans : dp[i][j];
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1404
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N,M,cnt[100010];

int main(){
    cin >> N >> M;

    int x,y,i;
    for (i=1; i<=M; i++){
        cin >> x >> y;
        cnt[x]++,cnt[y]++;
    }

    bool p=1;
    for (i=1; i<=N; i++)
        if (cnt[i]%2)
            p=0;

    if (p) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int a[3],count=0;
	for (int i = 0; i < 3; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + 3);
	if ((a[1] - a[0]) % 2 == 0) {
		count += (a[1] - a[0]) / 2;
		count += a[2] - a[1];
	}
	else {
		count = 1;
		a[0] += 1; a[2] += 1;
		count += (a[1] - a[0]) / 2;
		count += a[2] - a[1];
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder_b_085
{
    class _04
    {
        static void Main()
        {

            int N;
            int H;
            int count = 0;

            string[] str = Console.ReadLine().Split(' ');
            N = int.Parse(str[0]);
            H = int.Parse(str[1]);

            int[] a = new int[N];
            int[] b = new int[N];

            for(int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                a[i] = int.Parse(str[0]);
                b[i] = int.Parse(str[1]);
            }

            Array.Sort(a);
            Array.Reverse(a);
            Array.Sort(b);
            Array.Reverse(b);

            for(int i = 0; i < N; i++)
            {
                if(a[0] < b[i])
                {
                    H += -b[i];
                    count++;
                    if (H <= 0)
                    {
                        Console.WriteLine(count.ToString());
                        return;
                    }
                }
            }

            count += H / a[0];
            if(H % a[0] != 0)
            {
                count++;
            }

            Console.WriteLine(count.ToString());

        }
    }
}


Measured memory_bytes: 15804
from copy import copy


N, x = map(int, input().split())
A = list(map(int, input().split()))

a = copy(A)
ans1 = 0
for i in range(N-1):
    if a[i] + a[i+1] > x:
        surplus = a[i] + a[i+1] - x
        a[i+1] -= min(a[i+1], surplus)
        ans1 += surplus

a = copy(A)
ans2 = 0
for i in range(N-1):
    if a[N-i-1] + a[N-i-2] > x:
        surplus = a[N-i-1] + a[N-i-2] - x
        a[N-i-2] -= min(a[N-i-2], surplus)
        ans2 += surplus

print(min(ans1, ans2))


Measured memory_bytes: 15324
#include <stdio.h>
#define NIL -1
#define MAX 2000005
#define MIN -100000000

int T[MAX];
int hs;

void swap(int, int);
void maxHeapify(int);
void heapIncreaseKey(int, int);
void maxHeapInsert(int);
int heapExtractMax(void);
int parent(int);
int left(int);
int right(int);


int main()
{
  int i, a;
  char c[10];
 
  for(i=0; i<MAX; i++){
    T[i]=NIL;
  }

  for(i=1; ;i++){
    scanf("%s ",c);

    if(c[0]=='i'){
      scanf("%d", &a);
      maxHeapInsert(a);
    }
    else if(c[1]=='x'){
      a = heapExtractMax();
      printf("%d\n",a);
    }
    else break;
  }
  return 0;
}
  

void swap(int x, int y)
{
  int temp;
  temp=T[x];
  T[x]=T[y];
  T[y]=temp;
}


void maxHeapify(int i)
{
  int l = left(i);
  int r = right(i);
  int largest;

  if(l <= hs && T[l] > T[i]){
	largest = l;
  }
  else{
	largest = i;
  }
  if(r <= hs && T[r] > T[largest]){
	largest = r;
  }
  if(largest != i)
	{
	  swap(i, largest);
	  maxHeapify(largest);
	}
}


void heapIncreaseKey(int i, int key)
{
  if(key < T[i]) return;

  T[i] = key;
  while(i>1 && T[parent(i)] < T[i]){
    swap(i, parent(i));
    i = parent(i);
  }
}


void maxHeapInsert(int key)
{
  hs += 1;
  T[hs] = MIN;
  heapIncreaseKey(hs, key);
}


int heapExtractMax()
{
  int max;

  if(hs < 1){
    return NIL;
  }

  max = T[1];
  T[1] = T[hs];
  hs -= 1;
  maxHeapify(1);
  return max;
}

 
int parent(int i)
{
  return i/2;
}


int left(int i){
  return 2*i;
}


int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 8420
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    
    map<int, long long> ma;
    for(int i=0; i<n; i++){
        //map上の配列は初期値ゼロだから+=
        ma[a[i]] += b[i];
    }

    long long ans=0;
    for(auto shop : ma){
        long long buy = min((long long)m,shop.second);
        ans+=buy*shop.first;
        m-=(int)buy;
    }

    /*
    vector<pair<int, int>> ab(n);
    for(int i=0; i<n; i++){
        ab[i] = make_pair(a[i], b[i]);
    }
    sort(ab.begin(), ab.end());
    long long ans=0;
    for(int i=0; i<n; i++){
        //.secondはpair要素の2つ目を指す
        int buy = min(m,ab[i].second);
        ans+=(long long)buy*ab[i].first;
        m-=buy;
    }
    */
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second



int main(){
	string c;
	cin >> c;
	if(c == "a" ||c == "e" ||c == "i" ||c == "o" ||c == "u" ){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

LL dp[10001][2][101];  // keta, smaller, D

int main() {
  std::string N; std::cin >> N;
  int D; std::cin >> D;
  size_t length = N.length();

  // Initialize.
  for (size_t i = 0; i <= length; ++i) {
    for (int s = 0; s < 2; ++s) {
      for (int d = 0; d <= D; ++d) {
        dp[i][s][d] = 0;
      }
    }
  }

  dp[0][0][0] = 1;
  for (int i = 1; i <= length; ++i) {
    int v = N[i-1] - '0';
    for (int d = 0; d < D; ++d) {
      for (int n = 0; n < 10; ++n) {
        if (n < v) {
          dp[i][1][(d + n) % D] += dp[i-1][0][d] + dp[i-1][1][d];
        } else if (n == v) {
          dp[i][0][(d + n) % D] += dp[i-1][0][d];
          dp[i][1][(d + n) % D] += dp[i-1][1][d];
        } else { // n < v
          dp[i][1][(d + n) % D] += dp[i-1][1][d];
        }

        dp[i][0][(d + n)%D] %= kMod;
        dp[i][1][(d + n)%D] %= kMod;
      }
    }
  }

  std::cout << (dp[length][0][0] + dp[length][1][0] - 1 + kMod) % kMod << std::endl;
}


Measured memory_bytes: 16000
#include <iostream>
using namespace std;
int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int ans=0;
    for(int i=1; i<=n; i++) {
        int num=i, cnt=0;
        while(num>0) {
            cnt += num%10;
            num /= 10;
        }
        if(cnt>=a && cnt<=b) ans+=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# AOJ 0011 Drawing Lots
# あみだくじ

w = ARGF.gets.to_i

n = ARGF.gets.to_i
exchanges = []

n.times do
  exchanges << ARGF.gets.split(",").map {|x| x.to_i}
end

amida = []
(1..w).each do |from|
  to = from
  exchanges.each do |f, t|
    if to == f
      to = t
    elsif to == t
      to = f
    end
  end

  amida << {from: from, to: to}
end

amida.sort_by {|a| a[:to]}.each {|a| puts a[:from]}

Measured memory_bytes: 6124
/*
    Author : Simanta Deb Turja
*/
#include <bits/stdc++.h>
using namespace std;

#define Professor

using ll = long long;
using i64 = unsigned long long;

template <typename T> inline T Min (T a, T b, T c) { return min(a, min(b, c)); }
template <typename T> inline T Min (T a, T b, T c, T d) { return min(a, min(b, min(c, d))); }
template <typename T> inline T Max (T a, T b, T c) { return max(a, max(b, c)); }
template <typename T> inline T Max (T a, T b, T c, T d) { return max(a, max(b, max(c, d))); }

template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } 
template <typename T> inline T Floor(T a, T b) { return a / b; }

template <typename T> inline T Power (T a, T p) { T res = 1, x = a; while ( p ) { if ( p & 1 ) res = ( res * x ); x = ( x * x ); p >>= 1;}return res; }
template <typename T> inline T BigMod (T a,T p,T M) { a %= M;T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; }
template <typename T> inline T InverseMod (T a,T M) { return BigMod (a, M - 2, M); }

template <typename T> inline T gcd ( T a, T b ) { a = abs(a); b = abs(b); while ( b ) { a = a % b; swap ( a, b ); } return a; }
template <typename T> inline T lcm(T x,T y) { return (((x)/gcd((x),(y)))*(y)); }


#define endl '\n'
#define eb emplace_back

const int N = (int)4e5 + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = numeric_limits<ll>::max();
const int INF = numeric_limits<int>::max();
const ll MOD = (ll)1e9 + 7;

template <typename T> bool cmp (const pair <T, T> &a, const pair <T, T> &b) { return a.first < b.first; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    auto Solve = [&]() {
        #ifdef __APPLE__
            cout << "Running\n";
        #endif
        int n, k; 
        cin >> n >> k;
        vector <ll> h(n + 1, 0LL), dp(n + 1, (ll)1e10); 
        for (int i = 1; i <= n; ++i) {
            cin >> h[i];
        }
        dp[1] = 0LL;
        for (int i = 2; i <= n; ++i) {
            for (int j = 1; j <= min(i, k); ++j) {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
            }
        }
        cout << dp[n] << endl;
    };
    Solve();
    
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int main(int argc, char *args[])
{
	int n;
	int t;
	int min=1001;
	int c[500],ts[500];
	
	cin>> n >> t;
	for(int i=0;i<n;i++)
	{
		cin >> c[i];
		cin >> ts[i];
		if(ts[i] <= t)
			if(c[i] < min ) 
				min=c[i];
	}
	if(min==1001){
		cout<<"TLE" <<endl;
    	return 0;
	}
	cout<<min<< endl;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int n,d;
	cin>>n>>d;
	cout<<ceil((double)n/(2*d+1));
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 3800
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	int N;
	string S;
	cin >> N;
	cin >> S;

	string ls = S.substr(0, N / 2);
	string rs = S.substr(N / 2, (N-1));

	if (ls == rs && N % 2 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> xh(n);
    rep(i, n) cin >> xh[i].first >> xh[i].second;
    sort(all(xh));
    set<pair<ll, ll>> damage;
    ll dsum = 0;
    ll ans = 0;
    rep(i, n) {
        ll right = xh[i].first + 2 * d;
        ll cnt = (xh[i].second + (a - 1)) / a;
        for(auto it = damage.begin(); it != damage.end();) {
            if (it->first < xh[i].first) {
                dsum -= it->second;
                damage.erase(it++);
            }
            else {
                break;
            }
        }
        cnt = max(0LL, cnt - dsum);
        if (cnt > 0) {
            dsum += cnt;
            damage.insert(make_pair(right, cnt));
            ans += cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,sum=0,total=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		int p=i;
		sum=0;
		while(p!=0){
			sum+=p%10;
			p/=10;
		}
		if(sum>=a&&sum<=b)total+=i;
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  	int N,MAX;
  	cin >> MAX >> N;
  	vector<int> deff(N),data(N);
  	for(int i = 0;i < N;i++){
    	cin >> data[i]; 
    }
  	deff[0] = data[0] + (MAX - data[N - 1]);
  	for(int i = 1;i < N;i++){
    	deff[i] = data[i] - data[i - 1];
    }
  	int maxDefIndex = 0;
  	for(int i = 1;i < N;i++){
    	if(deff[i] > deff[maxDefIndex]){
        	maxDefIndex = i;
        }
    }
  	int i = (maxDefIndex == N - 1)?0:maxDefIndex  + 1;

  	int sum = 0;
  	while(i != maxDefIndex ){
      	//cout << i << ":"<<deff[i]<<endl;
  		sum += deff[i];
  		i++;
  		if(i >= N){
    		i = 0;
    	}
    }
  	cout << sum<<endl;
}

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

#define    ll      long long int

int main( )
{
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll m = min(a, b);
    m = min(m, c);
    m = min(m, d);
    m = min(m, e);
    ll cc = n / m;
    if (n % m != 0) cc++;
    cout << (cc + 4) << '\n';
    return 0;
}


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

using namespace std;

int m, n;
vector <int> book;

int f(int);

int main(){
	while(1){
		cin >> m >> n;
		if(m == 0 && n == 0)
			break;
		
		book = vector <int> (n);
		for(int i = 0; i < n; i++)
			cin >> book[i];
		
		int low = *max_element(book.begin(), book.end());
		int high;
		for(int i = 0; i < n; i++)
			high += book[i];
		int mid = (low + high) / 2;
		
		while(1){
			if(f(mid) == 1)
				high = mid;
			else
				low = mid + 1;
			
			if(low == high){
				cout << low << endl;
				break;
			}
			mid = (low + high) / 2;
		}
	}
	
	return 0;
}

int f(int width){
	int count = 0;
	int w = width;
	
	for(int i = 0; i < n; i++){
		if(book[i] <= w)
			w -= book[i];
		else{
			count++;
			if(count >= m)
				return 0;
			w = width - book[i];
		}
	}
	return 1;
}

Measured memory_bytes: 1220
#include <cstdio>
#include <algorithm>
using namespace std;
int n,k;
bool used[100001]={};
int num[100001];
int main(){
while(1){
		fill(used,used+100001,false);
	scanf("%d %d",&n,&k);
if(!n) break;
	for(int i=0;i<k;i++){
		scanf("%d",&num[i]);
		used[num[i]]=true;
	}
	sort(num,num+k);
	int s=0,e=0,sum=0,res=0;
	if(used[0]){
		for(;;){
			while(e<=n && sum<=1){
				if(!used[e]){
					sum++;
					e++;
				}else{
					e++;
				}
			}
			if(sum<=1){
                                res=max(res,e-s);
				break;
			}
			res=max(res,e-s);
			if(!used[s]){
				sum--;
			}
			s++;
		}
	}else{
                e=1;s=1;
		for(;;){
			while(e<=n && sum<=0){
				if(!used[e]){
					sum++;
					e++;
				}else{
					e++;
				}
			}
			if(sum<=0){
				break;
			}
			res=max(res,e-s);
			if(!used[s]){
				sum--;
			}
			s++;
		}
	}
	printf("%d\n",res-1);
}
}

Measured memory_bytes: 1460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstring>
#include<cstdlib>
#include <ctime>
#include <math.h>
using namespace std;
int main(void)
{
	int a,b,i,ans;
	cin >> a >> b;
	if(a<0 && 0<b) cout << "Zero" << endl;
	else if(b<0 && 0<a) cout << "Zero" << endl;
	else if(0<a && 0<b) cout << "Positive" << endl;
	else if((a-b)%2==0) cout << "Negative" << endl;
	else if((a-b)%2==-1) cout << "Positive" << endl;
}

Measured memory_bytes: 256
//51
#include<iostream>
#include<set>

#define T(a,b,c) (a*1000+b*10+c)

using namespace std;

int p[28];
int n;
set<int> s;

bool dfs(int pr,int u,int r){
  if(r==0){
    return true;
  }else if(s.count(T(u,r,pr))){
    return false;
  }else{
    for(int i=0;i<n;i++){
      if(!(u&1<<i)){
	for(int j=0;j<2;j++){
	  p[i]=p[i]/10+p[i]%10*10;
	  if(pr==p[i]/10){
	    if(dfs(p[i]%10,u|1<<i,r-1))return true;
	  }
	}
      }
    }
    s.insert(T(u,r,pr));
    return false;
  }
}

int main(){
  while(cin>>n){
    s.clear();
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    for(int i=0;i<n;i++){
      if(dfs(p[i]%10,1<<i,n-1)||dfs(p[i]/10,1<<i,n-1)){
	cout<<"Yes"<<endl;
	goto next;
      }
    }
    cout<<"No"<<endl;
  next:
    ;
  }
  return 0;
}

Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int kuraiwa(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }
  return sum;
}
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(void){
    string S;
    cin >> S;

    int len = S.length();
    int arr[len];
    for(int i = 0; i < len; i++){
        arr[i] = S[i] - '0';
    }
    long long res = 0;
    long long digit = 1;

    // cout << "len = " << len << "\n";

    for(int i = 0; i < (1<<(len-1)); i++){
        for(int j = 0; j < len; j++){
            if(j == 0){
                res += arr[len-1-j];
                digit = 1;
            }else if((i&(1<<(j-1))) != 0){
                res += arr[len-1-j];
                digit = 1;
            }else{
                digit *= 10;
                res += arr[len-1-j] * digit;
            }
        }
        // cout << static_cast<bitset<10>>(i) << "\n";
        // cout << res << endl;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	Node[] nodes;

	private static class Node{

		int parent;
		int childSize;
		int[] children;
	}

	public void solve() {
		int n = nextInt();

		nodes = new Node[n];

		for(int i = 0;i < n;i++){
			nodes[i] = new Node();
			nodes[i].parent = -1;
		}

		for(int i = 0;i < n;i++){
			int id = nextInt();
			int k = nextInt();

			nodes[id].childSize = k;

			nodes[id].children = new int[k];

			for(int j = 0;j < k;j++){
				int c = nextInt();
				nodes[id].children[j] = c;
				nodes[c].parent = id;
			}
		}

		for(int i = 0;i < n;i++){
			out.print("node " + i + ": ");
			out.print("parent = " + nodes[i].parent + ", ");
			int depth = 0;
			int parent = nodes[i].parent;
			while(parent != -1){
				parent = nodes[parent].parent;
				depth++;
			}

			out.print("depth = " + depth + ", ");

			if(nodes[i].parent == - 1){
				out.print("root, ");
			}else if(nodes[i].childSize == 0){
				out.print("leaf, ");
			}else{
				out.print("internal node, ");
			}

			out.print("[");
			for(int c = 0;c < nodes[i].childSize;c++){
				if(c != 0)out.print(", ");
				out.print(nodes[i].children[c]);
			}
			out.println("]");
		}

	}

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

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(void) {
	int a[3];
	for (int i = 0; i < 3; i++) {
		scanf("%d", &a[i]);
	}
	int K;
	scanf("%d", &K);
	sort(a, a + 3);
	printf("%d\n", a[0] + a[1] + a[2]*(int)pow(2., (double)K));
	return 0;
}


Measured memory_bytes: 4052
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

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


void solve() {
	int a, b; cin >> a >> b;
	string s, t;
	rep(i, b)s.push_back('0'+a);
	rep(i, a)t.push_back('0'+b);
	cout << min(s, t) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}

Measured memory_bytes: 256
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R second
#define mp make_pair
#define pb push_back
#define int ll
typedef long long ll;

const int maxn=1e5+10;

int n, a[maxn], ans;

main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    int sum=0;
    for(int i=0; i<n; i++) 
    {
	sum+=a[i];
	if(a[i]==0) ans+=sum/2, sum=0;
    }
    ans+=sum/2;
    cout<<ans<<endl;

}


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

int main(){
    int s; cin >> s;
    int MAX = 1000000;
    set <int> a;
    int tmp;
    rep(i, MAX){
        if(i==0){
            tmp = s;
            a.insert(tmp);
        }else{
            if(tmp%2==0){
                tmp /= 2;
            }else{
                tmp = tmp*3 + 1;
            }
        
            if(a.count(tmp)>0){
                cout << i+1 << endl;
                return 0;
            }
        a.insert(tmp);
        }
    }
    return 0;
}

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

using namespace std;
bool Flag[100002];

void solve()
{
	int n;
	while(cin >> n, n)
	{
		memset(Flag, 0, sizeof(Flag));
		for(int i = 0; i < n; ++i)
		{
			int input;
			cin >> input;
			Flag[input] = true;
		}
		int first_flag = true;
		for(int i = 1; i <= 100000; ++i)
		{
			if(Flag[i])
			{
				if(!first_flag)
				{
					cout << " ";
				}
				first_flag = false;
				int pos = i  + 1;
				while(Flag[pos] == true)
				{
					++pos;
				}
				if(pos == i + 1)
				{
					cout << i;
				}
				else
				{
					cout << i << "-" << pos - 1;
				}
				i = pos;
			}	
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
n = gets
ss = gets.strip.split("")

stack = []
stacked = 0
len = ss.length

0.upto(len-1) do |idx|
  current = ss[idx]

  if stack.empty?
    stack[stacked] = current
    next
  end

  if stack[stacked] == current
    next
  end

  stacked += 1
  stack[stacked] = current
end

puts stacked + 1

Measured memory_bytes: 7876
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
 // 	freopen("input.txt","r",stdin);
 // 	freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n , k;
		cin >> n >> k;
		cout << (n+k-1)/ k << endl;
	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int a1, a2, a3; cin >> a1 >> a2 >> a3;
	if (a1 + a2 + a3 >= 22) printf("bust\n");
	else printf("win\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <tuple>

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int N;
ll pat[50][50][61];
// iからjまで距離2^nのパス数
map<tuple<int, int, ll>, ll> dp;

ll route(int i, int j, ll K) {
    if (K == 0) return i == j;
    if (dp.find(make_tuple(i, j, K)) != dp.end()) {
        return dp[make_tuple(i, j, K)];
    }

    ll ret = 0;
    for (int k = 0; k < N; ++k) {
        for (int n = 60; n >= 0; --n) {
            if ((K >> n) & 1) {
                ret += pat[i][k][n] * route(k, j, K - (1LL << n));
                ret %= MOD;
                break;
            }
        }
    }

    dp[make_tuple(i, j, K)] = ret;
    return ret;
}

int main() {
    ll K;
    cin >> N >> K;

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

    for (int n = 1; n <= 60; ++n) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                for (int k = 0; k < N; ++k) {
                    pat[i][k][n] += pat[i][j][n - 1] * pat[j][k][n - 1];
                    pat[i][k][n] %= MOD;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            ans += route(i, j, K);
            ans %= MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10624
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

/*
(x+y+z)^2 - (xy + yz + zx)
x=y=z => 6x^2
6x^2 <= 10^4
x^2 <= 10^4/6
x <= 10^2 / sqrt(6)
 */
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 1; i <= n; i++) {
      map.put(i, 0);
    }
    int limit = (int) Math.ceil(Math.sqrt(n));
    for (int i = 1; i <= limit; i++) {
      int t1 = i * i;
      for (int j = 1; j <= limit; j++) {
        int t2 = j * j;
        int t3 = i * j;
        for (int k = 1; k <= limit; k++) {
          int r = t1 + t2 + k * k + t3 + j * k + k * i;
          if (r <= n) {
            map.put(r, map.get(r) + 1);
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      System.out.println(map.get(i));
    }
  }
}


Measured memory_bytes: 38680
#include <bits/stdc++.h>
using namespace std;
#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 v vector
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n;
    cin >> n;
    if(n%10 == 3) cout << "bon" << endl;
    else if (n%10 == 0||n%10 == 1||n%10 == 6||n%10 == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3632
//#include <boost/multiprecision/cpp_int.hpp> 
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define test    ll t=0;cin>>t;while(t--)
#define fast    ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision; 
using namespace std;
ll INF=10000000000;
int main(void) {
	fast;
	ll n;
	cin>>n;
	ll a[n],b[n]={0};
	rep(i,0,n)
	cin>>a[i];
	b[1]=abs(a[1]-a[0]);
    rep(i,2,n){ 
        if(b[i-1]+abs(a[i]-a[i-1])<=b[i-2]+abs(a[i]-a[i-2]))
        b[i] = abs(a[i]-a[i-1])+b[i-1];
        else
        b[i] = abs(a[i]-a[i-2])+b[i-2];
    }
    cout<<b[n-1];
	return 0;
}



Measured memory_bytes: 5144
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int x, y, z;

            while (true)
            {
                string[] num = Console.ReadLine().Split(' ');
                x = int.Parse(num[0]);
                y = int.Parse(num[1]);

                if (x == 0 && y == 0)
                {
                    break;
                }
                    if (x > y)
                    {
                        z = x;
                        x = y;
                        y = z;
                    }
                    Console.WriteLine(x + " " + y);
                
            }
        }
    }



Measured memory_bytes: 9228
from math import floor

while True:
    n = eval(input())
    if n != 0:
        ls = []
        for i in range(n):
            m = eval(input())
            ls.append(m)
        ls.remove(max(ls))
        ls.remove(min(ls))
        print(floor(sum(ls)/len(ls)))
    else:
        break

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    vector<int> dp(h+1, 1001001001);
    dp[0] = 0;

    rep(i, h+1){
        rep(j, n){
            if(i >= a[j]){
                dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
            }else{
                dp[i] = min(dp[i], dp[0] + b[j]);
            }
        }
    }

    cout << dp[h] << endl;

    return 0;
}


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

bool check(string S){
    bool flag = true;
    // if(S.size()%2 == 0){
        for(int i=0; i<S.size()/2; i++){
            if(S[i] != S[S.size()-1-i]) flag = false;
        }
    // }else{
    return flag;
    // }
    
}

int main(){
    string S;
    cin >> S;
    bool ans = false;
    
    if(check(S)){
        ans = check(S.substr(0,(S.size()-1)/2));
    }
    
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def d_flipping_signs(N, A):
    minus_count_parity = len([1 for a in A if a < 0]) % 2
    a = list(map(abs, A))
    return sum(a) + (-2 * min(a) if minus_count_parity == 1 else 0)

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))

Measured memory_bytes: 14412
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Remainder Minimization 2019
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MOD = 2019;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int l, r;
  scanf("%d%d", &l, &r);

  if (r - l + 1 >= MOD) {
    puts("0");
    return 0;
  }

  int minm = MOD;
  for (int i = l; i < r; i++) {
    int mi = i % MOD;
    for (int j = i + 1; j <= r; j++) {
      int m = (mi * (j % MOD)) % MOD;
      if (minm > m) minm = m;
    }
  }

  printf("%d\n", minm);
  return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

constexpr int MAXN = 8;
int n;
int x[MAXN], y[MAXN];

double dist(int a, int b) {
    int dx = x[a] - x[b];
    int dy = y[a] - y[b];
    return sqrt(dx * dx + dy * dy);
}

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

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

    vi order(n);
    iota(all(order), 0);
    double total = 0.0;
    do {
        for (int i = 1; i < n; ++i) {
            total += dist(order[i - 1], order[i]);
        }
    } while (next_permutation(all(order)));

    for (int i = n; i > 0; --i) {
        total /= i;
    }

    cout << fixed << setprecision(10) << total << '\n';
    
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else
    y->right = z;
}

void inorder(Node u){

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

  if(u != NIL){
  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] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25240
import sys
n,m=map(int,input().split())
ll = [list(map(int,input().split())) for _ in [0]*m]
s = '*'*n
for l in ll:
  if s[l[0]-1]!='*' and s[l[0]-1]!=str(l[1]):
    print(-1)
    sys.exit()
  s=s[:l[0]-1]+str(l[1])+s[l[0]:]
if s[0] == '*' and len(s)!=1:
  s='1'+s[1:]
s=s.replace('*','0',3)
if s[0]=='0' and len(s) != 1:
  print(-1)
  sys.exit()
print(s)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

// dp[i][j] := i番目までの商品から価値がv以上になるように選んだ時の重さの最小値
ll dp[110][100001];

int main() {
  int n, w_limit;
  cin >> n >> w_limit;

  repi(i, 0, n + 1) repi(j, 0, 100001) dp[i][j] = INF;
  dp[0][0] = 0;

  int w[n + 1], v[n + 1];
  repi(i, 1, n + 1) { cin >> w[i] >> v[i]; }

  repi(i, 1, n + 1) {
    repi(j, 0, 100001) {
      // i番目の商品を選ぶ
      if (j - v[i] >= 0) {
        chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
      }
      // i番目の商品を選ばない
      chmin(dp[i][j], dp[i - 1][j]);
    }
  }

  ll ans = 100000;
  while (dp[n][ans] > w_limit)
    ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 80128
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	long D, ans;
	long[] pow = new long[20];
	void Solve()
	{
		D = F();
		pow[0] = 1;
		for (var i = 1; i < 20; i++) pow[i] = pow[i - 1] * 10;
		WriteLine(Calc(D));
	}
	long Calc(long D)
	{
		if (D % 9 != 0) return 0;
		ans = 0;
		for (var n = 1; n <= 18; n++) DFS(new int[n / 2], n, D, 0);
		return ans;
	}
	void DFS(int[] a, int n, long d, int i)
	{
		if (i == n / 2)
		{
			if (d != 0) return;
			var p = a[0] >= 0 ? 9L - a[0] : 10 + a[0];
			for (var j = 1; j < n / 2; j++) p *= 10 - Abs(a[j]);
			ans += (n % 2 == 0 ? 1 : 10) * p;
		}
		else
		{
			var c = pow[n - i - 1] - pow[i];
			var t = d / c;
			if (d < 0 && d % c != 0) t++;
			Action<long> trial = z =>
			{
				if (-9 <= z && z <= 9)
				{
					a[i] = (int)z;
					DFS(a, n, d - z * c, i + 1);
				}
			};
			trial(t);
			trial(t + 1);
			trial(t - 1);
			trial(t - 2);
			trial(t + 2);
		}
	}
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(void){
  int i, n, x;
  long int max = -1000000, min = 10000000, sum = 0;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(max < x)  max = x;
    if(min > x)  min = x;
    sum += x;
  }
  printf("%ld %ld %ld\n", min, max, sum);
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

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

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int r,d,x;
  cin >> r >> d >> x;
  REP(i,10){
    x = x*r-d;
    cout << x << endl;
  }
}



Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        map<ll,ll> D;
        ll n;
        cin>>n;
        rep(i,n){
            ll a;
            cin>>a;
            D[a]++;
        }
        ll m;
        cin>>m;
        bool res=true;
        rep(i,m){
            ll a;
            cin>>a;
            D[a]--;
            if(D[a]<0)res=false;
        }
        if(res)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

Measured memory_bytes: 16092