akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    vector<vector<int64_t>> bingo(3, vector<int64_t>(3, 0));
    rep(j,3){
        rep(k,3){
            cin >> (bingo.at(j).at(k));
        }
    }
    int64_t n;
    cin >> n;
    vi b(n);
    rep(i,n) cin >> b.at(i);
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(bingo.at(j).at(k) == b.at(i)) bingo.at(j).at(k)=1;
            }
        }
    }
    string res = "No";
    rep(i,3){
        int64_t tmp = 0;
        rep(j,3){
            if(bingo.at(i).at(j)==1) tmp++;
        }
        if(tmp == 3) res = "Yes";
        tmp = 0;
        rep(j,3){
            if(bingo.at(j).at(i)==1) tmp++;
        }
        if(tmp == 3) res = "Yes";
    }
    if(bingo.at(0).at(0)+bingo.at(1).at(1)+bingo.at(2).at(2)==3) res = "Yes";
    if(bingo.at(0).at(2)+bingo.at(1).at(1)+bingo.at(2).at(0)==3) res = "Yes";
    cout << res << endl;
}


Measured memory_bytes: 256
import math

n, k = (int(i) for i in input().split())
alist = list(int(i) for i in input().split())
flist = list(int(i) for i in input().split())

alist=sorted(alist)
flist=sorted(flist, reverse=True)
low = 0
high = 10**12
t = (low + high) // 2

#print(alist)
#print(flist)

while (low<high):
    kaisu=0
    for i in range(n):
        wari=math.floor(t/flist[i])
        shugyo=max(alist[i]-wari,0)
        kaisu+=shugyo
    
    #print(t, kaisu, k, low, high)
    if kaisu<k:
        high=t
    elif kaisu>k:
        low=t+1
    elif kaisu==k:
        high=t #?
    if low<high:
        t=(low+high)//2
    
print(low)

Measured memory_bytes: 123084
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n; cin >> n;
  ll m = 1e18;
  rep(i, 5) {
    ll x; cin >> x;
    m = min(m, x);
  }
  cout << n/m+4 + (n%m > 0) << endl;
}


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

using namespace std;

using ll = long long;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define INF 1e9

int main(void)
{
    int n, s[105], sum = 0, i;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> s[i];
        sum += s[i];
    }

    sort(s, s + n);

    if(sum % 10 == 0){
        for(i = 0; i < n; i++){
            if(s[i] % 10 != 0){
                sum -= s[i];
                break;
            }
        }

        if(i != n){
            cout << sum << endl;
        }
        else{
            cout << "0" << endl;
        }   
    }
    else{
        cout << sum << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define PI 3.14159265358979323846264338327950L
 
int main(){
 
  int a,b;
  int h,m;
  scanf("%d%d%d%d",&a, &b, &h, &m);
 
  long double angle =  30*h + 0.5*(long double)m - (double)m * 6 ;
  long double rad;
    //rad = (angle /180)* M_PI;
 
  //printf("%.10f ",h);
  long double ans = (long double)a*a + (long double)b*b - (long double)(2*a*b)*cosl(angle * (PI / 180));
  printf("%20.20Lf\n",sqrtl(ans));
 
  return 0;
}

Measured memory_bytes: 2576
import itertools
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
min_t = float('inf')
for order in list(itertools.permutations([a,b,c,d,e],5)):
    t = 0
    for i in range(len(order)):
        t += order[i]
        if t % 10 != 0 and i != len(order) - 1:
            t = 10 * int(((t / 10) + 1))
    min_t = min(t, min_t)
print(min_t)

Measured memory_bytes: 3064
// D - Insertion
#include <bits/stdc++.h>
using namespace std;
#define ote(x) cout<<(x)<<endl

int main(){
	int _N; cin>>_N;//not used
	string S; cin>>S;
	int l = 0, r = 0;//r = depth
	for(char s:S){
		if(s == '(') r++;
		else{
			r--;
			if(r < 0){
				r = 0;
				l++;
			}
		}
	}
	ote(string(l,'(') + S + string(r,')'));
}

Measured memory_bytes: 256
class Point(object):
    x = 0.0
    y = 0.0
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __sub__(left, right):
        return Point(left.x - right.x, left.y - right.y)
    #cross
    def __mul__(left, right):
        return left.x * right.y - left.y * right.x

while True:
    try:
        (x1, y1, x2, y2, x3, y3, xp, yp) = map(float, raw_input().split())
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        pp = Point(xp, yp)
        p12 = p1 - p2
        p23 = p2 - p3
        p31 = p3 - p1
        pp1 = pp - p1
        pp2 = pp - p2
        pp3 = pp - p3
        c1 = (p12 * pp1 < 0.0)
        c2 = (p23 * pp2 < 0.0)
        c3 = (p31 * pp3 < 0.0)
        if(c1 ^ c2 or c2 ^ c3):
            print 'NO'
        else:
            print 'YES'
    except EOFError:
        break

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

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

    long long n; cin>>n; --n;
    long long h=1,i=26;
    for(; n>=i; h++)
    {
        n-=i;
        i*=26;
    }
    string ans;
    for(int j=0; j<h; j++)
    {
        i/=26;
        ans+='a'+n/i;
        n%=i;
    }
    cout << ans << "\n";




}

