akhauriyash/Code-Regression huggingface dataset:
//#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

/*
ID: jamerz1
PROG: hidden
LANG: C++11
*/

using namespace std;

// TIMER
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
	__duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
	std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
// END TIMER

//PI
#define M_PI		3.14159265358979323846
// fast input
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)

template <class T>
T min_(T a, T b) { return (a < b ? a : b); }
template <class T>
T max_(T a, T b) { return (a > b ? a : b); }

double EPS_ = 1e-16;
bool eq_(const double& lhs, const double &rhs) {
	return (fabs(lhs - rhs) < EPS_);
}

//#define F first
//#define S second

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

typedef pair<ll, ll> llll;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<llll> vllll;
typedef vector<int> vi;
typedef vector<ull> vull;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;

const int INF = int(2e9);
const ll INF_LL = LLONG_MAX;
const ll MOD = 1e9 + 7;

ll get_digit_sum(ll N) {
	ll sum = 0;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}

int main()  {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll N;
	cin >> N;
	ll sum = get_digit_sum(N);
	if (N % sum == 0)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

vector <pair <int,int> > g[N];
int n, m, k, L;
int a[N];
pair <int, int> d[400][400];
string ss;

void go(int x){
	for (int i = 1; i <= n; i++) d[x][i] = {inf, 0};
	set <pair <pair <int, int>, int > > S;
	d[x][x] = {0, 0};
	S.in({{0, 0}, x});
	while (S.size()){
		int v = S.begin() -> s;
		S.er(S.begin());
		for (auto i: g[v]){
			pair <int,int> cur = d[x][v];
			int to = i.f, w = i.s;
			//if (w > L) con;
			cur.s += w;
			if (cur.s > L){
				cur.s = w;
				cur.f++;
			}
			if (d[x][to] > cur){
				S.er(mp(d[x][to], to));
				d[x][to] = cur;
				S.in({d[x][to], to});
			}
		}
	}
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> L;
	for (int i = 0; i < m; i++){
		int x, y,z ;
		cin >> x >> y >> z;
		if (z > L) con;
		g[x].pb(mp(y, z));
		g[y].pb(mp(x, z));
	}
	for (int i = 1; i <= n; i++){
		go(i);
	}
	int t;
	cin >> t;
	for (int i = 0; i < t; i++){
		int x, y;
		cin >> x >> y;
		if (d[x][y].f == inf) cout << -1;
		else cout << d[x][y].f;
		cout << "\n";
	}
	return 0;
}












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

const int MOD = (int) 1e9 + 7;

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

    int n;
    cin >> n;

    long long tenX = 1, nineX = 1, eightX = 1;

    for (int i=1; i<=n; i++)
    {
        tenX = tenX * 10 % MOD;
        nineX = nineX * 9 % MOD;
        eightX = eightX * 8 % MOD;
    }

    cout << (tenX + MOD - nineX * 2 % MOD + eightX) % MOD << "\n";

    return 0;
}


Measured memory_bytes: 3616
r, c = map(int, input().split())

result = []
for _ in range(r):
    r_vec = list(map(int, input().split()))
    r_vec.append(sum(r_vec))
    result.append(r_vec)

last_row = [0] * (c + 1)
for i in range(r):
    for j in range(c+1):
        last_row[j] += result[i][j]
result.append(last_row)
        
for i in range(r+1):
    print(" ".join(map(str, result[i])))


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,prime_cnt[ohara],f[ohara],fr[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<pair<ll,ll>> prime;
//-------------------------↓↓↓↓↓↓------------------------

void Factorization(ll nn){
       for(ll i=2;nn!=1;i++){
           if(nn%i)continue;
           prime.push_back({i,0});
           while(nn%i==0){
             prime.back().second++;
             nn/=i;
           }
      }
}

ll mod_pow(ll xx,ll nn,ll mod){
  ll ret=1;
  while(nn>0){
    if(nn&1)ret=ret*xx%mod;
    xx=xx*xx%mod;
    nn>>=1;
  }
  return ret;
}

ll ncr(ll nn,ll r){
  if(nn<r)return 0;
  return f[nn]*fr[r]%MOD*fr[nn-r]%MOD;
}

void init(ll nn){
  f[0]=1;
  rrep(i,1,nn+3){
    f[i]=f[i-1]*i%MOD;
  }
  fr[nn+2]=mod_pow(f[nn+2],MOD-2,MOD);
  rrrep(i,nn+1,0){
    fr[i]=fr[i+1]*(i+1)%MOD;
  }
}

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n>>m;
      init(n+sqrt(m)+3);
      Factorization(m);
      ans=1;
      for(auto v : prime){
        (ans*=ncr(v.second+n-1,v.second))%=MOD;
      }
      Cout(ans%MOD);
    
       
return 0;
}


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

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

