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

using namespace std;

long long mod = 1000000007;

long long binpow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = binpow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return binpow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (int i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (int i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    long long rez = (binpow(2, n) - binomial(n, a) - binomial(n, b) - 1) % mod;
    rez = (rez + mod) % mod;
    cout << rez << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


vector<ll>a,b;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x),b.push_back(x);
	}
	ll ans=0;
	sort(b.begin(),b.end());
	for(int i=0;i<n;i++){
		ll now=a[i];
		auto Iter1 = lower_bound(b.begin(),b.end(), now);
		ll j=Iter1 - b.begin() ;
		ll sa=abs(j-i);
		ans+=(sa%2);
	}
	cout<< (ans+2-1)/2;
	// your code goes here
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N); rep(i, N) cin >> a[i];
    vec b(N); rep(i, N) b[i] = a[i] - (i+1);

    sort(all(b));

    int bn = b[N/2];
    ll res = 0;
    rep(i, N){
        res += abs(b[i]-bn);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5888
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

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

typedef double lf;
const lf pai = 3.141592653589793238462643383279;
class point{
public:
  lf x, y;
  point(){}
  point(lf X, lf Y){x = X; y = Y;}
};

point operator + (point x, point y){return point(x.x + y.x, x.y + y.y);}
point operator - (point x, point y){return point(x.x - y.x, x.y - y.y);}
point operator * (point x, lf y){return point(x.x * y, x.y * y);}
point operator * (lf x, point y){return point(x * y.x, x * y.y);}

lf dot(point a, point b){return a.x * b.x + a.y * b.y;}
lf det(point a, point b){return a.x * b.y - a.y * b.x;}
lf len2(point a){return a.x * a.x + a.y * a.y;}
lf len(point a){return sqrt(a.x * a.x + a.y * a.y);}
lf sqr(lf x){return x * x;}

class circle{
public:
  point a; lf r;
  circle(){}
  circle(point A, lf R){a = A; r = R;}
};

void MOD(lf &x){while (x > pai) x -= (pai + pai); while (x < -pai) x += (pai + pai);}
int cross(circle a, circle b, lf &r1, lf &r2){
  lf D = len2(a.a - b.a);
  if (D > sqr(a.r + b.r)) return 0;
  else if (D < sqr(a.r - b.r)) return 0;
  lf t1 = atan2(b.a.y - a.a.y, b.a.x - a.a.x);
  lf t2 = acos((D + sqr(a.r) - sqr(b.r)) / (2 * sqrt(D) * a.r));
  r1 = t1 - t2; r2 = t1 + t2; MOD(r1); MOD(r2);
  return 1;
}

point P[2333];
int n, M;

pair <lf, int> d[2333];
int l;
void add(lf L, lf R){d[++l] = make_pair(L, 1); d[++l] = make_pair(R, -1);}
bool check(int p, lf r){
  int i, j; lf _l, _r;
  circle cb(P[p], r);
  l = 0;
  for (i = 1; i <= n; i++)
    if (i != p){
      circle cr(P[i], r);
      if (cross(cb, cr, _l, _r)){
	if (_l > _r) add(_l, pai), add(-pai, _r);
	else add(_l, _r);
      }
    }
  sort(d + 1, d + l + 1);
  j = 0;
  for (i = 1; i <= l; i++){
    j += d[i].second; if (j >= M - 1) return 1;
  }
  return 0;
}

#define m (l + r) / 2
int p[2333];
int main(){
  int i, j;
  lf ans = 1e10, l, r;
  scanf("%d", &n);
  M=n;
  for (i = 1; i <= n; i++) scanf("%lf %lf", &P[i].x, &P[i].y), p[i] = i;
  random_shuffle(p + 1, p + n + 1);
  for (i = 1; i <= n; i++)
    if (check(p[i], ans)){
      for (l = 0, r = ans; r - l > 1e-7; )
	if (check(p[i], m)) r = m; else l = m;
      ans = r;
    }
  printf("%.9lf", ans);
  return 0;
}

Measured memory_bytes: 384
local mod = 1000000007

local function bmul(x, y) return (x * y) % mod end
local function badd(x, y) return (x + y) % mod end

local h, w, k = io.read("*n", "*n", "*n")
if w == 1 then
  print(1)
else
  local t = {1}
  for i = 2, w do t[i] = 0 end
  local tot = 2^(w - 1)
  local map = {}
  for i = 1, w do
    map[i] = {}
    for j = 1, w do
      map[i][j] = 0
    end
  end
  for it = 0, tot - 1 do
    local valid = true
    local flag = {}
    for i = 1, w - 1 do
      flag[i] = it % 2 == 1
      it = it // 2
    end
    for i = 1, w - 2 do
      if flag[i] and flag[i + 1] then
        valid = false
      end
    end
    if valid then
      for i = 1, w do
        if i == 1 then
          if flag[1] then
            map[1][2] = map[1][2] + 1
          else
            map[1][1] = map[1][1] + 1
          end
        elseif i == w then
          if flag[w - 1] then
            map[w][w - 1] = map[w][w - 1] + 1
          else
            map[w][w] = map[w][w] + 1
          end
        else
          if flag[i] then
            map[i][i + 1] = map[i][i + 1] + 1
          elseif flag[i - 1] then
            map[i][i - 1] = map[i][i - 1] + 1
          else
            map[i][i] = map[i][i] + 1
          end
        end
      end
    end
  end
  for ih = 1, h do
    local nt = {}
    for i = 1, w do nt[i] = 0 end
    for src = 1, w do
      for dst = 1, w do
        nt[dst] = badd(nt[dst], bmul(t[src], map[src][dst]))
      end
    end
    for i = 1, w do t[i] = nt[i] end
  end
  print(t[k])
end


Measured memory_bytes: 880
N = int(input())
A = list(map(int,input().split()))
print(*A)
for i in range(1,N):
    v = A[i]
    j = i - 1
    while j >= 0 and A [j] > v :
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(*A)

Measured memory_bytes: 5984
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000000000000001;
const long double E = 0.00000001;

using namespace std;

vector<p> factor(int n){
    vector<p> ans;
    int sqrt1 = sqrt(n);
    for (int q = 2; q <= sqrt1; q++){
        if (n % q == 0){
            ans.push_back({q, 1});
        }
        while (n % q == 0){
            n /= q;
            ans.back().second *= q;
        }
    }
    if (n != 1){
        ans.push_back({n, n});
    }
    return ans;
}

pair<int, p> ax_by(int x, int y){
    if (x > y){
        pair<int, p> k = ax_by(y, x);
        return {k.first, {k.second.second, k.second.first}};
    }
    if (x == 0){
        return {y, {0, 1}};
    }
    pair<int, p> k = ax_by(y % x, x);
    return {k.first, {k.second.second-k.second.first*((y-y % x)/x), k.second.first}};
}

int mul(int x, int y){
    if (x == 0 || INF/x >= y){
        return x*y;
    }
    return INF;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    n *= 2;
    vector<p> fact = factor(n);
    int N = (1 << fact.size()), ans = INF;
    for (int q = 0; q < N; q++){
        int pr = 1;
        for (int q1 = 0; q1 < fact.size(); q1++){
            if ((q >> q1) & 1){
                pr *= fact[q1].second;
            }
        }
        pair<int, p> ans1 = ax_by(pr, n/pr);
        if (ans1.first == 1){
            int t = min(mul(abs(ans1.second.first), pr), mul(abs(ans1.second.second), n/pr));
            if (t > 0 && ans > t) {
                ans = t;
            }
            if (ans1.second.first > 0){
                ans1.second.first -= n/pr/ans1.first, ans1.second.second += pr/ans1.first;
            }else{
                ans1.second.first += n/pr/ans1.first, ans1.second.second -= pr/ans1.first;
            }
            t = min(mul(abs(ans1.second.first), pr), mul(abs(ans1.second.second), n/pr));
            if (t > 0 && ans > t) {
                ans = t;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int a[3],i,j,buff,task;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atoi(p);
  p=strtok(NULL," \n");
  a[1]=atoi(p);
  p=strtok(NULL," \n");
  a[2]=atoi(p);
  
  for(i=0;i<3;i++){
    for(j=2;j>i;j--){
      if(a[j-1]>a[j]){
        buff=a[j-1],a[j-1]=a[j],a[j]=buff;
      }
    }
  }
  
  task=a[2]-a[0];
  printf("%d",task);
  
  return 0;
}

Measured memory_bytes: 128
import sys
import numpy as np

input = sys.stdin.readline

X, N = map(int, input().split())
p = set(map(int, input().split()))

abs_v = np.inf
res = 0
s = {i for i in range(102)}
for x in (s-p):
    if abs_v > abs(X-x):
        abs_v = abs(X-x)
        res = x

print(res)


Measured memory_bytes: 27180
#include<stdio.h>
#include<string.h>
 
#define N 3
#define LIM 32
#define HN 362897
 
 
 
struct dep{
  int depth,key;
};
   
   
   
int ans[N][N]={
  {1,2,3},
  {4,5,6},
  {7,8,0}
};
 
int min = LIM;
struct dep h[HN];
 
int hash1(int k)
{
  return k % HN;
}
int hash2(int k)
{
  return 1 + k%(HN-1);
}
int hash(int k, int i)
{
  return (hash1(k) + i*hash2(k))%HN;
}
 
 
void dfs(int p[N][N], int n)
{
  int i,j,i0,j0,a=0,b=1;
  int f=0;
  int tmp[N][N];
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      if(ans[i][j]!=p[i][j])f++;
      if(p[i][j]==0)
      {
        i0=i;
        j0=j;
      }
      a+=p[i][j]*b;
      b*=10;
    }
  }
 
  if(f==0)
  {
    if(min>=n)
    {
      min=n;
    }
    return;
  }
  if(n>min) return;
  i=0;
  while(1)
  {
    b=hash(a, i);
    if(h[b].key == 0)
    {
      h[b].key=a;
      h[b].depth=n;
      break;
    }
    else if(h[b].key == a)
    {
      if(h[b].depth>n)
      {
        h[b].depth=n;
        break;
      }
      else return;
    }
    i++;
  }
 
  if(i0>0 && i0<N)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0-1][j0];
    tmp[i0-1][j0]=f;
    dfs(tmp, n+1);
  }
  if(j0>0 && j0<N)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0-1];
    tmp[i0][j0-1]=f;
    
    dfs(tmp, n+1);
  }
 
  if(i0>=0 && i0<N-1)
  
  
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0+1][j0];
    tmp[i0+1][j0]=f;
    dfs(tmp, n+1);
  }
  if(j0>=0 && j0<N-1)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0+1];
    tmp[i0][j0+1]=f;
    dfs(tmp, n+1);
  }
 
 
}
 
