akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

char harta[51][51];

char descop[51][51];

int n, m;

int cautaBombe(int x, int y){
    int cntbombe = 0;
    for(int pi = x - 1; pi <= x + 1; pi++){
        for(int pj = y - 1; pj <= y + 1; pj++){
            if(pi != x || pj != y){
                if(harta[pi][pj] == '#')
                    cntbombe++;
            }
        }
    }
    return cntbombe;
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("\n");
        for(int j = 1; j <= m; j++){
            scanf("%c", &harta[i][j]);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(harta[i][j] == '.'){
                int bombe = cautaBombe(i, j);
                descop[i][j] = (char)(bombe + 48);
            }
            else{
                descop[i][j] = '#';
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            printf("%c", descop[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;


#define MOD 1000000007

ll deg(ll n){
    ll count = 0;
    while(n!= 0){
        n/=10;
        count++;
    }
    return count;
}

// int main(){
//     ll n;
//     cin >> n;
//     ll a[n];
//     ll p = 100001;
//     for(int i = 0; i < n;i++){
//       cin >> a[i];
//     }
//     ll c[p],d[p];
//     for(int i = 0;i < p;i++){
//         c[i] = 0;
//         d[i] = 0;
//     }
//     for(int i = 0;i < n;i++){
//         if(i%2 == 0)
//         c[a[i]]++;
//         else
//         d[a[i]]++;
//     }
//     pair<ll,ll> c1,c2,d1,d2;
//     for(int i = 0;i < p;i++){
//         c1 = make_pair<i,c[i]>;
//     }
       
    
// }

int main(){
   int a,b,c;
   cin >> a >> b >> c;
   int p = max(a,b);
   int r = c%p ? 1:0;
   cout << c/p +r<< endl;
}

Measured memory_bytes: 256
//edpc_i.cpp
//Sat Feb 16 10:29:29 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	double p[n+1];
	p[0] = 0;
	for (int i=1;i<n+1;i++){
		cin >> p[i];
	}

	double dp[2][n+1];
	for (int i=0;i<2;i++){
		for (int j=0;j<n+1;j++){
			dp[i][j] = 0;
		}
	}

	int num = 1;
	dp[num%2][0] = 1-p[1];
	dp[num%2][1] = p[1];
	num++;
	while (num <= n){
		dp[num%2][0] = dp[(num-1)%2][0]*(1-p[num]);
//		cout << dp[num%2][0] << " ";

		for (int i=1;i<n+1;i++){
			dp[num%2][i] = dp[(num-1)%2][i-1]*p[num]+dp[(num-1)%2][i]*(1-p[num]);
//			cout << dp[num%2][i] << " ";
		}
//		printf("\n");
		num++;
	}

	num--;

	double ans = 0;
	for (int i=(n+1)/2;i<n+1;i++){
		ans += dp[num%2][i];
	}

//	cout << << endl;
	printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, i, ans = 0;
  int val[20], cost[20];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &val[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &cost[i]);
  }

  for (i = 0; i < n; i++) {
    if ( val[i] > cost[i] ) {
      ans += (val[i] - cost[i]);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) break;

        vector<int> s(n);
        int sum = 0;
        rep(i, n) {
            cin >> s.at(i);
            sum += s.at(i);
        }
        double m = (double)sum/n;
        double sum_d = 0.0;
        rep(i, n) {
            sum_d += pow((double)s.at(i) - m, 2);
        }
        double ans = (double)sum_d/n;
        printf("%.8f\n", sqrt(ans));
    }
}



Measured memory_bytes: 3116
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
char s[110];
int ac, wa, tle, re;


int main()
{
	int n;
	scanf("%d", &n);
	
	ac = 0;
	wa = 0;
	tle = 0;
	re = 0;
	
	for (int i = 0 ; i < n ; i++) {
		scanf("%s\n", s);
		if (strcmp(s, "AC") == 0) {
			ac++;
		} else if (strcmp(s, "WA") == 0) {
			wa++;
		} else if (strcmp(s, "TLE") == 0) {
			tle++;
		} else if (strcmp(s, "RE") == 0) {
			re++;
		}
	}
	
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
	
	return 0;
}



Measured memory_bytes: 1736
<?php
list($n, $d) = ints();
$cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    list($x, $y) = ints();
    if ($x ** 2 + $y ** 2 <= $d ** 2) ++$cnt;
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16204
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int n;
	cin>>n;
	map<int,int>m;
	rep(i,n){
		int x;
		cin>>x;
		m[x]++;
	}
	ll ans=0;
	for(auto i:m){
		if(i.S>=i.F)ans+=i.S-i.F;
		else ans+=i.S;
	}
	cout<<ans;

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 8116
h,w = gets.chomp.split(" ").map(&:to_i)

arr = [Array.new(w+2, -1)]
keys = []
count = 0
result = 0
h.times do |h_i|
  tmp_arr = []
  str = gets.chomp
  w.times do |w_i|
    if str[w_i] == "#" then
      keys << [h_i + 1, w_i + 1]
      count += 1
      tmp_arr << 1
    else
      tmp_arr << 0
    end
  end
  arr << [-1] + tmp_arr + [-1]
end
arr << [Array.new(w+2, -1)]

while count < h * w do
  tmp_keys = keys
  keys = []
  result += 1
  tmp_keys.each do |(h_i, w_i)|
    if arr[h_i - 1][w_i] == 0 then
      keys << [h_i - 1, w_i]
      arr[h_i - 1][w_i] = 1
      count += 1
    end
    if arr[h_i + 1][w_i] == 0 then
      keys << [h_i + 1, w_i]
      arr[h_i + 1][w_i] = 1
      count += 1
    end
    if arr[h_i][w_i - 1] == 0 then
      keys << [h_i, w_i - 1]
      arr[h_i][w_i - 1] = 1
      count += 1
    end
    if arr[h_i][w_i + 1] == 0 then
      keys << [h_i, w_i + 1]
      arr[h_i][w_i + 1] = 1
      count += 1
    end
  end
end

puts result


Measured memory_bytes: 89980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz 500005
#define all(x) x.begin(),x.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define MOD 1000000007
void fastio(void);

int arr[sz], ans[sz], BIT[sz], li[sz];
vector<pair< pair<int,int>, int >> Q;

bool cmp(pair< pair<int,int>, int > &a, pair< pair<int,int>, int > &b){
    return a.first.second<b.first.second;
}

void update(int idx, int val, int n){
    while(idx<=n){
        BIT[idx]+=val;
        idx+=(idx&(-idx));
    }
}

int query(int idx){
    int ans=0;
    while(idx>0){
        ans+=BIT[idx];
        idx-=(idx&(-idx));
    }
    return ans;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n,q,la,l,r;
    scanf("%d%d",&n,&q);

    for(la=1;la<=n;la++)
        scanf("%d",&arr[la]);

    for(la=0;la<q;la++){
        scanf("%d%d",&l,&r);
        Q.pb({{l,r},la});
    }

    sort(all(Q), cmp);

    int cur=0, curr=0;
    
    for(la=0;la<q;la++){
        l=Q[la].first.first, r=Q[la].first.second;

        for(curr; curr<r; curr++){
            if(li[arr[curr+1]]!=0)
                update(li[arr[curr+1]], -1, n);
            update(curr+1, 1, n);
            li[arr[curr+1]]=curr+1;
        }

        cur=query(r)-query(l-1);
        
        ans[Q[la].second+1]=cur;
    }

    for(la=1;la<=q;la++)
        printf("%d\n", ans[la]);

    return 0;
}

void fastio(void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

Measured memory_bytes: 17488
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class SegmentTree {
    int n;
    const int e = INT_MAX;
    vector<int> node, lazy, lazy_flg;
    void eval(int k, int l, int r) {
        if (lazy_flg[k]) {
            lazy_flg[k] = false;
            node[k] = lazy[k];
            if (r - l > 1) {
                lazy_flg[2 * k] = lazy_flg[2 * k + 1] = true;
                lazy[2 * k] = lazy[2 * k + 1] = lazy[k];
            }
        }
    }

public:
    SegmentTree(const vector<int> &v) {
        int N = SZ(v);
        n = 1;
        while (n < N) n <<= 1;
        node.resize(2 * n, e);
        lazy.resize(2 * n);
        lazy_flg.resize(2 * n);
        REP(i, N) node[n + i] = v[i];
        for (int k = n - 1; k > 0; --k)
            node[k] = min(node[2 * k], node[2 * k + 1]);
    }
    void update(int a, int b, int x, int k = 1, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = x;
            lazy_flg[k] = true;
            eval(k, l, r);
            return;
        }
        update(a, b, x, 2 * k, l, (l + r) / 2);
        update(a, b, x, 2 * k + 1, (l + r) / 2, r);
        node[k] = min(node[2 * k], node[2 * k + 1]);
    }
    int get(int a, int b, int k = 1, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return e;
        if (a <= l && r <= b) return node[k];
        return min(get(a, b, 2 * k, l, (l + r) / 2),
                   get(a, b, 2 * k + 1, (l + r) / 2, r));
    }
};

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n, INT_MAX);
    SegmentTree seg(a);
    REP(i, q) {
        int query;
        cin >> query;
        if (query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            seg.update(s, t + 1, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << seg.get(s, t + 1) << endl;
        }
    }

    return 0;
}



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

int a, b, c;
int n[4];

int main(){
	while(true){
		scanf("%d %d %d", &a, &b, &c);
		if(a > b) swap(a, b);
		if(b > c) swap(b, c);
		if(a + b <= c) break;
		++n[0];
		if(a*a + b*b < c*c) ++n[3];
		else if(a*a + b*b == c*c) ++n[1];
		else ++n[2];
	}
	printf("%d %d %d %d\n", n[0], n[1], n[2], n[3]);
}


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

long long n,a[200005],b[200005];

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

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

    int l=1,d=n,br=n;
    if(n%2==0)
    {
        while(br)
        {
            b[l]=a[br];
            br--;
            b[d]=a[br];
            br--;
            l++;
            d--;
        }
        for(int i=1;i<=n;i++)
            cout<<b[i]<<" ";
        return 0;
    }
    else
    {
        b[n/2+1]=a[1];
        while(br>1)
        {
            b[l]=a[br];
            br--;
            b[d]=a[br];
            br--;
            l++;
            d--;
        }
        for(int i=1;i<=n;i++)
            cout<<b[i]<<" ";
        return 0;
    }

}


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

int main(){
  int k,x;
  cin >> k >> x;
  for(int i = x-k+1;i<=x+k-1;i++){
    cout << i << endl;
  }
}

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

int main()
{
    int n;
    cin >> n;
    char s[n+5];
    cin >> s;
    int tmp=0;
    int ans=0;
    for(int i=0; i<n; i++){
        if(s[i]=='I'){
            tmp++;
            if(ans<tmp){
                ans=tmp;
            }
        }else if(s[i]=='D'){
            tmp--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
fastinput=sys.stdin.readline
N,M=map(int,fastinput().split())
first=[False]*N
second=[False]*N
for _ in range(M):
    i,j=[int(k) for k in fastinput().split()]
    if i==1:
        first[j-1]=True
    if j==N:
        second[i-1]=True
if any([(first[a] and second[a]) for a in range(N)]):
    print("POSSIBLE")
else:print("IMPOSSIBLE")

Measured memory_bytes: 7856
m,d=map(int,input().split())

a=0
if d>=22:
    for i in range(d-21):
        day=d-i
        d1=int(str(day)[1])
        d10=int(str(day)[0])
        if int(str(day)[1])!=1:
            if d1*d10<=m and d1!=0:
                #print(d10,d1)
                a+=1

print(a)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int X,Y;
int dp[20][20];
char maps[20][20];
int bun(int x,int y);
int dx[3]={-1,0,1};
main(){
  while(1){
    cin>>X>>Y;
    if(X==0&&Y==0){
      break;
    }
    for(int i=1;i<=Y;i++){
      for(int j=1;j<=X;j++){
	cin>>maps[i][j];
	dp[i][j]=0;
      }
    }
    int ans=0;
    for(int i=1;i<=X;i++){
      if(maps[1][i]!='1'){
	ans+=bun(1,i);
      }
    }
    cout<<ans<<endl;
  }
}
int bun(int y,int x){
  if(y>=Y){
    return 1;
  }
  else if(dp[y][x]!=0){
    return dp[y][x];
  }
  else if(maps[y][x]=='2'){
    if(maps[y+2][x]!='1'){
      return dp[y][x]=bun(y+2,x);
    }
    else{
      return 0;
    }
  }
  else if(maps[y][x]=='1'){
    return 0;
  }
  else{
    int anss=0;
    for(int i=0;i<3;i++){
      int nx=x+dx[i];
      if(i!=1){
	if(nx>0&&nx<=X&&maps[y+1][nx]=='0'){
	  anss+=bun(y+1,nx);
	}
      }
      else{
	if(maps[y+1][nx]!='1'){
	  anss+=bun(y+1,nx);
	}
      }
    }
    return dp[y][x]=anss;
  }	  	  
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N, D, X;
	int A[100];
	cin >> N >> D >> X;
	rep(i, N) cin >> A[i];

	int kotae = X;
	rep(i, N) kotae += 1 + (D - 1) / A[i];

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int A[5];
  for(int i = 0; i < 5; ++i){
    cin >> A[i];
  }
  sort(A, A+5, greater<int>());
  for(int i = 0; i < 5; ++i){
    cout << A[i];
    if(i != 4){
      cout << " ";
    }
  }
  cout << endl;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s,t; cin >> s >> t;
	int res = s.size();
	forn(i,0,(int)s.size()){
		if(i+t.size()-1 >= (int)s.size())break;
		int cnt = 0;
		forn(j,0,t.size()){
			if(s[i+j] != t[j])cnt++;
		}
		res = min(res,cnt);
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3520
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	var inRanges []int

	for i := n; i > 0; i-- {
		sum := 0
		num := i
		for num > 0 {
			sum += num%10
			num /= 10
		}
		if a <= sum && sum <= b {
			inRanges = append(inRanges, i)
		}
	}

	ans := 0
	for _, value := range inRanges {
		ans += value
	}

	fmt.Println(ans)
}


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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<vector<int>> v(n+1, vector<int>(2,1<<30));
    v[0][0] = 0;
    v[0][1] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 10; k++){
                int have = j*10+k;
                if(have >= s[i]-'0')    v[i+1][0] = min(v[i+1][0], v[i][j]+have-(s[i]-'0')+k);
                if(have >= s[i]-'0'+1)  v[i+1][1] = min(v[i+1][1], v[i][j]+have-(s[i]-'0'+1)+k);
            }
        }
    }
    cout << v[n][0] << endl;
}

Measured memory_bytes: 57988
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0

if a[0] > x:
    ans += a[0] - x
    a[0] = x

for i in range(1, N):
    if a[i] + a[i - 1] > x:
        ans += a[i] - (x - a[i - 1])
        a[i] = x - a[i - 1]

print(ans)

Measured memory_bytes: 14548
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)
flag = true
i = 0
ans = 0
while flag
  flag = false
  (N - 1).downto(i + 1) do |j|
    if A[j] < A[j - 1]
      a = A[j]
      b = A[j - 1]
      A[j] = b
      A[j - 1] = a
      flag = true
      ans += 1
    end
  end
  i += 1
