akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1


ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll w, h;
ll s[100][100];
ll c[4];

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

ll d[4][100][100];

void dijkstra(P start) {
	rep(i, 4)rep(j, 100)rep(k, 100)d[i][j][k] = INF;
	d[0][start.first][start.second] = 0;

	typedef pair<P, P> PP;
	priority_queue<PP, vector<PP>, greater<PP>> que;
	que.push({ P(0, 0),start });

	while (!que.empty()) {
		PP p = que.top();
		que.pop();
		int y = p.second.first;
		int x = p.second.second;
		int dir = p.first.second;
		if (y == h - 1 && x == w - 1)continue;
		if (d[dir][y][x] < p.first.first)continue;
		for (int i = 0; i < 4; i++) {
			int ndir = (dir + i) % 4;
			int ny = y + dy[ndir];
			int nx = x + dx[ndir];
			if (ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
			if (i == s[y][x]) {
				if (d[ndir][ny][nx] > d[dir][y][x]) {
					d[ndir][ny][nx] = d[dir][y][x];
					que.push({ P(d[ndir][ny][nx], ndir),P(ny,nx) });
				}
			}
			else {
				if (d[ndir][ny][nx] > d[dir][y][x] + c[i]) {
					d[ndir][ny][nx] = d[dir][y][x] + c[i];
					que.push({ P(d[ndir][ny][nx], ndir),P(ny,nx) });
				}
			}
		}
	}
}

int main() {
	while (cin >> w >> h&&w + h) {
		rep(i, h) {
			rep(j, w)cin >> s[i][j];
		}
		rep(i, 4)cin >> c[i];
		dijkstra(P(0, 0));
		//rep(i, 4) {
		//	rep(j, h) {
		//		rep(k, w)cout << d[i][j][k] << " ";
		//		cout << endl;
		//	}
		//	cout << endl;
		//}
		ll ans = INF;
		rep(i, 4)ans = min(ans, d[i][h - 1][w - 1]);
		cout << ans << endl;
	}
}


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

signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());//いらなかった
  int l=0;int r=1e9+7;
  while(r-l>1){
    int m=(l+r)/2;
    //cout<<l<<" "<<r<<" "<<m<<" ";
    std::vector<int> c(N);
    for(int i=0;i<N;i++)c[i]=v[i];
    for(int i=0;i<N;i++)c[i]-=m*B;
    int bb=0;
    for(int i=0;i<N;i++){
      if(c[i]>0){
        bb+=c[i]/(A-B);
        if(c[i]%(A-B))bb++;
      }
    }
    //cout<<bb<<endl;
    if(bb<=m)r=m;
    else l=m;
  }
  cout<<r<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n; cin >> n;
	ll ans = 0;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		ans += x, mp[x]++;
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c; cin >> b >> c;
		cout << (ans += 1LL * (c - b) * mp[b]) << "\n";
		mp[c] += mp[b], mp[b] = 0;
	}
}

Measured memory_bytes: 8080
#include<stdio.h>
int main(void){
        int a,b,c,i;
        scanf("%d %d %d",&a,&b,&c);
        if(a>b){
                i=a;
                a=b;
                b=i;
        }
        if(b>c){
                i=b;
                b=c;
                c=i;
        }
        if(a>b){
                i=a;
                a=b;
                b=i;
        }
        printf("%d %d %d\n",a,b,c);
        return 0;
}


Measured memory_bytes: 2104
#include	<stdio.h>

int main(void)
{
	int indat1, indat2;
	int sum;
	int cnt;

	while (scanf("%d %d", &indat1, &indat2) != EOF){
		sum = indat1 + indat2;
		cnt = 0;
		while (sum != 0){
			sum /= 10;
			cnt++;
		}
		printf("%d\n", cnt);
	}

	return 0;
}

Measured memory_bytes: 600
n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
cd = sorted([[int(i) for i in input().split()] for _ in range(n)])
count = 0
out = []
output = []
for c in cd:
    flag = 0
    for a in ab:
        if a not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(a)
            flag = 1
    if flag == 1:
        output.append(max(out, key=lambda x:x[1]))
        out = []
        count += 1

print(count)

Measured memory_bytes: 3064
# AOJ ITP2_3_C: Count
# Python3 2018.6.24 bal4u

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	b, e, k = map(int, input().split())
	print(a[b:e].count(k))