int main()
{
  int i,j;
  int p[N][N];
 
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      scanf("%d",&p[i][j]);
    }
  }
  dfs(p,0);
 
 
  printf("%d\n",min);
 
  return 0;
}


Measured memory_bytes: 4676
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
typedef long long int lli;
void merge (long long int arr[], long long int l, long long int m, long long int r)
{
	long long int i, j, k, n1 = m - l + 1, n2 =  r - m, L[n1], R[n2];
	for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j];
	i = 0;j = 0;k = l;
	while (i < n1 && j < n2)
	{if (L[i] <= R[j]) arr[k++] = L[i++]; else arr[k++] = R[j++];}
	while (i < n1) arr[k++] = L[i++]; while (j < n2) arr[k++] = R[j++];
}
void mergesort (long long int arr[], long long int l, long long int r)
{
	if (l < r)
	{
		long long int m = l+(r-l)/2;
		mergesort(arr, l, m);
		mergesort(arr, m+1, r);
		merge(arr, l, m, r);
	}
}
int cmp (const void *a, const void *b)
{
	return *(long long int *)a - *(long long int *)b;
}

//qsort(arr,n,sizeof(long long int),cmp);
//mergesort(arr, 0, arr_size - 1);

int main ()
{
	long long int n,a,b,c,d,l1,l2,r1,r2,flag=0,lol=0 ;
	char str[210000] ;

	scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);
	scanf("%s", str);

	if (a<b)
	{
		l1=a;
		l2=c;
		r1=b;
		r2=d;
	}

	else
	{
		l1=b;
		l2=d;
		r1=a;
		r2=c;
	}

	if (r2<l2)
	{
		lol=5;
	}


	if (lol==5)
	{
		flag=1;

		for (int i=r1-1 ; i<r2 ; i++)
		{
			if (str[i-1]=='.' && str[i]=='.' && str[i+1]=='.')
				flag=0;
		}
	}

	for (int i=l1-1 ; i<l2-1 ; i++)
	{
		if (str[i]=='#' && str[i+1]=='#')
			flag++;
	}

	for (int i=r1-1 ; i<r2-1 ; i++)
	{
		if (str[i]=='#' && str[i+1]=='#')
			flag++;			
	}

	if (flag)
		printf("No\n");

	else
		printf("Yes\n");


	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll MOD;