using namespace std;

const int INF = 2e9 + 7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    string s1, s2;
    for (int i = 0; i < a; i++) {
        s1.push_back('0' + b);
    }
    for (int i = 0; i < b; i++) {
        s2.push_back('0' + a);
    }
    cout << min(s1, s2);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
#include <limits.h>
#include <unordered_map>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;

// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

	for (int i = 2; i * i <= value; ++i) {
		if ((value % i) == 0) {
			return true;
		}
	}
	return false;
}

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}

void DebugPrint(const vector<ll>& vec) {
	cout << "{";
	for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
		cout << *itr << ",";
	}
	cout << "}" << endl;
}

// valueが2のx乗以下である計算
ll calc2x(ll value) {
	ll n = 0;
	while (value > 0) {
		value /= 2;
		++n;
	}
	return n;
}

int main(void) {

	ll n;
	cin >> n;

	string ans = "hon";

	switch (n % 10) {
	case 3:
		ans = "bon";
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		ans = "pon";
		break;
	};

	auto output = ans;
	cout << output;

	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S;
	bool J = false;
	if(S[0] == 'A'){
		if(S[1] != 'C' && S[S.size() - 1] != 'C'){
			sort(S.begin(), S.end());
			if(S[1] == 'C' && S[2] >= 'a' && S[2] <= 'z') J = true;
		}
	}
	cout << ((J) ? "AC" :"WA") << endl;
}

Measured memory_bytes: 256
n_k = list(map(int,input().split()))
h = []
max_a = 1000000000

for i in range(n_k[0]):
    h.append(int(input()))

h.sort(reverse = True)

for j in range(n_k[0] - (n_k[1]-1)):
    a = h[j] - h[j + (n_k[1]-1)]
    if a <= max_a:
        max_a = a

print(int(max_a))

Measured memory_bytes: 7488
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int state = 0;
        string pre, suf;
        string s;
        cin >> s;

        Int Q;
        cin >> Q;
        while (Q--) {
            Int t;
            cin >> t;
            if (t == 1) {
                state = 1 - state;
            } else {
                Int f;
                char c;
                cin >> f >> c;
                if ((f == 1) ^ (state)) pre.push_back(c);
                else suf.push_back(c);
            }
        }
        string ans;
        if (state) {
            reverse(all(s));
            reverse(all(suf));
            ans += suf;
            ans += s;
            ans += pre;
        } else {
            reverse(all(pre));
            ans += pre;
            ans += s;
            ans += suf;
        }
//        if (state) reverse(all(s));
//        reverse(all(pre));

        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int a[2 * mx5], ans[2 * mx5];

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

    for(int i = 1; i <= n; i++)
        cin >> a[i];

    for(int i = n / 2 + 1, j = 1; i <= n; i++, j += 2)
        ans[i] = a[j];

    for(int i = n / 2, j = 2; i; i--, j += 2)
        ans[i] = a[j];

    if(n % 2){
        for(int i = n; i; i--)
            cout << ans[i] << ' ';
        cout << '\n';
        return 0;
    }

    for(int i = 1; i <= n; i++)
        cout << ans[i] << ' ';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 5164
n, q = map(int, input().split())
# tree = [list(map(int, input().split())) for i in range(n-1)]
edges = [set() for i in range(n)]
for _ in range(n-1):
    a, b= map(int,input().split())
    edges[a-1].add(b-1)
cnt = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

