akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
int main(void){int n;scanf("%d",&n);int m=(int)ceil((double)((-1+sqrt(1+8*n))/2));printf("%d\n",m);n-=m;while(n!=0){m--;if(n-m>=0){printf("%d\n",m);n-=m;}}}

Measured memory_bytes: 128
function Main(input) {
  input = input.split("\n");
  var r = parseInt(input[0].split(" ")[0]);
  var ans = "AGC";
  if(r<1200){
    ans = "ABC";
  }else if(r<2800){
    ans = "ARC";
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

int main()
{
    ll n, a[10000];
    cin >> n;
    REP(i, n)
    cin >> a[i];

    int ans = 0;
    REP(i, n)
    {
        if (a[i] % 2 == 0)
        {
            int cnt = 0;
            while (a[i] % 2 == 0)
            {

                a[i] /= 2;
                cnt++;
            }

            ans += cnt;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <math.h>

#define PI 3.141592

typedef struct{
  double x;
  double y;
} Point;

void kock(int,Point,Point);

int main(){
  
  Point p1={0.0 ,0.0},p2={100.0 ,0.0};
  int n;
  
  //in
  scanf("%d",&n);
  
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  
  return 0;
}

void kock(int n,Point p1,Point p2){
  Point s,t,u;
  
  double rad = (60*PI)/180.0;
  
  if(n==0) return ;
  
  //calc
  s.x = (2*p1.x+1*p2.x)/3.0;
  s.y = (2*p1.y+1*p2.y)/3.0;
  
  t.x = (1*p1.x+2*p2.x)/3.0;
  t.y = (1*p1.y+2*p2.y)/3.0;
  
  u.x = (t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
  u.y = (t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
  
  kock(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  kock(n-1,t,p2);

}

//memo:再起されるごとに関数のメモリが確保されるので、再起前の関数のデータは消えない

Measured memory_bytes: 636
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String s = sc.next();
		String t = sc.next();
		char[] a = s.toCharArray();
		char[] b = t.toCharArray();
		Arrays.sort(a);
		Arrays.sort(b);
		char[] c = new char[b.length];
		for (int i = 0; i < b.length; i++)
			c[i] = b[b.length - 1 - i];

		for (int i = 0; i < Math.min(a.length, c.length); i++) {
			if (a[i] < c[i]) {
				System.out.println("Yes");
				return;
			} else if (a[i] > c[i]) {
				System.out.println("No");
				return;
			}
		}
		if (a.length < c.length)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

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

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

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

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    vector<int> dp(n);
    /*
        dp[i] -> min cost to reach ith stone
        dp[0] -> 0
        dp[1] -> abs(h[1]-h[0])
        dp[2] -> abs(h[2]-h[0]), dp[1] + abs(h[1]-h[2])
    */
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),
                dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int duplicate_distance(int a, int b, int s, int t){
  return min(b,t) - max(a,s);
}
int main(){
  int n, m;
  cin >> n >> m;
  int ls, rs;
  bool flag = false;
  REP(i, m){
    int l, r;
    cin >> l >> r;
    if(i == 0){
      ls = l;
      rs = r;
      continue;
    }
    int d = duplicate_distance(ls, rs, l, r);
    if(d < 0) flag = true;
    int data[4] = {l, r, ls, rs};
    sort(data, data+4);
    ls = data[1];
    rs = data[2];
  }
  if(flag) cout << 0 << endl;
  else cout << rs - ls + 1 << endl;
}

Measured memory_bytes: 256
import sys

N = int(input())
A = map(int, sorted(input().split()))
count = 1

for i in A:
    count *= i

    if i == 0:
        print(0)
        sys.exit()
    elif count > 10 ** 18:
        print(-1)
        sys.exit()
    else:
        pass

print(count)

Measured memory_bytes: 19368
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = 0;
  ans += min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  k -= min(c, k);
  cout << ans << '\n';






  
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, m; cin >> n >> m;
    vector<vector<int>> adj(n + 10);
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        vector<int> pa(n + 10, 0);
        queue<int> q;
        for (int v : adj[i]) {
            q.push(v);
            pa[v] = i;
        }
        while (!q.empty()) {
            int v = q.front(); q.pop();
            if (v == i) {
                vector<int> all;
                all.push_back(i);
                v = pa[i];
                while (v != i) {
                    all.push_back(v);
                    v = pa[v];
                }
                if (ans.empty() || SZ(ans) > SZ(all)) {
                    ans = all;
                }
            }
            for (int u : adj[v]) {
                if (!pa[u]) {
                    pa[u] = v;
                    q.push(u);
                }
            }
        }
    }
    if (ans.empty()) {
        cout << "-1\n";
        exit(0);
    }
    cout << SZ(ans) << "\n";
    for (int x : ans) {
        cout << x << "\n";
    }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int cmp(const void* a,const void* b){return *(int*)a-*(int*)b;}

int main() {
  int N,L,i,ans=0;
  scanf("%d%d",&N,&L);
  if(L>0)ans=(N*(N+1))/2 + N*(L-1) - L;
  else if(L<0&&N+L<=0)ans=(N*(N+1))/2 + N*(L-1) - (N+L-1);
  else ans=(N*(N+1))/2 + N*(L-1);

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,ans;
void sgs(string s){
  if(s!=""&&stoll(s)>n) return;
  ll ss=s.size(),se=0,f=0,t=0;
  for(ll i=0;i<ss;i++){
    if(s[i]=='7') se++;
    if(s[i]=='5') f++;
    if(s[i]=='3') t++;
    if(se>=1&&f>=1&&t>=1){
      ans++;
      break;
    }
  }
  sgs(s+'7');
  sgs(s+'5');
  sgs(s+'3');
}
int main(){
  cin >>n;
  string s="";
  sgs(s);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#define re register
inline int read() {
	int s = 0; char ch = getchar(), f = ' ';
	while(ch < '0' || ch > '9') { if(ch == '-') f = '-'; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return f == '-' ? -s : s;
}
const int Max = 2e4 + 120;
int a, b, c;
int main() {
	a = read(); b = read();
	c = a - 2 * b;
	if(c > 0) printf("%d", c);
	else puts("0");
	return 0;
}

Measured memory_bytes: 128
const Main = (input) => {
  // 入力値の整形
  const inputArray = input.split('');
  const resultArray = inputArray
    .slice(0, inputArray.length - 2)
    .map((value, index) => {
      return value + inputArray[index + 1] + inputArray[index + 2];
    })
    .sort((a, b) => {
      return Math.abs(a - 753) - Math.abs(b - 753);
    });

  console.log(Math.abs(resultArray[0] - 753));
};

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

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

//INSERT ABOVE HERE
Int dp[200][200][200];
signed main(){
  Int a,b,c;
  cin>>a>>b>>c;
  const Int INF = 1e8;
  for(Int i=0;i<100;i++)
    for(Int j=0;j<100;j++)
      for(Int k=0;k<100;k++)
	dp[i][j][k]=INF;
  
  dp[a][b][c]=0;
  for(Int i=0;i<100;i++){
    for(Int j=0;j<100;j++){
      for(Int k=0;k<100;k++){
	chmin(dp[i+1][j+1][k],dp[i][j][k]+1);
	chmin(dp[i+1][j][k+1],dp[i][j][k]+1);
	chmin(dp[i][j+1][k+1],dp[i][j][k]+1);
	
	chmin(dp[i+2][j][k],dp[i][j][k]+1);
	chmin(dp[i][j+2][k],dp[i][j][k]+1);
	chmin(dp[i][j][k+2],dp[i][j][k]+1);
      }
    }
  }
	
  Int ans=INF;
  for(Int i=0;i<100;i++)
    chmin(ans,dp[i][i][i]);
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int a,b,s;
    cin>>a>>b;
    s=a+b;
    if(s%3==0)
        cout<<"Possible";
    else if(a%3==0||b%3==0)
        cout<<"Possible";

    else
        cout<<"Impossible";

 return 0;
}

Measured memory_bytes: 3552
/*
 * Code be weshen zyk :'(
 * I won't surrender quietly
 */
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 305, K = 205, MOD = 998244353;
const ll MX = 1e15;
vector<ii> banned[2][N + N][N + N];
int sq[800005];
int C[2][N + N][N + N];
void dfs(int i, int j, bool c, bool f) {
	if (~C[f][i][j])
		return;
	C[f][i][j] = c;
	for (auto x : banned[f][i][j]) {
		dfs(x.F, x.S, c ^ 1, f);
	}
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	memset(sq, -1, sizeof sq);
	for (int i = 0; i * i <= 800000; i++)
		sq[i * i] = i;

	int n, d1, d2;
	cin >> n >> d1 >> d2;

	set<ii> st;

	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++) {
			for (int ii = 0; ii <= 2 * n; ii++) {
				int tmp = (ii - i) * (ii - i);
				///tmp + (jj - j) * (jj - j) = d1
				///(jj - j) * (jj - j) = d1 - tmp
				if (d1 >= tmp) {
					int x = d1 - tmp;
					x = sq[x];
					if (~x) {
						///find jj such that (jj - j) = x, jj = x + j
						///or (j - jj) = x, j = jj + x, jj = j - x

						if (j - x < n + n && j - x >= 0)
							banned[0][i][j].pb( { ii, j - x });
						if (j + x < n + n && j + x >= 0)
							banned[0][i][j].pb( { ii, j + x });
					}
				}
				if (d2 >= tmp) {
					int x = d2 - tmp;
					x = sq[x];
					if (~x) {
						///find jj such that (jj - j) = x
						///or (j - jj) = x
						if (j - x < n + n && j - x >= 0)
							banned[1][i][j].pb( { ii, j - x });
						if (j + x < n + n && j + x >= 0)
							banned[1][i][j].pb( { ii, j + x });
					}
				}
			}
		}
	memset(C, -1, sizeof C);
	for (int i = 0; i < n + n; i++)
		for (int j = 0; j < n + n; j++) {
			if (C[0][i][j] == -1)
				dfs(i, j, 0, 0);
			if (C[1][i][j])
				dfs(i, j, 0, 1);
		}

	for(int f1 = 0; f1 < 2; f1++){
		for(int f2 = 0; f2 < 2; f2++){
			vector<ii> pts;
			for(int i = 0; i < n + n; i++){
				for(int j = 0; j < n + n; j++){
					if(C[0][i][j] == f1 && C[1][i][j] == f2)
						pts.pb({i, j});
				}
			}
			if(pts.size() >= n * n){
				for(int i = 0; i < n * n; i++){
					cout << pts[i].F << ' ' << pts[i].S << '\n';
				}
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 183540
N, M = map(int, input().split())
H = list(map(int, input().split()))
road = []
ans = [True for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1; B -= 1
    if H[A] < H[B]:
        ans[A] = False
    elif H[A] > H[B]:
        ans[B] = False
    else:
        ans[A] = False
        ans[B] = False

print(sum(ans))


Measured memory_bytes: 20116
N, K = map(int, input().split())

if N < K:
    if N <= K/2:
        print(N)
    else:
        print(K-N)

elif N == K:
    print(0)

else:
    N = K + (N - K) % K
    N = abs(N - K)

    if N < K:
        if N <= K/2:
            print(N)
        else:
            print(K-N)

    elif N == K:
        print(0)

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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = INT32_MAX;

int a[N];
int n;

int main() {
    ios_base::sync_with_stdio(false);

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
        cout<<"bust";
    else
        cout<<"win";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int N;
int main () {
    cin >> N;
    int d = 0;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        while(x&&x%2==0) x/=2,d++;
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    map <char,int> mp;
    for (int i = 0; i < (int)s.length(); i++) {
        mp[s[i]]++;
    }
    string ans = "Yes";
    for (int i = 0; i < (int)s.length(); i++) {
        if (mp[s[i]]%2) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
using System;
using System.Linq;

namespace ABC058
{
    class C
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] count = new int[26, n];
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < s.Length; j++)
                {
                    count[s[j] - 'a', i]++;
                }
            }

            int[] res = new int[26].Select(x => x = 1000000).ToArray();
            for (int i = 0; i < 26; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (count[i, j] == 0) { res[i] = 0; break; }
                    else res[i] = Math.Min(res[i], count[i, j]);
                }
            }

            string ans = "";
            for (int i = 0; i < 26; i++)
            {
                if (res[i] != 0 && res[i] < 1000000)
                {
                    for (int j = 0; j < res[i]; j++)
                    {
                        ans += (char)(i + 'a');
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
    char c;
    cin >> c;

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 3612
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        distance = 0
        for k in range(D):
            distance += pow(abs(X[i][k] - X[j][k]), 2)
        if int(sqrt(distance)) == sqrt(distance):
            cnt += 1
print(cnt)

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

signed main(void)
{
	int n, tmp, sum;
	cin >> n;

	sum = 0;
	tmp = n;
	while (tmp)
	{
		sum += tmp % 10;
		tmp /= 10;
	}
	if (n % sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
N,x = map(int,input().split())
As = list(map(int,input().split()))
As.sort()
cnt = 0
ans = 0
while x > 0:
    if cnt + 1 == N and x != As[cnt]:
        x = 0
    elif x >= As[cnt]:
        x -= As[cnt]
        ans+=1
    cnt += 1
else:
    print(ans)

Measured memory_bytes: 3060
INF=10**30
from heapq import heapify,heappop,heappush
N=int(input())
a=list(map(int,input().split()))

right=list(map(lambda x:-x,a[2*N:]));heapify(right)
rmin=[INF]*(3*N);rmin[2*N]=sum(right)*-1

for i in reversed(range(N,2*N)):
    p=heappop(right)*-1
    b=min(p,a[i])
    d=0 if b==p else b-p
    heappush(right,b*-1)
    rmin[i]=rmin[i+1]+d

left=a[:N];heapify(left)
lmax=[-INF]*(3*N);lmax[N-1]=sum(left)
for i in range(N,2*N):
    p=heappop(left)
    b=max(p,a[i])
    d=0 if b==p else b-p
    heappush(left,b)
    lmax[i]=lmax[i-1]+d
res=-INF
for i in range(N,2*N+1):
    res=max(res,lmax[i-1]-rmin[i])
print(res)

Measured memory_bytes: 119720
import numpy as np
N, K = tuple(map(int, input().split()))
mod = 1000000007

m = N ** 0.5
cnt = [N // i - N // (i + 1) for i in range(1, int(m) + 1)] 
cnt = np.array((cnt + [1 for _ in range(N - sum(cnt))])[::-1])
nxt = cnt[:]
for _ in range(K - 1):
    cnt = nxt * np.cumsum(cnt)[::-1] % mod

print(sum(cnt) % mod)


Measured memory_bytes: 21580
inf = float("inf")
class Node():

    def __init__(self, _id):
        self.id = _id
        self.d = inf
        self.pi = None
        self.color = 0
    
    def input_data(self):
        data = [int(i) for i in input().split()]
        self.adj = {G[i]: d
                    for i, d in enumerate(data)
                    if d != -1}
    
    def __hash__(self):
        return hash(self.id)
        
    

def prim():
    G[0].d = 0
    while True:
        mincost = inf
        for i in G:
            if i.color != 1 and i.d < mincost:
                mincost = i.d
                u = i
        
        if mincost == inf:
            break

        u.color = 1
        for v in u.adj.keys():
            if v.color != 1 and u.adj[v] < v.d:
                v.pi = u.id
                v.d = u.adj[v]

if __name__ == "__main__":
    n = int(input())
    G = [Node(i) for i in range(n)]
    [i.input_data() for i in G]
    prim()
    print(sum(g.d for g in G))


Measured memory_bytes: 6056
#include <stdio.h>
int main(void){
    int x,y;
   while(1){
       scanf("%d %d",&x,&y);
       if(x == 0 && y == 0) break;
       if(x >= y){
           printf("%d %d\n",y,x);
       }else{
           printf("%d %d\n",x,y);
       }
   }
    return 0;
}


Measured memory_bytes: 2032
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << (a * b) / __gcd(a, b) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 998244353;

string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    print(n==m?"Yes":"No");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int a = 0;	scanf("%d", &a);
	int b = 0;	scanf(" %d", &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: 2052
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, h;
    cin >> n >> h;
    vector<pair<ll, ll>> ab(n); // fi:a_i, se: b_is
    for (ll i = 0; i < n; i++)
    {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ALL(ab), [](const auto &a, const auto &b) { return a.first > b.first; });
    ll a_mx = ab[0].first; // aの最大値
    vector<ll> bb;
    for (ll i = 0; i < n; i++)
    {
        if (ab[i].second >= a_mx)
        {
            bb.push_back(ab[i].second);
        }
    }
    sort(bb.rbegin(), bb.rend());
    ll ans = 0;
    ll total = 0;
    for (ll i = 0; i < (ll)bb.size(); i++)
    {
        if (total < h)
        {
            ans++;
            total += bb[i];
        }
    }
    if (total < h)
    {

        ans += ceil(1.0 * (h - total) / a_mx);
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	Vi A(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> A[i];
		--A[i];
	}

	Vi p(N);
	for (int i = 0; i < Q; ++i) {
		++p[A[i]];
	}

	for (int i = 0; i < N; ++i) {
		bool is_ok = K - Q + p[i] > 0;
		cout << (is_ok ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
 
 public class Main {
   	public static void main (String arg[]){
      	Scanner in = new Scanner (System.in);
       	String s = in.nextLine();
      	String t = in.nextLine();
      	
       int count =0;
      for(int i =0; i<3; i++)
      	if (s.charAt(i)==t.charAt(i)){
          count++;
        }
      
      System.out.println(count);
      
      
    }
   
 }

Measured memory_bytes: 23380
import math
n = int(input())
l =[0 for i in range(6*n+1)]

for i in range(1,int(math.sqrt(n))):
    for j in range(1,int(math.sqrt(n))):
        for q in range(1,int(math.sqrt(n))):
            
            l[i**2+j**2+q**2 +i*j +i*q+q*j]+=1
for i in range(1,n+1):
    print(l[i])


Measured memory_bytes: 71552
//Author:Chacha
//Date:18/01/19

#include<bits/stdc++.h>

using namespace std;

int mincost[100005],height[100005],dif,way1,way2,dif1,dif2;

int main(){
    int n,i;

    cin>>n;

    for(i=1;i<=n;i++){
        scanf("%d",&height[i]);
    }

    mincost[1]=0;
    dif=height[2]-height[1];
    if(dif<0)
        dif=-dif;
    mincost[2]=dif;

    for(i=3;i<=n;i++){
        dif1=height[i]-height[i-2];
        if(dif1<0)
            dif1=-dif1;
        way1=mincost[i-2]+dif1;

        dif2=height[i]-height[i-1];
        if(dif2<0)
            dif2=-dif2;
        way2=mincost[i-1]+dif2;

        mincost[i]=min(way1,way2);
    }

    cout<<mincost[n]<<endl;

    return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int k;
ll s(ll x){
	ll res=0;
	while(x){
		res+=x%10ll;
		x/=10ll;
	}
	return res;
}
bool check(ll x,ll y){
	ll s1=s(x);
	ll s2=s(y);
	return x*s2>y*s1;
}
int main(){
	SF("%d",&k);
	ll y=1;
	ll now=0;
	while(k){
		while(check(now+y,now+y*10)==1)
			y*=10ll;
		now+=y;
		PF("%lld\n",now);
		k--;
	}
} 

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

int main(){
  int N; cin >> N;
  int d[110];
  for(int i = 0; i < N; i++) cin >> d[i];
  
  /*配列num[i]を用意して、iがいくつあるかを記録する*/
  int num[110] = {0};
  
  for(int i = 0; i < N; i++)
  {
    num[d[i]]++; 
  }
  
  int res = 0;
  for(int i = 0; i <= 100; i++)
  {
    if(num[i] > 0)
    {
      res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    double money = 0.0;
    double x;
    string u;
    while (n--) {
        cin >> x >> u;
        if (u == "BTC")
            money += x * 380000.0;
        else
            money += x;
    }
    cout << fixed << setprecision(6) << money << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args : Array<String>) {
    println(inOutExec(Scanner(System.`in`)))
}

fun inOutExec(scanner: Scanner): String {
    val total = scanner.nextInt()
    val num = scanner.nextInt()
    val trees = IntArray(total)
    repeat(total) {
        trees[it] = scanner.nextInt()
    }

    var result: Int = Int.MAX_VALUE
    trees.sort()
    for (i in trees.indices) {
        if (i + num-1 >= total) {
            break
        }
        val diff = Math.abs(trees[i + num-1] - trees[i])
        if (diff < result) {
            result = diff
        }
    }

    return result.toString()
}


Measured memory_bytes: 57208
import math
N = int(input())
A = list(map(int,input().split()))
B = [0] * (N)
lcmall = A[0]
for i in range(1,N):
    gcdall = math.gcd(lcmall,A[i])
    lcmall = lcmall*A[i] // gcdall
sum = 0
for i in range(N):
    B[i] =int(lcmall // A[i])
    sum += B[i]
print(sum % (10 ** 9 + 7))

Measured memory_bytes: 268096
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            print(roop[(k - i) % len(roop)])
            exit()

   


Measured memory_bytes: 49400
/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>
#include <map>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <functional>
*/
#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

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

const ll INF = 999999999;
const ll atcoder = 1000000007;
const int dx[4] = { 1 , 0 , -1 ,0 };
const int dy[4] = { 0 , 1 , 0 , -1 };

int d[1000][1000];

void Daijkstra() { //単一始点最短経路

	priority_queue< P, vector<P>, greater<P> > Q;


}

void Warshall(){ //全点対最短経路 O(V^3)

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = INF;
		}
	}

	for (int i = 0; i < m; i++) {//m : 節の数
		int a, b, t;
		cin >> a >> b >> t;
		d[a - 1][b - 1] = d[b - 1][a - 1] = t;
	}

	for (int k = 0; k < n; k++) { //n : 頂点数
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}


int main() {

	string s;
	cin >> s;

	for (int i = 0; i < s.length(); i += 2)
		cout << s[i];
	cout << endl;
	

	return 0;

}

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

int main() {
    int n, a[100000],b[10]={0};
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        if(a[i]%4==0) b[4]++;
        else if(a[i]%2==0) b[2]++;
        else b[0]++;
    }

    if(b[2]>0) b[0]++;
    if(b[4]+1>=b[0]) cout << "Yes";
    else cout << "No";
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 2e5L + 11;
int p[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;

	ios :: sync_with_stdio(0);

	for(int n; cin >> n && n; ) {
		int ans = 0;
		for(int i = 2; i < N; i ++) if(p[i] == i && n) {
			n --;
			ans += i;
		}
		cout << ans << '\n';
	}

	return 0;
}

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

int N, T;
pair<int, int> items[3000];
int dp[3000][3000];

int main(){
  cin >> N >> T;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    items[i].first = a;
    items[i].second = b;
  }
  sort(items, items + N);

  int ans = 0;
  // dp[i][j]
  for(int i = 0; i < N; i++){
    for(int j = 0; j < T; j++){
      dp[i + 1][j] = dp[i][j];
      if(j >= items[i].first){
	dp[i + 1][j] = max(dp[i][j], dp[i][j - items[i].first] + items[i].second);
      }
    }
    ans = max(ans, dp[i][T - 1] + items[i].second);
  }

  cout << ans << endl;
}


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

int main() {
  int a,b,c ; cin >> a >> b >> c ;
  if(a+b==c||a+c==b||b+c==a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - Echo
 * 入力された数字が九九として表現できる場合はYes,できない場合はNoを出力する
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 文字列の桁数
        int n = sc.nextInt();
        String str = sc.next();
        // 繰り返しなしの桁数
        int strLen = n / 2;

        // 繰り返しなしの文字列
        String string1 = str.substring( 0, strLen );
        // ２回目の文字列
        String string2 = str.substring( strLen );


        if( string1.equals( string2 ) ) {
            System.out.println( "Yes" );
        }
        else {
            System.out.println( "No" );
        }

        sc.close();
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>

#define MOD 1000000007

using namespace std;

int N, M;

long long permutation(int num) {
    long long a = 1;
    for(int i = 1; i <= num; i++) a = a * i % MOD;
    return a;
}


void solve() {
    if(abs(N - M) > 1) {
        cout << 0 << endl;
        return;
    }
    long long ans = permutation(N) * permutation(M) % MOD;
    if(N - M == 0) ans = ans * 2 % MOD;
    cout << ans << endl;
}

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

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

#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
using namespace std;

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << ": " << arg1 << endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int b[NN];
int n, m, k;
string s;


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

    int n;
    cin >> n;
    int have = 0;
    while (have < n){
        have += 1000;
    }
    cout << have - n;


}

//2 9 1 1 2 4 4 2 9

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

const int MAX_NUM = 1001;

int main() {
	int d, g;
	cin >> d >> g;

	vector<pair<int, int>>  p_score(d);

	for (int i = 0; i < d; i++) {
		int p, c;
		cin >> p >> c;
		p_score[i] = make_pair(p, c);
	}



	vector<int> comp_score(d);
	for (int i = 0; i < d; i++) {
		comp_score[i] = p_score[i].first *(i + 1) * 100 + p_score[i].second;
	}

	int ans = 1000;
	for (int i = 0; i < (1 << d); i++) {
		int unUse_max = 0;

		int sum = 0;
		int cnt = 0;

		for (int j = 0; j < d; j++) {
			if ((i >> j) & 1) {
				sum += comp_score[j];
				cnt += p_score[j].first;
			}
			else {
				unUse_max = j;
			}
		}

		for (int j = 0; j < p_score[unUse_max].first;j++) {
			if (sum >= g) {
				break;
			}
			sum += (unUse_max + 1) * 100;

			cnt++;
		}

		if (sum >= g && ans > cnt) {
			
			ans = cnt;
			
		}

	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

template<typename T>
struct SegmentTree {
private:
	int sz, n;
	vector<T> data;
	function<T(T, T)> f;
	T identity_element;
public:
	/* constructor */
	SegmentTree(
		const vector<T>& v, // initial data
		T identity_element, // identity element
		function<T(T, T)> f // operation
	) {
		sz = v.size();
		n = 1; while (n < sz) n <<= 1;
		this->f = f;
		this->identity_element = identity_element;
		data.resize(2 * n - 1, identity_element);
		for (int i = 0; i < sz; ++i)
			data[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; --i)
			data[i] = f(data[2 * i + 1], data[2 * i + 2]);
	}
	/* update query */
	void update(int idx, const T val) {
		idx += n - 1;
		data[idx] = val;
		while (idx) {
			idx = (idx - 1) >> 1;
			data[idx] = f(data[2 * idx + 1], data[2 * idx + 2]);
		}
	}
	/* get query */
	T get(int left, int right, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= left || right <= l) return identity_element;
		if (left <= l && r <= right) return data[k];
		T val_l = get(left, right, 2 * k + 1, l, (l + r) / 2);
		T val_r = get(left, right, 2 * k + 2, (l + r) / 2, r);
		return f(val_l, val_r);
	}
};

int main(void){
	int N, K;
	cin >> N >> K;
	SegmentTree<int> dp(
		vector<int>(300001, 0), 0, 
		[](int a, int b){ return max(a, b); }
	);
	while (N--){
		int a; cin >> a;
		int l = max(0, a - K);
		int r = min(300000, a + K) + 1;
		int tmp = dp.get(l, r);
		dp.update(a, tmp + 1);
	}
	int ans = dp.get(0, 300001);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8536
#include<stdio.h>

int main(void){
  int w[10]={1,2,4,8,16,32,64,128,256,512};
  int i,n,ans[10],end;

  while(scanf("%d",&n)!=EOF){
    end=-1;
    for(i=0;i<10;i++)ans[i]=0;
    for(i=9;i>=0;i--){
      if(w[i]<=n){
	n-=w[i];
	ans[i]=1;
	if(end<0)end=i;
      }
    }
    for(i=0;i<10;i++){
      if(ans[i]==1 && i==end)printf("%d\n",w[i]);
     else if(ans[i]==1 && i!=end)printf("%d ",w[i]);
    }
}
  return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

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

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

void run(){
  vvi dp(4,vi(4001));
  rep(i,1001)dp[0][i]=1;
  rep(i,3){
    rep(j,4001){
      if(dp[i][j]){
	rep(k,1001){
	  dp[i+1][j+k]+=dp[i][j];
	}
      }
    }
  }
  int n;
  while(cin>>n){
    cout<<dp[3][n]<<endl;
  }
}



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

int main() {
    int n = 5;
    vector<int> annt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        annt.push_back(x);
    }
    int k = 0;
    cin >> k;
    // int ret = 0;
    // for (int i = 1; i < n; i++) {
    //     if (annt[i] - annt[i-1] > k) {
    //         ret++;
    //         break;
    //     }
    // }
    if (annt[4] - annt[0] > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}


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

class G
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var es = new int[h[1]].Select(_ => Read()).ToArray();

		var map = Array.ConvertAll(new int[n], _ => new List<int>());
		var map_r = Array.ConvertAll(new int[n], _ => new List<int>());
		foreach (var e in es)
		{
			map[e[0]].Add(e[1]);
			map_r[e[1]].Add(e[0]);
		}

		var u = new bool[n];
		var order = new List<int>();
		var gs = new List<List<int>>();
		List<int> lg = null;

		void Dfs(int v)
		{
			u[v] = true;
			foreach (var nv in map[v]) if (!u[nv]) Dfs(nv);
			order.Add(v);
		}
		for (int v = 0; v < n; v++) if (!u[v]) Dfs(v);

		void Dfs_r(int v)
		{
			u[v] = true;
			foreach (var nv in map_r[v]) if (!u[nv]) Dfs_r(nv);
			lg.Add(v);
		}
		Array.Clear(u, 0, n);
		order.Reverse();
		foreach (var v in order) if (!u[v]) { gs.Add(lg = new List<int>()); Dfs_r(v); }

		Console.WriteLine(gs.Count);
		Console.WriteLine(string.Join("\n", gs.Select(g => string.Join(" ", g.Prepend(g.Count)))));
	}
}


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

int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	if(a%2&&b%2||a%2==0&&b%2==0){
		printf("%lld\n",(a+b)/2);
	}
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
S = input()
    
l = 0
r = int(N / 2)
f = False

if N % 2 == 1:
    f = True
    print("No")
        
while r < N and f == False:
    if S[l] != S[r]:
        print("No")
        f = True
        break
    l += 1
    r += 1
    
if f == False:
    print("Yes") 



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=10010;
const ll mod=1e9+7;

int main(){
  string s;
  int x,y;
  cin >> s >> x >> y;
  int sz = s.size();
  int cnt = 0;
  int t = 0;
  vector<int> m[2];
  rep(i,sz){
    if(s[i]=='F'){
      cnt++;
    } else {
      m[t%2].emplace_back(cnt);
      cnt=0;
      t++;
    }
  }
  m[t%2].emplace_back(cnt);

  vector<vector<int>> dp(2, vector<int>(mx*2,0));
  dp[0][mx]=dp[1][mx]=1;
  rep(k,2){
    int z = m[k].size();
    rep(j,z){
      int it = m[k][j];
      vector<int> tmp(mx*2,0);
      rep(i,mx*2)if(dp[k][i]){
        if(0<=i-it && !(k==0&&j==0)){ tmp[i-it]=1; }
        if(i+it<mx*2){ tmp[i+it]=1; }
      }
      dp[k] = tmp;
    }
  }
  if(dp[0][x+mx]==1 && dp[1][y+mx]==1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
     long long a,b,c,d;
     cin>>a>>b>>c;
     if(a==b&&b==c)
     {
         cout<<"No"<<endl;
     }
     else if(a!=b&&a!=c&&b!=c)
     {
         cout<<"No"<<endl;
     }
     else
     {
         cout<<"Yes"<<endl;
     }
     return 0;
}

Measured memory_bytes: 3612
import copy
while True :
    card = list(input())
    if card[0] == "-" :
        break
    
    new_card = [''] * (len(card))
    m = int(input())
    for i in range(m) :
        h = int(input())
        for c in range(len(card)) :
            if c < len(card) - h :
                new_card[c] = card[h + c]
            else :
                new_card[c] = card[c + h - len(card)]
        card = copy.copy(new_card)
    for i in range(len(card)) :
        print(card[i], sep="", end="")
    print()   


Measured memory_bytes: 6336
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int N;
    int t = 0;
    int num;
    cin >> N;
    for(int i=0; i < N; i++)
    {
        cin >> num;
        t += num;
    }
    cout << (t-N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>


using namespace std;

int main(){
  int n;
  cin >> n;
  //int *d = (int*)malloc(sizeof(int)*n);
  int d[n];
  for(int i=0;i<n;i++) cin >> d[i];
  long sum=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      sum += d[i]*d[j];
    }
  }
  cout << sum << endl;
  return 0;
}




Measured memory_bytes: 256