end
print "#{A[0]}"
(1..N-1).each do |k|
  print " #{A[k]}"
end
puts ''
puts ans



Measured memory_bytes: 6872
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
coupon=[list(map(int,input().split())) for i in range(M)]
mini=2*(10**5)
for j in range(M):
    p_a=coupon[j][0]
    p_b=coupon[j][1]
    p_c=coupon[j][2]
    ans=aa[p_a-1]+bb[p_b-1]-p_c
    if ans<mini:
            mini=ans
mosi=min(aa)+min(bb)
if mosi<mini:
    mini=mosi

print(mini)

Measured memory_bytes: 38572
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    s = list(map(int, IS()))
    n = len(s)
    p = 2019
    cnt = 0
    d = [0]*p
    d[0] = 1 # 0(mod p)はそれ単体で割り切れるため+1しておく
    ss = 0
    x = 1
    for si in s[::-1]:
        ss += x*si
        ss %= p
        d[ss] += 1
        x = (10*x)%p # %p無しだとTLE
    cnt = 0
    for di in d:
        cnt += di*(di-1)//2 # calc combination(n_C_2)
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12336
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int h,w;
    cin >> h >> w;
    vs s(h);
    rep(i,h)cin >> s[i];
    vvi tate(w),yoko(h);
    rep(i,h)rep(j,w)if(s[i][j] == '#'){
        tate[j].push_back(i);
        yoko[i].push_back(j);
    }
    rep(i,w){
        tate[i].push_back(-1),tate[i].push_back(h);
        sort(all(tate[i]));
    }
    rep(i,h){
        yoko[i].push_back(-1),yoko[i].push_back(w);
        sort(all(yoko[i]));
    }
    int ans = 0;
    rep(i,h)rep(j,w)if(s[i][j] == '.'){
        int t = 1;
        int y = lower_bound(all(tate[j]),i) - tate[j].begin();
        t += tate[j][y] - i;
        t += i - tate[j][y-1];
        int x = lower_bound(all(yoko[i]), j) - yoko[i].begin();
        t += yoko[i][x] - j;
        t += j - yoko[i][x-1];
        //cout << i << " " << j << endl;
        //cout << tate[j][y] - i << " " <<  i - tate[j][y-1] << " " << yoko[i][x] - j << " " << j - yoko[i][x-1] << " " << t << endl;
        ans = max(ans, t-4);
    }
    cout << ans << endl;
}


