akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

class UnionFind {
    vector<int> parent;

    public:
        UnionFind(int size) {
            parent = vector<int>(size, -1);
        }

        int find(int x) {
            if (parent[x] < 0) {
                // parent itself
                return x;
            } else {
                return parent[x] = find(parent[x]);
            }
        }

        bool unite(int x, int y) {
            int rX, rY;
            if ((rX = find(x)) == (rY = find(y))) {
                // already united
                return false;
            }
            if (size(rX) < size(rY)) {
                int tmp = rX;
                rX = rY;
                rY = tmp;
            }
            parent[rX] += parent[rY];
            parent[rY] = rX;
            return true;
        }

        int size(int x) {
            return -parent[find(x)];
        }

        bool is_same(int x, int y) {
            return find(x) == find(y);
        }

        // CAUTION!! : This method is heavy due to scanning linearly.
        int component_count() {
            int c = 0;
            for (const int x : parent) {
                if (x < 0) {
                    c++;
                }
            }
            return c;
        }
};

void solve() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int a, b;
    REP(i, m) {
        cin >> a >> b;
        uf.unite(a, b);
    }
    int q;
    cin >> q;
    REP(i, q) {
        cin >> a >> b;
        cout << (uf.is_same(a, b) ? "yes" : "no") << endl;
    }
}