Measured memory_bytes: 3616
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]


def bfs(s,n,g):
    went = [False]*n
    dis = [0]*n
    que = deque([])
    que.append(s)
    went[s] = True
    while que:
        go = que.pop()
        for i in range(len(g[go])):
            if went[g[go][i]]:
                continue
            dis[g[go][i]] = dis[go] + 1
            went[g[go][i]] = True
            que.append(g[go][i])
    return dis

def main():
    n,u,v = inpm()
    g = [[] for _ in range(n)]
    g1 = [[] for _ in range(n)]
    ab = []
    for _ in range(n-1):
        a,b = inpm()
        a -= 1
        b -= 1
        g[b].append(a)
        g[a].append(b)
        ab.append((a,b))
    dis = bfs(u-1,n,g)
    path = [v-1]
    que = deque([])
    que.append(v-1)
    d = dis[v-1]-1
    while que:
        go = que.pop()
        for i in range(len(g[go])):
            if dis[g[go][i]] == d:
                d -= 1
                path.append(g[go][i])
                que.append(g[go][i])
    ans = int(len(path)/2)-1
    path.reverse()
    for i in range(n-1):
        if (ab[i][0],ab[i][1]) == (path[ans],path[ans+1]) or (ab[i][1],ab[i][0]) == (path[ans],path[ans+1]):
            continue
        g1[ab[i][0]].append(ab[i][1])
        g1[ab[i][1]].append(ab[i][0])
    dis1 = bfs(path[ans],n,g1)
    x = ans+max(dis1)
    if len(path)%2==1:
        x+=1    
    print(x)




if __name__ == "__main__":
    main()

Measured memory_bytes: 86396
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

// PMAMP :)
// INL , IIWOIL

int main()
{
    jaldi
    int n;
    cin>>n;
    vector<string> v(n);
    map<string,int> m;
    int mf=-1;
    for(string &s:v) 
    {
        cin>>s;
        m[s]++;
        mf=max(mf,m[s]);
    }
    set<string> s;
    for(string st:v)
    {
        if(m[st]==mf) s.insert(st);
    }
    for(string st:s) cout<<st<<endl;
    return 0;
}

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

int main(void){
  int A,B,C;
  cin >> A >> B >> C;
  bool flag = false;
  for(int i=0;i<B;i++){
    if(((A%B)*i)%B==C) flag = true;
  }
  cout << (flag ? "YES" : "NO") << endl;
  return 0;
}


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

const int mxn = 3001;
const int M = 1e9 + 7;

int n;
double ans;