Measured memory_bytes: 71040
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long long ll;
const int mod = 1000000007;

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


int main() {
	int n, k;
	cin >> n >> k;

	combination c(n);

	mint ans = 0;
	for (int z = 0; z <= min(k, n - 1); ++z)
		ans += c(n - 1, n - z - 1) * c(n, z);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5940
# A:容器１の最大容量
# B:容器１に入っている現在の数量
# C:容器２に入っている現在の数量

A,B,C = map(int,input().split())

to_A = A-B # Aに入れることが出来る数量

result = 0

if to_A < C:
    result = C - to_A
else :
    result = 0

print(result)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define ll long long

int main(){
    int N;
    cin >> N;
    string A[3];
    cin >> A[0] >> A[1] >> A[2];
    ll s=0;
    for(int i=0;i<N;i++){
        char abc[30] = {0};
        for(int j=0;j<3;j++){
            abc[A[j][i] - 'a'] += 1;
        }
        int maxchar = 0;
        for(int j=0;j<30;j++){
            if (abc[j] > maxchar) maxchar = abc[j];
        }
        s += 3 - maxchar;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define comp(x) (x).begin(), (x).end()
#define dbg(x) cout << #x << " " << x << endl

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pi;
typedef map<int, int> mi;
typedef set<int> si;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1, s2;
    cin >> s1;
    cin >> s2;
    s2.pop_back();
    if (s1 == s2) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }


}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string s, t;
vector<int> idx[26];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    for(int i = 0; i < s.length(); ++i){
        idx[s[i] - 'a'].emplace_back(i);
    }
    int last = -1;
    ll cnt = 0;
    for(int i = 0; i < t.length(); i++){
        int al = t[i] - 'a';
        vector<int>& v = idx[al];
        auto it = upper_bound(v.begin(), v.end(), last);
        if(it != v.end()) last = *it;
        else if(v.size() == 0){
            cout << -1 << endl;
            return 0;
        }else{
            last = v[0];
            cnt++;
        }
    }
    cout << cnt * s.length() + last + 1 << endl;
    return 0;
}

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