l = [0]
l2 = [cnt[0]]
while len(l) != 0:
    a = l.pop()
    b = l2.pop()
    if a != 0:
        cnt[a] += b
    for i in edges[a]:
        l.append(i)
        l2.append(cnt[a])
print(*cnt)


Measured memory_bytes: 78752
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

const ll MX = 200005;
ll N, X[MX], Y[MX];
ll RX[MX], RY[MX];

ll solve(){
    for(int i=0; i<N; i++){
        ll x = X[i], y = Y[i];
        ll rx = x - y, ry = x + y;
        RX[i] = rx; RY[i] = ry;
    }
    sort(RX, RX + N); sort(RY, RY + N);
    return max(RX[N-1]-RX[0], RY[N-1]-RY[0]);
}

int main(){
    //freopen("in.txt", "r", stdin);
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>X[i]>>Y[i];
    }
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 9796
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final int H = sc.nextInt();
		final int N = sc.nextInt();
		final int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		int damage = 0;
		for(int i=N-1;i>=0;i--) {
			damage += A[i];
		}
		if(damage >= H) {
			out.println("Yes");
		}else {
			out.println("No");
		}
	}
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    ll h,n;
    cin >> h >> n;

    
    ll dp[n+1][h+1] = {};
    rep(i,0,n+1) rep(j,0,h+1) dp[i][j] = LINF;
    dp[0][0] = 0;

    ll a[n] = {},b[n] = {};
    rep(i,0,n) cin >> a[i] >> b[i];

    rep(i,0,n){
        rep(j,0,h+1){
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
            dp[i+1][min(h,j+a[i])] = min(dp[i+1][min(h,j+a[i])],dp[i+1][j] + b[i]);
        }
    }
    
    cout << dp[n][h] << endl;
    return 0;
}


Measured memory_bytes: 81792
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
long long sousuu = 1, ans;

