akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define ld long double
#define ull unsigned long long
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long ,long long>
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007


 
//     long long power(long long x, long long y, long long p) 
// { 
//     long long res = 1;      
  
//     x = x % p;  
  
//     while (y > 0) 
//     { 
      
//         if (y & 1) 
//             res = (res*x) % p; 

//         y = y>>1; 
//         x = (x*x) % p; 
//     } 
//     return res; 
// } 
  

// long long modInverse(long long n, long long p) 
// { 
//     return power(n, p-2, p); 
// }  

// long long ncrp(long long n, long long r, long long p) 
// { 
   
//    if (r==0) 
//       return 1; 
  
    
//     long long fac[n+1]; 
//     fac[0] = 1; 
//     // for (long long i=1 ; i<=n; i++) 
//     //     fac[i] = fac[i-1]*i%p; 
  
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }




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


   if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
   


   string s,t;
   cin>>s>>t;

   ll n,m;

   n=s.length();
   m=t.length();

   ll i,j;
   
   ll dp[n+1][m+1];

   for(i=0;i<=n;i++)
   {
      for(j=0;j<=m;j++)
      {
          if(i==0||j==0)
          {
              dp[i][j]=0;
          }
          else{
              if(s[i-1]==t[j-1])
              {
                  dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
              }
              else{
                  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
              }
          }
      }
   }
//    for(i=0;i<=n;i++)
//    {
//       for(j=0;j<=m;j++)
//       {
//          cout<<dp[i][j]<<" ";
//       }
//       cout<<endl;
//    }
   string res="";
   i=n;
   j=m;

  while(i>0&&j>0)
  {
          
      
          if(dp[i][j]!=max(dp[i-1][j],dp[i][j-1]))
           {
            //    cout<<i<<" "<<j<<endl;
            //    cout<<s[i-1]<<" "<<endl;
               res+=s[i-1];
               
               i--;
               j--;
           }
           else{
             if(dp[i-1][j]>dp[i][j-1])
             {
                 i--;
             }
             else{
                 j--;
             }
           }
       
   }

//    cout<<dp[n][m]<<endl;

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

   cout<<res<<endl;
   

 



  

    return 0;
}

Measured memory_bytes: 70656
N = int(input())
BA = [[0] * 2 for i in range(N)]
for i in range(N):
    A, B = map(int, input().split())
    BA[i][0] = B
    BA[i][1] = A

BA.sort()
t = 0
ans = 'Yes'
#print(BA)
for ba in BA:
    B = ba[0]
    A = ba[1]
    t += A
    if t > B:
        ans = 'No'
        break

print(ans)


Measured memory_bytes: 66112
#include <iostream>

int main()
{
	int N;
	std::cin >> N;

	int *H = new int[N];
	for (int i = 0; i < N; i++){
		std::cin >> H[i];
	}

	int maxMovable = 0;
	int movable;
	int halfN = N / 2;
	for (int i = 0; i < N - 1; i++){
		movable = 0;
		for (int j = i; j < N - 1; j++){
			if (H[j] >= H[j + 1])
				movable++;
			else
				break;
		}
		if (movable > maxMovable)
			maxMovable = movable;
		if (movable > halfN)
			break;
	}

	std::cout << maxMovable << std::endl;
	
	delete[] H;
	return 0;
}


Measured memory_bytes: 640
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
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; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 



using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll N;cin>>N;
    P pn[N];
    ll m0=0;
    REP(i, N){
        pn[i].second=i;
        cin >> pn[i].first;
    }

    sort(ALL(pn,N));
    REP(i,N){
        cout<<pn[i].second+1<<" ";
    }
    cout<<"\n";
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 q, h, s, d;
    cin >> q >> h >> s >> d;
    i64 n;
    cin >> n, n *= 4;

    d = min(d, 2 * s);
    d = min(d, 4 * h);
    d = min(d, 8 * q);
    s = min(s, 2 * h);
    s = min(s, 4 * q);
    h = min(h, 2 * q);

    i64 ans = 0;
    ans += n / 8 * d, n %= 8;
    ans += n / 4 * s, n %= 4;
    ans += n / 2 * h, n %= 2;
    ans += n / 1 * q, n %= 1;
    cout << ans << endl;
}

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


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

int n,h[100010];