int main() {
    int N, A[100001];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    long long sum = 0;
    for (int i = 0; i < N; ++i) sum += A[i];

    if (sum % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 640
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort()
nn = a[-1]
ind = bisect.bisect_left(a,nn//2)
kouho1 = -inf
if ind > 0:
    kouho1 = a[ind-1]
kouho2 = a[ind]
if abs(nn/2 - kouho1) <= abs(nn/2 - kouho2):
    print(nn, kouho1)
else:
    print(nn, kouho2)

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

int N;

int main() {
  cin >> N;bool kanou=false;
  for (int i=1;i<sqrt(2*N)+1;i++) {
    if (i*(i-1)==2*N) {
      kanou=true;int Use[i][i-1];queue<int> Q;
      cout << "Yes" << endl;
      cout << i << endl;
      for (int j=0;j<N;j++) {
        Q.push(j+1);
      }
      for (int j=1;j<=i;j++) {
        for (int k=0;k<i-1;k++) {
          Use[j-1][k]=-1;
        }
      }
      for (int j=0;j<i;j++) {
        for (int k=0;k<i-1;k++) {
          if (Use[j][k]==-1) {
            int x=Q.front();Q.pop();
            Use[j][k]=x;Use[k+1][j]=x;
          }
        }
      }
      for (int j=0;j<i;j++) {
        cout << i-1;
        for (int k=0;k<i-1;k++) {
          cout << " " << Use[j][k];
          if (k==i-2) cout << endl;
        }
      }
      break;
    }
  }
  if (!kanou) cout << "No" << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n],b[m];
    for(ll i=0; i<n; i++)
        cin>>a[i];
    for(ll i=0; i<m; i++)
        cin>>b[i];
    ll now=0;
    ll cb[m];
    cb[0]=b[0];
    for(ll i=1; i<m; i++)
        cb[i]=cb[i-1]+b[i];
    ll tot=0;
    for(ll i=0; i<n; i++)
    {
        now+=a[i];
        if(now>k)
            break;
        ll low=0,high=m-1;
        ll ans=0;
        while(low<=high)
        {
            ll mid=(low+high)/2;
            if(cb[mid]<=k-now)
            {
                ans=mid+1;
                low=mid+1;
            }
            else
                high=mid-1;

        }
        tot=max(tot,ans+i+1);

    }
    ll low=0,high=m-1;
    ll ans=0;
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(cb[mid]<=k)
        {
            ans=mid+1;
            low=mid+1;
        }
        else
            high=mid-1;

    }
    tot=max(tot,ans);
    cout<<tot;
}



Measured memory_bytes: 8328
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
   string s;
   cin >> s;
   string result;
   if (s=="abc" || s== "acb" || s== "bac" || s=="bca" || s=="cab" || s=="cba"){
    result= "Yes";
   }else {
   result = "No";}
   cout <<result;
    return 0;
}