Measured memory_bytes: 5632
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  int n;
  cout << fixed;
  cout << setprecision(7);
  cin >> n;
  vector<int> v(n);
  
  double ret = 0.0;
  for (int i = 0; i < n; i++) cin >> v[i];
  
  sort(all(v));
  
  ret= v[1] + v[0];
  ret /= 2.00;
  for (int i = 2; i < n; i++)
  ret = (ret + v[i]) / 2.00;
  
  cout << ret << endl;
  	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	ll h, w, i, ans = 1e+12, s1, s2,s3;
	cin >> h >> w;
	for (i = 1; i < h; i++) {
		s1 = i * w;
		if (w % 2 == 0 || (h - i) % 2 == 0) {
			s2 = (h - i)*w / 2;
			s3 = s2;
		}
		else {
			s2 = max(h - i, w) / 2 * min(h - i, w);
			s3 = s2 + min(h - i, w);
		}
		ans = min(ans, max(max(s1, s2), s3) - min(min(s1, s2), s3));
	}
	swap(h, w);
	for (i = 1; i < h; i++) {
		s1 = i * w;
		if (w % 2 == 0 || (h - i) % 2 == 0) {
			s2 = (h - i)*w / 2;
			s3 = s2;
		}
		else {
			s2 = max(h - i, w) / 2 * min(h - i, w);
			s3 = s2 + min(h - i, w);
		}
		ans = min(ans, max(max(s1, s2), s3) - min(min(s1, s2), s3));
	}
	cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<int> num_w(N + 1, 0);
  vector<int> num_e(N + 1, 0);
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'W') {
      num_w[i+1] = num_w[i] + 1;
    } else {
      num_w[i+1] = num_w[i];
    }
    if (S.at(i) == 'E') {
      num_e[i+1] = num_e[i] + 1;
    } else {
      num_e[i+1] = num_e[i];
    }
  }
  
  int ans = 300000;
  for (int i = 0; i < N; i++) {
    int count = 0;
    
    count += num_w[i] - num_w[0];
    count += num_e[N] - num_e[i + 1];
    
    ans = min(ans, count);
  }

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

Measured memory_bytes: 2948
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 10
char mp[maxn][maxn];
int n, m;
void dfs(int x, int y)
{
	if (x == n && y == m)
	{
		puts("Possible");
		exit(0);
		return ;
	}
	if (x < n && mp[x + 1][y] == '#') dfs(x + 1, y);
	if (y < m && mp[x][y + 1] == '#') dfs(x, y + 1);
}
int main()
{
//	setfile();
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (mp[i][j] == '#')
				++cnt;
	if (cnt != n + m - 1) {puts("Impossible"); return 0;}
	dfs(1, 1);
	puts("Impossible");
	return 0;
}


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