int main() {
	ans = 0.0;
	cin >> n;
	vector<double> p(n);
	
	for(int i = 0; i < n; i++) {
		cin >> p[i];
	}
	vector<double> dp(n+1);
	dp[0] = 1.0;
	
	for(int i = 1; i <= n; i++) {
		vector<double> new_dp(n+1);
		for(int heads = 0; heads <= i; heads++) {
			if(heads == 0) {
				new_dp[heads] = dp[heads] * (1 - p[i-1]);
			}
			else new_dp[heads] = dp[heads] * (1 - p[i-1]) + dp[heads-1] * p[i-1];
		}
		dp = new_dp;
	}
	
	for(int i = 1; i <= n; i++) {
		if( i > (n-i)) {
			ans += dp[i];
		}
	}
	cout << setprecision(10);
	cout << ans << "\n";
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

bool prime_check(ll x){
	bool flag = true;
	ll sqx = sqrt(x)+1;
    for(ll j=2;j<sqx+1;j++){
    	if(x==j) continue;
        if(x%j==0){
            flag = false;
            break;
        }
    }
    return flag;
}

int main(){
	ll Q;
	cin >> Q;
	vector<ll> l(Q), r(Q);
	REP(i, Q) cin >> l[i] >> r[i];

	vector<ll> judge(101010);
	REP(i, 101010){
		if(i==0||i==1||i==2) judge[i] = 0;
		else{
			judge[i] = (prime_check(i) && prime_check((i+1)/2));
		}
	}
	vector<ll> judge_sum(101011);
	judge_sum[0] = 0;
	REP(i, 101010) judge_sum[i+1] = judge_sum[i] + judge[i];

	REP(i, Q){
		cout << judge_sum[r[i]+1] - judge_sum[l[i]] << endl;
	}
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;

bool isInteger(double x) {
	return floor(x) == x;
}

int main() {
	int N, D; cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(0));
	rep(i, N) {
		rep(j, D) {
			int x; cin >> x;
			X[i].push_back(x);
		}
	}

	int ans = 0;
	rep(i, N) {
		rep2(j, i + 1, N) {
			double distance = 0;
			rep(k, D) {
				distance += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			if (isInteger(sqrt(distance))) {
				//cout << distance << endl;
				++ans;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll
#define F first
#define S second

const int N = 41;
const int MOD = 1e9 + 7;
void add(int &a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int mult(int a, int b) {
	return (a * 1ll * b) % MOD;
}

const int MX = (1 << 18) + 10;
int dp[N][MX], pw[N];

bool c(int mask, int bit) {
	return (mask >> bit) & 1;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	pw[0] = 1;
	for (int i = 1; i <= n; i++) {
		pw[i] = mult(pw[i - 1], 10);
	}
	int sz = x + y + z + 1, all = (1 << sz) - 1;
	int ans = 0;
	dp[0][1] = 1;
	for (int i = 0; i < n; i++) {
		for (int mask = 0; mask < (1 << sz); mask++) {
			if (c(mask, x) && c(mask, x + y) && c(mask, x + y + z)) {
				add(ans, mult(dp[i][mask], pw[n - i]));
				continue;
			}
			for (int take = 1; take <= 10; take++) {
				add(dp[i + 1][((mask << take) | (1 << take)) & all], dp[i][mask]);
			}
		}
	}
	for (int mask = 0; mask < (1 << sz); mask++) {
		if (c(mask, x) && c(mask, x + y) && c(mask, x + y + z)) {
			add(ans, dp[n][mask]);
		}
	}
	cout << ans << '\n';
}

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

using namespace std;

int main()
{
    int M, N, X, ans = -1;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    for (int bit = 0; bit < (1 << N); bit++)
    {
        bool clear = true;
        int money = 0;
        vector<int> B(M, 0);
        for (int i = 0; i < N; i++)
        {
            if (bit & (1 << i))
            {
                money += C[i];
                for (int j = 0; j < M; j++)
                    B[j] += A[i][j];
                
            }
        }

        for (int j = 0; j < M; j++)
            if (B[j] < X)
                clear = false;

        if (clear)
        {
            if (ans == -1)
                ans = money;
            else
                ans = min(ans, money);
        }
    }

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


Measured memory_bytes: 3632
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	if (N == 0) {
		out << 0 << endl;
		return 0;
	}
	std::string res;
	while (N != 0) {
		if (N%-2!=0) {
			N -= 1;//(-2)^0の桁に1を立てる -> Nの上の桁は残りN-1だけ表せば良い
			res += '1';
		}
		else {
			res += '0';
		}
		N /= -2;
	}
	std::reverse(res.begin(), res.end());
	out << res << endl;


	return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	int num1, num2;
	
	char c;
	
	cin >> num1;
	
	while(true){
		cin >> c;
		if(c == '='){
			break;
		}
		cin >> num2;
		if(c == '+'){
			num1 += num2;
		}else if(c == '-'){
			num1 -= num2;
		}else if(c == '*'){
			num1 *= num2;
		}else if(c == '/'){
			num1 /= num2;
		}
	}
	
	printf("%d\n", num1);
	
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int a, b;
    cin >> a >> b;
    repi(i, 2001) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            put(i);
            return 0;
        }
    }

    put(-1)
    
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
int n, t[1005], a[1005], ta = 1, mu = 1, iwa;
signed main() {
	cin >> n;
	rep(i,n) {
		cin >> t[i] >> a[i];
	}
	ta = t[0];
	mu = a[0];
	for (int i = 1; i < n; i++) {
		iwa = max(ta / t[i], mu / a[i]);
		if (t[i] * iwa>= ta && a[i] * iwa >= mu) {
			ta = t[i] * iwa;
			mu = a[i] * iwa;
		}
		else {
		ta = t[i] * (iwa + 1);
		mu = a[i] * (iwa + 1);
		}
	}
	cout << ta + mu << endl;
	endre;
}

Measured memory_bytes: 256
n = int(input())
p = [int(x) for x in input().split(' ')]

cnt = 0

for a in range(n-2) :
    x = [p[a], p[a+1], p[a+2]]
    x.sort()
    if(x[1] == p[a+1]) :
        cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}

void solve(){
	int n;
	cin>>n;
	if(n%1000==0)cout<<0;
	else cout<<1000-(n%1000);
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	while(numberofsubtestcases--){
		solve();
	}
}




Measured memory_bytes: 3632
#include<iostream>
using namespace std;
#define MAX 100
void SelectionSort(int x[],int n);

int main(){
	int i,N;
	int x[MAX] = {0} ;
	
	cin >> N ;

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

	SelectionSort(x,N);
	return 0;

}

void SelectionSort(int x[],int n){
	int i,j,tmp,count=0,mini;

	for(i=0;i<n;i++){
		mini = i ;
		for(j=i;j<n;j++){
			if(x[j] < x[mini]){
				if(mini == i) count++;
				mini = j ;
			}

		}

		tmp = x[i] ;
		x[i] = x[mini] ;
		x[mini] = tmp ;
	}

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

	if(i<(n-1))cout << x[i] << ' ' ;
	if(i == (n-1))cout << x[i] << endl ;

	}
	
	cout << count << endl ;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define F first
//#define S second
//#define T second.first
//#define C second.second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pair<int,int>> piii;

const int N= 1e5+5, L = 14, OO = 0x3f3f3f3f;
const ll M=10 ;
const double ESP = 1e-8;


int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,h,a,b,x,y;
    cin>>n>>h;
    a = 0,b=0;
    int A[n],B[N];
    for(int i=0; i<n; i++){
        cin>>A[i]>>B[i];
    }
    int cnt = 0;
    sort(A,A+n, greater<ll>());
    sort(B, B+n,greater<ll>());
    a = A[0];
    for(int i=0; i<n; i++){
        if(h<=0){
            cout<<cnt<<endl;
            return 0;
        }
        if(B[i]>a){
            h-=B[i];cnt++;
        }
        else
            break;
    }
    if(h<=0)
        cout<<cnt;
    else{
        if(h%a)
            cnt++;
        cout<<cnt+(h/a)<<endl;
    }
}
/*
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i, m) cin >> p[i].second >> p[i].first;
  sort(all(p));
  ll ans = 0, now = 0;
  rep(i, m) {
    if(p[i].second <= now) continue;
    ans++;
    now = p[i].first - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
    int n;
    int tmp;
    int sum=0;
    cin >> n;
    for(int max = 1; max <= n; max++){
        sum=0;
        for(int i = 1; i*i <= max; i++){
            for(int j = i; j*j <= max; j++){
                for(int k = j; k*k <= max; k++){
                    //cout << (pow(i+j+k,2)-(i*j+j*k+k*i)) << " ";
                    tmp = pow(i+j+k,2)-(i*j+j*k+k*i);
                    if(tmp == max){
                        if(i == j && i == k)sum++;
                        else if(i != j && i != k&& j != k)sum += 6;
                        else sum += 3;
                    }else if(tmp > max) break;
                }
            }
        }
        cout << sum << endl;

    }

    //cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3560
<?php
    fscanf(STDIN, "%s", $s);
    $result = '';
    if($s == 'Sunny'){
        $result = 'Cloudy';
    }elseif($s == 'Cloudy'){
        $result =  'Rainy';
    }elseif($s == 'Rainy'){
        $result = 'Sunny';
    }
    echo $result;
  ?>

Measured memory_bytes: 3576
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        d = b[i] - a[i]

        if a[i + 1] < d:
            count += a[i + 1]
            a[i + 1] = 0
        else:
            count += d
            a[i + 1] -= d

    else:
        count += b[i]

print(count)


Measured memory_bytes: 19116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
using namespace std;

int main()
{
  long long n, sum = 0, nsum = 0;

  cin >> n;

  int v[n][2];

  for(int i = 0; i < 2; i++)
  {
    for(int l = 0; l < n; l++)
    {
      cin >> v[l][i];
    }
  }

  for(int i = 0; i < n; i++)
  {
    long long tmp = v[i][0] - v[i][1];
    if(tmp > 0)
    {
      sum += tmp;
      // cout << "sum: " << sum << "tmp: " << tmp;
    }

    else if(tmp < 0)
    {
      nsum += tmp / 2;
      // cout << "nsum: " << sum << "tmp: " << tmp;
    }

  }

  // cout << "nsum: " << nsum << "  sum: " << sum << endl;

  if(abs(nsum) >= sum)
  {
    cout << "Yes" <<endl;
  }
  else
  {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 384
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static int n;
	
	static boolean q(int... a)
	{
		assert a.length == n;
		out.print("?");
		for(int v : a){
			out.print(" " + (v+1));
		}
		out.println();
		out.flush();
		return in.next().trim().equals("Red");
	}
	
	static boolean qq(int k)
	{
		int[] a = new int[n];
		for(int j = 0;j < n;j++){
			a[j] = (k+j) % (2*n);
		}
		return q(a);
	}
	
	static void solve()
	{
		n = ni();
		int l, r;
		if(!qq(0)){
			l = 0;
			r = n;
		}else{
			l = n;
			r = 2*n;
		}
		while(r - l > 1){
			int h = r+l>>1;
			if(qq(h)){
				r = h;
			}else{
				l = h;
			}
		}
		int tar = l;
		
		int[] color = new int[2*n];
		// f -> t
		// tar = blue, tar+n = red
		color[tar] = -1; 
		color[(tar+n)%(2*n)] = 1;
		for(int k = 1;k < n;k++){
			int[] a = new int[n];
			for(int j = 0;j < n;j++){
				a[j] = (tar+j) % (2*n);
				if(j == k){
					a[j] = (tar+n) % (2*n);
				}
			}
			if(q(a)){
				color[(tar+k) % (2*n)] = -1;
			}else{
				color[(tar+k) % (2*n)] = 1;
			}
		}
		for(int k = 1;k < n;k++){
			int[] a = new int[n];
			for(int j = 0;j < n;j++){
				a[j] = (tar+n+j) % (2*n);
				if(j == k){
					a[j] = tar;
				}
			}
			if(q(a)){
				color[(tar+n+k) % (2*n)] = -1;
			}else{
				color[(tar+n+k) % (2*n)] = 1;
			}
		}
		out.print("! ");
		for(int i = 0;i < 2*n;i++){
			out.print(color[i] == 1 ? 'R' : 'B');
		}
		out.println();
		out.flush();
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 26788
'use strict'

function main(input) {
  input = input.split('\n')
  const n = ~~input[0]
  const h = input[1].split(/\s/).map(v => ~~v)

  let cnt = 0
  let stack = [h]

  //0. 配列をstackにつむ、
  //1 .stack から取り出し　すべての要素が　1 以上なら
  //  - 1してstackに戻す
  //  cnt++ > 1へ
  //2. 0があったらそこを基準に分割
  //3.分割したものをまたstackに積む
  //4.繰り返す > 1へ

  while (true) {
    if (stack.length > 0) {
      let tmp = stack.shift()
      // console.log(tmp)
      //全ての値が1以上だったら
      if (tmp.every(v => v > 0)) {
        stack.push(tmp.map(v => v - 1))
        cnt++
      } else {
        let p = tmp.indexOf(0)
        if (p > 0) stack.push(tmp.slice(0, p))
        if (p + 1 < tmp.length) stack.push(tmp.slice(p + 1, tmp.length))
      }
    } else {
      console.log(cnt)
      return
    }
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 8388
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto ab = readln.split.map!(to!int);
	while (1) {
		bool f;
		foreach (y; ab[0]..ab[1]+1) {
			if (isLeapYear(y)) {
				y.writeln;
				f = 1;
			}
		}
		if (!f) writeln("NA");
		ab = readln.split.map!(to!int);
		if (ab[0] + ab[1] == 0) break;
		writeln("");
	}
}

bool isLeapYear(int year) {
	if (year % 4) return 0;
	if (year % 400 == 0) return 1;
	if (year % 100 == 0) return 0;
	return 1;
}

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

int main()
{
    int n, m;
    cin >> n;
    m = n / 10;
    m = m * 10;
    n = n - m;

    if (n == 3)
    {
        cout << "bon";
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8)
    {
        cout << "pon";
    }
    else
    {
        cout << "hon";
    }
    return 0;
}

Measured memory_bytes: 3676
use std::io::*;
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<i64>();
    println!("{}",max(max(v[0]+v[1],v[0]-v[1]),v[0]*v[1]));
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void)
{
    int i,a,min,max;
    int b[10000];
    long long sum;
   
    sum = 0;
    min = 1000000;
    max = -1000000;
 
    scanf("%d",&a);
 
    for(i=0;i<a;i++)
    {
        scanf("%d", &b[i]);
 
        if(b[i] < min)
        {
            min = b[i];
        }
        if(b[i] > max)
        {
            max = b[i];
        }
 
        sum = sum + b[i];
    }
 
    printf("%d %d %lld\n",min,max,sum);
 
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int a,b,c;
      cin>>a>>b>>c;
      if(a+b+c>=22)cout<<"bust";
      else cout<<"win";
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
//#include "unordered_map"
//#include "unordered_set"
#include "iomanip"
#include "cmath"
//#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
const int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;

//const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> K;
	}
	for (int i = 0; i < N; i++)cin >> K;
	cin >> K;
	for (int i = 0; i < K; i++)cout << -1 << endl;
}


Measured memory_bytes: 1000
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	if(((S.find("N")==-1)^(S.find("S")==-1))||((S.find("E")==-1)^(S.find("W")==-1))){
		prin("No");
	}
	else prin("Yes");
	return 0;
}


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

/* -128 ~ 127 */
using i8  = int8_t;
/* 0 ~ 255 */
using u8  = uint8_t;
/* -32,768 ~ 32,767 */
using i16 = int16_t;
/* 0 ~ 65,535 */
using u16 = uint16_t;
/* -2,147,483,648 ~ 2,147,483,647 */
using i32 = int32_t;
/* 0 ~ 4,294,967,295 */
using u32 = uint32_t;
/* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using i64 = int64_t;
/* 0 ~ 18,446,744,073,709,551,615 */
using u64 = uint64_t;
/* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f32 = float;
/* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f64 = double;
using f80 = __float80;

template <class T>
using Vec = vector<T>;

template <typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

/* 定数 */
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1000000007;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

void Main() {
    u32 N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    Vec<u32> a(N, 0);
    for (int i = 1; i < N; i++) {
        if(S[i - 1] == 'A' && S[i] == 'C') {
            a[i] = 1;
        }
    }
    Vec<u32> s(N + 1, 0);
    for (int i = 0; i < N; i++) s[i + 1] = s[i] + a[i];
    for (int i = 0; i < Q; i++) {
        u32 l, r;
        cin >> l >> r;
        cout << s[r] - s[l] << endl;
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}




Measured memory_bytes: 1872
//---------------------------
// AOJ???????????¬???
// made by Kevin
// 2015/6/19
//---------------------------
 
#include <stdio.h>
 
int main(void)
{
    int in_second;//??\??????????????????S 
    int out_hour, out_minute, out_second;//?????????h:m:s
 
    //??\???
    scanf("%d", &in_second);
 
    //?????????????¨????
    out_second = in_second % 60; 
    out_minute = (in_second /60) % 60; 
    out_hour = (in_second / 60) /60;
 
    //??????
    printf("%d:%d:%d\n", out_hour, out_minute, out_second);
 
    return 0;
}

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

int main(){
  ll a,b; cin >> a >> b;
  vector<ll> aa,bb;
  int al=sqrt(a); int bl=sqrt(b);
  
  for(int j=2; j<=al; j++){
      if(a%j==0){
          aa.push_back(j);
          a/=j;
      while(a%j==0) a/=j;
      }
  }
  if(a!=1) aa.push_back(a);

vector<ll> ans;

  for(int j=2; j<=bl; j++){
      if(b%j==0){
          b/=j;
          rep(i,aa.size()){
              if(aa[i]==j){
                ans.push_back(j);
                break;
              }
          }
      while(b%j==0) b/=j;
      }
  }
  if(b!=1){
      rep(i,aa.size()){
              if(aa[i]==b){
                ans.push_back(b);
                break;
              }
       }
  }
  cout << ans.size()+1 << endl;
  
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
ll f[2009],ans=0;
ll pow1(ll a,int b)
{
    ll res=1;
    while(b)
    {
        if(b%2)
            res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res;
}
int main()
{
    int s;
    ll ans=0;
    cin>>s;
    f[0]=1;
    for(int i=1;i<=s;i++)
        f[i]=f[i-1]*i%mod;
    for(int i=1;i<=s/3;i++)
    {
        ans=(ans+f[s-2*i-1]*pow1(f[i-1],mod-2)%mod*pow1(f[s-3*i],mod-2))%mod;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3772
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

bool solve(int s, int g, int[] ns) {
    auto N = ns.length;
    auto DP = new bool[][](N+1, 8000*2+1);
    void sv(int i, int n) {
        if (!DP[i][n]) {
            DP[i][n] = true;
            if (i == N) return;
            sv(i+1, n+ns[i]);
            sv(i+1, n-ns[i]);
        }
    }
    sv(0, s+8000);
    return DP[N][g+8000];
}

void main()
{
    int[] xs, ys;
    int n, t;
    auto s = readln.chomp;
    foreach (c; s) {
        if (c == 'T') {
            if (n != 0) {
                if (t%2 == 0) {
                    xs ~= n;
                } else {
                    ys ~= n;
                }
                n = 0;
            }
            ++t;
        } else {
            ++n;
        }
    }
    if (n != 0) {
        if (t%2 == 0) {
            xs ~= n;
        } else {
            ys ~= n;
        }
    }
    int x;
    if (s[0] != 'T') {
        x = xs[0];
        xs = xs[1..$];
    }

    auto xy = readln.split.to!(int[]);
    auto gx = xy[0];
    auto gy = xy[1];

    writeln(solve(x, gx, xs) && solve(0, gy, ys) ? "Yes" : "No");
}

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

using namespace std;
#define K 100010
#define N 110

int a[N],dp[K];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<a[0];i++)
        dp[i]=0;
    dp[a[0]]=1;
    int check;
    int l=0;
    for(int i=a[0];i<=k;i++){
       
        if(l<n){ 
        if(i==a[l]){//cout<<a[l]<<endl;
            dp[i]=1;
            l++;
            continue;
        }}
        check=0;
        for(int j=0;j<n;j++){
            if(i-a[j]>0){
            if(dp[i-a[j]]==0){
                check=1;
                break;
            }}
        }
        dp[i]=check;
    }
   /* for(int i=0;i<=k;i++)
        cout<<dp[i]<<" ";
    cout<<endl;*/
    if(dp[k]==1)
        cout<<"First\n";
    else cout<<"Second\n";
}

Measured memory_bytes: 640
(defun main ()
  (let ((n (read))
        (a (make-array 0 :element-type 'integer
                         :adjustable t
                         :fill-pointer 0))
        (ans (make-array 0 :element-type 'integer
                           :adjustable t
                           :fill-pointer 0))
        temp
        (s 0))
    (dotimes (i n)
      (setf temp (read))
      (vector-push-extend temp a)
      (incf s temp))
    (loop for i from 1 upto (floor n 2)
          do (decf s (* 2 (aref a (1- (* 2 i))))))
    (vector-push-extend s ans)
    (loop for i from 1 below n
          do (vector-push-extend (- (* 2 (aref a (1- i))) (aref ans (1- i))) ans))
    (dotimes (i (1- n))
      (format t "~A " (aref ans i)))
    (format t "~A~%" (aref ans (1- n)))))

(main)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	long long N; cin >> N;
	if (N % 2 == 1) {
		cout << 0;
		return 0;
	}

	long long pow5 = 5 * 2;
	long long ans = 0;
	while (true) {
		int num = N / pow5;
		if (num == 0)break;
		ans += N / pow5;
		pow5 *= 5;
	}
	cout << ans;
}

Measured memory_bytes: 256
n=int(input())
m,M=[],[]
for i in range(n):
  a,b=map(int,input().split())
  m+=[a]
  M+=[b]
m.sort()
M.sort()
d=n//2
print(M[d]-m[d]+1+(M[d-1]+-m[d-1])*(1-n%2))

Measured memory_bytes: 25392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<ll> dp(100000, INF);
//dp.at(i)は足場i+1にたどり着く最小コスト

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  rep(i, N){
    cin >> h.at(i);
  }
  dp.at(0) = 0;
  rep(i, N){
    rep2(j, 1, min((int)K, i)+1){
      chmin(dp.at(i), dp.at(i-j)+abs(h.at(i)-h.at(i-j)));
    }
  }
  cout << dp.at(N-1) << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
  int v,i,j,q;
  int A[100],N;

  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]); //input number
    printf("%d",A[i]); //output number
    if(i != N-1) printf(" "); 
  }
  printf("\n");
  
  for(i=1;i<N;i++){ //insert A[i] into the soted sequence
    v = A[i]; 
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v; 
    for(q=0;q<N;q++){
      printf("%d",A[q]); 
      if(q != N-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    string s;
    cin >> s;

    int c = 0;
    for(int i=0; i<s.size(); i++){
        c += s[i] - '0';
    }

    if(c % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
    int x,a,b;
    cin>>x>>a>>b;

    if(b-a<=x)
        if(b-a<=0)
            cout<<"delicious"<<endl;
        else
            cout<<"safe"<<endl;
    else
        cout<<"dangerous"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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 pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
template<typename T>
struct SegmentTree{
private:
    int n;
    vector<T> node;
    T identity;
public:
    T merge(T x,T y){
        return max(x,y);
    }
    SegmentTree(vector<T> v,T id){
        int sz=(int)v.size();
        n=1; while(n<sz)n*=2;
        identity=id;
        node.resize(2*n-1,id);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--){
            node[i]=merge(node[2*i+1],node[2*i+2]);
        }
    }
    void update(int x,T val){
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=merge(node[2*x+1],node[2*x+2]);
        }
    }
    T query(int a,int b,int idx=0,int l=0,int r=-1){ /* get [a,b) */
        if(r<0) r=n;
        if(r<=a||b<=l) return identity;
        if(a<=l&&r<=b) return node[idx];
        T vl=query(a,b,2*idx+1,l,(l+r)/2);
        T vr=query(a,b,2*idx+2,(l+r)/2,r);
        return merge(vl,vr);
    };
    T operator[](int k){return node[k+n-1];}
};
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    int k; cin >> k;
    vector<int> dp(n,0);
    SegmentTree<int> seg(dp,0);
    vector<int> a(n);
    vector<int> b(n);
    vector<P> c(n);
    rep(i,n){
        cin >> a[i];
        b[i]=a[i];
        c[i].fi=a[i]; c[i].se=i;
    }
    sort(ALL(a));
    sort(ALL(c));
    vector<int> num(n);
    rep(i,n){
        num[c[i].se]=i;
    }
    rep(i,n){
        int lf=int(lower_bound(ALL(a),b[i]-k)-a.begin());
        int rf=int(upper_bound(ALL(a),b[i]+k)-a.begin());
        if(b[i]-k<=0) lf=0;
        if(a[n-1]<=b[i]+k) rf=n;
        //[lf,rf)
        if(lf>=rf){
            seg.update(num[i],1);
            continue;
        }
        int mx=seg.query(lf,rf);
        seg.update(num[i],mx+1);
    }
    //rep(i,n) cout << seg[i] << " ";
    cout << seg.query(0,n) << endl;
}




Measured memory_bytes: 14456
#include<iostream>
using namespace std;
int main()
{
	int n, x, l;
	cin >> n >> x;
	int tmp = 0, ans;

	if (x > 0) {
		ans = 1;
	}
	else {
		ans = 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> l;
		tmp += l;
		if (tmp <= x) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    short a = scan.nextShort();
    short b = scan.nextShort();
    int product = a * b;
    if ((product % 2) == 0) {
      System.out.println("Even");
    }else {
      System.out.println("Odd");
    }
  }
}


Measured memory_bytes: 21588
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = 0
min_dis = 10**10
ch = [0 for i in range(102)]
for i in range(len(p)):
    ch[p[i]] = 1
for i in range(102):
    idx = 101-i
    if ch[idx] == 0 and abs(x-idx) <= min_dis :
        min = idx
        min_dis = abs(x-idx)
print(min)


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

typedef pair<long long, long long> pairLL;
typedef vector<pairLL> resArr;

//#include <fstream>

int main(void)
{
	//ifstream fin("in.txt");
	istream& in=cin;
	resArr result;

	while(1)
	{
		int n;
		in >> n;
		if(n == 0)break;

		result.clear();

		for(int i=0; i<n; i++)
		{
			long long id, p, q;
			in >> id >> p >> q;

			resArr::iterator it;
			for(it=result.begin(); it!=result.end(); it++)
				if(it->first == id)
					break;
			
			if(it == result.end())
				result.push_back( pairLL(id, p*q) );
			else
				it->second += p*q;
		}

		bool exist=false;
		resArr::iterator it=result.begin();
		for(it; it!=result.end(); it++)
		{
			if((*it).second >= 1000000)
			{
				cout << (*it).first << endl;
				exist=true;
			}
		}
		if(!exist)
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <vector>

int main(){
    int myvector[3];
    std::cin >> myvector[0] >> myvector[1] >> myvector[2];
    std::sort (myvector, myvector+3);
    std::cout << myvector[2] - myvector[0];
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m,fa[100005],dis[100005];
bool flag=1;
int find(int x)
{
    if(fa[x]!=x)
	{
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++)
	{
        int l,r,d;
        cin>>l>>r>>d;
        int rl=find(l),rr=find(r);
        if (rl==rr&&dis[l]-dis[r]!=d) flag=0;
        if (rl!=rr)
		{
            fa[rl]=rr;
            dis[rl]=d+dis[r]-dis[l];
        }
    }
    if (flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
} 


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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;
using P = pair<int, int>;

signed main() {
	int n, m; cin >> n >> m;
	dsu d(n);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b; a--; b--;
		d.merge(a, b);
	}
	set<int>st;
	for (int i = 0; i < n; i++)st.insert(d.leader(i));
	cout << st.size() - 1 << endl;
	return 0;
}


Measured memory_bytes: 7784
#include<stdio.h>
int main(void)
{
    int a,b,sum,i,j;
    int P,J;
    a=2000;
    b=2000;
    for(i=1;i<=3;i++) {
        scanf("%d",&P);
            if(a>P) {
            a=P;
            }
    }
    for(j=1;j<=2;j++) {
        scanf("%d",&J);
            if(b>J) {
            b=J;
            }
    }
    sum=a+b-50;
    printf("%d\n",sum);
     
    return 0;
}


Measured memory_bytes: 2104
x, k, d = [int(x) for x in input().split()]
if x < 0: x = -x
jmps = x//d
if (jmps >= k):
    x = x - d*k
    print(x)
else:
    k -= (x//d)
    x = x - (x//d)*d

    if (k%2 == 0):
        print(x)
    else:
        print(d - x)

Measured memory_bytes: 61776
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x,y,X;
  X = 0;
  x=0,y=0;
  cin >> a >> b;
  char A[a][b];
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
       cin >> A[i][j];
    }
  }
   for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
       if(A[i][j] == '#'){
           cout << '#';
           X = 1;
       }else{
           for(int k=0;k<a;k++){
               if(A[k][j] == '#'){
                  x = 1;
                   break;
               }
           }
           for(int l=0;l<b;l++){
                  if(A[i][l] == '#'){
                    y = 1;
                    break;
                  }
            }
          if(x == 1 && y == 1){
              cout << '.';
              X = 1;
          }
          x = 0,y = 0;
        }
        }
        if(X != 0) cout << endl;
        X = 0;
    }
  }

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		if (a >= b) {
			System.out.println(getGCD(a, b));
		} else {
			System.out.println(getGCD(b, a));
		}
	}

	public static int getGCD(int a, int b) {
		if (a % b == 0) return b;
		else if (a < b) {
			return getGCD(a, b % a);
		}
		else return getGCD(b, a % b);
	}
}

Measured memory_bytes: 24432