akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int ans = 0, ext = 0;
	map<int,int> mope;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if( mope[x] == 0 ){
			mope[x] = 1;
			ans++;
		}
		else{
			ext++;
		}
	}
	ans -= ext % 2 ;
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int data[] = new int[n];
		int group[] = new int[101];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			data[i] = sc.nextInt();
			group[data[i]]++;
		}
		for(int i = 0; i < 101; i++) {
			if(group[i]>0) {
				sum++;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int w;
    cin >> w;
    for (int i = 0; i < s.size(); i += w) {
        cout << s[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n;
int *a;

int solve(int i, int m) {
    if (m == 0) { return 1; }
    if (i >= n) { return 0; }
    int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res; 
}

int main() {
    scanf("%d", &n);
    a = new int[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int q;
    scanf("%d", &q);
    int m;
    for (int i = 0; i < q; i++) {
        scanf("%d", &m);
        if (solve(0, m)) { printf("yes\n"); }
        else { printf("no\n"); }
    }

    return 0;
}


Measured memory_bytes: 2692
# S = input()
N = int(input())
#W = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
#P = [int(input()) for _ in range(N)]

ans = 0

count1 = 0
count2 = 0
count3 = 0

for p in P:
    if p<= A:
        count1 += 1
    elif p<=B:
        count2 += 1
    else:
        count3 += 1



print(min(count1,count3,count2))


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int k, t; cin>>k>>t;
    vector<int> a(t);
    for(int i=0; i<t; i++) cin>>a[i];

    cout << max(0, 2 * *max_element(a.begin(), a.end()) - 1 - k) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int H, W;
        while(true){
            H = scan.nextInt();
            W = scan.nextInt();
            if(H == 0 && W == 0) break;
            drawChessboard(H, W);
            System.out.println();
        }
    }
    public static void drawChessboard(int H, int W){
        for(int i = 0; i < H; i++){
            for(int k = 0; k < W; k++){
                if((i + k) % 2 == 0){
                    System.out.print("#");
                }else{
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 35216
import scala.math.max

object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b, c = sc.nextInt

    val mx = max(max(a, b), c)
    val m = if (3 * mx % 2 == (a + b + c) % 2) {
      mx
    } else {
      mx + 1
    }

    val ans = ((3 * m) - (a + b + c)) / 2
    println(ans)
  }
}


Measured memory_bytes: 25924
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n,t[N],hm;
ll res = 0;

int main(){
	si(n);
	repi(i,1,n){
		si(t[i]);
		if(t[i] > hm)
			hm = t[i];
		else
			res += hm - t[i];
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4372
N = int(input())

result = 0

n = N
e = 0
while True:
    if n%2 == 0:
        n = n//2
        e += 1
    else:
        m = 1
        while e >= m:
            e -= m
            result += 1
            m += 1
        break

p = 3
e = 0
l = int(N**(1/2))
while True:
    if n%p == 0:
        n = n//p
        e += 1
    else:
        m = 1
        while e >= m:
            e -= m
            result += 1
            m += 1
        e = 0
        p += 2
        if p >= l:
            break

if n != 1 and N != 1:
    result += 1

print(result)

Measured memory_bytes: 9368
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,t[100002],x[100002],y[100002];
int nowx,nowy,now;
bool flag=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d %d",&t[i],&x[i],&y[i]);
		int a=sqrt((x[i]-nowx)*(x[i]-nowx))+sqrt((y[i]-nowy)*(y[i]-nowy));
		nowx=x[i],nowy=y[i];
		if(t[i]-now-a<0||(t[i]-now-a)%2) flag=0;
		now=t[i];
	}
	flag? printf("Yes"):printf("No");
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n,l;
    cin >> n >> l;
    vector<string> vec(n);
    for(int i=0;i<n;i++)
    {
        string tmp;
        cin >> tmp;
        vec[i] = tmp;
    }
    sort(begin(vec),end(vec));
    for(int i=0;i<n;i++)
    {
        cout << vec[i];
    }
    return 0;
}

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

int main(){
        int count[4][3][10];
        int a;
        scanf("%d",&a);
        for(int x=0;x<4;x++){
                for(int y=0;y<3;y++){
                        for(int z=0;z<10;z++){
                                count[x][y][z]=0;
                        }
                }
        }
        for(int i=0;i<a;i++){
                int b,f,r,v;
                scanf("%d %d %d %d",&b,&f,&r,&v);
                count[b-1][f-1][r-1]+=v;
        }
        for(int x=0;x<4;x++){
                for(int y=0;y<3;y++){
                        for(int z=0;z<10;z++){
                                if(z!=9){
                                    printf(" %d",count[x][y][z]);
                                }else{
                                    printf(" %d\n",count[x][y][z]);
                                }
                        }
                }
                if(x!=3){
                        printf("####################\n");
                }
        }
        return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 1;
    
    for (int i = n; i > 0; i--) {
        if (ans * 2 < ans + k) {
            ans = ans * 2;
        }
        
        else {
            ans += k;
        }
    }
    
    cout << ans << endl;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, ma, mb;
  cin >> n >> ma >> mb;

  vll as(n), bs(n), cs(n);
  rep(i,n){
    cin >> as[i] >> bs[i] >> cs[i];
  }

  ll gmax = 405;
  vector<vvll> dp(n + 1, vvll(gmax, vll(gmax, INF)));

  dp[0][0][0] = 0;

  repLRE(i, 1, n){
    rep(j, gmax) rep(k, gmax){
      ll pj = j - as[i-1], pk = k - bs[i-1];
      bool cond = pj >= 0 && pk >= 0;
      dp[i][j][k] = dp[i-1][j][k];
      if(cond) chmin(dp[i][j][k], dp[i-1][pj][pk] + cs[i-1]);
    }
  }

  ll ans = INF;
  repLRE(j, 1, gmax-1) repLRE(k, 1, gmax-1) {
    bool ok = k*ma == j*mb;
    if(ok) chmin(ans, dp[n][j][k]);
  }
  if(ans == INF) ans = -1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 57624
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;cin>>a>>b;
  int ans=0;
  if(max(a,b)==a){
    ans+=a;a--;
  }else{ ans+=b;b--;}
  if(max(a,b)==a){
    ans+=a;a--;
  }else{ ans+=b;b--;}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n;
    cin >> n;
    vector<long long> v(n), cnt(n);
    rep(i, n)
    {
        cin >> v[i];
        v[i]--;
        cnt[v[i]]++;
    }
    long long ret = 0;
    rep(i, n)
    {
        ret += cnt[i] * (cnt[i] - 1) / 2;
    }
    rep(i, n)
            cout
        << ret - cnt[v[i]] + 1 << "\n";
}

Measured memory_bytes: 5760
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;

int		main(void)
{
	long long A, B, K;
	cin >> A >> B >> K;
	if (K - A >= 0)
	{
		K -= A;
		A = 0;
		if (K - B >= 0)
			B = 0;
		else
			B -= K;
	}
	else
		A -= K;
	cout << A << " " << B << endl;
}


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

void fnInput(llong& rnLow, llong& rnHigh, int& rnDivsor1, int& rnDivsor2)
{
  cin >> rnLow >> rnHigh >> rnDivsor1 >> rnDivsor2;
}
  

llong fnAntiDivCnt(llong nNum, int nDivsor1, int nDivsor2)
{
  int nDividend = max(nDivsor1, nDivsor2);
  int nDivisor  = min(nDivsor1, nDivsor2);

  while (nDividend % nDivisor)
  {
    int nRemndr = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemndr;
  }
  llong nDivLcm = (llong)nDivsor1 * (nDivsor2 / nDivisor);
  llong nDiv1Cnt = nNum / nDivsor1;
  llong nDiv2Cnt = nNum / nDivsor2;
  llong nDLcmCnt = nNum / nDivLcm;

  return nNum - (nDiv1Cnt + nDiv2Cnt - nDLcmCnt);
}
  
int main()
{
  llong nLow, nHigh;
  int nDivsor1, nDivsor2;

  fnInput(nLow, nHigh, nDivsor1, nDivsor2);
  cout << fnAntiDivCnt(nHigh, nDivsor1, nDivsor2) - fnAntiDivCnt(nLow - 1, nDivsor1, nDivsor2);
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <set>

using namespace std;

map<string,string> m;
set<string> parsed;
set<string> result;

void dfs(string s){
  if(parsed.count(s))
    return;
  parsed.insert(s);
  string tbp = m[s]; //to be parsed
  for(int i=0; i<tbp.size(); i++)
    if(tbp[i] == ',' || tbp[i] == '.')
      tbp[i] = ' ';
  
  stringstream ss(tbp);
  for(string st; ss>>st;){
    if(m.count(st))
      dfs(st);
    else
      result.insert(st);
  }
}


int main(){
  int n;
  while(true){
    string g1;
    cin >> n;
    if(n==0)
      break;
    m.clear();
    parsed.clear();
    result.clear();
    for(int i=0; i<n; i++){
      string s, s1, s2;
      cin >> s;
      s1 = s.substr(0,s.find(':'));
      s2 = s.substr(s.find(':')+1);
      m[s1] = s2;      
      if(i==0)
	g1 = s1;
    }
    dfs(g1);
    cout << result.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <vector>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

struct info{
    int a, b, c, d;
};

int main(void){
    int h, w;
    cin >> h >> w;
    int a[500][500];
    REP(i,h)REP(j,w)cin>>a[i][j];
    vector<info>moves;
    
    REP(i,h){
        if(i%2==0){
            REP(j, w-1){
                if(a[i][j] % 2 == 1){
                    moves.push_back({i+1,j+1,i+1,j+2});
                    a[i][j]--;
                    a[i][j+1]++;
                }
            }
            if(i < h - 1 && a[i][w-1] % 2 == 1){
                moves.push_back({i+1,w,i+2,w});
                a[i][w-1]--;
                a[i+1][w-1]++;
            }
        }else{
            for(int j = w - 1 ; j > 0; j--){
                if(a[i][j] % 2 == 1){
                    moves.push_back({i+1,j+1,i+1,j});
                    a[i][j]--;
                    a[i][j-1]++;
                }
            }
            if(i < h - 1 && a[i][0] % 2 == 1){
                moves.push_back({i+1,1,i+2,1});
                a[i][0]--;
                a[i+1][0]++;
            }
        }
    }
    cout<<moves.size()<<endl;
    for(auto x:moves){
        cout<<x.a<<" "<<x.b<<" "<<x.c<<" "<<x.d<<endl;
    }
}

Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main() {
	
	int N,color=10000;
	cin>>N;
	vector<int> A;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	for(int i=1;i<N;i++){
		if(A[i]==A[i-1]){
			A[i]=color;
			color--;
		}
	}
	cout<<10000-color<<endl;

	return 0;
}


Measured memory_bytes: 256
import sys

N = int(input())
H = list(map(int,input().split()))

if N == 1:
    print("Yes")
    sys.exit()
if H[0] >= H[1]:
    H[0] -= 1
if H[0] > H[1]:
    print("No")
else:
    for i in range(1, N-1):
        H[i] -= 1
        if H[i-1] <= H[i] and H[i] <= H[i+1]:
            continue
        else:
            H[i] += 1
        if H[i-1] <= H[i] and H[i] <= H[i+1]:
            continue
        else:
            print("No")
            sys.exit()
    print("Yes") 

Measured memory_bytes: 14400
#include<bits/stdc++.h>
using namespace std;
long long n,m,A,B,i,ans,f[200005],x[200005],t1[800005],t2[800005],sum[200005],id[200005],rk[200005];
bool cmp(long long  a,long long  b){
    return x[a]<x[b];
}
void build(long long  k,long long  l,long long  r)
{
	t1[k]=t2[k]=2000000000000000;
    if (l==r)
		return;
	long long  mid=(l+r)/2;
	build(k*2,l,mid);
	build(k*2+1,mid+1,r);
}
void xiugai(long long  k,long long  l,long long r,long long x,long long y)
{
	if ((x>r)  || (l>x))
	 return;
	if (l==r)
	{
		t1[k]=y;
		return;
	}
	long long mid=(l+r)/2;
	xiugai(k*2,l,mid,x,y);
	xiugai(k*2+1,mid+1,r,x,y);
    t1[k]=min(t1[k*2],t1[k*2+1]);
 } 
void xiugai2(long long k,long long l,long long r,long long x,long long y)
{
	if ((x>r)  || (l>x))
	 return;
	if (l==r)
	{
		t2[k]=y;
		return;
	}
	long long  mid=(l+r)/2;
	xiugai2(k*2,l,mid,x,y);
	xiugai2(k*2+1,mid+1,r,x,y);
    t2[k]=min(t2[k*2],t2[k*2+1]);
 } 
long long query(long long k,long long t,long long w,long long x,long long y)
{
	if ((x>w) || (t>y))
	  return 2000000000000000;
	if ((t>=x) && (w<=y))
	  return t1[k];
	long long  mid=(t+w)/2;
	return min(query(k*2,t,mid,x,y),query(k*2+1,mid+1,w,x,y));
}
long long query2(long long k,long long t,long long w,long long x,long long y)
{
	if ((x>w) || (t>y))
	  return 2000000000;
	if ((t>=x) && (w<=y))
	  return t2[k];
	long long mid=(t+w)/2;
	return min(query2(k*2,t,mid,x,y),query2(k*2+1,mid+1,w,x,y));
} 

void work()
{
	build(1,1,m+1);
	xiugai(1,1,m+1,rk[0],f[1]-sum[1]-x[0]);
	xiugai2(1,1,m+1,rk[0],f[1]-sum[1]+x[0]);
	for (i=2;i<=m;i++)
	{
		f[i]=query(1,1,m+1,1,rk[i])+x[i]+sum[i-1];
		f[i]=min(f[i],query2(1,1,m+1,rk[i],m+1)-x[i]+sum[i-1]);
		xiugai(1,1,m+1,rk[i-1],f[i]-sum[i]-x[i-1]);
		xiugai2(1,1,m+1,rk[i-1],f[i]-sum[i]+x[i-1]); 
	}
	for (i=1;i<=m;i++)
	  ans=min(ans,f[i]+sum[m]-sum[i]);
 } 
int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&A,&B);
    for (i=1;i<=m;i++)
    {
    	scanf("%lld",&x[i]);
    	if (i>1) sum[i]=abs(x[i]-x[i-1]);
	}
	for (i=1;i<=m;i++)
	 sum[i]=sum[i]+sum[i-1];
	ans=2000000000000000;
	x[0]=A;
	f[1]=abs(x[1]-B);
    for (i=0;i<=m;i++) id[i]=i;
    sort(id,id+m+1,cmp);
    for (i=0;i<=m;i++) rk[id[i]]=i+1;
	work();
	x[0]=B;
	f[1]=abs(x[1]-A);
    for (i=0;i<=m;i++) id[i]=i;
    sort(id,id+m+1,cmp);
    for (i=0;i<=m;i++) rk[id[i]]=i+1;
	work();
	printf("%lld\n",ans);
	return 0; 
} 

Measured memory_bytes: 20608
N = int(input())
S = input()
s = list(S)
alp = ["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", "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"]
for c in s:
    print(alp[alp.index(c) + N], end="")










Measured memory_bytes: 43224
// Get Many Persimmon Trees
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1125

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int NONE = false;
const int TREE = true;

int N;
int W, H, S, T;
vector<vector<bool>> field;

int get_persimmon_trees(int x, int y) {
    int total = 0;
    for (int i = y; i < y+T; ++i) {
        for (int j = x; j < x+S; ++j) {
            if (field[i][j] == TREE) total++;
        }
    }
    return total;
}

int main() {
    while (cin >> N) {
        if (N == 0) break;
        cin >> W >> H;
        field.assign(H, vector<bool>(W, NONE));

        for (int i = 0; i < N; ++i) {
            int x, y;
            cin >> x >> y;
            x--; y--;
            field[y][x] = TREE;
        }
        cin >> S >> T; 

        int ans = 0;
        for (int y = 0; y <= H-T; ++y) {
            for (int x = 0; x <= W-S; ++x) {
                ans = max(get_persimmon_trees(x, y), ans);
            }
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int x;
    cin >> x;
    if (x == 3  || x == 5 || x == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <string>
using namespace std;
int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){cout << "YES" << endl;}
    else cout << "NO" << endl;

    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> days(M);
  
  for(int i = 0; i < M; i++) {
  cin >> days.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < M; i++) {
  sum += days.at(i);
  }
  
  if(sum > N) {
  cout <<"-1" << endl;
  }
  else if(sum <= N) {
  cout << N - sum << endl;  
  }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000000;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int x[4] = { 0, 1, 0, -1 };
int y[4] = { 1, 0, -1, 0 };
int main() {
	init();

	int H, W; cin >> H >> W;
	vector<string>maze(H);
	rep(i, H)cin >> maze[i];

	int ans = 0;
	rep(i, H) {
		rep(j, W) {
			if (maze[i][j]=='.') {
				int cnt = 0;
				Graph G(H, vector<int>(W, -1));
				queue<pair<int, int>>xy;
				xy.push(make_pair(j, i));
				G[i][j] = 0;
				while (!xy.empty()) {
					pair<int, int>nxy = xy.front();
					xy.pop();
					rep(k, 4) {
						int nx = nxy.first + x[k],ny = nxy.second + y[k];
						if (out(ny, nx, H, W) || maze[ny][nx] == '#' || G[ny][nx] != -1)continue;
						G[ny][nx] = G[nxy.second][nxy.first] + 1;
						cnt = max(cnt, G[ny][nx]);

						xy.push(make_pair(nx, ny));
					}
				}
				ans = max(ans, cnt);
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

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

int taxx(int p,int x){
  return p*(100+x)/100;
}
int taxy(int p,int y){
  return p*(100+y)/100;
}

int main(){
  int i,j;
  int p1,p2,x,y,s;
  int max;
  int p3,p4;

  while(1){
    p3=0;
    p4=0;
    max=-1;
    cin >> x >> y >> s;
    if(x==0 && y==0 && s==0)break;
    for(i=1;i<=s/2;i++){
      for(j=1;j<=s-1;j++){
	p1=taxx(i,x);
	p2=taxx(j,x);
	if(p1+p2==s){
	  p1=taxy(i,y);
	  p2=taxy(j,y);
	if(p1+p2>max){
	  max=p1+p2;
	}
      }
    }
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define drep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define MAGICLINE ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define se second
#define fs first
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, pair<int, int> > PII;
typedef priority_queue<PII,
                       vector<PII>,
                       greater<PII> > dijQ;

const int MN = 1002, M = 1000000007;
LL T[MN][MN];

int main(){
    int n, m; cin >> n >> m;
    char k;
    T[1][1] = 1;

    rep(i, 1, n+1){
        rep(j, 1, m+1){
            cin >> k;
            if(k == '.') T[i][j] = (T[i][j] + T[i-1][j] + T[i][j-1]) % M;
            else T[i][j] = 0;
        }
    }

    cout << T[n][m] << "\n";
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long double a, b;
  cin >> a >> b;
  unsigned long long ans = a * b;
  
  cout << ans << endl;
  
  return 0;
}

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

def main():
    """ main """
    N = int(input())
    VS = list(map(int, input().split()))
    heapify(VS)
    for _ in range(N-1):
        a, b = heappop(VS), heappop(VS)
        new_item = (a+b)/2
        heappush(VS, new_item)
    print(VS[0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int a, b, c, i, j, n, tmp;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    b = c = 0;
    tmp=0;
    for(j=0; j<10; j++){
      scanf("%d", &a);
      
      if(a>b){
	b = a;
	("b%d\n", b);
	 tmp++;
	continue;
      }else if(a>c){
	c = a;
	("c%d\n", c);
	 tmp++;
	continue;
      }else{
	
      }
      
    }

    if(tmp==10){
      printf("YES\n");
    }else{
      printf("NO\n");
    }    
  }
  return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
	ll n;
	cin >> n;
	vector<ll> a(5);
	for(int i = 0; i < 5; i++)cin >> a[i];
	ll nax = *min_element(a.begin(), a.end()); //一回の人
	cout << (n + nax - 1) / nax + 4 << endl;
}

Measured memory_bytes: 256
c = []
for i in range(3):
  c_ = list(map(int, input().split()))
  c.append(c_)
  
if c[2][2] == c[0][2] + c[2][0] -c[0][0] and c[2][2] == c[1][2] + c[2][1] -c[1][1] and c[1][1] == c[0][1] + c[1][0] -c[0][0]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
int A[MAX_N];
bool B[MAX_N];
int L, R;
int ans[MAX_N];

void add(int v) {
	ans[M++] = v;
}

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll es = 0, os = 0; //even sum, odd sum
	bool ok = false;// is B[i] == true exists?
	ll mx = -linf; int at = -1; //mxv and where mxv is located
	for(int i = 0; i < N; i++) {
		if(A[i] >= 0) {
			B[i] = true;
			ok = true;
			if(i % 2 == 0) es += A[i];
			else os += A[i];
		}
		if(mx < A[i]) {
			mx = A[i];
			at = i;
		}
	}
	if(!ok) {
		es = at % 2 == 0 ? mx : -linf;
		os = at % 2 == 0 ? -linf : mx;
		B[at] = true;
	}
	if(es >= os) {
		L = 0; 
		R = (N - 1) % 2 == 0 ? N - 1 : N - 2;
	}
	else {
		L = 1;
		R = (N - 1) % 2 == 0 ? N - 2 : N - 1;
	}
	while(!B[L]) L += 2;
	while(!B[R]) R -= 2;
	M = 0;
	rep(i, 0, N - 1 - R) {
		add(N - 1 - i);
	}
	rep(i, 0, L) {
		add(0);
	}
	for(int l = L; l < R; l += 2) {
		if(!B[l + 2]) add(2);
		else add(1);
	}



	cout << max(es, os) << "\n";
	cout << M << "\n";
	rep(i, 0, M) {
		cout << ans[i] + 1 << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

std::string ans;
std::vector<int> a;

void dfs(int i,int sum,std::string s){
    if(i == 4){if(sum == 7 && s[0] != '-')ans = s;}
    else{
        dfs(i + 1, sum + a[i], s + "+" + std::to_string(a[i]));
        dfs(i + 1, sum - a[i], s + "-" + std::to_string(a[i]));
    }
}



int main()
{
    std::string s;
    std::cin >> s;
    a.resize(4);
    for(int i = 0; i < 4; i++)a[i] = s[i] - '0';
    dfs(0,0,"");
    ans.erase(ans.begin());
    std::cout << ans + "=7" << std::endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B) << endl;

	return 0;
}

Measured memory_bytes: 256
S = str(input())

if (1 <= int(S[0:2]) <=12) and (1 <= int(S[2:]) <=12):
    print('AMBIGUOUS')
elif (1 <= int(S[2:]) <=12):
    print('YYMM')
elif (1 <= int(S[0:2]) <=12):
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940
#include <stdio.h>
int main(void){

    int w,n,i,tmp,a,b = 0;
    scanf("%d %d", &w, &n );
    int num[w];

    for( i = 0; i < w; i++ ){
        num[i] = i + 1;
    }

    for( i = 0; i < n; i++ ){
        scanf("%d,%d", &a, &b);
        a--;
        b--;
        tmp = num[a];
        num[a] = num[b];
        num[b] = tmp;
    }

    for( i = 0; i < w; i++ ){
        printf("%d\n" , num[i]);
    }

}



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

string S, C;
int Q, T, F;
bool rev;

int main() {
    cin >> S >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> T;
        if (T == 1) rev ^= 1;
        else {
            cin >> F >> C;
            if (rev ^ (F == 1)) {
                S.insert(0, C);
            } else {
                S += C;
            }
        }
    }
    if (rev) reverse(S.begin(), S.end());
    cout << S << endl;
}

Measured memory_bytes: 900
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[1000005],u;
template<typename T>void read(T &a)
{
    T x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(; isdigit(c);c=getchar())x=x*10+c-'0';
    a=x*f;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)read(u),a[u]=i;
	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]) {
  size_t a, b, c;
  cin >> a >> b >> c;

  if (c > b) {
    for (int i = 0; i < 10; ++i) {
      c = a * c - b;
      cout << c << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
C = gets.chomp

c = C.each_char.to_a.map{ |_c| if _c == "R" then 0 else 1 end }.to_a.join

count = 0
left = 0
right = N - 1
while true
  if c[left] == "1"
    if c[right] == "0"
      left = left + 1
      right = right - 1
      count += 1
      break if left >= right
    else
      right = right - 1
      break if left >= right
    end
  else
    left = left + 1
    break if left >= right
  end
end

puts count


Measured memory_bytes: 32396
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();
		}
		int l = 0, r = 0, temp = a[0];
		long cout = 0;
		while (l < n) {
			while (r < n - 1) {
				if (temp + a[r + 1] == (temp ^ a[r + 1])) {
					temp += a[r + 1];
					r++;
				} else
					break;
			}
			cout += r + 1 - l;
			temp -= a[l];
			l++;
		}
		System.out.println(cout);
	}
}

Measured memory_bytes: 73100
let n = Int(readLine()!)!
func f(_ n: Int) -> Int {
    var c = 0
    for x in 1...n {
        guard x*x <= n else { break }
        for y in 1...n {
            guard x*x+y*(x+y) <= n else { break }
            for z in 1...n {
                guard x*x+y*(x+y)+z*(x+y+z) <= n else { break }
                if x*x+y*(x+y)+z*(x+y+z) == n {
                    c += 1
                }
            }
        }
    }
    return c
}
for i in 1...n {
    print(f(i))
}


Measured memory_bytes: 7428
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define ll long long
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 100000000
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mk(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)              (x>y)?x:y
#define min2(x,y)              (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define en cout<<"\n";

int main()
{
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,d;
    cin>>n>>d;
    ll tmp = (n)/(2*d+1);
    if(n-tmp*(2*d+1)>0)
        tmp++;
    cout<<tmp<<endl;
}

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

int main() {
  string s, ans, key;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '1')
      ans += '1';
    else if (s[i] == '0')
      ans += '0';
    else if (s[i] == 'B') {
      if (ans.size() != 0)
        ans.pop_back();
      /*
      if (ans.size() == 1)
        ans = "";
      else if (ans.size() != 1) {
        rep(i, ans.size() - 1) {
          key[i] = ans[i];
          ans = "";
          ans = key;
          key = "";
        }
      }
    }*/
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int l = s.size();
  vector<int> n(l);
  for(int i = 0; i < l; i++) n.at(i) = s.at(i) - '0';
  
  int dp[110][2][110];
  dp[0][0][0] = 1;
  for(int i = 0; i < l; i++){
    for(int sma = 0; sma < 2; sma++){
      for(int j = 0; j <= k; j++){
        for(int x = 0; x <=(sma ? 9: n.at(i)); x++){
          if(x == 0) dp[i+1][sma || x < n.at(i)][j] += dp[i][sma][j];
          else dp[i+1][sma || x < n.at(i)][j+1] += dp[i][sma][j];
        }
      }
    }
  }
  
  cout << dp[l][0][k] + dp[l][1][k] << endl;
  
}

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

using namespace std;

typedef long long LL;
const int N = 2e5 + 3;

LL a[N], b[N];

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    for (int i = 1; i < n; i++) a[i] += a[i - 1];

    LL s = 0;
    int ans = 0;
    for (int i = 0; i <= m; i++){
        if (s > k) break;
        int x = upper_bound(a, a + n, k - s) - a;
        ans = max(ans, x + i);
        s += b[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6760
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    i64 a,b,r,x,tmp;
    cin>>a>>b;

 x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  cout<< x/b << endl;


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) (x&(-x))
#define X first
#define Y second
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
const int maxn=1e5+50;
const int mod=998244353;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 5;
ll a[N];
int main(){
#ifdef local
    freopen("input","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    ll ans = INF;
    for(int i = 1; i <= n; i++){
        int r = min(i + m - 1,n);
        if(r - i + 1 == m){
            if(a[i] <= 0 && a[r] >= 0){
                ans = min(ans,min(-2 * a[i] + a[r],2 * a[r] - a[i]));
            }
            else if(a[r] <= 0){
                ans = min(ans,-a[i]);
            }
            else if(a[i] >= 0)ans = min(ans,a[r]);
        }
    }
    cout<<ans<<endl;


}


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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define debug(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

ll memo[3001][3001];

ll ncr(ll n, ll k){
    if(n < k){
        return 0;
    }
    if(memo[n][k] != -1){
        return memo[n][k];
    }
    rep(i,n+1){
        rep(j, (i<k?i:k) +1){
            if(j == 0 || j == i){
                memo[i][j] = 1;
            }
            else {
                memo[i][j] = memo[i-1][j-1] + memo[i-1][j];
            }
        }
    }
    return memo[n][k];
}

ll solve(ll R, ll G, ll B, ll n){
    ll ans = 0;

    for(ll r= 0; r*R<=n; r++){
        for(ll b = 0; (b*B+r*R)<=n; b++){
            if((n-r*R-b*B)%G == 0){
                ans++;
            }
        }
    }
    return ans;

}

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

    ll R,G,B,N;
    cin>>R>>G>>B>>N;
    rep(i,N+1){
        rep(j,N+1){
            memo[i][j] = -1;
        }
    }
    cout<<solve(R,G,B,N)<<endl;

    timer();
    return 0;
}


Measured memory_bytes: 70656
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

vector<long long> fact(long long M) {
    vector<long long> fact;
    for (int i = 1; i * i <= M; i++) {
        if (M % i == 0) {
            fact.push_back(i);
            if (i != M / i) {
                fact.push_back(M / i);
            }
        }
    }
    return fact;
}

int main() {

    long long N, M;
    cin >> N >> M;

    auto f = fact(M);
    long long ans = LONG_LONG_MIN;

    for (auto x : f) {
        if(N <= M / x){
            ans = max(x, ans);
        }
    }

    cout << ans << endl;

    return 0;
}

















































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

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int total = 0;
  if (n <= k) total += n * x;
  else total += (k * x) + ((n - k) * y);
  cout << total << endl;
}

Measured memory_bytes: 3596
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    ll n,m;cin>>n>>m;
    vector<ll>X(m),v;
    rep(i,m)cin>>X[i];
    sort(all(X));
    rep(i,m-1)v.push_back(X[i+1]-X[i]);
    sort(all(v));
    // for(auto&&i:v)cout<<i<<endl;
    
    ll ans=0;
    rep(i,m-n)ans+=v[i];
    cout<<ans<<endl;
    return false;
}

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


Measured memory_bytes: 2168
//natsugiri
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
 
typedef long long LL;
typedef vector<int> VI;
 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
 
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
 
int N;
pair<LL, int> A[200111];
 
void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%lld", &A[i].first);
    sort(A, A+N);
 
    int ans = 0;
    for (int i=N; i--;) {
	if (A[i].second) continue;
	LL t = 2LL<<__lg(A[i].first);
	int k = upper_bound(A, A+i, make_pair(t - A[i].first, 0)) - A;
	if (0 < k && k <= i && A[i].first + A[k-1].first == t) {
	    ans++;
	    A[k-1].second = 1;
	}
    }
    printf("%d\n", ans);
}
 
int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

Measured memory_bytes: 3328