int main()
{


	while (1) {
		int machi[20][20] = { 0,0 }, a, b, n;
		cin >> a >> b; if (a == 0 && b == 0) { break; }cin >> n; a--; b--;
		//if (n == 0) { break; }//cout << n << endl;
		bool kouji[20][20] = { false };
		for (int i = 0; i < n; i++)
		{
			int d, e; cin >> d >> e;
			kouji[d - 1][e - 1] = true;
		}
		machi[0][0] = 1;
		REP(i, a + 1) {
			if (kouji[i][0] == false) {
				machi[i][0] = 1;
			}
			else {
				//			cout << i<<"a";
				break;
			}
		}

		REP(i, b + 1) {
			if (kouji[0][i] == false) {
				machi[0][i] = 1;
			}
			else { break; }
		}
		FOR(i, 1, a + 1) {
			FOR(j, 1, b + 1) {
				if (kouji[i][j] != true) {
					machi[i][j] = machi[i - 1][j] + machi[i][j - 1];
				//	cout << i << " " << j << " " << machi[i][j] << endl;
				}
			}
		}
		cout << machi[a][b] << endl;
	}

	//	cout << "s";
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <set>
#include <queue>
#include <map>
#include <stdlib.h>

using namespace std;

struct Point{
	int tx;
	int ty;
	int kx;
	int ky;
	Point( int dtx, int dty, int dkx, int dky ){
		tx = dtx;
		ty = dty;
		kx = dkx;
		ky = dky;
	}
};

Point move( int next, const Point& point, int stage[51][51] )
{
	switch( next ){
		case 0:
			return Point( stage[point.tx + 1][point.ty] ? point.tx : point.tx + 1, point.ty, stage[point.kx - 1][point.ky] ? point.kx : point.kx - 1, point.ky );
		case 1:
			return Point( stage[point.tx - 1][point.ty] ? point.tx : point.tx - 1, point.ty, stage[point.kx + 1][point.ky] ? point.kx : point.kx + 1, point.ky );
		case 2:
			return Point( point.tx, stage[point.tx][point.ty + 1] ? point.ty : point.ty + 1, point.kx, stage[point.kx][point.ky - 1] ? point.ky : point.ky - 1);
		case 3:
			return Point( point.tx, stage[point.tx][point.ty - 1] ? point.ty : point.ty - 1, point.kx, stage[point.kx][point.ky + 1] ? point.ky : point.ky + 1);
	}

	return Point(1,1,1,1);
}
	

int change( const Point& data )
{
	return data.tx + data.ty * 51 + data.kx * 51 * 51 + data.ky * 51 * 51 * 51;
}

int bfs( const Point& start, int stage[51][51] )
{
	set<int> history;
	queue<Point> q;
	map<int,int> dist;

	dist[change( start )] = 0;
	history.insert( change( start ) );

	q.push( start );
	while( !q.empty() ){
		Point u = q.front();
		if( u.tx == u.kx && u.ty == u.ky ) return dist[change( u )];

		for( int i = 0;i < 4;i++ ){
			Point v = move( i, u, stage );
			if( history.count( change( v ) ) ) continue;
			dist[change( v )] = dist[change( u )] + 1;
			history.insert( change( v ) );
			q.push( v );
		}

		q.pop();
	}
	return -1;
}
int main(int argc, char const* argv[])
{
	int X,Y;
	Point point(0,0,0,0);
	int stage[51][51];

	while( cin >> X >> Y && X != 0 ){
		cin >> point.tx >> point.ty;
		cin >> point.kx >> point.ky;
		for( int i = 0;i < 51;i++ ){
			for( int j = 0;j < 51;j++ ){
				stage[i][j] = 1;
			}
		}

		for( int i = 1;i <= Y;i++ ){
			for( int j = 1;j <= X;j++ ){
				cin >> stage[j][i];
			}
		}

		int answer = bfs( point, stage );
		if( answer == -1 ) cout << "NA" << endl;
		else cout << answer << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

void dfs(int v, int n, vector<vector<int>> G, vector<bool> &used, int &count, int &depth){
    used[v] = true;
    depth++;
    if(depth == n) count++;
    else if(depth < n){
        for(auto nv : G[v]){
            if(used[nv] == false) { dfs(nv, n, G, used, count, depth); }
        }
    }
    used[v] = false;
    depth--;
    return;
}

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    
    vector<bool> used(n,false);
    int count = 0;
    int depth = 0;
    dfs(0, n, G, used, count, depth);
    cout << count << endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));
	
	public static void main(String[] args) {
		int a=scan.nextInt();
		int b=scan.nextInt();
		int cnt=0;
		for(int i=1;i<=a;i++) {
			for(int j=10;j<=b;j++) {
				int c=j%10;
				int d=j/10;
				if(c>1&&d>1&&c*d==i) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string str; cin >> str;
    ll k; cin >> k;

    ll n = str.length();

    char before;
    vector<ll> vcnt;
    ll index = 0;
    rep(i, n){
        if(i == 0){
            before = str[i];
            vcnt.push_back(1);
        }
        else if(before == str[i]){
            vcnt[index]++;
        }
        else{
            before = str[i];
            vcnt.push_back(1);
            index++;
        }
    }

    // cout << endl;
    // rep(i, vcnt.size()){
    //     cout << vcnt[i] << endl;
    // }

    ll ans = 0;
    rep(i, vcnt.size()){
        if(vcnt[i] >= 2){
            ans += vcnt[i] / 2;
        }
    }
    ans *= k;

    if(str[0] == str[n-1]){
        if(vcnt[0] % 2 == 1 && vcnt[vcnt.size()-1] % 2 == 1){
            ans += k - 1;
        }
    }

    if(n == 1){
        ans = k / 2;
    }

    map<char, int> mp;
    rep(i, n){
        mp[str[i]]++;
    }

    if(mp.size() == 1){
        ans = n * k / 2;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        ans += a[j] > a[i];
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3176
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;
const int MOD = 1e9+7;
typedef long long ll;

int main(){
    ll n,k,sum = 0,cnt;
    cin>>n>>k;
    for(int i = k;i <= n+1;i++){
        cnt = ((n-i+1)*i)%MOD+1;
        //cout<<"cnt = "<<cnt<<endl;
        sum = (sum+cnt)%MOD;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;
int n,k;
double a[222222];
double kit,cnt,ans;
signed main(void){
   cin>>n>>k;
   rep(i,n)cin>>a[i];
   rep(i,k){
       kit+=(1.0+a[i])*a[i]/2.0/a[i];
   }
   ans=kit;
   for(int i=k;i<n;i++){
       kit+=(1.0+a[i])*a[i]/2.0/a[i];
       kit-=(1.0+a[i-k])*a[i-k]/2.0/a[i-k];
       ans=max(ans,kit);
   }
  // cout<<ans<<endl;
   printf("%.8lf",ans);
}


Measured memory_bytes: 1792
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
a=list(map(int,input().split()))

d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1

b=[]
for i in d.values():
    b.append(i)

b.sort()
l=len(b)
if l<=k:
    print(0)
else:
    print(sum(b[0:l-k]))

Measured memory_bytes: 132724
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,M,y,p,ix;
int main(){
    cin >> N >> M;
    vector<pair<int,pair<int,int>>> city;
    vector<string> ans(M+1);
    rep(i,M) cin >> p >> y, city.pb(mp(p,mp(y,i+1)));
    sort(ALL(city));
    int k = 1;
    rep(i,M){
        int num = city[i].second.second;
        string ps = to_s(city[i].first); 
        string s = "";
        rep(i,6-sz(ps)) s += "0";
        s += ps;
        rep(i,6-sz(to_s(k))) s+="0";
        s += to_s(k);
        ans[num] = s;
        
        if(i < M-1 && city[i+1].first == city[i].first) ++k;
        else k = 1;
    }
    rep1(i,M) pr(ans[i]);
    
    
}

Measured memory_bytes: 9716
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;
 
int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}
 
 
// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }
 
bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}
 
 
int main() {
 
    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }
 
    return 0;
}
int clue() {
 
    
    int a,b,c;
    cin>>a>>b>>c;
 
    int x=c-a+b;
    if(x<0)x=0;
    cout<<x<<endl;
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3588
N=int(input())
A=list(map(int,input().split()))
count=0

for i in range(N):
    minj=i
    for j in range(i,N):
        if(A[j]<A[minj]):
            minj=j
    v=A[minj]
    A[minj]=A[i]
    A[i]=v
    if(minj!=i):
        count+=1
s=" ".join(map(str,A))
print(s)
print(count)


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;
  
  string message;
  if(left >  right) message = "Left";
  if(left <  right) message = "Right";
  if(left == right) message = "Balanced";
 
  cout << message << endl; 
}

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

int main() {
	int n;
  	int count =0;
	cin >> n;
    int a[n];
 	for(int i=0;i<n;i++){
		cin >> a[i];
	}
  	for(int i=0;;i++){
      bool amari=true;
	    for(int j=0;j<n;j++){
    	  if(a[j]%2 != 0){
           amari = false;
           break;
          }
          a[j]/=2;
   	 	}
      if(!amari)break;
      count++;
    }
  cout << count << endl;
}

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

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<ll> X{a,b};
    vector<ll> Y{c,d};
    ll ans=-1e18;
    rep(i,2){
        rep(j,2){
            ans = max(ans, X[i]*Y[j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=1000000000;
struct data{
	int l,r;
}a[410001];
struct tnode{
	int l,r,ls,rs,v;
}t[810001];
int i,j,k,n,m,b[410001],tot,ans;
void mt(int l,int r){
	int p=++tot,m;
	t[p].l=l;t[p].r=r;t[p].v=inf;
	if (l<r){
		m=(l+r)>>1;
		t[p].ls=tot+1;mt(l,m);
		t[p].rs=tot+1;mt(m+1,r);
	}else t[p].ls=t[p].rs=0;
}
void change(int p,int x,int v){
	int m=(t[p].l+t[p].r)>>1;
	t[p].v=min(v,t[p].v);
	if (!t[p].ls) return;
	change((x<=m)?t[p].ls:t[p].rs,x,v);
}
int query(int p,int l,int r){
	int res=inf,m=(t[p].l+t[p].r)>>1;
	if (l<=t[p].l&&t[p].r<=r) return t[p].v;
	if (l<=m) res=query(t[p].ls,l,r);
	if (r>=m+1) res=min(res,query(t[p].rs,l,r));
	return res;
}
bool cmp(data x,data y){
	return x.l<y.l||x.l==y.l&&x.r<y.r;
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&b[i]),ans+=1-b[i];
	tot=0;mt(1,n);scanf("%d",&m);
	for (i=1;i<=m;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+1+m,cmp);
	for (i=j=1;i<=n;i++){
		for (;j<=m&&a[j].l==i;j++) change(1,a[j].r,(i>1)?query(1,i-1,a[j].r):0);//,printf("** %d\n",j);
		change(1,i,((i>1)?query(1,i-1,i-1):0)+((b[i])?1:-1));
	}
	ans=ans+query(1,n,n);
	printf("%d\n",ans);
	return 0;
}

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

int SelectionSort(int a[],int n);

int main(){
    
    int a[1000],n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int count =SelectionSort(a,n);
    for(int i=0;i<n;i++){
        if(i)cout<<" ";//i!=0//0以外ならここが起動する
        cout<<a[i];
    }
    cout <<'\n';
    cout <<count<<'\n';

    return 0;
}

int SelectionSort(int a[],int n){
    int count=0;
    for(int i=0;i<n;i++){//未ソート部index 0からスタート
        int minj = i;
        for(int j=minj;j<n;j++){
            if(a[j]<a[minj]){ //minj 固定して
                minj=j;//より小さいのがあれば更新
            }
        }
        swap(a[i],a[minj]);
        if(i != minj)count +=1;
    }
    return count;
}

//未ソート部から最小の位置を特定する。
//最小の位置と未ソート部先頭を入れ替えて一回の処理が完了。これを繰り返す。


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

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  int cnt = 1;
  for (int i=0; i<n; i++)
    cin >> s.at(i);
  
  sort(s.begin(), s.end());
  
  for (int i=1; i<n; i++) {
    if (s.at(i) != s.at(i-1)) cnt++;
  }
  
  cout << cnt << endl;
}
  


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main()
{
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    cout << W * H / 2.0 << " ";
    if (W == 2 * x && H == 2 * y) {
        cout << "1";
    } else {
        cout << "0";
    }
    return 0;
}


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

namespace Atc_0042
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var A = int.Parse(S.Split(' ')[0]);
            var B = int.Parse(S.Split(' ')[1]);
            var C = int.Parse(S.Split(' ')[2]);

            if ((C - A) <= B && A <= C)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll A, B, Q;
    cin >> A >> B >> Q;
    ll xi;
    vector<ll> S, T;
    vector<ll> res;
    for(int i=0;i<A;i++){
        cin >> xi;
        S.push_back(xi);
    }
    for(int i=0;i<B;i++){
        cin >> xi;
        T.push_back(xi);
    }
    for(int i=0;i<Q;i++){
        cin >> xi;

        auto iS = lower_bound(S.begin(), S.end(), xi);
        auto iT = lower_bound(T.begin(), T.end(), xi);
        vector<ll> s, t;
        if     (iS == S.end())   {s.push_back(S.back());}
        else if(A == 1)          {s.push_back(S.back());}
        else if(iS == S.begin()) {s.push_back(*iS);}
        else                     {s.push_back(*iS); s.push_back(*prev(iS));}
        if     (iT == T.end())   {t.push_back(T.back());}
        else if(B == 1)          {t.push_back(T.back());}
        else if(iT == T.begin()) {t.push_back(*iT);}
        else                     {t.push_back(*iT); t.push_back(*prev(iT));}
        auto vmin = numeric_limits<ll>::max();
        for(auto v1 : s){
            for(auto v2 : t){
                vmin = min(vmin, abs(xi-v1) + abs(v1-v2) );
                vmin = min(vmin, abs(xi-v2) + abs(v1-v2) );
            }
        }
        res.push_back(vmin);
    }
    for(auto v : res) cout<<v<<endl;

    return 0;
}

Measured memory_bytes: 3828
N = int(input())
A = list(map(int, input().split()))
S = set()
sa = 0
for i in A:
    a = i // 400
    if a < 8:
        S.add(a)
    else:
        sa += 1
ans1 = max(len(S), 1)
ans2 = len(S) + sa
print(ans1, ans2)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
int n;
string s;
long long ans;
unordered_map<string,int> mp;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        ans+=mp[s];
        mp[s]++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";
#define INF INT_MAX

int N, M;

int main() {
	cin >> N >> M;
	vi a(M, 0);
	long long int total = 0;
	rep(i, M) {
		cin >> a[i];
		total += a[i];
	}

	if (total <= N) {
		cout << N - total;
	} else {
		cout << "-1";
	}

	return 0;
}

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

const double pi = 3.141592653589793238462643383279;
using namespace std;
using namespace __gnu_pbds;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const ll INF = -(1LL<<60);

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集
template<typename T = int> struct SegmentTree{

  vector<T> node;
  int N;

  SegmentTree(int n){
    N = 1;
    while(N < n) N*=2;
    node.resize(2*N-1, 0);
  }

  void update(int x, int val){
    x += N-1;
    
    node[x] = val;
    while(x > 0){
      x = (x-1)/2;
      node[x] = max(node[2*x+1], node[2*x+2]);
    }
  }

  // [a, b)について求める
  T getmax(int a, int b, int k=0, int l=0, int r=-1){

    if(r < 0) r = N;
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return node[k];
    
    T vl = getmax(a, b, 2*k+1, l, (l+r)/2);
    T vr = getmax(a, b, 2*k+2, (l+r)/2, r);
    return max(vl, vr);
  }


};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);

  ll N, K; cin >> N >> K;

  vector<ll> A(N);
  REP(i,N) cin >> A[i];

  SegmentTree<ll> seg(301010);
  REP(i,N){

    int que = seg.getmax(max(0LL, A[i]-K), A[i]+K+1) + 1;
    
    seg.update(A[i], que);
  }

  cout << seg.getmax(0, 301010) << endl;
  return 0; 
}

Measured memory_bytes: 13744
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

type node struct {
	value  int
	parent *node
	left   *node
	right  *node
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	var root *node
	m := eGetInt(reader)
	for i := 0; i < m; i++ {
		line := eGetline(reader)
		elements := strings.Fields(line)
		if len(elements) == 1 {
			// print
			var buffer bytes.Buffer
			printInOrder(root, &buffer)
			fmt.Println(buffer.String())
			buffer.Reset()

			printPreOrder(root, &buffer)
			fmt.Println(buffer.String())
			buffer.Reset()
		} else {
			val := eAtoi(elements[1])
			if strings.HasPrefix(line, "insert") {
				root = insert(root, val)
			} else if strings.HasPrefix(line, "find") {
				if find(root, val) {
					fmt.Println("yes")
				} else {
					fmt.Println("no")
				}
			}
		}
	}
}

func insert(root *node, value int) *node {
	var y *node
	x := root
	for x != nil {
		y = x // 親を覚えておく
		if value < x.value {
			x = x.left
		} else {
			x = x.right
		}
	}
	x = &node{value, y, nil, nil}
	if y == nil {
		return x
	} else if x.value < y.value {
		y.left = x
	} else {
		y.right = x
	}
	return root
}
func find(root *node, value int) bool {
	x := root
	for x != nil {
		if x.value == value {
			return true
		}

		if value < x.value {
			x = x.left
		} else {
			x = x.right
		}
	}
	return false
}

func printInOrder(root *node, buf *bytes.Buffer) {
	if root.left != nil {
		printInOrder(root.left, buf)
	}
	buf.WriteString(fmt.Sprintf(" %d", root.value))
	if root.right != nil {
		printInOrder(root.right, buf)
	}
}
func printPreOrder(root *node, buf *bytes.Buffer) {
	buf.WriteString(fmt.Sprintf(" %d", root.value))
	if root.left != nil {
		printPreOrder(root.left, buf)
	}
	if root.right != nil {
		printPreOrder(root.right, buf)
	}
}

func eGetInt(reader *bufio.Reader) int {
	return eAtoi(eGetline(reader))
}

func eGetline(o *bufio.Reader) string {
	s, err := o.ReadString(byte('\n'))
	if err != nil {
		if err == io.EOF {
			return s
		}
		log.Fatal(err.Error())
	}
	return strings.TrimRight(s, "\r\n")
}
func eAtoi(s string) int {
	v, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err.Error())
	}
	return v
}



Measured memory_bytes: 49796
import java.util.Scanner;

public class Main {

	static public String solve(String str){

		
		for(int i = 0; i < str.length(); i++){
			if(i > 0){
				if(str.charAt(i) == str.charAt(i-1))
					return (i) +" " + (i+1);
			}
			if(i > 1){
				if(str.charAt(i) == str.charAt(i-2)){
					return (i-1) + " " + (i+1);
				}
			}
		}
		return "-1 -1";
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String str = scanner.nextLine();

		System.out.println(solve(str));
		
	}

}


Measured memory_bytes: 13504
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = Integer.valueOf(String.valueOf(a) + String.valueOf(b));
        int d = Double.valueOf(Math.sqrt(c)).intValue();
        if (d * d == c) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=1e3+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
int a[maxn];
int ma[maxn][maxn],Tru[maxn],ans;
void update(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;++j){
            if(ma[i][j]==-1)continue;
            if(Tru[i]&&Tru[j]&&!ma[i][j])return;
            if(Tru[i]&&!Tru[j]&&ma[i][j])return;
        }
    }
    int S=0;
    for(int i=1;i<=n;++i)if(Tru[i])S++;
    ans=max(ans,S);return;
}
void doit(int x){
    if(x==n+1){update();return;}
    Tru[x]=0;doit(x+1);
    Tru[x]=1;doit(x+1);Tru[x]=0;
}
signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            ma[i][j]=-1;
        }
    }
    for(int i=1;i<=n;++i){
        int num=read();
        for(int j=1;j<=num;++j){
            ma[i][read()]=read();
        }
    }
    doit(1);
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int countDigit(int n)
{
  int digit = 1;
  while((n /= 10) != 0)
    digit++;
  return digit;
}

