akhauriyash/Code-Regression huggingface dataset:
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    cout << min(n % k, k - n % k) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

using pt = complex<ld>;
const int N = 60;
int n, k;
ld x[N], y[N], c[N];

vector<pt> cxc(pt c1, ld r1, pt c2, ld r2) {
  ld dq = norm(c1-c2), rq=r1*r1-r2*r2;
  pt c = (c1+c2)+(c2-c1)*rq/dq; c*=.5;
  ld dt=2*dq*(r1*r1+r2*r2)-dq*dq-rq*rq;
  if (dt < -EPS) return {};
  if (dt < EPS) return {c};
  dt=sqrt(dt)/2/dq;
  pt d = (c2-c1)*pt(0,1)*dt;
  return {c+d, c-d};
}

bool poss(ld t) {
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      auto pts = cxc({x[i], y[i]}, t/c[i], {x[j], y[j]}, t/c[j]);
      for (pt p : pts) {
        int cnt = 0;
        for (int l = 0; l < n; ++l) {
          pt o = {x[l], y[l]};
          ld d = abs(o-p);
          if (d - EPS < t/c[l]) {
            cnt++;
            if (cnt >= k) return true;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    pt p(x[i], y[i]);
    int cnt = 0;
    for (int l = 0; l < n; ++l) {
      pt o = {x[l], y[l]};
      ld d = abs(o-p);
      if (d - EPS < t/c[l]) {
        cnt++;
        if (cnt >= k) return true;
      }
    }
  }
  return false;
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> c[i];
  }
  ld lo = 0, hi = 1e10;
  while (abs(hi - lo) > EPS) {
    ld mid = (lo+hi)/2;
    if (poss(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << nl;

  return 0;
}



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

using namespace std;

using ll = long long;

ll memo[4];

int main() {
  ll n, W;
  cin >> n >> W;
  vector<vector<ll>> vv(4);
  for (int i = 0; i < n; ++i) {
    ll w, v;
    cin >> w >> v;
    vv[w % 4].push_back(v);
    memo[w % 4] = w;
  }
  for (int i = 0; i < 4; ++i) {
    sort(vv[i].rbegin(), vv[i].rend());
    for (int j = 1; j < (int)vv[i].size(); ++j) {
      vv[i][j] += vv[i][j - 1];
    }
  }
  for (int i = 0; i < 4; ++i) {
    vv[i].insert(vv[i].begin(), 0);
  }
  ll ans = 0;
  for (int i = 0; i < (int)vv[0].size(); ++i) {
    for (int j = 0; j < (int)vv[1].size(); ++j) {
      for (int k = 0; k < (int)vv[2].size(); ++k) {
        for (int l = 0; l < (int)vv[3].size(); ++l) {
          if (memo[0] * i + memo[1] * j + memo[2] * k + memo[3] * l <= W) {
            ans = max(ans, vv[0][i] + vv[1][j] + vv[2][k] + vv[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main() {
  ll i, j, k;
  
  
  ll a, b, c;
  cin >> a >> b >> c;
  pt(c<<" "<<a<<" "<<b);
  
  
  
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  const int N, K;
  scanf("%d %d", &N, &K);

  int no[10] = {0};

  for(int i = 0; i < K; i++){
    int d;
    scanf("%d", &d);
    no[d] = 1;
  }

  int i = N;
  for(; i <= 10*N; i++){
    int j = i;
    while(j > 0 && !no[j%10]) j /= 10;
    if(!j) break;
  }
  printf("%d", i);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int Mod=998244353,MAXN=1e6+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}int n,k,ans,Fac[MAXN],iFac[MAXN],Inv[MAXN];
inline int C(int n,int m){if(n<0||m<0||n<m)return 0;return 1ll*Fac[n]*iFac[m]%Mod*iFac[n-m]%Mod;}
inline int Calc(int R,int B){return R<B?0:R==B?Calc(R,B-1):(C(R+B,R)-C(R+B,B-R+n-1)+Mod)%Mod;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),k=read();if(k<n){puts("0");return 0;}
	Inv[1]=1;Rep(i,2,k)Inv[i]=1ll*Inv[Mod%i]*(Mod-Mod/i)%Mod;
	Fac[0]=iFac[0]=1;Rep(i,1,k)iFac[i]=1ll*iFac[i-1]*Inv[i]%Mod,Fac[i]=1ll*Fac[i-1]*i%Mod;
	Rep(i,0,k)ans=(ans+Calc(i,k-i))%Mod;cout<<ans<<"\n";
	return 0;
}




Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);

	char dummy;
	int T, a,b, arr[35],i,n;
	for (i=1; i<=35; i++) arr[i] = i;
	
	scanf("%d", &n);
	scanf("%d", &T);
	while (T--){
		scanf("%d%c%d", &a,&dummy,&b);
		swap(arr[a], arr[b]);
	}
	for (i=1; i<=n; i++)printf("%d\n", arr[i]);
	
	return 0;
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int INF = 1e9;
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve()
{
    ll n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3568
import numpy as np

def getBoundary(p, k, k2):
    if p - k + 1 >= 0:
        return [(p - k + 1, p + 1)]
    else:
        return [(0, p + 1), ((p - k + 1) % k2, k2)]

n, k = map(int, input().strip().split())
k2 = k * 2
b = [[0 for i in range(k2 + 1)] for j in range(k2 + 1)]

for i in range(n):
    x_str, y_str, c_str = input().strip().split()
    x = int(x_str) % k2
    y = (int(y_str) + (c_str == 'B') * k) % k2
    for xb, xe in getBoundary(x % k2, k, k2):
        for yb, ye in getBoundary(y % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1
    for xb, xe in getBoundary((x + k) % k2, k, k2):
        for yb, ye in getBoundary((y + k) % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1

arr_b = np.array(b)
for i in range(k2):
    arr_b[i + 1] += arr_b[i]
for j in range(k2):
    arr_b[:, j + 1] += arr_b[:, j]
print(arr_b.max())


Measured memory_bytes: 76012
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {
	int out=0;
	string s,t;
	cin>>s>>t;
	rep(i,3){
		if(s[i]==t[i])
			out++;
	}

	cout<<out<<endl;
	return 0;

}


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


Measured memory_bytes: 256
c=input()
a=["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","a"]
for i in range(len(a)):
  if(c==a[i]):
    print(a[i+1])
    break

Measured memory_bytes: 3060
N, L = map(int, input().split())
temp = 10000
count = 0
for i in range(1, N+1):
    if abs(temp) > abs(L+i-1):
        temp = (L+i-1)

for i in range(1, N+1):
    count += L+i-1

count -= temp
print(count)


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

using namespace std;

int dp[1001][1001];
int mod = 1e9+7;
int h, w;

void find_paths() {
    if(dp[0][0] >=0) dp[0][0] = 1;
    for(int i=1; i<w; i++) 
        if(dp[0][i] >= 0) 
            if(dp[0][i-1] >=0) dp[0][i] = dp[0][i-1];

    for(int i=1; i<h; i++) {
        if(dp[i-1][0] >= 0)
            if(dp[i][0] >= 0) dp[i][0] = dp[i-1][0];
        for(int j=1; j<w; j++) {
            int t1=0, t2=0;
            if(dp[i-1][j] >= 0) t1 = dp[i-1][j]; 
            if(dp[i][j-1] >= 0) t2 = dp[i][j-1];
            if(dp[i][j] >= 0) dp[i][j] = ( ((dp[i][j] + t1) % mod) + t2 ) % mod; 
        }
    }
}

int main() {
    cin >> h >> w;
    for(int i=0; i<h; i++) {
        char t1[w];
        cin >> t1;
        for(int j=0; j<w; j++)
            if(t1[j] == '#') dp[i][j] = -1;
    }

    find_paths();
    cout << dp[h-1][w-1] << endl;

/*    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) printf("%2d ", dp[i][j]);
        cout << endl;
    } */ 
}


Measured memory_bytes: 4096
#include<stdio.h>
#define MAX_M 100000
int f(int);
int main(){
    int s,m,flag=0;
    int a[MAX_M];
    scanf("%d",&s);
    a[1] = s;

    for(int i=1;i<MAX_M;i++){
        a[i+1]=f(a[i]);
        for(int j=1;j<i;j++){
            if(a[i]==a[j]){
                m=i;
                flag=1;
                break;
            }
        }
        if(flag==1) break;
    }

    printf("%d",m);

    return 0;
}
int f(int n){
    if(n%2==0) return n/2;
    else return 3*n+1;
}

Measured memory_bytes: 128
main(){
int a,b,c,p,q;scanf("%d", &a);scanf("%d", &b);scanf("%d", &c);
p=c/a;q=c%a;
if(p<7){
  printf("%d\n", (c+a-1)/a);
}
else{
  p=c/(7*a+b);q=c%(7*a+b);
  if((q/a)<7){
    printf("%d\n", (q+a-1)/a+7*p);
  }
  else{
    printf("%d\n", 7*(p+1));
  }
}}


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

using namespace std;
int main()
{
 string s;
 cin>>s;
 int n=s.size();
 int i,ans=0;
 for(i=0;i<n;i++)
 {
  if(s[i]!=s[n-i-1]) ans++;
  }
  cout<<ans/2;

 }













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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s<< endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<long long> a(n);
    rep(i,n) cin>>a.at(i);
    rep(i,n-k){
        if(a.at(i)<a.at(k+i)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4840
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  ll a, b, c; cin >> a >> b >> c;
  ll k; cin >> k;
  ll ans = min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  print(ans);
}

int main() {
  int t; t = 1;
  while(t--) solve();
}


Measured memory_bytes: 3640
import sys
from heapq import *
readline = sys.stdin.readline

def solve2(left):
    if len(left) == 0:
        return 0
    ans = 0
    k2values = {}
    for v, k in left:
        if k not in k2values:
            k2values[k] = []
        k2values[k].append(v)
    
    pq = []
    maxk = max(k for v,k in left)
    for k in range(maxk, 0, -1):
        if k in k2values:
            for v in k2values[k]:
                heappush(pq, -v)
        if len(pq) > 0:
            v = heappop(pq)
            ans += -v
    return ans


def solve():
    N = int(readline())
    
    left = []
    right = []
    
    ans = 0
    
    for i in range(N):
        k, l, r = map(int, readline().split())
        if l > r:
            left.append((l - r, k))
            ans += r
        else:
            right.append((r - l, N - k))
            ans += l
    
    ans += solve2(left)
    ans += solve2(right)
    
    print(ans)

T = int(readline())
for i in range(T):
    solve()

Measured memory_bytes: 116980
#include<cstdio>
int main(){
    int d;
    while(scanf("%d",&d)!=-1){
        int ans=0;
        int upto=600-d;
        for(int i=d;i<=upto;i+=d){
            ans+=(i*i)*d;
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 0
import java.security.SecureRandom;
import java.sql.Array;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a[]= new int[n];
        for (int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        int count=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                for (int k=j+1;k<n;k++){
                    if (a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k])count++;
                }
            }
        }
        System.out.println(count);
    }

}





Measured memory_bytes: 36204
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;
 
#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
 
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  bool a[32005];
  bool b[32005];
 
  rep(i,32005){
    a[i] = b[i]  = false;
  }
  a[0]= b[0] = true;
 
  
  string str;cin >> str;
  str+='T';
  vector<ll>s;
  ll x,y ; cin >> x >> y;
 
  vector<ll> xx, yy;
 
  ll co=0;
  rep(i,str.size()){
    if(str[i]!='T')co++;
    else {s.pb(co); co=0;}
  }
  rep(i,s.size()){
    if(i%2==0) xx.pb(s[i]);
    else yy.pb(s[i]);
  }
 
  //初期はxの正に向いてる
  x -= xx[0];
  xx.erase(xx.begin()+0);
 
  //正も負も足せばいいので
  xx.pb(abs(x)); yy.pb(abs(y));
  
  sort(rall(xx));
  sort(rall(yy));
 
 
  ll sumx = 0; rep(i,xx.size()) sumx += xx[i];
  ll sumy = 0; rep(i,yy.size()) sumy += yy[i];
 
  x = 0;
  rep(i,xx.size()){
    x+= xx[i];
    for(ll j = x ; j >= 0; j-- )
      if(a[j]) a[j+xx[i]] = true;
    
  }
 
  y = 0;
  rep(i,yy.size()){
    y+=yy[i];
    for(ll j  = y;  j >= 0; j--){
      if(b[j]) b[j+yy[i]] = true;
    }
  }
 
  if(((sumx%2)==0) && ((sumy%2)==0)){
    if(a[sumx/2] && b[sumy/2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
 
  cout << "No" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

h = []
for _ in range(n):
    h.append(int(input()))

h.sort()

ans = 1100000000
for i in range(n - k + 1):
    hh =  h[i + k - 1] - h[i]
    if hh < ans:
        ans = hh

print(ans)

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

int main(){

    int a, b;
    cin >> a;
    cin >> b;

    if(a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    if(a - b <= 1){
        cout << a + b << endl;
    }
    else{
        cout << a + (a - 1) << endl;
    }

}

Measured memory_bytes: 256
n = int(input())

cnt = [[0] * n for _ in range(26)]
for i in range(n):
    s = input()
    for c in s:
        cnt[ord(c) - ord('a')][i] += 1

for i in range(26):
    for _ in range(min(cnt[i])):
        print(chr(ord('a')+i), end='')

Measured memory_bytes: 81204
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}



Measured memory_bytes: 384
N = int(input())
ans = 0
for i in range(1, N + 1, 2):
    res = 0
    for j in range(1, i):
        if i < j * j:
            break
        if i % j == 0:
            if j != i / j:
                res += 2
            else:
                res += 1
    if res == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(j,n) for(int i=(int)(j);i<=(int)(n);i++)
int main(){
  int M,D;
  cin>>M>>D;
  int count=0;
  if(D>=22){
  rep(22,D){ 
    if(1<=(i%10)*(i/10)&&(i%10)*(i/10)<=M&&i%10>=2) count++;
  }
}
  else count=0;
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, m;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (n == 1) {
        if (m == 1) cout << 1 << endl;
        else {
            cout << m-2 << endl;
        }
    } else {
        cout << (n-2) * (m-2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s=input()
ng=len(s)

rl=[]
lr=[-1]

answer=[]
for i in range(ng):
    answer.append(0)

for i in range(ng-1):
    if s[i]=='R' and s[i+1]=='L':
        rl.append(i)
    elif s[i]=='L' and s[i+1]=='R':
        lr.append(i)

lr.append(ng-1)
#print(rl ,lr)
for i in range(len(rl)):
    haji=lr[i]+1
    naka=rl[i]
    owar=lr[i+1]
    if naka%2==1:
        if haji%2==1:
            hajiji=haji
        else:
            hajiji=haji+1
        if owar%2==1:
            owawa=owar
        else:
            owawa=owar-1
    else:
        if haji%2==0:
            hajiji=haji
        else:
            hajiji=haji+1
        if owar%2==0:
            owawa=owar
        else:
            owawa=owar-1
    answer[naka]+=int(((owawa-hajiji)/2)+1)
    answer[naka+1]+=int((owar-haji)-((owawa-hajiji)/2))
#print(answer)

for ans in answer:
    print(ans, end=" ")

Measured memory_bytes: 8740
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

double dist(pii xy1, pii xy2) {
	return sqrt((xy1.first - xy2.first) * (xy1.first - xy2.first) + (xy1.second - xy2.second) * (xy1.second - xy2.second));
}

signed main() {
	fio();
	int n;
	cin >> n;
	vector<pii> xy(n);
	rep (i, n) cin >> xy[i].first >> xy[i].second;

	vi perm(n);
	rep (i, n) perm[i] = i;

	vl fact(n + 1);
	fact[0] = 1;
	rep1 (i, n) fact[i] = fact[i - 1] * i;

	double sum = 0;
	do {
		double ans = 0;
		rep (i, n - 1) {
			int idx1 = perm[i], idx2 = perm[i + 1];
			ans += dist(xy[idx1], xy[idx2]);
		}
		sum += ans;
	} while (next_permutation(all(perm)));

	sum /= fact[n];
	Sp(sum);
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    n = int(input())
    a = list(map(int, input().split()))
    res = []
    x = sum(a[::2]) - sum(a[1::2])
    res.append(x)
    for i in range(1, n):
        x = 2 * a[i - 1] - x
        res.append(x)
    print(" ".join(str(x) for x in res))

if __name__ == "__main__":
    main()


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  ll n, m;
  cin >> n >> m;
  vecll p(m), y(m);
  vector<vector<ll>> country(n+1);

  rep(i,m){
    cin >> p[i] >> y[i];
    country[p[i]].pb(y[i]);
  }

  rep(i,n+1){
    sortall(country[i]);
  }

  rep(i,m){
    ll tmp=0;
    tmp += 1000000*p[i];
    auto k = lower_bound(all(country[p[i]]), y[i]);
    tmp += k - country[p[i]].begin() + 1;
    prtfill(12, tmp);
    cout << "\n";
  }
}


Measured memory_bytes: 10384
#include<bits/stdc++.h>
using namespace std;
typedef pair<string, int>si;
int main(){
	int n; cin>>n;
	queue<si>q;
	q.push({"a",1});
	while(!q.empty()){
		si cur=q.front(); q.pop();
		string str=cur.first;
		int cur_len=cur.second;
		if(str.size()==n){
			cout<<str<<'\n';
			continue;
		}
		for(int i=1;i<=cur_len+1;i++){
			char nxt=i-1+'a';
			if(i<=cur_len)
				q.push({str+nxt,cur_len});
			else
				q.push({str+nxt,i});
		}
	}
	return 0;
}

Measured memory_bytes: 8832
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#include<string>
#include<stack>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pqueue priority_queue
#define NEW(a,b) memset(a,b,sizeof(a))
const double pi=4.0*atan(1.0);
const double e=exp(1.0);
const int maxn=1e5+8;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const ULL base=1e7+7;
using namespace std;
int a[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int ans=0;
    for(int i=2;i<=n-1;i++){
        if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1])){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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


int main() {
  ll a,b; cin>>a>>b;
  ll k=1;
  while(true){
    if((a*k)%b==0){cout<<a*k;break;}
    else{k++;}
  }
}

Measured memory_bytes: 256
*r,=c=[0]*9**6
_,*z=[[*map(int,t.split())]for t in open(0)]
for y,x in z:r[y]+=1;c[x]+=1
print(-(r.count(h:=max(r))*c.count(w:=max(c))==sum(h+w==r[y]+c[x]for y,x in z))+h+w)

Measured memory_bytes: 74360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;
    VVL d(10, VL(10, 1e18));
    rep(h, 0, 10){
        rep(w, 0, 10){
            cin >> d[h][w];
        }
    }
    rep(i, 0, 10){
        rep(j, 0, 10){
            rep(k, 0, 10){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    VL A(10,0);
    rep(i, 0, H*W){
        ll a;
        cin >> a;
        if(a != -1) A[a]++;
    }

    ll ans = 1e18;
    ll c = 0;
    rep(j, 0, 10){
        if(1LL == j) continue;
        c += d[j][1] * A[j];
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string S; cin >> S;
	for (int i = 0; i < S.size()-1; i++) {
		if (S[i] == S[i + 1]) { cout << i + 1 << " " << i + 2 << endl; return 0; }
	}
	for (int i = 0; i < S.size() - 2; i++) {
		if (S[i] == S[i + 2]) { cout << i + 1 << " " << i + 3 << endl; return 0; }
	}
  cout<<-1<<" "<<-1<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;

    VVi to(n);
   // VVi color(n,Vi(n,0));
    vector<map<int,int>> color(n);
    vector<Pi> edge;
    ll a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        to[a].pb(b);
        to[b].pb(a);
        edge.emplace_back(a,b);
    }

    Vi par(n);
    stack<int> q;
    q.push(0);
    int k=0;
    while (!q.empty()){
        int now = q.top();
        q.pop();
        int c = 0;
        Each(nx,to[now]){
            if(nx==par[now])continue;
            int &parc = color[now][par[now]];
            c++;
            if(c==parc){
                c++;
            }
            par[nx] = now;
            color[now][nx]=c;
            color[nx][now]=c;
            q.push(nx);
            k = max(k,c);
        }
    }

    cout<<k<<endl;
    rep(i,n-1){
        cout<<color[edge[i].fi][edge[i].se]<<endl;
    }

    return  0;
}


Measured memory_bytes: 21240
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[5];
  int ans = 0;
  int maxi = 0;
  
  for(int i = 0;i < 5;i++){
	cin >> a[i];
	ans += a[i];
	if(a[i] % 10 != 0){
	  ans += (10 - a[i] % 10);
	  maxi = max(maxi, 10 - a[i] % 10);
	}
  }

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

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

int main() {
	
	int a, b, k;
	cin >> a >> b >> k;
	
	int cnt = 0;
	for (int i = min(a, b); i > 0; i--) {
		if (a % i == 0 && b % i == 0) {
			cnt++; // cnt = cnt + 1;
		}
		if (cnt == k) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
ans = 0
temp = 1
for i in range(n-1):
    if data[i] == data[i+1]:
        temp += 1
    else:
        if temp != 0:
            ans += temp*(temp-1)//2
            temp = 1
if temp >= 2:
    ans += temp*(temp-1)//2
print(ans)

Measured memory_bytes: 24652
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = 10 ** N - 9 ** N - 9 ** N + 8 ** N
print(a % mod)
# 9 ** (N)
# ans = N * (N - 1) * 10 ** (N)
# print(ans % mod)
# a = 8 ** N
# b = 10 ** N
# ans = (b - a) % mod
# print(ans)



Measured memory_bytes: 12472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 



//ここから書き始める
int main(int argc, char const *argv[])
{
	int N,T,A;
	cin >> N >> T >> A;

	int h[N];

	REP(i,N)
	{
		cin >> h[i];
	}
	float t;

	int ans = 0;
	t = T - h[0] * 0.006;
	float sa = abs(A - t);

	FOR(i,1,N)
	{
		float tmp_t = T - h[i] * 0.006;
		float tmp_sa = abs(A - tmp_t);
		if(tmp_sa < sa)
		{
			t = tmp_t;
			sa = tmp_sa;
			ans = i;
		}
	}
	cout << ans + 1 << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	map<int,int> M;
	for(int i =0; i < N; i++) {
		int a;
		cin >> a;
		M[a]++;
	}
	int ans =0;
	ALL_THE(M,it) {
		if(it->ss < it->ff) ans +=it->ss;
		else ans +=it->ss-it->ff;
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 4736
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<isize> = vec![0; n + 2];
    for i in 1..n + 1 {
        a[i] = iterator.next().unwrap().parse().unwrap();
    }

    let mut total = 0;
    for i in 1..n + 2 {
        total += (a[i] - a[i - 1]).abs();
    }

    let mut ans = String::new();
    for i in 1..n + 1 {
        ans.push_str(
            &format!(
                "{}\n",
                total - (a[i] - a[i - 1]).abs() - (a[i + 1] - a[i]).abs() + (a[i + 1] - a[i - 1]).abs()
            )
        );
    }
    return ans.trim().to_string();
}


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

using namespace std;

void Main() {
    int N, K;
    cin >> N >> K;
    vector<double> expectations(N, 0.0);
    for (int i = 0; i < N; ++i) {
        int pi;
        cin >> pi;
        double p = (double)pi;
        expectations[i] = 0.5 * p * (p + 1.0) / p;
    }

    vector<double> accumSum(N, 0.0);
    accumSum[0] = expectations[0];
    for (int i = 1; i < N; ++i) {
        accumSum[i] = accumSum[i - 1] + expectations[i];
    }

    double ans = accumSum[K - 1];
    for (int i = K; i < N; ++i) {
        ans = max(ans, accumSum[i] - accumSum[i - K]);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <queue>
#include <utility>
typedef long long ll;

using namespace std;

bool withinArea(int x, int y);
ll bfs(int startX, int startY);

bool used[400][400];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int W, H;
string S[400];

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    ll count = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            count += bfs(x, y);
        }
    }

    cout << count << endl;
    
    return 0;
}

ll bfs(int startX, int startY) {
    if (used[startY][startX]) return 0;
    ll black = 0, white = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(startX, startY));
    used[startY][startX] = true;
    while (que.size() > 0) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if (S[y][x] == '#') {
            black++;
        } else {
            white++;
        }
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (!withinArea(nx, ny)) continue;
            if (used[ny][nx]) continue;
            if (S[y][x] == S[ny][nx]) continue;
            que.push(make_pair(nx, ny));
            used[ny][nx] = true;
        }
    }
    return black * white;
}

bool withinArea(int x, int y) {
    return 0 <= x && x < W && 0 <= y && y < H;
}


Measured memory_bytes: 640
from heapq import heappush, heappop

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

C = []
for i in range(N):
    heappush(C, (-B[i], i))

ans = 0
while C:
    val, i = heappop(C)
    val = -val
    if B[i] < A[i]:
        print(-1)
        exit()

    left = (i - 1) % N
    right = (i + 1) % N
    k = (B[i] - A[i]) // (B[left] + B[right])
    B[i] = B[i] - (B[left] + B[right]) * k
    ans += k
        
    if B[i] != A[i]:
        if B[i] > B[left] and B[i] > B[right]:
            print(-1)
            exit()
        heappush(C, (-B[i], i))
    
print(ans)


Measured memory_bytes: 124312
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, d, x;
    cin >> n >> d >> x;
    int sum = x;
    rep(i, n){
        int a;
        cin >> a;
        //cout << a << endl;
        sum += (d - 1) / a + 1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
using namespace std;

int main() {
	while(1) {
		int n, m, tarou_ch=0, hanako_ch=0, min=201;
		scanf("%d%d", &n, &m);
		if (n == 0 && m == 0) break;
		int input;
		vector<int> tarou, hanako;
		for (int i=0; i<n; i++) {
			scanf("%d", &input);
			tarou.push_back(input);
		}
		for (int i=0; i<m; i++) {
			scanf("%d", &input);
			hanako.push_back(input);
		}
		vector<int>::iterator v1=tarou.begin(), v2=hanako.begin();
		int tarou_sum = accumulate( tarou.begin(), tarou.end(), 0 );
		int hanako_sum = accumulate( hanako.begin(), hanako.end(), 0 );
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				// // printf("test:%d %d\n", tarou_sum-*v1+*v2, hanako_sum+*v1-*v2);
				// printf("test:%d %d\n", *v1, *v2);
				if ((tarou_sum-*v1+*v2) == (hanako_sum+*v1-*v2)) {
					if (*v1+*v2<min) {
						min=*v1+*v2; tarou_ch=*v1; hanako_ch=*v2;
					}
				}
				v2++;
			}
			v1++;
			v2=hanako.begin();
		}
		if(min == 201) { printf("-1\n");}
		else printf("%d %d\n", tarou_ch, hanako_ch);
	}
}

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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        for (int i = 0; i <= X; i++) {
            if ((i * (i + 1)) / 2 >= X) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

const int N = 2e5 + 10;
int r[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    r[x] = i;
  }
  int64 ret = 0;
  set<int> A;
  for (int i = 1; i <= n; ++i) {
    int x = r[i];
    auto it = A.upper_bound(x);
    int R = it == A.end() ? n - 1 : *it - 1;
    int L = it == A.begin() ? 0 : *prev(it) + 1;
    // cout << L << " " << R << endl;
    A.insert(x);
    ret += (int64)(x - L + 1) * (R - x + 1) * i;
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 10368
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, m, c) = readLine().split(' ').map(_.toInt)
  val bs = readLine().split(' ').toVector.map(_.toInt)
  
  val result = (0 until n).map { _ =>
    val as = readLine().split(' ').toVector.map(_.toInt)
    val combinations = as.zip(bs)
    val sum = combinations.foldLeft(0) { case (s, (a, b)) =>
      s + a * b
    }
    sum > -c
  }.count(b => b)
  
  println(result)
}

Measured memory_bytes: 55068
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s, t;
    ll i, j, num, ans=INF;

    cin >> s >> t;

    for(i=0; i<s.size()-t.size()+1; i++){
        num = 0;
        for(j=0; j<t.size(); j++){
            if(s[i+j]!=t[j]) num++;
        }
        chmin(ans,num);
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define fi first
#define se second

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

int N;
vector<pii> D;
vector<int> G[12][10][10];
ll dp[14][1 << 12][10];

int main() {
	while(cin >> N, N) {
		D.clear();
		rep(i,14) {
			rep(j,1<<12) {
				rep(k,10) {
					dp[i][j][k] = 0;
				}
			}
		}
		rep(i,12)
			rep(j,10)
				rep(k,10)
					G[i][j][k].clear();

		D.resize(N);
		rep(i,N) {
			cin >> D[i].fi >> D[i].se;
		}

		rep(i, D.size()) {
			for(int j = max(10, D[i].fi); j <= D[i].se; j++)
				G[i*2][j/10][j%10].push_back(i*2+1);
			
			rep(j, 10) {
				if(i < (int)D.size()-1) {
					for(int k = D[i+1].fi; k <= min(9, D[i+1].se); k++)
						G[i*2+1][j][k].push_back((i+1)*2+1);
					for(int k = max(D[i+1].fi / 10, 1); k <= D[i+1].se / 10; k++)
						G[i*2+1][j][k].push_back((i+1)*2);
				}
				else {
					rep(k,10)
						G[i*2+1][j][k].push_back((i+1)*2);
				}
			}
		}

		for(int i = 1; i < 10; i++) {
			int s = 0;
			if(D[0].fi <= i && i <= D[0].se)
				s |= 1 << 1;
			if(D[0].fi / 10 <= i && i <= D[0].se / 10)
				s |= 1;
			dp[1][s][i] = !!s;
		}

		ll res = 0;
		for(int i = 1; i <= D.size()*2; i++) {
			for(int j = 1; j < (1 << (D.size()*2)); j++) {
				for(int k = 0; k < 10; k++) {
					if(dp[i][j][k] == 0)
						continue;
					/*
					cout << i << " ";
					for(int m = 0; m < 16; m++) {
						cout << !!(j & (1 << m));
					} cout << " " << k << endl;
					// */
					for(int l = 0; l < 10; l++) {
						int s = 0;
						for(int m = 0; m < D.size()*2; m++) {
							if(j & (1 << m)) {
								for(int a = 0; a < G[m][k][l].size(); a++) {
									s |= 1 << G[m][k][l][a];
								}
							}
						}
						if(s & (1 << (D.size()*2))) {
							res += dp[i][j][k];
						}
						dp[i+1][s & ((1 << (D.size()*2)) - 1)][l] += dp[i][j][k];
					}
				}
			}
		}
		/*
		for(int i = 0; i <= D.size()*2; i++) {
			for(int j = 0; j < (1 << (D.size()*2)); j++) {
				for(int k = 0; k < 10; k++) {
					cout << dp[i][j][k] << " ";
				} cout << endl;
			}
			cout << endl;
		}
		// */
		cout << res / 10 << endl;
	}
}

Measured memory_bytes: 5752