Measured memory_bytes: 3592
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        l: [u64; n]
    }

    let mut lm = l;
    lm.sort();
    let rest = lm .iter().take(n-1).fold(0, |acc, &x| acc + x);
    println!("{}", if rest > lm[n-1] {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    ll n;
    cin >> n;
    ll mxa=inf,mna=0,mxb=inf,mnb=0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        ll a=x+y;
        ll b=x-y;
        if(i==0){
            mxa=a;mna=a;
            mxb=b;mnb=b;
        }
        chmax(mxa,a);
        chmax(mxb,b);
        chmin(mna,a);
        chmin(mnb,b);
    }
    ll ans=max(mxa-mna,mxb-mnb);
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int a[205];
int main()
{
	int n;
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		int flag=1;
		int t=0;
		while(flag){
			for(int i=0;i<n;i++){
				if(a[i]%2==1){
					flag=0;
					break;
				}
				else a[i]/=2;
			}
			if(flag) t++;
		}
		cout<<t<<endl;
	}
	return 0;
}


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

int N, cnt[42];
lint K, A[100005];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> K;
    for(int i=0;i<N;i++){
        int cur = 0;
        cin >> A[i];
        lint a = A[i];
        while(a){
            cnt[cur] += (a & 1);
            a >>= 1; cur++;
        }
    }

    lint ans = 0, X = 0;
    for(int i=41;0<=i;i--){
        if(cnt[i]<=N/2 && X+(1LL<<i)<=K) X += (1LL<<i);
    }

    for(int i=0;i<N;i++) ans += X ^ A[i];

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

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min(); 
}