int main()
{
  int d,g; cin >> d >> g;
  vector<int> p,c;
  p.resize(d);c.resize(d);
  rep(i,d) cin >> p[i] >> c[i];
  int solve_ini = 10001;
  int point,solve = 0;
  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 0; bit < (1<<d); ++bit) { //1<<nでビットの桁数を指定
      point=0;
      solve = 0;
      for (int i = 0; i < d; ++i) { 
          if (bit & (1<<i)) { 
              point += p[i]*100*(i+1) + c[i];
              solve += p[i];
          }
      }
      if(point >= g) {
        chmin(solve_ini,solve);
        //cout << "Fbit:" << bitset<10>(bit) << ", solve:" << solve << ", point:" << point << endl;
        continue;
      }
      for (int i = d-1; i >=0; --i) { 
          if (!(bit & (1<<i))) { 
              rep(j,p[i]){
                point += (i+1)*100;
                ++solve;
                if(point >= g) {
                  chmin(solve_ini,solve);
                  //cout << "Lbit:" << bitset<10>(bit) << ", solve:" << solve << ", point:" << point << endl;
                  continue;
                }
              }
              continue; 
          }

      }
  }
  cout << solve_ini;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)

n = int(input())
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

dist1 = [-1]*n
dist1[0] = 0
dist2 = [-1]*n
dist2[n-1] = 0
def dfs(now,dist):
    for nxt in G[now]:
        if dist[nxt] != -1: continue
        dist[nxt] = dist[now]+1
        dfs(nxt,dist)
dfs(0,dist1)
dfs(n-1,dist2)

fennec = snuke = 0
for i in range(n):
    if dist1[i] <= dist2[i]: fennec += 1
    else: snuke += 1
print("Fennec" if fennec > snuke else "Snuke")

Measured memory_bytes: 117348
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,K;
	int i;
	int sum;
	while (cin>>N>>K){
		sum=1;
		for(i=0;i<N;i++){
			if(sum*2<sum+K)
			{
				sum*=2;
			}else if(sum*2>sum+K){
				sum+=K;
			}
			else
			sum*=2;
		}
		cout<<sum<<endl;
	}


	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    for(int i = 1;i < 10;i++){
      for(int j = 1;j < 10;j++){
        if(N == i * j){
          ans = 1;
        }
      }
    }
    if(ans == 1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}


Measured memory_bytes: 21844