using namespace std;
int main() {
    string s;
    int len;
    int flag [26] = {};

    cin >> s;
    len = s.length();

    for (int i = 0; i < len; i++) {
        flag[s[i]-'a'] = 1;
    }

    for (int i = 0; i < 26; i++) {
        if (flag[i] == 0) {
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	static final int MOD = (int) 1e9 + 7;

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt(), k = sc.nextInt();
		ArrayList<Long> pos = new ArrayList<>();
		ArrayList<Long> neg = new ArrayList<>();
		
		for(int i = 0; i < n; i++) {
			long x = sc.nextInt();
			if(x < 0) neg.add(-x);
			else pos.add(x);
		}
		
		int rem = k - pos.size();
		if((rem > 0 && rem % 2 != 0 && neg.size() <= rem) || (pos.size() == 0 && k % 2 == 1)) { //minimize
			Collections.sort(pos);
			Collections.sort(neg);
			
			long ans = 1;
			for(int i = 0, j = 0; k > 0; k--) {
				long po = i < pos.size() ? pos.get(i) : Integer.MAX_VALUE;
				long ne = j < neg.size() ? neg.get(j) : Integer.MAX_VALUE;
				
				if(po <= ne) {
					i++;
					ans *= po;
					ans %= MOD;
				}else {
					j++;
					ans *= ne;
					ans %= MOD;
				}
			}
			
			ans = (-ans + MOD) % MOD;
			out.println(ans);
			
		}else {
			
			Collections.sort(pos, Collections.reverseOrder());
			Collections.sort(neg, Collections.reverseOrder());
			
			int i = Math.min(k - 1, pos.size() - 1);
			if((k - i - 1) % 2 != 0) i--;
			int j = k - i - 2;
			
			while(i > 0 && j < neg.size() - 2) {
				long ne = neg.get(j + 1) * neg.get(j + 2);
				long po = pos.get(i) * pos.get(i - 1);
				
				if(ne > po) {
					j += 2;
					i -= 2;
				}else {
					break;
				}
			}
			
			long ans = 1;
			for(int idx = 0; idx <= i; idx++) {
				ans *= pos.get(idx);
				ans %= MOD;
			}
			
			for(int idx = 0; idx <= j; idx++) {
				ans *= neg.get(idx);
				ans %= MOD;
			}
			
			out.println((ans + MOD) % MOD);
		}
		
		out.close();
	}

}

class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	public Scanner(String file) throws Exception {
		br = new BufferedReader(new FileReader(file));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

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

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

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

Measured memory_bytes: 60984
from collections import deque

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

MOD = 10**9 + 7

# 0以上の数
X = []
# 負の数
Y = []

# 左の方が絶対値が大きくなるようにそれぞれソート
for a in A:
    if a >= 0:
        X.append(a)
    else:
        Y.append(a)
X.sort(reverse=True)
X = deque(X)
Y.sort()
Y = deque(Y)
# print(X)
# print(Y)

nums = []
# 全部選ぶしかない場合
if K == N:
    nums = A
# どうやっても負にしかならない場合（Aが全て負 and Kが奇数）
# 絶対値が小さくなるように取っていく
elif len(Y) == N and K % 2 == 1:
    for _ in range(K):
        nums.append(Y.pop())
# 上記以外の場合、結果を0以上（負ではない）にすることが出来る
# 絶対値が大きくなるように and 負にならないように 取っていく
# X,Yについて、「2個以上ある場合」、「1個の場合」、「0個の場合」の3*3=9通りに分けられる
# Yが1個、0個の場合はまとめることが出来たので、結局3*2=6通り

# 残り1個しか追加出来ない時に注意

else:
    while len(nums) < K:
        if len(X) >= 2 and len(Y) >= 2:
            if X[0] * X[1] >= Y[0] * Y[1] or len(nums) == K - 1:
                nums.append(X.popleft())
            else:
                nums.append(Y.popleft())
                nums.append(Y.popleft())
        elif len(X) >= 2 and len(Y) <= 1:
            nums.append(X.popleft())

        elif len(X) == 1 and len(Y) >= 2:
            if X[0] >= Y[0] * Y[1] or len(nums) == K - 1:
                nums.append(X.popleft())
            else:
                nums.append(Y.popleft())
                nums.append(Y.popleft())
        elif len(X) == 1 and len(Y) <= 1:
            nums.append(X.popleft())

        elif len(X) == 0 and len(Y) >= 2:
            if len(nums) == K - 1:
                # 負にならざるを得ない場合、絶対値が小さい方の負の数を追加する(ここだけpopleftではなくpop)
                # 絶対に0以上に出来るという前提に矛盾しているが、形式上記述しておく
                nums.append(Y.pop())
            else:
                nums.append(Y.popleft())
                nums.append(Y.popleft())
        # K<=Nなので、共に0になることは起こり得ない
        elif len(X) == 0 and len(Y) <= 1:
            num.append(Y.pop())

ans = 1
for num in nums:
    ans *= num
    ans %= MOD
print(ans)


Measured memory_bytes: 108812
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

lint Q, H, S, D;
lint N, ans;

int main(void){
    // input
    cin >> Q >> H >> S >> D;
    cin >> N;
    while (N > 0) {
        if (N >= 2) {
            N -= 2;
            ans += min({8*Q, 4*H, 2*S, D});
        } else {
            N -= 1;
            ans += min({4*Q, 2*H, S});
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define maxn 500010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,L; 
struct P{
    double v,t;
}a[maxn],q[maxn];
double S,V;
int l=1,r=0;
int main()
{
    n=read();L=read();
    for(int i=1;i<=n;i++)
    {
        a[i].t=read();a[i].v=read();
        V+=a[i].v;S+=a[i].v*a[i].t;
        while(V>L&&l<=r)
        {
            if(q[l].v<=V-L)
            {
                V-=q[l].v;S-=q[l].v*q[l].t;
                l++;
            }
            else{
                q[l].v-=V-L;
                S-=(V-L)*q[l].t;V=L;
                break;
            }
        }
        q[++r]=a[i];
        printf("%.7lf\n",S/L);
        while(l<r)
        {
            if(q[r].t>q[r-1].t)  break;
            q[r-1].t=(q[r-1].t*q[r-1].v+q[r].t*q[r].v)/(q[r-1].v+q[r].v);
            q[r-1].v+=q[r].v;
            r--;
        }
    }
    return 0;
}

Measured memory_bytes: 24704
n, k, q = gets.split.map(&:to_i)
corrects = Hash.new(0)
q.times do
  corrects[gets.to_i] += 1
end

(1..n).each do |index|
  incorrect = q - corrects[index]
  if incorrect >= k
    puts "No"
  else
    puts "Yes"
  end
end


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

using namespace std;

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

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

const int MAXN = 18;

int N;
pii arr[1 << MAXN];

pii merge(pii p1, pii p2){
    if(p1.first > p2.first){
        return pii(p1.first, max(p1.second, p2.first));
    } else {
        return pii(p2.first, max(p1.first, p2.second));
    }
}

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    cin >> N;
    
    for(int a = 0; a < (1 << N); a++){
        cin >> arr[a].first;
        //arr[a].second = -999999
    }
    for(int b = 0; b < N; b++){
        for(int a = 0; a < (1 << N); a++){
            if(a & (1 << b)){
                continue;
            }

            arr[a | (1 << b)] = merge(arr[a | (1 << b)], arr[a]);
        }
    }

    int best = 0;
    for(int a = 1; a < (1 << N); a++){
        best = max(best, arr[a].first + arr[a].second);
        cout << best << "\n";
    }
}


Measured memory_bytes: 5120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.solve();
    }
    private void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        int N = scan.scanInt();
        List<Path>[] graph = new List[N];
        for (int i = 0; i < N; i++) {
            graph[i] = new ArrayList<>(2);
        }
        for (int i = 0; i < N - 1; i++) {
            int a = scan.scanInt()-1;
            int b = scan.scanInt()-1;
            long c = scan.scanLong();
            graph[a].add(new Path(b, c));
            graph[b].add(new Path(a, c));
        }
        int Q = scan.scanInt();
        int K = scan.scanInt()-1;
        Queue<Integer> queue = new ArrayDeque<>();
        long[] distances = new long[N];
        boolean[] visited = new boolean[N];
        Arrays.fill(distances, Long.MAX_VALUE);
        distances[K] = 0;
        queue.add(K);
        while(!queue.isEmpty()) {
            int current = queue.poll();
            visited[current] = true;
            for (Path p : graph[current]) {
                if (visited[p.to]) {
                    continue;
                }
                distances[p.to] = distances[current] + p.cost;
                queue.add(p.to);
            }
        }
        for (int i = 0; i < Q; i++) {
            int from = scan.scanInt() - 1;
            int to = scan.scanInt() - 1;
            System.out.println(distances[from] + distances[to]);
        }
    }

    class Path {
        int to;
        long cost;
        Path(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }
    }
    class FastScan {
        BufferedReader br;
        StringTokenizer st;
        FastScan(InputStream is) {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String next() throws IOException {
            while (this.st == null || !this.st.hasMoreTokens()) {
                this.st = new StringTokenizer(br.readLine().trim());
            }
            return st.nextToken();
        }
        long scanLong() throws IOException {
            return Long.parseLong(this.next());
        }
        int scanInt() throws IOException {
            return Integer.parseInt(this.next());
        }
        double scanDouble() throws IOException {
            return Double.parseDouble(this.next());
        }
        char scanCharacter() throws IOException {
            return this.next().charAt(0);
        }
        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

using namespace std;


int main() {
	int n, p, minP;
	double h, w, currentDiffBMI, minBMI;

	while (cin >> n, n) {
		minBMI = DBL_MAX;
		for (int i = 0; i < n; i++) {
			cin >> p >> h >> w;
			currentDiffBMI = fabs(w / pow(h, 2) * 10000 - 22);
			//cout << p << ends << currentBMI << endl;
			if (fabs(currentDiffBMI - minBMI) < 0.000001) {
				if (p < minP) {
					minBMI = currentDiffBMI;
					minP = p;
				}		
			}
			else if (currentDiffBMI < minBMI) {
				minBMI = currentDiffBMI;
				minP = p;
			}
			//cout << minBMI << ends << minP << endl;
		}
		cout << minP << endl;
	}

	return 0;
}


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

int func(int a, int b) {
  if (a <= 0 && b >= 0) {
    return 0;
  }

  if (a > 0) {
    return 1;
  }

  int t = b - a - 1;

  return t % 2 ? -1 : 1;
}

int main() {
  int a, b;
  cin >> a >> b;
  int f = func(a, b);
  if (f == 1) {
    cout << "Positive" << endl;
  } else if (f == -1) {
    cout << "Negative" << endl;
  } else {
    cout << "Zero" << endl;
  }
  return 0;
}


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

module Main where

import Data.Char
import Control.Monad
import Control.Applicative


readInt :: IO Int
readInt = read <$> input
    where input = do
            c <- getChar
            if isDigit c
                then (c :) <$> input
                else return []

main = do
    [a, b] <- replicateM 2 readInt
    let s = a * b
        t = (a + b) * 2
    putStrLn $ show s ++ " " ++ show t



Measured memory_bytes: 3516
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
S = [input() for _ in range(2)]

MOD = 10 ** 9 + 7


def main():
    ans, i = (3, 1) if S[0][0] == S[1][0] else (6, 2)
    while i < N:
        if S[0][i] == S[1][i]:
            x = 2 if S[0][i - 1] == S[1][i - 1] else 1
            i += 1
        else:
            x = 2 if S[0][i - 1] == S[1][i - 1] else 3
            i += 2
        ans = ans * x % MOD
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
/*
Author : N_o_o_B
Created : April 11 2020 10:55:14 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;


    string s;
    cin >> s;
    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;


    time_taken();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    
    int n, r, i = 0;
    cin >> n >> r;

    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + 1000 - 100 * n << endl;
    }

    //r = nota mostrada [display raiting]
    //i = inner rating
    //r = i - 100 * ( 10 - n )

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;

int main(){
  ll H,W;
  cin>>H>>W;
  
  vector<vector<char>>s(H,vector<char>(W));
  bool flag=true;
  
  for(ll i=0;i<H;i++){
for(ll j=0;j<W;j++){
  cin>>s[i][j];
}
  }

  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++){
      ll sum=0;
      if(s[i][j]=='#'){
        if(i-1>=0){//上方向
          if(s[i-1][j]=='#'){
            sum++;
          }
        }
        if(j+1<W){//右方向
          if(s[i][j+1]=='#'){
            sum++;
          }
        }
        if(j-1>=0){
          if(s[i][j-1]=='#'){//左方向
            sum++;
          }
        }
if(i+1<H){//下方向
if(s[i+1][j]=='#'){
  sum++;
}
}
        if(sum==0){
flag=false;
      }
    }
        
    }
  }
    
    if(flag){
     cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  

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

using namespace std;

typedef long long ll;

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

    if (n < 10){
        cout << n << endl;
        return 0;
    }

    vector<int> num;
    while(n > 0){
        num.emplace_back(n % 10);
        n /= 10;
    }

    reverse(num.begin(), num.end());

    bool flag = false;
    for (int i = 1; i < (int)num.size(); ++i) {
        if (num[i] != 9){
            flag = true;
            break;
        }
    }

    if (flag){
        cout << num[0] - 1 + 9 * (num.size() - 1) << endl;
    }else{
        cout << num[0] + 9 * (num.size() - 1) << endl;
    }
}

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

int isprime(int);

int main()
{
  int n,i,count = 0;
  scanf("%d",&n);
  int A[n];
  for(i = 0;i < n;i++)
    {
      scanf("%d",&A[i]);
    }
  for(i = 0;i < n;i++)
    {
      count += isprime(A[i]);
    }
  printf("%d\n",count);
}

int isprime(int x)
{
  int i;
  if(x == 2)
    {
      return 1;
    }

  if(x < 2 || x%2 == 0)
    {
      return 0;
    }
  i = 3;
  while(i <= sqrt(x))
    {
      if(x%i == 0)
	{
	  return 0;
	}
      i = i+2;
    }
  return 1;
}



Measured memory_bytes: 2144
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> g(n+1);
    FOR(i,0,m){
      ll a,b;
      cin>>a>>b;
      g[a].push_back(b);
    }
    ll M = 1e9;
    vector<vector<ll>> v(n+1,vector<ll>(3,M));
    ll s,t;
    cin>>s>>t;

    deque<P> q;
    q.push_back(P(0,s));
    while(!q.empty()){
      ll cost = q.front().first;
      ll from = q.front().second;
      q.pop_front();
//      cout<<"from = "<<from<<" cost = "<<cost<<endl;
      if(cost >= v[from][cost%3]) continue;
      else v[from][cost%3] = cost;
      FOR(i,0,g[from].size()){
        ll to = g[from][i];
        q.push_back(P(cost+1,to));
      }
    }
    if(v[t][0] == M)cout<<-1<<endl;
    else cout<<v[t][0]/3<<endl;
}


Measured memory_bytes: 11264
def solve(s):
    # 'AC' か 'WA' を返す

    # Sの先頭の文字は大文字の A である。
    if s[0] != 'A':
        return 'WA'

    # Sの先頭から3文字目と末尾から
    # 2文字目の間（両端含む）に大文字の C
    # がちょうど  1  個含まれる。
    if len([True for c in s[2:-1] if c == 'C']) != 1:
        return 'WA'

    # 以上の A, C を除くSのすべての文字は小文字である。
    n_diff = 0
    for s_ in s:
        sl_ = s_.lower()
        if s_ != sl_:
            n_diff += 1

    if n_diff != 2:
        return 'WA'

    return 'AC'


s = input()
print(solve(s))


Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int i=0;
  while(a>0 && c>0)
  {
    if(i%2==0)
	{
		c=c-b;
		}	
		else
		{
			a=a-d;
		}
		i++;
  }
  if(a<=0)
  {
  	cout<<"No";
  }
  else
  {
  	cout<<"Yes";
  }
}


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

//--------------some #defines-------------------------
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define get1(x) int x; cin>>x
#define get2(x,y) int x,y; cin>>x>>y
#define min2(x,y) (x<y?x:y)
#define max2(x,y) (x>y?x:y)

#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rev(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define endl '\n'

#define vi vector<int>

#define matrix(x,n,m) vector<vector<int> > x(n,vi (m))
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define ff first
#define ss second
#define vpii vector<pair<int,int> >
#define ll long long


//#define gcd(x,y) __gcd(x,y)
//#define lcm(x,y) (x)*(y)/__gcd(x,y)

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

int main()
{
    boost;
    get1(t);
    int ac=0,wa=0,tle=0,re=0;
    loop(i,0,t)
    {
        string arr;
        cin>>arr;
        if(arr=="AC")
            ac++;
        else if(arr=="WA")
            wa++;
        else if(arr=="TLE")
            tle++;
        else
            re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;


    return 0;
}



Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;


public class Main{
	public static void main(String args[]){
		Scanner stdIn = new Scanner(System.in);
		int[] intArray = new int[5];
		for(int i = 0;i < intArray.length; i++){
			intArray[i] = stdIn.nextInt();
		}

		Arrays.sort(intArray);

		for(int i = intArray.length - 1;i >= 0; i--){
			if(i == 0){
				System.out.println(intArray[i]);
			}else{
				System.out.print(intArray[i] + " ");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
bool f(int x){
  int digit=0;
    while(x){
      x /= 10;
       digit++;
    }
  return digit % 2 == 1;
}
int main() {
int N;
int ans =0;
  cin >> N;
  for(int i = 1;i <= N;++i){
   
  if(f(i))
    ans++;
  }
cout << ans << endl;
}

Measured memory_bytes: 256
import collections
import sys
def input():
    return sys.stdin.readline()[:-1]
    
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll X, K, D;
    cin >> X >> K >> D;

    long double X2 = abs(X);
    long double K2 = K;
    long double D2 = D;

    long double check = X2/D2;

    if(check > K){
        cout << abs(X)-K*D << endl;
    }
    else{
        ll c = abs(X) / D;
        ll m = abs(X) % D;
        ll k = K - c;
        if(k%2 == 0){
            cout << m << endl;
        }
        else{
            cout << D-m << endl;
        }
    }
    return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,m;
	cin>>n>>m;
	int a[n],sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int an=sum/(4*m),co=0;
	if(sum%(4*m)!=0) an++;
	for(int i=0;i<n;i++){
		if(a[i]>=an)
			co++;
	}
	if(co>=m)
		cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3592
// id: ALDS1_1_D
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::min;
using std::max;

static const int MAX_N = 200000;

int main()
{
	int n;
	int r[MAX_N];
	int minv, maxp;

	cin >> n;
	for ( int i = 0; i < n; ++i )
		cin >> r[i];

	minv = r[0];
	maxp = r[1] - r[0];

	for ( int i = 2; i < n; ++i ) {
		minv = min(minv, r[i - 1]);
		maxp = max(maxp, r[i] - minv);
	}

	cout << maxp << endl;

	return 0;
}


Measured memory_bytes: 3880
s = input()
odd = s[::2]
even = s[1::2]

flag1 = 1
for i in odd:
    if i not in ["R", "U", "D"]:
        flag1 = 0
flag2 = 1
for i in even:
    if i not in ["L", "U", "D"]:
        flag2 = 0
        
if flag1 == flag2 == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
    
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=10;
int[] k=new int[n];
for(int i=0;i<n;i++){
k[i]=Integer.parseInt(br.readLine());
}
Arrays.sort(k);
for(int i=0;i<3;i++){
System.out.println(k[n-i-1]);
}
}
}

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

int main(){
    int n;
    scanf("%d",&n);
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        int save;scanf("%d",&save);
        p[i]=make_pair(save,i);
    }
    sort(p,p+n);
    for(int i=0;i<n;i++){
        printf("%d ",p[i].second+1);
    }
}

Measured memory_bytes: 1536
#include<stdio.h>
int main(){
  int n,ans = 0;
  scanf("%d",&n);
  int a[2][n];
  for(int j = 0;j < 2;j++){
    for(int i = 0;i < n;i++){
      scanf("%d",&a[j][i]);
    }
  }
  for(int i = 0;i < n;i++){
    int sum = 0;
    for(int j = 0;j <= i;j++){
      sum += a[0][j];
    }
    for(int j = i;j < n;j++){
      sum += a[1][j];
    }
    if(ans < sum){
      ans = sum;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
n, m, c = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)

ans = 0

n.times do
  a = gets.chomp.split(" ").map(&:to_i)
  tmp = 0
  m.times do |i|
    tmp += a[i]*b[i]
  end
  ans += 1 if tmp+c > 0
end

puts(ans)


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define MOD 1000000007LL
#define C1  401
#define C2  397
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;

using namespace std;

int h,w,r,c;

vector<vector<ll> > genHash(const vector<string> v, int xs, int ys)
{
  vector<vector<ll> > h1(xs,vector<ll>(ys,0));
  vector<vector<ll> > h2(xs,vector<ll>(ys,0));
  ll cn1 = 1, cn2 = 1;
  REP(i,c) cn1 = (cn1*C1)%MOD;
  REP(i,r) cn2 = (cn2*C2)%MOD;
  REP(i,xs)
  {
    ll h = 0;
    REP(j,c) h=(h*C1+v[i][j])%MOD;
    REP(j,ys-c+1)
    {
      h1[i][j] = h;
      if(j+c<ys) h = (h*C1-v[i][j]*cn1+v[i][j+c])%MOD;
      h = (h<0)?h+MOD:h;
    }
  }
  REP(j,ys)
  {
    ll h = 0;
    REP(i,r) h=(h*C2+h1[i][j])%MOD;
    REP(i,xs-r+1)
    {
      h2[i][j] = h;
      if(i+r<xs) h = (h*C2-h1[i][j]*cn2+h1[i+r][j])%MOD;
      h = (h<0)?h+MOD:h;
    }
  }
  return h2;
}

int main()
{
  cin >> h >> w;
  vector<string> a(h);
  REP(i,h) cin >> a[i];
  cin >> r >> c;
  vector<string> b(r);
  REP(i,r) cin >> b[i];
  if(h<r||w<c) return 0;
  auto f = genHash(a,h,w);
  auto p = genHash(b,r,c);
  REP(i,h-r+1) REP(j,w-c+1) if(f[i][j] == p[0][0])
    printf("%d %d\n",i,j);
  return 0;
}

Measured memory_bytes: 28436
#include<iostream>
#include<algorithm>
#include<set>
#include<stdlib.h>
#define int long long
using namespace std;

int n, d;
struct Star {
	int x, y, b;
}star[200000];

signed compare(const void *s1, const void *s2) {
	int t1 = ((Star*)s1)->b;
	int t2 = ((Star*)s2)->b;
	return t1 - t2;
}
signed main() {
	int i;
	cin >> n >> d;
	for( i = 0; i < n; i++ )
		cin >> star[i].x >> star[i].y >> star[i].b;
	qsort(star, n, sizeof(star[0]), compare);

	static multiset<int> X;
	static multiset<int> Y;
	multiset<int>::iterator it;
	multiset<int>::reverse_iterator rit;
	int ins = 0;
	int del = 0;
	int j;
	int ans = 0;

	for( i = 0; i < n; i++ ) {
		ins = i;
		X.insert( star[ins].x );
		Y.insert( star[ins].y );
		for(; del < n; del++ ) {
			if( star[del].b < star[i].b - d ) {
				it = X.find( star[del].x );
				X.erase( it );
				it = Y.find( star[del].y );
				Y.erase( it );
			} else {
				break;
			}
		}

		it = X.begin();
		int minx = *it;
		rit = X.rbegin();
		int maxx = *rit;
		it = Y.begin();
		int miny = *it;
		rit = Y.rbegin();
		int maxy = *rit;
		ans = max( ans, (maxx - minx) * (maxy - miny) );
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int ans = 0;
  REP(i, a + 1) {
    REP(j, b + 1) {
      REP(k, c + 1) {
        if (500  * i + 100 * j + 50 * k == x)
          ++ans;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int a, b;
  cin >> a >> b;
  if (2 * b >= a) cout << 0 << endl;
  else cout << a - 2 * b << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  REP(i,n) cin>>a[i];

  vector<int> b;
  if(n%2){
    for(int i=n-1;i>=0;i-=2) b.emplace_back(a[i]);
    for(int i=1;i<n;i+=2) b.emplace_back(a[i]);
  }else{
    for(int i=n-1;i>=0;i-=2) b.emplace_back(a[i]);
    for(int i=0;i<n;i+=2) b.emplace_back(a[i]);
  }
  REP(i,b.size()){
    if(i!=0) cout<<" ";
    cout<<b[i];
  }
  cout<<endl;
  
  return 0;
}

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

int main()
{
	string s,str;
    cin>>s;
    int i;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='B' && str.length()>0)
        {
            str.erase(str.length()-1);
        }
        else if(s[i]=='0' || s[i]=='1')
        {
            str+=s[i];
        }
       // cout<<str<<endl;
            
    }
   // cout<<"ih"<<endl;
    cout<<str;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define all(v) v.begin(),v.end()
#define mset(a,i) memset(a,i,sizeof(a))
#define mii map<int,int>  
#define pii pair<int,int>
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds1;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { if(0) return; cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args){   
    if(0) return; 
    const char* comma = strchr (names + 1, ',');
    cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
void get_it_done(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int gcd(int a,int b){
    if(b==0) return a;
    if(a<b) return gcd(b,a);
    return gcd(b,a%b);
}
const int N = 3e5+5;

void solve(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    loop(i,0,n) cin>>a[i];
    sort(all(a));
    int ans = 0;
    loop(i,0,k) ans += a[i];

    cout<<ans<<endl;
}

int32_t main(){
    get_it_done(); 
    int tc=1;
    // cin >> tc;
    while (tc--){
        solve();        
    }
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,m; cin >> n >> m;
    vector<int> x(n),y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    vector<ll> sumx(n+1),sumy(m+1);
    rep(i,n){
        sumx[i+1] = sumx[i] + x[i];
    }
    rep(i,m){
        sumy[i+1] = sumy[i] + y[i];
    }
    ll sum1 = 0;
    rep(i,n-1){
        sum1 += sumx[n]-sumx[i+1]-(ll)x[i]*(n-i-1);
        sum1 %= MOD;
    }
    ll sum2 = 0;
    rep(i,m-1){
        sum2 += sumy[m]-sumy[i+1]-(ll)y[i]*(m-i-1);
        sum2 %= MOD;
    }
    ll ans = sum1*sum2%MOD;
    cout << ans << endl;
}



Measured memory_bytes: 2560
N, M = map(int,input().split())
L = [[int(x) for x in input().split()]for i in range(M)]

if M==0 and N==1:
  print(0)
  exit()

if M == 0:
  print(10**(N-1))
  exit()
  
number = [None]*N  
for i in range(M):
  if N>1 and (L[i][0] == 1 and L[i][1] == 0):
    print(-1)
    exit()
  elif number[L[i][0]-1]==None:
    number[L[i][0]-1]=L[i][1]
  elif number[L[i][0]-1]==L[i][1]:
    continue
  else:
    print(-1)
    exit()

Sum = 0    
    
if number[0]==None:
  Sum += 10**(N-1)
  for i in range(1,N):
    if number[i]!=None:
      Sum += number[i]*(10**(N-i-1))
    
else:
  for i in range(N):
    if number[i]!=None:
      Sum += number[i]*(10**(N-i-1))
    
print(Sum)


Measured memory_bytes: 38256
#include <stdio.h>

int main(void)
{
	int num[5];
	int i = 0, ans;

	while (i < 5)
	{
		scanf("%d ", &num[i]);
		if (num[i] == 0)
		{
			ans = i + 1;
			break;
		}
		i++;
	}
	printf("%d\n", ans);
	return (0);
}

Measured memory_bytes: 1724
n = int(input())
s = list(input().strip())

ans = -1
for i in range(n-1):
    temp = 0
    s_1st = list(set(s[0:i+1]))
    s_2nd = list(set(s[i+1:n+1]))
    for j in range(len(s_1st)):
        if s_1st[j] in s_2nd:
            temp += 1
    if ans <= temp:
        ans = temp
        
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[200010],c[200010];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    c[i]=0;
  }
  vector<int> v;
  for(int i=n;i>=1;i--){
    for(int j=i*2;j<=n;j+=i){
      a[i]^=c[j];
    }
    c[i]=a[i];
    if(c[i])v.push_back(i);
    
  }
  cout<<v.size()<<endl;
  for(auto t:v)cout<<t<<endl;
  return 0;
}
  
  


Measured memory_bytes: 3064