Measured memory_bytes: 3244
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k, x, y;
    cin >> n >> k >> x >> y;

    if(n <= k) {
        out(x*n);
    }
    else {
        out(x*k + y*(n-k));
    }

    re0;
}

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


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n) cin >> a[i];

    b[0] = a[0];
    
    for(int i = 1; i < n; i++){
        b[i] = b[i - 1] + a[i];
    }
    
    ll ans = 1e12;
    
    rep(i,n-1){
        ans = min(ans,abs((b[n-1]-b[i]) - b[i]));
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}
int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); 
    for(int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        for(int weight_already = W - weight; weight_already >= 0; --weight_already) {
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= W; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 4016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
int le = (1 << 20) + 1;
vel BIT(le, 0);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	list = ql;
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int r, d, x; cin >> r >> d >> x;
	rep(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
main()
{
     long n;
     cin>>n;
     long a[n];
     long dp[1000000];
     for(long i=1;i<=n;i++)
     {
         cin>>a[i];
         //dp[i]=a[i];

     }
     dp[1]=0;
     dp[2]=abs(a[1]-a[2]);
     for(long i=3;i<=n;i++)
     {
         dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
     }
     cout<<dp[n];
}


Measured memory_bytes: 3840
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

bool f(string s) {
//	DD(s);
	ll N = s.size();
	REP(i, N/2) if(s[i]!=s[N-1-i]) return false;
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		ll N = s.size();
		string ans = f(s) && f(s.substr(0, (N-1)/2)) && f(s.substr((N+3)/2-1, N*2)) ? "Yes":"No";
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 888
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   string s,t;cin>>s>>t;
   int i,j;
   int mn=1e5;
   for(i=0;i<=(sz(s)-sz(t));i++)
   {
       j=0;
       int k=i;
       int cnt=0;
       while(j<sz(t))
       {
           if(s[k]!=t[j])cnt++;
           j++;k++;
       }
       mn=min(mn,cnt);
   }
   cout<<mn<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3640
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    string s;
    cin >> s;
    int n = s.size();
    string ans = "AC";
    if (s[0] != 'A') {
        ans = "WA";
    }
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (isupper(s[i])) {
            if (i == 1 || i == n-1 || s[i] != 'C') {
                ans = "WA";
            }
            cnt++;
        }
    }
    if (cnt != 1) ans = "WA";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		// solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		// N = 0;
		N = 3;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] a = new int[3];
	int[] b = new int[3];
	int[] p = new int[5];

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		a[cnt] = Integer.parseInt(strArr[0]);
		b[cnt] = Integer.parseInt(strArr[1]);
		p[a[cnt]]++;
		p[b[cnt]]++;
		cnt++;
	}

	public void solve() {
		// System.out.println(a[0] + " " + a[1] + " " + a[2]);
		// System.out.println(b[0] + " " + b[1] + " " + b[2]);
		for (int i = 1; i <= 4; i++) {
			if (p[i] > 2) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
int n,min=1000000001,max=0;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int j=0;j<n;j++)
    {if(min>a[j])
        min=a[j];
    if(max<a[j])
         max=a[j];
    }
    cout<<max-min;}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
 
using namespace std;

signed main() {
	int H, W;
	cin >> H >> W;

	int N;
	cin >> N;

	vector<int> a(N);
	rep(i, N) cin >> a[i];

	vector<vector<int>> board = vector<vector<int>>(H, vector<int>(W, 0));

	int pt = 1;
	rep(y, H) {
		if (y % 2) {
			rep(x, W) {
				board[y][x] = pt;
				a[pt - 1]--;
				if (a[pt - 1] == 0) pt++;
			}
		} else {
			for (int x = W - 1; x >= 0; x--) {
				board[y][x] = pt;
				a[pt - 1]--;
				if (a[pt - 1] == 0) pt++;
			}
		}
	}

	rep(y, H) {
		rep(x, W - 1) {
			cout << board[y][x] << ' ';
		}
		cout << board[y][W - 1] << endl;
	}

	return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;

    vector<i64> V(N),C(N);
    rep(i,0,N){
        cin >> V[i];
    }
    rep(i,0,N){
        cin >> C[i];
    }

    i64 ans=0;
    rep(i,0,N){
        ans+=max(V[i]-C[i],i64(0));
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

static int days[] = {
  0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30
};

static char* week[] = {
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday"
};

int main(void)
{
  int i;
  for (i=0; i<11; ++i) {
    days[i+1] += days[i];
  }

  int month, day;
  while (scanf("%d %d", &month, &day) != EOF) {
    if (month==0 && day==0) {
      break;
    }

    day += days[month-1];
    day += 2;
    day %= 7;

    printf("%s\n", week[day]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,a[N];
LL s[N];
int main(){
	n=read();
	for (int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	int ans=0;
	for (int i=n;i>=1;i--)
		if (s[i]*2<a[i+1])
			break;
		else
			ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 1408
/**
 * 長方形の中に円が含まれるかを判定するプログラムを作成してください。
 * 次のように、長方形は左下の頂点を原点とし、右上の頂点の座標 (W,H)  が与えられます。
 * また、円はその中心の座標 (x,y)  と半径 r  で与えられます
 * −100?x,y?100
 * 0<W,H,r?100

 * @author 前島佑介
 *@version 2014/12/1
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


// 2-D 長方形の中に円が含まれるかを判定するプログラムを作成してください。
class Main {

	// プログラムのエントリポイント
	public static void main(String[] args) {


		//右上の頂点の座標(W,H)のW
		int intW = 0;

		//右上の頂点の座標(W,H)のH
		int intH = 0;

		//円の中心の座標(x,y)のx
		int intX = 0;

		//円の中心の座標(x,y)のx
		int intY = 0;

		//半径ｒ
		int intR =0;

		try{
			//キーボードからの入力準備
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			//キーボードからの入力をString型で受け取る
			String strLine = br.readLine();

			//文字列の分割:入力値を" "で分ける
			//分けた文字列はstrLineAry[0]とstrLineAry[1]と?に分けられる
			String[] strLineAry = strLine.split(" ");

			//入力値の１つ目の値
			intW = Integer.parseInt(strLineAry[0]);

			//２つ目の値
			intH = Integer.parseInt(strLineAry[1]);

			//３つ目の値
			intX = Integer.parseInt(strLineAry[2]);

			//４つ目の値
			intY = Integer.parseInt(strLineAry[3]);

			//５つ目の値
			intR = Integer.parseInt(strLineAry[4]);

			//前提条件−100?x,y?100,0<W,r?100
			if(-100 <= intX || intY < 100 || 0 < intW || intR <= 100) {
				//問題なし
			} else {
				//上記でない場合はエラー出力
				System.out.println("−100?x,y?100,0<W,r?100です");
			}

			//x+r?W 円が右へはみ出さない条件
			if((intX + intR) <= intW &&

			//0?x-r 円が左へはみ出さない条件
			0 <= (intX -intR) &&

			//y+r?H 円が上へはみ出さない条件
			(intY + intR) <= intH &&

			//0?y-r 円が下へはみ出さない条件
			0 <= (intY - intR) ) {

				//上記は問題なし
				System.out.println("Yes");
			} else 	{

				//上記以外なら
				System.out.println("No");
			}


			//例外処理
			}catch(IOException e) {

				//例外時の出力
				System.out.println(e);

			}catch(NumberFormatException e) {

				//数値以外の入力値で出力
				System.out.println("数値で入力して下さい");
			}
	}
}

Measured memory_bytes: 17060
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[510];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	int L=0;
	int R=0;

	for(int i=0;i<a;i++){
		L=min(L,p[i]);
		R=max(R,p[i]);
	}
	vector<pair<int,int> > ans;
	if(ABS(L)<ABS(R)){
		int at=0;
		for(int i=0;i<a;i++){
			if(R==p[i]){
				at=i;
			}
		}
		for(int i=0;i<a;i++){
			ans.push_back(make_pair(at,i));
		}
		for(int i=0;i<a-1;i++){
			ans.push_back(make_pair(i,i+1));
		}
	}else{
		int at=0;
		for(int i=0;i<a;i++){
			if(L==p[i]){
				at=i;
			}
		}
		for(int i=0;i<a;i++){
			ans.push_back(make_pair(at,i));
		}
		for(int i=a-1;i>0;i--){
			ans.push_back(make_pair(i,i-1));
		}
	}
	printf("%d\n",ans.size());
	for(int i=0;i<ans.size();i++){
		printf("%d %d\n",ans[i].first+1,ans[i].second+1);
	}
}

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

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').Select(x => int.Parse(x)).ToList();

            var p = list[0];
            var q = list[1];
            var r = list[2];

            var total = list.OrderBy(x => x).Take(2).Sum();

            Console.WriteLine(total.ToString());
        }
    }
}


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

int main()
{
    using P = pair<int, int>;
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        vector<P> book(N);
        int read_sum = 0;
        int write_sum = 0;
        for (int i = 0; i < N; i++) {
            int r, w;
            cin >> r >> w;
            book[i] = make_pair(r, w);
            read_sum += r;
            write_sum += w;
        }
        sort(book.begin(), book.end());
        const int total = max(2 * book[N - 1].first, read_sum);
        const int mergin = total - read_sum;
        vector<vector<bool>> dp(N, vector<bool>(mergin + 1, false));
        dp[0][0] = true;
        for (int i = 0; i < N - 1; i++) {
            for (int w = 0; w <= mergin; w++) {
                dp[i + 1][w] = dp[i + 1][w] or dp[i][w];
                if (w + book[i].second <= mergin) {
                    dp[i + 1][w + book[i].second] = dp[i + 1][w + book[i].second] or dp[i][w];
                }
            }
        }

        int w = mergin;
        for (w = mergin; w >= 0; w--) {
            if (dp[N - 1][w]) {
                break;
            }
        }
        cout << write_sum + total - w << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	/*
	int n,i,a,b;
	cin>>n;
	vector<int> a(n,0),b(n,0);
	rep(i,n)cin>>a[i]>>b[i];
	*/
	ll a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	vector<ll> wa;
	vector<ll> su;
	ll answa=1,anssu=0;
	double nomax=-1;
	ll i,j;
	for(i=0;i<f;i++){
		for(j=0;j<f;j++){
			if(c*i+d*j<=f&&a*i+d*j>0){
				su.push_back(c*i+d*j);
			}
		}
	}
	
	for(i=0;i<f;i++){
		for(j=0;j<f;j++){
			if((a*i+b*j)*100<=f&&a*i+b*j>=0){
				wa.push_back((a*i+b*j)*100);
			}
		}
	}
	
	for(i=0;i<wa.size();i++){
		for(j=0;j<su.size();j++){
			
//			cout<<t<<endl;
			double m=(wa[i])*e/100;
			int s=su[j];
//			cout<<s<<" "<<m<<endl;
			if(s<=m){
				double per=(double)s/(wa[i]+s);
				if(nomax<=per&&wa[i]+s<=f){
					answa=wa[i];
				anssu=su[j];
				nomax=per;
				}
				
			}
		}
	}
	if(answa==1){
		answa=min(a,b)*100;
	}
	cout<<answa+anssu<<" "<<anssu<<endl;
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000009
#define pb push_back
#define endl '\n'
#define tez_chal ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)



const ll INF=1e9+7;

int solve()
{
 
  ll n;cin>>n;
  vector<ll>v(n),dp(n,INF);
  for(auto &i:v) cin>>i;
  dp[0]=0;
  for(ll i=1;i<n;i++){
  	for(ll j:{i-1,i-2} ){
  		if(j>=0){
  			dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
  		}
  	}
  }
  cout<<dp[n-1]<<endl;
 



return 0;
}


 








int main()
{  
    tez_chal;     ll t=1;  //cin>>t;
    
    while(t--) solve();

    // ll testcase=1;
    // while(t--){
    // 	cout<<"Case #"<<testcase++<<": ";
    // 	solve();
    // }

    return 0;
}




Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;main(){int f,i,m;string s;for(cin>>f;cin>>s;f?puts(f-2?"A":"B"):puts("NA")){f=0;for(i=1;s[0]+s[1]==101&(m=s.find(35))!=string::npos&s[m-i]==s[m+i];)m-++i-1|m+i-s.size()+1|s[m+i]-'~'||(f=1);for(i=2;s[0]+s[1]==156&s[i]==81&s[i+1]==61;)++++i-s.size()+2|s[i]+s[i+1]-252||(f=2);}}

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

int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(){
  int N, X;
  cin >> N >> X;
  int x[N];
  int ans = 0;
  for(int i = 0; i < N; i++){
    cin >> x[i];
    x[i] -= X;
    ans = gcd(ans, x[i]);
  }
  cout << abs(ans) << endl;
  return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
VI G[200011];
int C[200011];
int par[200011];

int sz[200011];
map<int, int> mp[200011];

LL tri(LL x) { return x * (x+1) / 2; }
LL ans[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", C+i), C[i]--;
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }

    VI que;
    que.reserve(N);
    que.push_back(0);
    REP (i, N) {
	int v = que[i];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    que.push_back(*e);
	}
    }

    REP (i, N) ans[i] = tri(N);

    REP (i, N) {
	int v = que[N-1-i];
	EACH (e, G[v]) if (*e != par[v]) {
	    auto it = mp[*e].find(C[v]);
	    if (it == mp[*e].end()) {
		ans[C[v]] -= tri(sz[*e]);
	    } else {
		ans[C[v]] -= tri(sz[*e] - it->second);
	    }
	}

	sz[v] = 1;
	EACH (e, G[v]) if (*e != par[v]) {
	    if (mp[*e].size() > mp[v].size()) {
		swap(mp[*e], mp[v]);
	    }
	    EACH (f, mp[*e]) {
		mp[v][f->first] += f->second;
	    }

	    sz[v] += sz[*e];
	}

	mp[v][C[v]] = sz[v];
    }

    REP (i, N) {
	auto it = mp[0].find(i);
	if (it == mp[0].end()) {
	    ans[i] = 0;
	} else {
	    ans[i] -= tri(N - it->second);
	}
    }
    REP (i, N) printf("%lld\n", ans[i]);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 67216
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n],b[n];
  rep(i,n) cin >> a[i] >> b[i];
  ll ans=0,sum=0;
  rrep(i,n) {
    ll x=(a[i]+sum)%b[i];
    if(x) x=b[i]-x;
    ans+=x;
    sum+=x;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

ll mx[200000],mn[200000],h[200000];
int n;
bool valid = true;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;mn[n+1] = INT_MAX;
    for(int i=1;i<=n;i++)cin>>h[i];
    for(int i=n;i>=1;i--){
        mn[i] = min(h[i],mn[i+1]);
    }

    for(int i=1;i<n;i++){
        ll z = mn[i+1];
        if(h[i]>z){
            if(h[i]-z >= 2){valid=false;break;}
        }
    }
    if(valid)cout<<"Yes\n";
    else cout<<"No\n";



}


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

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


int main() {
    string s,t; cin >> s >> t;
    sort(ALL(s));
    sort(ALL(t), greater<char>());

    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; i*j <= n; j ++) {
			ans += i * j;
		}
	}
	print(ans);
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

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

	var n int
	fmt.Fscan(r, &n)

	var e = make([]int, n)

	for x := 0; x < n; x++ {
		fmt.Fscan(r, &e[x])
	}

	a, c := selectionSort(e, n)
	fmt.Printf("%v\n%d\n", strings.Trim(fmt.Sprint(a), "[]"), c)
}

func selectionSort(e []int, n int) ([]int, int) {
	cnt := 0
	for i := 0; i < n; i++ {
		minj := i
		for j := i; j < n; j++ {
			if e[j] < e[minj] {
				minj = j
			}
		}
		if i != minj {
			tmp := e[i]
			e[i] = e[minj]
			e[minj] = tmp
			cnt++
		}
	}
	return e, cnt
}



Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] a = new String[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.next();
		}

		String[] b = new String[m];

		for (int i = 0; i < m; i++) {
			b[i] = sc.next();
		}

		for (int i = 0; i < n - m + 1; i++) {

			loop: for (int j = 0; j < n - m + 1; j++) {
				boolean flag = true;
				for (int k = 0; k < m; k++) {

					if (!(a[j + k].substring(i, i + m).equals(b[k]))) {
						flag = false;
						continue loop;
					}
				}
				if (flag == true) {
					System.out.println("Yes");
					System.exit(0);
				}

			}
		}

		System.out.println("No");
		sc.close();
	}
}


Measured memory_bytes: 23636
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Data.Bool

main :: IO ()
main = do
  [n, a, b] <- map read.words <$> getLine
  cs <- getLine
  putStr.unlines.map(bool"No""Yes")$solve a b cs

solve :: Int -> Int -> String -> [Bool]
solve a0 b0 cs = go 0 0 cs
  where
    go !ab !b ('a':cs)
      | ab < a0 + b0 = True : go (ab+1) b cs
      | otherwise = False : go ab b cs
    go !ab !b ('b':cs)
      | ab < a0 + b0, b < b0 = True : go (ab+1) (b+1) cs
      | otherwise = False : go ab b cs
    go !ab !b ('c':cs) = False : go ab b cs
    go _ _ (_:_) = undefined
    go _ _ [] = []

Measured memory_bytes: 5372
#!/usr/bin/env python3
from collections import Counter
import math

def make_prime_list(N):
    prime_list = [2]
    for i in range(3,int(N**0.5)+1,2):
        flag = True
        for j in range(3,int(i**0.5)+1):
            if i % j == 0:
                flag = False
                break
        if flag:
            prime_list.append(i)
    return prime_list

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())
    C = Counter(prime_factorize(N))
    # print(C)
    ans = 0
    for c in C.values():
        tmp = c
        i = 1
        while tmp >= i:
            tmp -= i
            ans += 1
            i += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9480
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

class ModInt(x: Long) {

    companion object {
        const val MOD = 1e9.toLong() + 7
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

val fac = mutableListOf<ModInt>()

fun fact(n: Long): ModInt {
    if (fac.count() == 0) fac.add(ModInt(1))
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
    }
    return fac[n.toInt()]
}

fun comb(n: Long, k: Long): ModInt {
    return fact(n) / fact(k) / fact(n - k)
}

fun comb2(n: Long, k: Long): ModInt {
    var ans = ModInt(1)
    for (i in 0 until k) {
        ans = ans * ModInt(n - i) / ModInt(k - i)
    }
    return ans
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    var ans = ModInt(0L)
    var s1 = (0L..n).take(k).sum()
    var s2 = (n downTo 0L).take(k).sum()
    for (i in k..n + 1) {
        ans += ModInt(s2 - s1 + 1)
        s1 += i
        s2 += n - i
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 47408
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 600006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , k;
int A[MAXN];

int T[MAXN << 2];
void mdfy( int rt , int l , int r , int x , int c ) {
	if( l == r ) { T[rt] = max( T[rt] , c ); return; }
	int m = l + r >> 1;
	if( x <= m ) mdfy( rt << 1 , l , m , x , c );
	else mdfy( rt << 1 | 1 , m + 1 , r , x , c );
	T[rt] = max( T[rt << 1] , T[rt << 1 | 1] );
}
int que( int rt , int l , int r , int L , int R ) {
	if( L <= l && R >= r ) return T[rt];
	int m = l + r >> 1 , ret = 0;
	if( L <= m ) ret = max( ret , que( rt << 1 , l , m , L , R ) );
	if( R > m ) ret = max( ret , que( rt << 1 | 1 , m + 1 , r , L , R ) );
	return ret;
}

int dp[MAXN];

void solve() {
	cin >> n >> k;
	rep( i , 1 , n ) scanf("%d",A + i);
	int rr = 6e5 + 3 , res = 0;
	rep( i , 1 , n ) {
		dp[i] = que( 1 , 0 , rr , max( A[i] - k , 0 ) , A[i] + k ) + 1;
		mdfy( 1 , 0 , rr , A[i] , dp[i] );
		res = max( res , dp[i] );
	}
	cout << res << endl;
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


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

long long dp[100];

int main()
{
    long long n,a,b,c,d,e,f,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        if(i==0)
        {
            dp[0]=a;
            dp[1]=b;
            dp[2]=c;
            continue;
        }
        d=dp[0];
        e=dp[1];
        f=dp[2];
        dp[0]=a+max(e,f);
        dp[1]=b+max(d,f);
        dp[2]=c+max(d,e);
    }
    cout<<max(dp[0],max(dp[1],dp[2]))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

int main(void)
{
    ll N;
    cin >> N;
    ll cnt = 0;
    vector<ll> factors(25, 0);
    REP(i, N) {
        ll n = i+1;
        REP(j, 25) {
            ll k = n;
            ll p = primes[j];
            while(k%p == 0) {
                factors[j]++;
                k /= p;
            }
        }
    }

    sort(factors.begin(), factors.end());
    ll m2 = 0, m4 = 0, m14 = 0, m24 = 0, m74 = 0;
    REP(i, 25) {
        if (factors[24 - i] >= 2)
            m2 = i+1;
        if (factors[24 - i] >= 4)
            m4 = i+1;
        if (factors[24 - i] >= 14)
            m14 = i + 1;
        if (factors[24 - i] >= 24)
            m24 = i + 1;
        if (factors[24 - i] >= 74)
            m74 = i + 1;
    }
    cnt = m4 * (m4 - 1) / 2 * max(0LL, m2 - 2);
    cnt += m14 * (m4 - 1);
    cnt += m24 * (m2 - 1);
    cnt += m74;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = 0;
        for (int i = 0; i < str.length(); i++) {
            n += Integer.parseInt(str.substring(i, i + 1));
        }
        if (n % 9 == 0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 49948
#include <stdio.h>

int main() {

  int a, b;
  scanf("%d %d", &a, &b);
  if(a < b) {
    printf("a < b\n");
  } else if(a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }
  
 return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

struct edge{
    int to,cost;
};
int v,e,r;

vector<edge> G[100010];
vector<int> d(100010,INF);

void dijkstra(){
    priority_queue<P> q;
    q.push(MP(0,r));
    while(!q.empty()){
        P p=q.top();
        q.pop();
        int now=p.se;
        int cost=-p.fi;
        if(cost>d[now]) continue;
        rep(i,0,G[now].size()){
            edge e=G[now][i];
            int to=e.to;
            int new_cost=cost+e.cost;
            if(new_cost<d[to]){
                d[to]=new_cost;
                q.push(MP(-d[to],to));
            }
        }
    }
}
int main(){
    cin>>v>>e>>r;
    d[r]=0;
    rep(i,0,e){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].pb(edge{b,c});
        //cout<<G[a][0].to<<" "<<G[a][0].cost<<endl;
    }
    dijkstra();
    rep(i,0,v){
        if(d[i]==INF)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 12956
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  for(int i=0;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      for(int k=0;k<100;++k) {
        if((i&(1<<k)) != (j&(1<<k))) {
          cout<<k+1<<" ";
          break;
        }
      }
    }
    cout<<endl;
  }
}



Measured memory_bytes: 3596
// Aizu 1159: Next Mayor
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <string.h>

int x[53];

int main()
{
	int n, p, k, m, ans;

	while (scanf("%d%d", &n, &p) && n) {
		m = p, k = 0;
		memset(x, 0, sizeof(x));
		while(1) {
			if (m > 0) x[k]++, m--;
			else m += x[k], x[k] = 0;
			if (x[k] == p){ ans = k; break; }
			k++, k %= n;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1728