int main(){
    cin>>n>>h[0];
    if(n==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    h[0]--;
    for(int i=1;i<n;i++){
        cin>>h[i];
        if(h[i]>h[i-1])h[i]--;
        if(h[i]<h[i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int gcd(int a,int b){
  
  return b>0 ? gcd(b,a%b):a;

}

int lcm(int a,int b){

  return a/gcd(a,b)*b;

}

int main(){
  int a,b;
  while(cin>>a>>b){
    cout<<gcd(a,b)<<' '<<lcm(a,b)<<endl;
  }
}

Measured memory_bytes: 3076
if __name__ == '__main__':
    N, M, K = map(int, raw_input().split() )
    ans = 0

    for a in xrange(N+1):
        for b in xrange(M+1):
            if (((N-a) * b + a * (M - b)) == K):
                ans = 1

    if ans == 1:
        print "Yes"
    else:
        print "No"







Measured memory_bytes: 2568
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
chk = []
for _ in range(Q):
    *abcd, = map(int, input().split())
    chk.append(abcd)

li = [list(x) for x in list(combinations_with_replacement(range(1, M+1), N))]
ans = 0
for item in li:
    sub = 0
    for c in chk:
        if item[c[1]-1] - item[c[0]-1] == c[2]:
            sub += c[3]
    ans = max(ans, sub)
print(ans)

Measured memory_bytes: 35392
package main

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

func main() {
	fmt.Println(A())
}

func A() int {
	A, B := ReadSeparateInt()
	out := 1
	ans := 0
	for out < B {
		out--
		out += A
		ans++
	}
	return ans
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(nextLine())
	return a
}
func ReadSeparateInt() (int, int) {
	s := nextLine()
	a, b := strings.Split(s, " ")[0], strings.Split(s, " ")[1]
	c, _ := strconv.Atoi(a)
	d, _ := strconv.Atoi(b)
	return c, d
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

const int mod = 998244353;
int add(int a, int b) { return (a += b) < mod? a : a - mod; }
int sub(int a, int b) { return (a -= b) >=  0? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int& a, int b) { a = add(a, b); }
void subs(int& a, int b) { a = sub(a, b); }
void muls(int& a, int b) { a = mul(a, b); }
void maxs(int& a, int b) { a = max(a, b); }
void mins(int& a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }


int n, s;
int a[3000];
int dp[3000][3000];

int f(int i, int sum)
{
    if (sum > s)
        return 0;
    if (sum == s)
        return n - i + 1;
    if (i == n)
        return 0;
    int& sol = dp[i][sum];
    if (sol != -1)
        return sol;
    return sol = add(f(i + 1, sum), f(i + 1, sum + a[i]));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    memset(dp, -1, sizeof dp);
    int sol = 0;
    for (int i = 0; i < n; ++i)
        adds(sol, mul(i + 1, f(i + 1, a[i])));
    cout << sol;
}


Measured memory_bytes: 35584
#include <stdio.h>

int main(void)
{
    int N, answer = 0;
    int A[200000] = {0};
    int K[200000] = {0};
    scanf("%d", &N);
    for (int i = 0; i < N-1; i++)
    {
        scanf("%d", &A[i]);
    }

    for (int j = 0; j < N-1; j++)
    {
        K[A[j]-1] ++;
    }

    for (int x = 0; x < N; x++)
    {
        printf("%d\n", K[x]);
    }

    return 0;
}

Measured memory_bytes: 3272
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    }
}

Measured memory_bytes: 183332
#include <stdio.h>
#include <string.h>
#include <math.h>

int solved(char *num, int i){
  int s = 0, j;
  if(*num == 'X' && num[1] != '\0' && i == 0) return -1;
  for(j = 0;num[j] != '\0';j++){
    s *= 10;
    if(num[j] == 'X')
      s += i;
    else 
      s += num[j] - '0';
  }
  return s;
}

int main(){
  int i;
  char f[130], s[130], ans[130];
  while(scanf(" %[^+]+%[^=]=%s",f, s, ans) != EOF){
    for(i = 0;i < 10;i++)
      if(solved(f, i) + solved(s, i) == solved(ans, i))
	break;
    printf(i != 10 ? "%d\n" : "NA\n", i);
  }
  return 0;
}

Measured memory_bytes: 540
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
using namespace std::chrono;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n;--i)
#define pb push_back
#define m_p make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 2147483647
#define present(c,x)    ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define mem(p,v) memset(p,(lli)v,sizeof p);
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
void show(vector<lli> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(vector<int> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(int a[], int arraysize)
{
    for (int i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(lli a[], lli arraysize)
{
    for (lli i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(unordered_set<int> s)
{
    for (auto it = s.begin(); it != s.end(); it++)
    {
        cout << *it << " ";
    }
    cout<<endl;
}
void show(unordered_map<int,int> mp)
{
    for (auto it = mp.begin(); it != mp.end(); it++)
    {
        cout << it->first << " "<<it->second<<endl;
    }
    cout<<endl;
}
int main()
{
    lli t,n,m;
    t=1;
    while(t)
    {
        cin>>n>>m;
        lli a[n];
        fr(i,0,n)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        lli s=0;
        fr(i,0,m)
        s+=a[i];
        cout<<s<<endl;
        t--;
    }
    return 0;
}





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

using Tile=array<int,4>;

Tile rotate(Tile c,int r){
	rotate(c.begin(),c.begin()+r,c.end());
	return c;
}

void normalize(Tile& c){
	Tile res=c;
	for(int i=0;i<4;++i){
		res=rotate(res,i);
		if(res<c) c=res;
	}
} 

int multiplicity(const Tile& c){
	int res=0;
	for(int i=0;i<4;++i) if(c==rotate(c,i)) ++res;
	return res;
}

int n;
Tile c[444];
map<Tile,int> cnt,mul;

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n;
	for(int i=0;i<n;++i) for(int j=0;j<4;++j) cin>>c[i][j];
	for(int i=0;i<n;++i) normalize(c[i]);
	for(int i=0;i<n;++i) ++cnt[c[i]];
	for(auto it:cnt) mul[it.fi]=multiplicity(it.fi);
	ll res=0LL;
	for(int bi=0;bi<n;++bi) for(int ai=0;ai<bi;++ai){
		--cnt[c[ai]];
		--cnt[c[bi]];
		for(int r=0;r<4;++r){
			const Tile& a=c[ai];
			Tile b=rotate(c[bi],r);
			vector<Tile> d(4);
			d[0]={b[0],b[3],a[1],a[0]};
            d[1]={b[3],b[2],a[2],a[1]};
            d[2]={b[2],b[1],a[3],a[2]};
            d[3]={b[1],b[0],a[0],a[3]};
			ll tmp=1LL;
			map<Tile,int> used;
			for(auto& it:d){
				normalize(it);
				if(!cnt.count(it)){
					tmp=0LL;
					break;
				}
				++used[it];
				tmp*=mul[it]*(cnt[it]-used[it]+1);
			}
			res+=tmp;
		}
		++cnt[c[ai]];
		++cnt[c[bi]];
	}
	cout<<res/3LL;
}

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


int main() {
  int K, X;
  cin >> K >> X;
  if ( 500 * K >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a, wa = 0, i;
	for (i = 0; i < 5; i++) {
		scanf("%d", &a);
		if (a < 40) {
			a = 40;
		}
		wa = a + wa;
	}
	wa = wa / 5;
	printf("%d\n", wa);
}

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

int main() {
    int N;
    cin >> N;
    vector <vector <int>>data(N,vector<int>(2));
    for (int i = 0; i < N; i++){
        cin >> data.at(i).at(0) >> data.at(i).at(1);
    }
    int X =0;
    for (int i = 0; i<N-2 ; i++){
        if (
            data.at(i).at(0) == data.at(i).at(1) &&
            data.at(i+1).at(0) == data.at(i+1).at(1) &&
            data.at(i+2).at(0) == data.at(i+2).at(1)
        ){
            X ++ ;
        }}

    if (X > 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
//Name: Rotation of a Pattern
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * がんばる。
 */
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int S = 8;
void rotate(vector<string> &v) {
    for(int r = 0; r < S/2; ++r) {
        for(int c = 0; c < S/2; ++c) {
            const char tmp = v[r][c];
            v[r][c] = v[S-c-1][r];
            v[S-c-1][r] = v[S-r-1][S-c-1];
            v[S-r-1][S-c-1] = v[c][S-r-1];
            v[c][S-r-1] = tmp;
        }
    }
}

template<typename T>
ostream& operator <<(ostream &os, const vector<T> &v) {
    for(const T &t : v) {
        os << t << endl;
    }
    return os;
}

bool solve(bool first) {
    vector<string> v(S);
    for(int i = 0; i < S; ++i) {
        cin >> v[i];
    }
    for(int r = 90; r <= 270; r += 90) {
        cout << r << endl;
        rotate(v);
        cout << v;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1188
n = int(input())
s = input()
lst_search = [chr(i) for i in range(65, 65+26)]
lst = [chr(i) for i in range(65, 65+26)] *2


ans = ''
for i in s:
    idx = lst_search.index(i)
    ans += lst[idx+n]

print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
A=int(input())
B=int(input())
C=int(input())
D=int(input())

print(min(A,B)+min(C,D))


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}

vi x;

void factorize(long long n)
{

	int count = 0 ;
	// count the number of times 2 divides
	while (!(n % 2)) {
		n >>= 1; // equivalent to n=n/2;
		count++;
	}

	// if 2 divides it
	if (count)
		x.pb(2);

	// check for all the possible numbers that can
	// divide it
	for (long long i = 3; i <= sqrt(n); i += 2) {
		count = 0;
		while (n % i == 0) {
			n = n / i;
			count++;
		}
		if (count)
			x.pb(i);
	}

	// if n at the end is a prime number.
	if (n > 2)
		x.pb(n);

	return;
}




int32_t main() {


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

	int val = __gcd(a, b);

	//Factorize Val
	factorize(val);
	cout << x.size() + 1;





	return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return 1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void)
{
	int i,n,m;
	long int sum=0;
	scanf("%d%d",&n,&m);
	if(m==1){
		printf("0");
		return 0;
	}
	if(n>=m){
		printf("0");
		return 0;
	}
		
	int x[m];
	int d[m-1];
	for(i=0;i<m;i++)
		scanf("%d",&x[i]);
	
	qsort(x, sizeof(x) / sizeof(x[0]), sizeof(int), cmpnum);
	
	for(i=0;i<m-1;i++){
		d[i]=x[i+1]-x[i];
		sum+=d[i];
	}
	
	qsort(d, sizeof(d) / sizeof(d[0]), sizeof(int), cmpnum);
	
	for(i=0;i<n-1;i++)
		sum-=d[m-2-i];
	
	printf("%ld",sum);

	return 0;
}


Measured memory_bytes: 1396
#include <stdio.h>
#include <math.h>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main() {
    int n;
    int s=0;
    vector<int>vec;
    cin>>n;
    for(int i=1;i<=n;i++){
        s+=i;
        vec.push_back(i);
        if(s==n){
            break;
        }
        if(s>n){
            for(int j=0;j<vec.size();j++){
                if(vec[j]==s-n){
                    vec[j]=-1;
                }
            }
            break;
        }
    }
    for(auto a:vec){
        if(a!=-1){
            cout<<a<<endl;
        }
    }
    return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void Main() {
  string S; cin >> S;
  string T = S + S;
  ll K; cin >> K;
  ll s = 0, t = 0;
  ll res = 0;

  bool same = true;
  rep(i, 0, S.size()){
    if(S[i] != S[0]) same = false;
  }
  
  rep(i, 0, S.size() - 1){
    if(S[i] == S[i + 1]){
      S[i + 1] = '?';
      s++;
    }
  }
  rep(i, 0, T.size() - 1){
    if(T[i] == T[i + 1]){
      T[i + 1] = '?';
      t++;
    }
  }
  res = s + (K - 1) * (t - s);
  
  if(same){
    if(S.size() % 2){
      if(K % 2) res = t * ((K - 1) / 2) + s;
      else res = t * (K / 2);
    }else{
      res = K * s;
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 8064
N, A, B = list(map(int, input().split()))
S = input()

a = 0
b = 0
for s in S:
    if s == 'a':
        if a + b < A + B:
            print('Yes')
            a += 1
        else:
            print('No')
    elif s == 'b':
        if (a + b < A + B) and b < B:
            print('Yes')
            b += 1
        else:
            print('No')
    else:
        print('No')


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

int dfs(vector<vector<int>> &graph, vector<bool> seen, int vertex) {
  // 頂点を訪問済みにする
  seen.at(vertex) = true;

  auto f = [](bool seen) { return seen == true; };
  bool all_seen = all_of(seen.begin(), seen.end(), f);
  if (all_seen) {
    return 1;
  }

  int cnt = 0;
  // vertex から訪問可能な頂点を探索する
  for (auto next_vertex : graph.at(vertex)) {
    // 次の頂点が訪問済みの場合はスキップ
    if (seen.at(next_vertex) == true) { continue; }
    cnt += dfs(graph, seen, next_vertex);
  }

  return cnt;
}

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

  // 入力受取
  vector<vector<int>> graph(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--; // 0-indexed
    graph.at(x).push_back(y);
    graph.at(y).push_back(x); // 無向グラフ
  }

  // 訪問情報の初期化
  vector<bool> seen(n, false);

  // DFSで探索
  int cnt = dfs(graph, seen, 0);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3616
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int calc(int x, int d){  // 1~xでd桁目が立っている個数（の偶奇）
  int res = 0;
  int N = 42;
  stringstream ss;
  ss << bitset<42>(x);
  string s = ss.str();

  int dp[2][N+1];
  dp[0][0] = 1;
  dp[1][0] = 0;
  rep(i, 1, N+1){
    if (i!=d){
      if (s[i-1]=='0'){
        dp[0][i] = dp[0][i-1];  // select 0
        dp[1][i] = 2*dp[1][i-1];  // select 1
      }
      else{
        dp[0][i] = dp[0][i-1];  // select 1
        dp[1][i] = dp[0][i-1];  // select 0
        dp[1][i] += 2*dp[1][i-1];  // select 1, 0
      }
    }
    else{
      if (s[i-1]=='0'){
        dp[0][i] = 0;  // select 0
        dp[1][i] = dp[1][i-1];  // select 1
      }
      else{
        dp[0][i] = dp[0][i-1];  // select 1
        dp[1][i] = dp[0][i-1];  // select 0
        dp[1][i] = dp[1][i-1];  // select 1
      }
    }
    dp[0][i] %=2;
    dp[1][i] %=2;
  }
  // dump_1d(dp[0], N+1);
  // dump_1d(dp[1], N+1);

  return (dp[0][42]+dp[1][42])%2;
}

int solve(){
  int a,b;cin>>a>>b;

  assert(calc(4, 42)==0);

  int res = 0;
  int mlt = 1;
  rrep(i, 1, 43){
    dump(i, calc(b, i), calc(a-1, i));
    res += mlt * ((calc(b, i) + calc(a-1, i))%2);
    mlt *= 2;
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
W, H, x, y, r = [int(i) for i in input().rstrip().split(" ")]
hidari, migi = x-r, x + r
shita, ue = y-r, y+r

if (0 <= hidari) and (migi <= W) and (0 <= shita) and (ue <= H):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5604
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <limits>


template<class... Ts> using tuple_t = std::tuple<Ts...>;
template<class T, class U> using map_t = std::map<T, U>;
template<class T, class U> using pair_t = std::pair<T, U>;
template<class T> using vector_t = std::vector<T>;
template<class T> using set_t = std::set<T>;

uint64_t digit(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		++i;
		num /= base;
	}
	return i;
}

uint64_t digit_sum(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		i += num % base;
		num /= base;
	}
	return i;
}

int min(vector_t<int> nums)
{
	int min_ = std::numeric_limits<int>::max();
	for(auto& i :nums)
		if(min_ > i)
			min_ = i;
	return min_;
}
int first_min(vector_t<int> nums, int start = 0)
{
	int min_ = min(nums);
	for(int i = start; i < nums.size(); ++i)
		if(nums[i] == min_)
			return i;

}


int first_not_min(vector_t<int> nums, int start = 0)
{
	int min_ = min(nums);
	for(int i = start; i < nums.size(); ++i)
		if(nums[i] != min_)
			return i;
	return nums.size();
}

int f(int n, int k)
{
	if((n - 1) % (k - 1))
		return (n - 1) / (k - 1) + 1;
	else
		return (n - 1) / (k - 1);
}

int main()
{
	int N, K, n;
	vector_t<int> nums;
	std::cin >> N >> K;
	for(int i = 0; i < N; ++i)
	{
		std::cin >> n;
		nums.push_back(n);
	}

	std::cout<<f(nums.size(),K)<<std::endl;
	return 0;
}


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

template<typename T1,typename T2> inline void cmax(T1 &a,T2 b) {
  if (a < b) a = b;
}

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  static vector V(H + 1, vector(W + 1, 0));
  for (int h, w, v; cin >> h >> w >> v;) V.at(--h).at(--w) = v;
  static vector DP(H + 1, vector(W + 1, vector(5, 0L)));
  DP.at(0).at(0).at(1) = V.at(0).at(0);
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int i = 0; i < 4; i++) {
        long now = DP.at(h).at(w).at(i);
        cmax(DP.at(h + 1).at(w).at(0), now);
        cmax(DP.at(h + 1).at(w).at(1), now + V.at(h + 1).at(w));
        cmax(DP.at(h).at(w + 1).at(i), now);
        cmax(DP.at(h).at(w + 1).at(i + 1), now + V.at(h).at(w + 1));
      }
    }
  }
  cout << *max_element(DP.at(H - 1).at(W - 1).begin(), DP.at(H - 1).at(W - 1).begin() + 4) << "\n";
}


Measured memory_bytes: 671972
fn main() {
    let s = {
        let mut s = String::new(); 
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_string()
    };

    let mut tokens = s.split(" ")
        .map(|num| num.parse().unwrap())
        .collect::<Vec<i32>>();
    tokens.sort();

    println!("{} {} {}", tokens[0], tokens[1], tokens[2]);
}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    s = " " + s;
    vector<int> f(n + 2), g(n + 2);
    f[0] = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = f[i - 1];
        if (s[i] == 'o') {
            f[i] = max(1, f[i]);
        }
        if (s[i] == 'o' && i - c - 1 >= 0) {
            f[i] = max(f[i], 1 + f[i - c - 1]);
        }
    }
    if (f[n] < k) {
        return 0;
    }
    g[n + 1] = 0;
    for (int i = n; i >= 1; --i) {
        g[i] = g[i + 1];
        if (s[i] == 'o') {
            g[i] = max(1, g[i]);
        }
        if (s[i] == 'o' && i + c + 1 <= n + 1) {
            g[i] = max(g[i], 1 + g[i + c + 1]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'x') {
            continue;
        }
        if (f[i - 1] + g[i + 1] >= k) {
            continue;
        }
        if (f[i - 1] + g[i + 1] + 1 >= k) {
            cout << i << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3408
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        long ans = 3 * r * r;
        System.out.println(ans);
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 23764
N=int(input())
A=input().split()
B=input().split()
for i in range(0,N):
    A[i]=int(A[i])
    B[i]=int(B[i])
A[N]=int(A[N])
s=0
for i in range(0,N):
    if B[i]<=A[i]:
        s=s+B[i]
    else:
        if A[i+1]>=B[i]-A[i]:
            s=s+B[i]
            A[i+1]=A[i+1]-B[i]+A[i]
        else:
            s=s+A[i]+A[i+1]
            A[i+1]=0
print(s)

Measured memory_bytes: 19412
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private static String solve(Scanner scanner) {
        boolean ret = solveInner(scanner);
        return ret ? "Yes" : "No";
    }

    private static boolean solveInner(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        int[] nums = lineTointNums(scanner.nextLine());

        int n4 = 0;
        int nOdds = 0;
        for (int num : nums) {
            if (num == 0) continue;
            if (num % 2 == 1) {
                nOdds++;
            } else if (num % 4 == 0) {
                n4++;
            }
        }

        if (nOdds > n4) return nOdds + n4 == N && nOdds == n4 + 1;
        return true;    
    }

    public static void main(String[] args) {
//        tests();

        Scanner scanner = new Scanner(System.in);
        System.out.println(solve(scanner));
    }

    private static String ex1 = "3\n" +
            "1 10 100";
    private static String ex2 = "4\n" +
            "1 2 3 4";
    private static String ex3 = "3\n" +
            "1 4 1";
    private static String ex4 = "2\n" +
            "1 1";
    private static String ex5 = "6\n" +
            "2 7 1 8 2 8";

    private static void tests() {
        System.out.println(solve(new Scanner(testCaseToInputStream(ex1))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex2))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex3))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex4))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex5))));
    }

    private static ByteArrayInputStream testCaseToInputStream(String ex) {
        try {
            return new ByteArrayInputStream(ex.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }

    private static int[] lineTointNums(String line) {
        String[] numStrs = line.split(" ");
        int[] nums = new int[numStrs.length];
        for (int i = 0; i < nums.length; i ++) {
            nums[i] = Integer.parseInt(numStrs[i]);
        }
        return nums;
    }
}


Measured memory_bytes: 46740
N, Y = map(int, input().split(" "))
found = False
for x in range(N + 1):
    if 10000 * x + 5000 * (N - x) + 1000 * (N - x) < Y:
        continue
    for y in range(N - x + 1):
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            print("{} {} {}".format(x,y,N - x - y))
            found = True
            break
        if found:
            break
    if found:
        break
else:
    print("-1 -1 -1")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll partition(vl& A, ll p, ll r){
    ll x = A[r];
    ll si = p - 1;
    repe(i, p, r){
        if(A[i]<=x){
            si++;
            swap(A[i], A[si]);
        }
    }
    swap(A[si + 1], A[r]);
    return si + 1;
}
int main() {
    init();
    ll N;
    cin >> N;
    vl A(N), L, R;
    rep(i, N) cin >> A[i];

    ll pi = partition(A, 0, N - 1);
    rep(i, pi) cout << A[i] << " ";
    cout << '[' << A[pi] << ']';
    repe(i, pi + 1, N) cout << " " << A[i];
    cout << endl;
}


Measured memory_bytes: 3444
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100+ 2)
#define MAX_K (100000+ 2)
int n, k;
ll a[MAX_N];
ll dp[MAX_K][MAX_N];

ll rec(int k, int index){
  if (index == -1){
    return k == 0 ? 1 : 0;
  }

  if (k < 0){
    return 0;
  }

  if (dp[k][index] != -1){
    return dp[k][index];
  }

  // dp[k][index] = 0;
  // for (int i = 0; i <= a[index]; i++){
  //   if (k - i < 0){
  //     break;
  //   }
  //   ll tmp = rec(k - i, index - 1);
  //   dp[k][index] = (dp[k][index] + tmp) % MOD;
  // }
  dp[k][index] = (rec(k, index - 1) + rec(k-1, index)) % MOD;
  if (k - 1 - a[index] >= 0){
    dp[k][index] -= rec(k - 1 - a[index], index - 1);
    if (dp[k][index] < 0){
      dp[k][index] += MOD;
    }
    dp[k][index] %= MOD;
  }

  // printf("dp[%d][%d] = %lld\n", k, index, dp[k][index]);

  return dp[k][index];
}

void exec(){
  cin >> n >> k;

  for (int i = 0; i < MAX_K; i++){
    for (int j = 0; j < MAX_N; j++){
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++){
    scanf("%lld", &a[i]);
  }

  cout << rec(k, n-1) << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 86144
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
	macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    let a = get!();
    let b = get!();
    let c = get!();
    let ab = (a - b).abs();
    let bc = (b - c).abs();
    let ca = (c - a).abs();
    use std::cmp::min;
    let ans = min(min(ab+bc,bc+ca),ab+ca);
    println!("{}", ans);
        
}


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

int main()
{
	double n;

	cin >> n;
	vector<double> a(n);
	vector<double> f(n);

	for(double i=0;i<n;i++){
		cin >> a[i];
		f[i] = 0;
	}

	double now = a[0];

	for(double i = 0;i<n;i++){
		if(now > a[i]){
			f[i] = now - a[i];
		}else if(now < a[i]){
			now = a[i];
		}
	}

	long long cnt=0;
	for(double i=0;i<n;i++){
		cnt = cnt + f[i];
	}

/*
cout << "-------------" << endl;
	for(double i=0;i<n;i++){
		cout << f[i] << " ";
	}
	cout << endl;
	for(double i=0;i<n;i++){
		cout << f[i] + a[i] << " ";
	}
	cout << endl;
cout << "------------" << endl;
*/

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 6388
N = int(input())
A = [int(a) for a in input().split()]

dp = [[0]*N for _ in range(N)]
        
for k in range(N):
    for i in range(N-k):
        if k == 0:
            dp[i][i] = A[i]
            continue
    
        dp[i][i+k] = max(A[i]-dp[i+1][i+k], A[i+k]-dp[i][i+k-1])

print(dp[0][N-1])

Measured memory_bytes: 112092
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue> 
using namespace std;
int main(void){
    int n,i,sum1=0,sum2=0,ans=10000000;
    cin>>n;
    int w[n];
    for(i=0;i<n;i++){
        cin>>w[i];
        sum1+=w[i];
    }
    for(i=0;i<n;i++){
        sum2+=w[i];
        sum1-=w[i];
        ans=min(ans,abs(sum1-sum2));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
using namespace std;
 
const int INF = 1e9;
 
int main(){
  int H, W;
  cin >> H >> W;
  
  int D[H][W];
  rep(i,H) fill(D[i], D[i]+W, INF);
  
  queue<pair<int,int> > que;
  rep(i,H){
    rep(j,W){
      char c;
      cin >> c;
      if(c == '#'){
        que.push(make_pair(i,j));
        D[i][j] = 0;
      }
    }
  }
  
  while(!que.empty()){
    pair<int,int> p = que.front();
    que.pop();
    
    int dy[] = {1,-1,0,0};
    int dx[] = {0,0,1,-1};
    
    rep(m,4){
      int y = p.first + dy[m];
      int x = p.second + dx[m];
      if(y < 0 || H <= y || x < 0 || W <= x) continue;
      if(D[y][x] != INF || D[y][x] < D[p.first][p.second] + 1) continue;
      D[y][x] = D[p.first][p.second] + 1;
      que.push(make_pair(y,x));
    }	
  }
  
  int ans = 0;
  rep(n,H){
    rep(o,W){
      ans = max(ans,D[n][o]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 12304
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ull  a,b,x;
    cin >> a >> b >> x;
    ull A = a/x * a;
    ull B = b/x * b;
    if(a == 0){
        cout << b/x + 1 << endl;
        return 0;
    }
    cout << b/x - (a - 1ull)/x << endl;

}

Measured memory_bytes: 384
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var s = next(), w = next();
  return s <= w ? "unsafe" : "safe";
}

Measured memory_bytes: 29628
import java.util.Scanner;

 class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);

	        int sumOfLeft=0;
        	int max=0;
	        int side=0;
		int N=s.nextInt();
        	 for(int i=0;i<N;i++){
	         	side=s.nextInt();
			sumOfLeft+=side;
        		if(max<side) max=side;
        	 }
	         if(sumOfLeft<=(2*max)) System.out.println("No");
        	 else System.out.println("Yes");
     }
 }

Measured memory_bytes: 23252
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  priority_queue<ll> que;
  REP(i,0,n) {
    ll a;
    cin >> a;
    que.push(a);
  }
  REP(i,0,m) {
    ll a = que.top();
    que.pop();
    que.push(a / 2);
  }
  ll sum = 0;
  while (! que.empty()) {
    sum += que.top();
    que.pop();
  }
  cout << sum << endl;

  return 0;
}


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

int main(int argc, const char * argv[]) {
    
    while(true){
        int H,W;
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout << "#";
            }
            cout << endl;
        }
        
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1152
list_dish = [input() for i in range(0, 5)]
list_disit1 = [int(list_dish[i][-1]) for i in range(0, 5)]
marking = 0
min = 9
ans = 0
for i in range(0, 5):
    if list_disit1[i] != 0 and list_disit1[i] <= min:
        marking = i
        min = list_disit1[i]
for i in range(0, 5):
    if i == marking:
        ans += int(list_dish[i])
    else: ans += -(-int(list_dish[i]) // 10) * 10
print(ans)

Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 600000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int imos[32][MAX];

//abc080d
void solve(void){
    int N, C;
    cin >> N >> C;
    memset(imos, 0, sizeof(imos));
    rep(N, i) {
        int s, t, c;
        scanf("%d %d %d\n", &s, &t, &c);
        imos[c][2*s-1]++;
        imos[c][2*t]--;
    }
    int maxi = 0;
    rep(MAX-1, i) {
        rep(32, j) {
            imos[j][i+1] += imos[j][i];
        }
    }
    rep(MAX, i) {
        int tsum = 0;
        rep(32, j) {
            if(imos[j][i]) tsum++;
        }
        maxi = max(maxi, tsum);
    }
    cout << maxi << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 75264