const ll INF = (1ll << 60);

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    ll k;
    cin >> k;

    MOD = k;

    ll ans = 7;

    for (ll i = 1; i < 1000010; i++)
    {

        if (ans % k == 0)
        {
            cout << i  << endl;
            return 0;
        }

        ans += 7 * power(10, i);

        ans %= MOD;
    }

    cout << -1 << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    int sum=0,neg=0;
    rep(i,n){
        cin >> a[i];
        if(a[i]<0) neg++;
        a[i]=abs(a[i]);
        sum+=a[i];
    }
    if(neg%2==1) cout<<sum-MIN(a)*2<<endl;
    else cout<<sum<<endl;
    
}

Measured memory_bytes: 3864
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i]=0

for i in range(N):
    for w in range(W+1):
        if weight[i]<=w:
            dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w]=dp[i][w]
print(dp[N][W])


Measured memory_bytes: 171656
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>
#include <cassert>

using namespace std;

using i64 = long long int;
using u64 = std::uint_fast64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
constexpr i64 MOD = 1000000007;
constexpr i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

vector<int64_t> dijkstra(Graph G, int64_t s) {
    vector<int64_t> dist(G.size(), INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s);
    while (!que.empty()) {
        int64_t cost, idx;
        tie(cost, idx) = que.top(); que.pop();
        if (dist[idx] < cost) continue;
        for (edge e : G[idx]) {
            int64_t next_cost = cost + e.cost;
            if (dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main() {
    i64 a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k % 2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {


  var inp = input.split('\n');

  var buf = inp[0].split(' ');

  var N = parseInt(buf[0]);
  var x = parseInt(buf[1]);

  var an = inp[1].split(' ');

  // ソート
  an.sort(function (a, b) {
    return a - b;
  })

  var ans = 0;
  for (var i = 0; i < N; i++) {
    if(an[i] <= x){
      x -= an[i];
      ans++;
    }else{
      break;
    }
    if(i === N - 1){
      if(x !== 0) ans--;
    }
  }

  console.log('%d', ans);

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



Measured memory_bytes: 21320
#include<bits/stdc++.h>
#define YOU setprecision
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e,f;
  for(int n=0;n<5;n++) cin >>i[n];
  cin >>a;
  if(i[4]-i[0]>a) cout <<":(\n";
  else cout <<"Yay!\n";
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, f[MAXN];
vector<int> a[MAXN], b[MAXN], gr, A[MAXN], B[MAXN];
bool visit1[MAXN], visit2[MAXN];

void dfs1(int u) {
    gr.emplace_back(u);
    visit1[u] = true;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (!visit1[v]) dfs1(v);
    }
}

void dfs2(int u) {
    gr.emplace_back(u);
    visit2[u] = true;
    FOR(i,0,SZ(b[u])-1) {
        int v = b[u][i];
        if (!visit2[v]) dfs2(v);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        int x, y;
        cin >> x >> y;
        A[x].emplace_back(y);
        B[y].emplace_back(x);
    }
    FOR(i,1,100000) {
        if (SZ(A[i]) > 1) {
            FOR(j,0,SZ(A[i])-2) {
                b[A[i][j]].emplace_back(A[i][j+1]);
                b[A[i][j+1]].emplace_back(A[i][j]);
                // cout << "b " << A[i][j] << ' ' << A[i][j+1] << "\n";
            }
        }
        if (SZ(B[i]) > 1) {
            FOR(j,0,SZ(B[i])-2) {
                a[B[i][j]].emplace_back(B[i][j+1]);
                a[B[i][j+1]].emplace_back(B[i][j]);
                // cout << "a " << B[i][j] << ' ' << B[i][j+1] << "\n";
            }
        }
    }
    FOR(i,1,100000)
        if (!visit2[i]) {
            gr.clear();
            dfs2(i);
            FOR(j,0,SZ(gr)-1) f[gr[j]] = SZ(gr);
        }
    ll res = 0;
    FOR(i,1,100000)
        if (!visit1[i]) {
            gr.clear();
            dfs1(i);
            if (SZ(A[gr[0]]) == 0) continue;
            int e = f[A[gr[0]][0]];
            if (SZ(gr) >= 2 && e >= 2) { 
                ll kq = (ll) SZ(gr) * e;
                FOR(j,0,SZ(gr)-1) kq -= SZ(A[gr[j]]);
                res += kq;
            }
            //cout << i << ' ' << res << endl;
        }
    cout << res;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  bool a = false;
  for(int i=0;i<3;i++){
    if(S.at(i)==S.at(i+1)){
      a=true;
      break;
    }
  }
  if(a){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  dsu d(n);
  rep(i,m) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    d.merge(a,b);
  }
  ll cnt = d.groups().size();
  ll ans = cnt-1;
  cout << ans << endl;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

vvl memo(2001,vl(2001,-1));
ll choose(ll x,ll y){
  if(memo[x][y]!=-1){
    return memo[x][y];
  }
  else{
    if(x<0||y<0){
      return 0;
    }
    else if(x<y){
      memo[x][y]=0;
      return 0;
    }
    else if(y==0){
      memo[x][y]=1;
      return memo[x][y];
    }
    else if(x==y){
      memo[x][y]=1;
      return 1;
    }
    else{
      memo[x][y]=(choose(x-1,y-1)+choose(x-1,y))%MOD;
      return memo[x][y];
    }
  }
}

int main() {
  ll n,k;
  cin >> n >> k;
  FOR(i,1,k+1){
    cout << choose(n-k+1,i)*choose(k-1,i-1)%MOD << endl;
  }
}

Measured memory_bytes: 31744
#そもそもO(N^2)の意識がなかった
#無理やり最短距離を求めようとして数え忘れたパターンがあった
#このパターンはしっかりサンプル見て実験していれば避けれていた
#自分の考察に自信を持つ姿勢はいいけど、詰まったら疑って実験する
n,x,y=map(int,input().split())
ans=[[1000000]*n for i in range(n)]
for i in range(n-1):
    ans[i][i+1]=1
ans[x-1][y-1]=1
for i in range(n-1):
    for j in range(i+1,n):
        ans[i][j]=min(j-i,abs(x-1-i)+1+abs(y-1-j))
_ans=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        _ans[ans[i][j]-1]+=1
for i in range(n-1):
    print(_ans[i])


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

using namespace std;

vector < int > g[100005];

main() {
    //freopen("input.txt", "r", stdin):
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, x, y, ans = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> x >> y;
        g[x].push_back(y);
    }
    multiset < int > Q;
    for (int i = m; i >= 1; --i) {
        for (auto key : g[m - i + 1]) {
            Q.insert(key);
        }
        if ((int)Q.size() != 0) {
            int x = (*Q.rbegin());
            ans += x;
            Q.erase(Q.find(x));
        }
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l;
string s;
int main() {
  cin>>n;
  for(long long i=1;i<=n;i++) {
      for(long long j=1;j<=n;j++) {
          for(long long a=1;a<=n;a++) {
              b=__gcd(i,j);
              c=__gcd(b,a);
              //cout<<c<<" ";
              k+=c;
          }
      }
  }
  cout<<k;
}


Measured memory_bytes: 3636
/*
 *       ~ AtCoder  Botay ~
 *        code by kazalika
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const ll mod = 998244353;

ll fact[N], invf[N];

ll pw(ll a, ll b) {
  if (!b)
    return 1;
  if (b & 1)
    return (pw(a, b - 1) * a) % mod;
  ll v = pw(a, b / 2);
  return (v * v) % mod;
}

ll inv(ll x) {
  return pw(x, mod - 2);
}

ll mult(ll a, ll b) {
  return (a * b) % mod;
}

ll C(ll k, ll n) {
  return mult(invf[k], mult(fact[n], invf[n - k]));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  fact[0] = 1;
  invf[0] = inv(1);
  for (int i = 1; i < N; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
    invf[i] = inv(fact[i]);
  }
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans += mult(m, mult(C(i, n - 1), pw(m - 1, n - i - 1)));
    if (ans >= mod)
      ans -= mod;
  }
  cout << ans;

}

Measured memory_bytes: 6740
<?php
/*
    Problem URL : http://agc002.contest.atcoder.jp/tasks/agc002_c

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// N L
// a1 a2 … aN


fscanf(STDIN, "%d %d", $N, $L);
$a = explode(" ", trim(fgets(STDIN)));

$b = array();
$p = null;

for ($i = 0; $i < $N - 1; $i++) {
    $b[$i] = $a[$i] + $a[$i+1];
    if ($b[$i] >= $L) {
        $p = $i;
    }
}

if (max($b) >= $L) {
    echo "Possible\n";
} else {
    exit("Impossible\n");
}

for ($i = 1; $i <= $p; $i++) {
    echo $i . PHP_EOL;
}

for ($i = $N-1; $i > $p; $i--) {
    echo $i . PHP_EOL;
}


Measured memory_bytes: 35888
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=60;
int  n,m,g[maxn][maxn];
int dr[8][2]={1,0,-1,0,0,1,0,-1,1,1,-1,1,1,-1,-1,-1};
char ch[maxn][maxn];
bool check(int x,int y){
	if(x>0&&x<=n&&y>0&&y<=m)
		return true;
	return false;
}
int main(){
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(i=1;i<=n;i++){
			scanf("%s",ch[i]+1);
		}
		memset(g,0,sizeof(g));
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(ch[i][j]=='#'){
					int k,xx,yy;
					for(k=0;k<8;k++){
						xx=i+dr[k][0];
						yy=j+dr[k][1];
						if(check(xx,yy)){
							g[xx][yy]++;
						}
					}
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(ch[i][j]=='#')
					printf("%c",ch[i][j]);
				else
					printf("%d",g[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    int N,K;
    cin >> N >> K;
    int l[N];
    REP(i,N){
        cin >> l[i];
    }
    sort(l,l+N);
    int sum=0;
    FOR(i,N-K,N){
        sum += l[i];
    }
    cout << sum;
}

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

int main(void) {
  int i, j, k, a, b, t = 1;
  char s[50];
  scanf("%d%d", &a, &b);
  scanf("%s", s);
  if(strlen(s) != a + b + 1) {
    printf("No");
    return 0;
  }
  for(i = 0; i < a; ++i) {
    if(s[i] < '0' || s[i] > '9') t = 0;
  }
  if(s[a] != '-') t = 0;
  for(i = a + 1; i < a + b + 1; ++i) {
    if(s[i] < '0' || s[i] > '9') t = 0;
  }
  if(t) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main()
{
    ll N, K;
    cin >> N >> K;

    map<ll, ll > map;
    for ( ll i = 0; i < N; ++ i ){
        ll n;
        cin >> n;
        map[n]++;
    }
    if ( map.size() < K ){
        cout << 0 << endl;
    }
    else{
        vector< ll > vec;
        for ( auto m : map ){
            vec.push_back(m.second);
        }
        sort(vec.begin(), vec.end());
        ll count =0;
        for ( ll i = 0; i < vec.size() - K; ++ i ){
            count += vec[i];
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 17688
R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n//R+1):
  for g in range((n-r*R)//G+1):
    b = (n-r*R-g*G)//B
    if r * R + g*G + b*B == n:
      cnt += 1
print(cnt)

Measured memory_bytes: 40556
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<ll> a(N, 0LL);
	rep (i, N){
		cin >> a[i];
	} // end rep

	map<ll,int> cnt; cnt.clear();
	rep (i, N){
		++cnt[a[i]];
	} // end rep

	vector<ll> cand2; cand2.clear();
	vector<ll> cand4; cand4.clear();
	map<ll,int>::iterator it = cnt.begin();
	for (;it != cnt.end(); ++it){
		ll side = (*it).first;
		int c = (*it).second;
		if (c >= 2){
			cand2.push_back(side);
		} // end if
		if (c >= 4){
			cand4.push_back(side);
		} // end if
	} // end for

	ll res = 0LL;
	if (!cand2.empty()){
		sort(ALL(cand2), greater<ll>());
		if ((int)cand2.size() >= 2){
			res = max(res, cand2[0] * cand2[1]);
		} // end if
	} // end if

	if (!cand4.empty()){
		sort(ALL(cand4), greater<ll>());
		res = max(res, cand4[0] * cand4[0]);
	} // end if
	cout << res << endl;
 
	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

int A,B,C,D,k;

inline bool check(int mid)
{
	int a=A-mid/(k+1)*k-mid%(k+1);
	int b=B-mid/(k+1);
	return b<=1LL*a*k;
}

int main()
{
	int T=read();
	while (T--)
	{
		A=read(),B=read(),C=read(),D=read();
		k=max(ceil(1.0*A/(B+1)),ceil(1.0*B/(A+1)));
		int left=0,right=A+B+1;
		while (left<right)
		{
			int mid=(left+right)>>1;
			if (check(mid))
				left=mid+1;
			else
				right=mid;
		}
		int a=A-left/(k+1)*k-left%(k+1);
		int b=B-left/(k+1);
		right=left+b-a*k+1;
		for (int i=C;i<=min(D,left);i++)
		{
			if (i%(k+1))
				cout << 'A';
			else
				cout << 'B';
		}
		for (int i=max(C,left+1);i<=D;i++)
		{
			if ((A+B-i+1)%(k+1))
				cout << 'B';
			else
				cout << 'A';
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  
  sort(S.begin(),S.end());
  
  string answer;
  
  for(int i = 0; i < N; i++){
    answer += S.at(i);
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
	ll N;
  	cin >> N;
  	vll L(1000);
  	L[0] =2;
  	L[1] =1;
  	for(int i=2;i<=200;i++)L[i]=L[i-1]+L[i-2];
  	cout << L[N] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int A[500005],i,H;
void maxHeapify(int p)
{
    int l=p*2+1;
    int r=p*2+2;
    int lg=p;
    if(l<=H&&A[l]>A[lg])
        lg=l;
    if(r<=H&&A[r]>A[lg])
        lg=r;
    if(lg!=p){
 
        r=A[p];
        A[p]=A[lg];
        A[lg]=r;
        maxHeapify(lg);
    }
}
int main()
{
    scanf("%d",&H);
    for(i=0;i<H;i++)
        scanf("%d",A+i);
    for(i=H/2;i>=0;i--)
        maxHeapify(i);
    for(i=0;i<H;i++)
        printf(" %d",A[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string s; 
  cin >> s;
  
  string res = "No";
  
  if (s.at(2) == s.at (3) && s.at(4) == s.at (5)) { 
    res = "Yes";
  } 

  cout << res << endl;
  
}

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

int main(){
	int n;  
	cin >> n;
  	int hun = n /100;
  	int ten = (n - hun *100)/10;
  	int one = (n - hun * 100)%10;
  	//cout << hun <<ten << one;
  	if(hun == 1){
      hun = 9;
    }
  	else if(hun == 9){
      hun =1;
    }
  
  	if(ten == 1){
      ten = 9;
    }
  	else if(ten == 9){
      ten =1;
    }
  	
  	if(one == 1){
      one = 9;
    }
  	else if(one == 9){
      one =1;
    }
  cout << hun <<ten <<one;
  	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(Console.ReadLine());
		}
		Array.Sort(A);
		long a = 0;
		long b = 0;
		long max = 0;
		if(N%2==1){
			a = 0;
			b = A[N/2];
			for(var i=0;i<=N/2-1;i++){
				a += Math.Abs(A[i]- b);
				b = A[i];
				a += Math.Abs(A[N-1-i] - b);
				b = A[N-1-i];
			}
			max = a;
			a = 0;
			b = A[N/2];
			for(var i=0;i<=N/2-1;i++){
				a += Math.Abs(A[N-1-i]- b);
				b = A[N-1-i];
				a += Math.Abs(A[i] - b);
				b = A[i];
			}
			max = Math.Max(a,max);
		} else {
			a = 0;
			b = A[N/2-1];
			for(var i=0;i<=N/2-2;i++){
				a += Math.Abs(A[i]- b);
				b = A[i];
				a += Math.Abs(A[N-1-i] - b);
				b = A[N-1-i];
			}
			a += Math.Abs(A[N/2] - b);
			max = a;
			a = 0;
			b = A[N/2-1];
			for(var i=0;i<=N/2-2;i++){
				a += Math.Abs(A[N-1-i]- b);
				b = A[N-1-i];
				a += Math.Abs(A[i] - b);
				b = A[i];
			}
			a += Math.Abs(A[N/2] - b);
			max = Math.Max(a,max);
		}
		Console.WriteLine(max);
	}
}

Measured memory_bytes: 17344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		long min = Long.MAX_VALUE;
		int diff = r - l;
		int start = l;
		int end = r;
		if (diff >= 2019) {
			for (int i = 0; i < 2019; i++) {
				if (min > (l + i) % 2019L) {
					start = l + i;
					min = (l + i) % 2019L;
				}
			}
			
			end = start + 2019;
		}
		
		min = Long.MAX_VALUE;
		for (int i = start; i <= end; i++) {
			for (int j = start; j <= end; j++) {
				if (i == j) {
					continue;
				}
				long tmp = (i % 2019L * j % 2019L) % 2019;
				if (min > tmp) {
					min = tmp;
				}
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 23124
from typing import List

def parent(i: int) -> int:
	return i // 2

def left(i: int) -> int:
	return 2 * i

def right(i: int) -> int:
	return 2 * i + 1


def maxHeapify(A: List[int], i: int) -> None:
	l = left(i)
	r = right(i)
	if l <= H and A[l] > A[i]:
		largest = l
	else:
		largest = i
	if r <= H and A[r] > A[largest]:
		largest = r
	
	if largest != i:
		A[i], A[largest] = A[largest], A[i]
		maxHeapify(A, largest)

def buildMaxHeap(A: List[int]) -> None:
	for i in range(H//2, 0, -1):
		maxHeapify(A, i)


if __name__ == "__main__":
	H = int(input())
	A = [None] + list(map(int, input().split()))
	buildMaxHeap(A)
	for i in range(1, H + 1):
		print(f" {A[i]}", end="")
	print()


Measured memory_bytes: 63996
#include <stdio.h>
#include <math.h>
int main(void)
{
  unsigned long n,d;
  double p,q;
  int count = 0;
  scanf("%lu%lu", &n, &d);
  for(int i=0; i<n; ++i) {
    unsigned long p, q;
    scanf("%lu%lu", &p, &q);
    p = p*p;
    q = q*q;
    count += (sqrt(p+q) <= d) ? 1 : 0;
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2152
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> box(N);
  int X = 0,count = 0,countx = 0;
  for(int i = 0;i < N;i++){
    cin >> box.at(i);
    count = max(count,box.at(i));
    if(count != countx){
      X = i;
    }
    countx = count;
  }
  int countt = 0;
  for(int i = 0;i < N;i++){
    if(i != X){
      countt = max(countt,box.at(i));
    }
  }
  for(int i = 0;i < N;i++){
    if(i != X){
      cout << count << endl;
    }else{
      cout << countt << endl;
    }
  }
}


Measured memory_bytes: 3932
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b, c;
	cin >> a >> b >> c;
	if(c >= a && c <= b)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
high = list(map(int, input().split()))

tenbodai = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    tenbodai[a-1] = max(tenbodai[a-1], high[b-1])
    tenbodai[b-1] = max(tenbodai[b-1], high[a-1])

res = sum([high[i] > tenbodai[i] for i in range(n)])
print(res)

Measured memory_bytes: 20124
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Int, a: IntArray, b: IntArray){
    val edgeColors = IntArray(N-1)
    data class Edge(val id: Int, val destNode: Int)
    val nodeToEdges = Array(N){ mutableListOf<Edge>() }
    for(i in 0 until N-1){
        nodeToEdges[a[i]-1].add(Edge(i, b[i]-1))
        nodeToEdges[b[i]-1].add(Edge(i, a[i]-1))
    }
    val K = nodeToEdges.map{ it.size }.max()!!
    fun iterColor(exclude: Int) = (1..K).asSequence().filter{ it != exclude }.iterator()
    val doneNodes = mutableSetOf<Int>()
    val queue = ArrayDeque<Pair<Int, Int>>()
    queue.add(1 to -1)
    while(queue.size > 0){
        val (node, usedColor) = queue.removeFirst()
        val colors = iterColor(usedColor)
        nodeToEdges[node].forEach{
            if(it.destNode !in doneNodes){
                val color = colors.next()
                edgeColors[it.id] = color
                queue.addLast(it.destNode to color)
            }
        }
        doneNodes.add(node)
    }
    pw.println(K)
    for (color in edgeColors) pw.println(color)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = IntArray((N-1))
    val b = IntArray((N-1))
    for (i in 0 until (N-1)) {
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
    }
    solve(N, a, b)
}



Measured memory_bytes: 85292
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int H, W;
string S[2010];
VI sH[2010];
VI sW[2010];


signed main(){
    cin >> H >> W;
    rep(i, 0, H) cin >> S[i];

    rep(i, 0, H){
        sH[i].pb(-1);
        rep(j, 0, W)
            if(S[i][j] == '#') sH[i].pb(j);
        sH[i].pb(W);
    }
    rep(j, 0, W){
        sW[j].pb(-1);
        rep(i, 0, H)
            if(S[i][j] == '#') sW[j].pb(i);
        sW[j].pb(H);
    }

    int ans = 0;
    rep(i, 0, H){
        rep(j, 0, W){
            if(S[i][j] == '#') continue;
            int x = distance(sH[i].begin(), lb(ALL(sH[i]), j));
            int y = distance(sW[j].begin(), lb(ALL(sW[j]), i));
            chmax(ans, sH[i][x]-sH[i][x-1]-1+sW[j][y]-sW[j][y-1]-1-1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 68480
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	var x int
	sc.nextInts(&x)
	for i := x; i < 1e6; i++ {
		var ng bool
		for j := 2; j <= int(math.Sqrt(float64(i))); j++ {
			if i%j == 0 {
				ng = true
				break
			}
		}
		if !ng {
			fmt.Println(i)
			return
		}
	}
}

type scanner struct {
	sc *bufio.Scanner
}

var sc *scanner

func init() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	sc = &scanner{sc: s}
}

func (s *scanner) nextInts(ints ...*int) {
	for i := range ints {
		s.sc.Scan()
		*ints[i], _ = strconv.Atoi(s.sc.Text())
	}
}

func (s *scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut a: i64 = read();
    let mut b: i64 = read();
    if a == b {
        println!("{}", 1);
        return;
    }
    let mut a2: Vec<i64> = vec![0; 61];
    let mut b2: Vec<i64> = vec![0; 61];
    let mut index = 0;
    while a > 0 {
        a2[60 - index] = a % 2;
        a /= 2;
        index += 1;
    }
    index = 0;
    while b > 0 {
        b2[60 - index] = b % 2;
        b /= 2;
        index += 1;
    }
    let mut r = 60;
    for i in 0..61 {
        if a2[i] != b2[i] {
            r = i;
            break;
        }
    }
    let mut a = 0;
    for i in r..61 {
        a *= 2;
        a += a2[i];
    }
    let po1 = 2_i64.pow(60 - r as u32) - 1;
    let mut ans = (po1 - a + 1) * 2;
    let mut flag = false;
    let mut po2 = 0;
    for i in r + 1..61 {
        if b2[i] == 1 {
            flag = true;
        }
        po2 *= 2;
        po2 += if flag { 1 } else { b2[i] };
    }
    po2 += 2_i64.pow(60 - r as u32);
    let b = 2_i64.pow(60 - r as u32);
    let c = a + 2_i64.pow(60 - r as u32);
    ans += po2 - b + 1;
    if c <= po2 {
        ans -= (po2 - c) + 1;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352