auto pow5(std::int64_t v)
{
	return v * v * v * v * v;
}


void one_case()
{
	std::int64_t X;
	std::cin >> X;
	std::int64_t min = lib::max_v<std::int64_t>;
	for (auto a : boost::irange(-118, 120))
	{
		for (auto b : boost::irange(-119, 118))
		{
			if (pow5(a) - pow5(b) == X)
			{
				std::cout << a << " " << b << std::endl;
				return;
			}
			else
			{
				min = std::min(min, std::abs(pow5(a) - pow5(b) - X));
			}
		}
	}
	std::cout << "none: " << min << std::endl;
}

void Main()
{
	one_case();
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int N, maxt = 0;
    cin >> N >> M;
    vector<ll> x(M);
    vector<ll> diffs;
    rep(i, M) cin >> x[i];
    sort(x.begin(), x.end());
    for(int i = 1; i < x.size(); i++) diffs.push_back(x[i] - x[i - 1]);
    sort(diffs.begin(), diffs.end(), greater<ll>());

    ll res = x.back() - x[0];
    for(int i = 0; i < min((int)diffs.size(), N - 1); i++) res -= diffs[i];
    cout << res << endl;
    return 0;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 10;

int n, k, a[maxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for1(i, n)
    {
        cin >> a[i];
    }
    fore(i, k + 1, n)
    {
        cout << (a[i] > a[i - k] ? "Yes" : "No") << "\n";
    }
    return 0;
}


Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
int n,f,a[200005];
int main()
{
	cin>>n;
	if(n%2==1)
	{
		cout<<-1;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		f^=a[i];
	}
	for(int i=1;i<=n;i++)
		cout<<(f^a[i])<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 200005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m;
D p[maxn], ans, sum[maxn];
int main() {
	n = read(), m = read();
	rep(i, 1, n) p[i] = (1 + read()) / 2.0, sum[i ] = sum[i - 1] + p[i];
	rep(i, m, n) ans = max(ans, sum[i] - sum[i - m]);
	printf("%.10lf", ans);
	return 0;
}


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

fun solve(H: Int, W: Int, S: Array<String>){
    val L = Array<IntArray>(H){ IntArray(W){ 0 } }
    val R = Array<IntArray>(H){ IntArray(W){ 0 } }
    val U = Array<IntArray>(H){ IntArray(W){ 0 } }
    val D = Array<IntArray>(H){ IntArray(W){ 0 } }
    for ( y in 0 until H ){
        for ( x in 0 until W ){
            if (S[y][x] == '#' ){
                R[y][x] = -1
                U[y][x] = -1
                continue }
            R[y][x] = if (x == 0) 0 else R[y][x - 1] + 1
            U[y][x] = if (y == 0) 0 else U[y - 1][x] + 1
        }
    }
    for ( y in H - 1 downTo 0 ){
        for ( x in W - 1 downTo 0 ){
            if (S[y][x] == '#' ){
                L[y][x] = -1
                D[y][x] = -1
                continue }
            L[y][x] = if (x == W - 1 ) 0 else L[y][x + 1] + 1
            D[y][x] = if (y == H - 1 ) 0 else D[y + 1][x] + 1
        }
    }
    var ans = 0
    for ( y in 0 until H ){
        for ( x in 0 until W ){
            if (R[y][x] < 0 ||  L[y][x] <0 || U[y][x] < 0 || D[y][x] < 0){ continue }
            var lamp = R[y][x] + L[y][x] + U[y][x] + D[y][x] + 1
            ans = Math.max(ans, lamp)
        }
    }
    println(ans)
    return
}


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



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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin >>n;
    vector<ll> A(n);
    ll s = 0;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        s = s xor A[i];
    }
    for (int i = 0; i < n; ++i) {
        cout << (s xor A[i]) << " ";
    }
    cout << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll g(ll N,ll K){
  if(N%K==0)return N/K;
  else{
    ll a=N/K;
    ll x=(N-a*K)/(a+1);
    if((N-a*K)%(a+1)!=0)x++;
    return g(N-x*(a+1),K);
  }
}

int main(){

  int n;
  cin>>n;
  ll gr=0;
  rep(i,n){
    ll A,B;
    cin>>A>>B;
    gr^=g(A,B);
  }
  if(gr==0)cout<<"Aoki"<<endl;
  else cout<<"Takahashi"<<endl;
  return 0;
}


Measured memory_bytes: 256