akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main(int argc, char** argv) {
    int n;
    cin >> n;

    std::vector<int> vec(n + 1);
    vec[0] = 0;
    for (int i = 1; i < n+1; ++i) {
        cin >> vec[i];
    }
    std::vector<int> dp(n + 1);
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(vec[2]-vec[1]);
    for (int i = 3; i < n+1; ++i) {
        dp[i] = std::min(dp[i-1] + abs(vec[i]-vec[i-1]), dp[i-2] + abs(vec[i]-vec[i-2]));
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {

    int ans = 0;
    int N; cin >> N;
    REP(i,N) {
        int l,r; cin >> l >> r;
        ans += r - l + 1;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

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

    vector<int> num;
    for(int i = 1; i*i <= m; i++){
        if(m % i == 0) num.pb(i), num.pb(m / i);
    }
    num.pb(m);
    
    int ans = 1;
    REP(i, num.size()){
        if(num[i] <= m / n){
            ans = max(ans, num[i]);
        }
    }
    
    cout << ans << endl;
}


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

string S;

int main(void) {
	cin >> S;

	int bw = 0;		// 黒白 01 の順にする
	int wb = 0;		// 白黒 10 の順にする
	for (int i = 0; i < (int)S.length(); ++i) {
		if ((i & 1) == 0) {
			if (S[i] == '0')
				++wb;
			else
				++bw;
		}
		else {
			if (S[i] == '1')
				++wb;
			else
				++bw;
		}
	}

	int ans = min(bw, wb);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll x;
    cin>>x;
    ll a = x/500;
    x%=500;
    ll e=x/5;
    x%=5;
    cout<<a*1000+e*5<<endl;

}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

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

    ll N,M; cin >> N >> M;
    ll A[100005];
    for (int i = 0;i < N;i++){
        cin >> A[i];
    }

    sort(A,A+N);

    P D[100005];

    for (int i = 0;i < M;i++){
        ll B,C; cin >> B >> C;
        D[i] = P(C,B);
    }

    sort(D,D+M);
    reverse(D,D+M);

    ll idx = 0;
    ll ans = 0;

    for (int i = 0;i < N;i++){
        //cout << A[i] << " " << D[idx].first << endl;
        if(A[i] < D[idx].first){
            ans += D[idx].first;
            D[idx].second--;
            if(D[idx].second == 0) idx++;
        }
        else ans += A[i];
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll a, b, x; cin >> a >> b >> x;
  cout << b/x - (a+x-1)/x + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

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

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

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	A := make([]int, n+1)
	for i := range A {
		fmt.Fscan(read, &A[i])
	}

	cnt := 0
	for i := 0; i < n; i++ {
		var b int
		fmt.Fscan(read, &b)

		for j := 0; j < 2; j++ {
			if A[i+j] > b {
				cnt += b
				A[i+j] -= b
				b = 0
			} else {
				cnt += A[i+j]
				b -= A[i+j]
				A[i+j] = 0
			}
		}
	}
	fmt.Fprintln(write, cnt)
}


Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<stack>
#include<queue>
using namespace std;

int main(){
	int a, b, c, d;
	int A, B;
	cin >> a >> b >> c >> d;
	A = max(a, c);
	B = min(b, d);
	if (B - A > 0)cout << B - A << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
int n;
int ans, d;
char i;
int main(){
 n = nextInt();
    for(i=0; i<6; i++){
        d = n%10;
        n = n/10;
        ans += d;
    }
    if(ans == 1){
        ans = 10;
    }
 printInt(ans);
 println();
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N;
  in(N);
  vi X(N);
  int mine = INF, maxe = 0;
  each(x, X) {
    in(x);
    mine = min(mine, x);
    maxe = max(maxe, x);
  }

  int ans = INF;
  for (int i = mine; i <= maxe; i++) {
    int sum = 0;
    each(x, X) {
      sum += (i - x) * (i - x);
    }
    ans = min(ans, sum);
  }

  print(ans);
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
K,S = map(int, input().split())
ans = 0

"""
for x in range (0, K+1):
    for y in range (0, K+1):
        for z in range (0, K+1):
            if S == x+y+z:
                ans += 1
"""

for x in range (0, K+1):
    for y in range (0, K+1):
        if 0 <= S-x-y and K >= S-x-y:
            ans += 1

print(ans)

Measured memory_bytes: 3064
//
// Created on 2020/06/21.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    char c;
    cin>>c;
    int a = c - 'A';

    if(a < 32){
        cout<<"A"<<endl;
        return 0;
    }else{
        cout<<"a"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define vvll vector< vector<int> >
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e10
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 2010
     

int32_t main(){
    IOS;
    
    int k;cin>>k;
    int x=0;
    rep(i,1,1e7){
    	x=10*x+7,x%=k;
    	if(x==0){cout<<i;return 0;}
    }
    cout<<"-1";
   	
	
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h> 
 #include <string.h> 
  
  
 int main(){ 
     int m, h; 
     char cards[256], temp[256], result[256]; 
     int i, j=0, len; 
  
  
     while(1){ 
         scanf("%s", cards); 
         len=strlen(cards); 
         if(strcmp(cards, "-")==0&&len==1)break; 
         scanf("%d", &m); 
         for(;m>0;m--){ 
             scanf("%d", &h); 
             strcpy(temp, cards); 
             for(i=0;i<h;i++){ 
                 cards[len-h+i]=temp[i]; 
             } 
             for(i=0;i<len-h;i++){ 
                 cards[i]=temp[i+h]; 
             } 
         } 
         for(i=0;i<len;i++){ 
             result[j++]=cards[i]; 
         } 
         result[j++]='\n'; 
     } 
     result[j]='\0'; 
     printf("%s", result); 
  
  
     return 0; 
 }


Measured memory_bytes: 2128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//templete
int main() {
    int N;
    cin>>N;
    vint P;
    ll idx[SIZE]={};
    for(int i=0;i<N;i++){
        int p;
        cin>>p;
        P.pb(p);
        idx[p]=i;
    }
    multiset<ll> tes;
    tes.insert(-1);
    tes.insert(-1);
    tes.insert(N);
    tes.insert(N);
    tes.insert(idx[N]);

    ll ans=0;
    for(int i=N-1;i>0;i--){
        auto la=tes.lower_bound(idx[i]), ra=tes.upper_bound(idx[i]);
        la--;ra++;
        auto lb=tes.lower_bound(idx[i]), rb=tes.upper_bound(idx[i]);
        lb--;lb--;

        ans+=i*(idx[i]-*la)*(*ra-*rb);
        ans+=i*(*la-*lb)*(*rb-idx[i]);
        tes.insert(idx[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

int W, H;

void debugprint(vector<vector<char>> &data) {
    cerr << endl;
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            cerr << data[h][w];
        }
        cerr << endl;
    }
    cerr << endl;
}

int tansaku(vector<vector<char>> &data, int w, int h)
{
    int counter = 0;
    data[h][w] = 'x';
    counter += 1;
    if(w+1<W && data[h][w+1]=='.') counter += tansaku(data, w+1, h);
    if(w-1>=0 && data[h][w-1]=='.') counter += tansaku(data, w-1, h);
    if(h-1>=0 && data[h-1][w]=='.') counter += tansaku(data, w, h-1);
    if(h+1<H && data[h+1][w]=='.') counter += tansaku(data, w, h+1);
    return counter;
}

int solve() {
    int start_pos_w, start_pos_h;
    cin >> W >> H;
    if(W==0&&H==0) return 0;

    vector<vector<char>> datas;
    datas.resize(H);

    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            char data;        
            cin>>data;
            if(data=='@') {
                start_pos_w = w;
                start_pos_h = h;
            }
            datas[h].push_back(data);
        }
    }

    int count = tansaku(datas, start_pos_w, start_pos_h);
    cout << count << endl;
    return 1;
}

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



Measured memory_bytes: 3116
div2::Int->Int
div2 n = if mod n 2 == 0 then 1 + (div2 (div n 2)) else 0

solver::[Int]->Int
solver = minimum.(map div2)

main::IO()
main=do
  _<-getLine
  s<-getLine
  let d = map read (words s)
  print (solver d)

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define N 200000 + 5
#define M 
#define inf 123456789
#define Inf 1000000000000000000
#define Mod 1000000007
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++i)
#define dep(i, l, r) for(register int i = r; i >= l; --i)
#define Next(i, u) for(register int i = h[u]; i; i = e[i].next)
#define mem(f, x) memset(f, x, sizeof(f))
#define file(a) freopen(#a".in","r",stdin); freopen(#a".out","w",stdout);
typedef long long ll;
typedef double D;
int n, m, k, l, r, pos1, pos2, pos, pre, len, a[N], b[N];
int read(){
	char c; int x = 0, f = 1;
	c = getchar();
	while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ x = (x << 3) + (x << 1) + c - '0'; c = getchar();}
	return x * f;
}
int Mul(int a, int b) { return 1ll * a * b % Mod; }
int Inc(int a, int b) { return (a += b) >= Mod ? a - Mod : a; }
int Dec(int a, int b) { return (a -= b) < 0 ? a + Mod : a; }
bool check(int Mid){
    int sum = 0;
    if(Mid < 0){
        if(pos > n) return false;
        rep(i, 1, pos - 1){
            int l = pos, r = n;
            while(l < r){
                int mid = (l + r) >> 1;
                if(a[i] * a[mid] <= Mid) r = mid;
                else l = mid + 1; 
            }
            if(a[i] * a[r] > Mid) r++;
            if(r == i) r++;
            if(n >= r) sum += n - r + 1;
        }
        if(sum >= k) return true;
        else return false;
    }
    else if(Mid == 0){
        sum = (pos - 1) * (n - pos + 1) + pre;
        if(sum >= k) return true;
        else return false;
    }
    else{
        sum = (pos - 1) * (n - pos + 1) + pre;
        rep(i, 1, pos - 1){
            int l = i, r = pos - 1;
            while(l < r){
                int mid = (l + r) >> 1;
                if(a[i] * a[mid] <= Mid) r = mid;
                else l = mid + 1; 
            }
            if(a[i] * a[r] > Mid) r++;
            if(r == i) r++;
            if(pos > r) sum += pos - r;
        }
        rep(i, pos, n){
            int l = i, r = n;
            while(l < r){
                int mid = (l + r) >> 1;
                if(a[i] * a[mid] < Mid) l = mid + 1;
                else r = mid;
            }
            if(a[i] * a[r] > Mid) r--;
            if(r > i) sum += r - i;
        }
        if(sum >= k) return true;
        else return false;
    }
}
signed main(){
	//file(data);
	n = read(), k = read();
    rep(i, 1, n) b[i] = read();
    sort(b + 1, b + n + 1);
    b[n + 1] = 1;
    rep(i, 1, n){
        if(b[i] == 0 && !pos1) pos1 = i;
        if(b[i] == 0 && b[i + 1] != 0 && !pos2) pos2 = i;
    } 
    if(pos1) len = pos2 - pos1 + 1, pre += len * (len - 1) / 2 + (n - len) * len;
    m = n, n = 0;
    rep(i, 1, m) if(!(i >= pos1 && i <= pos2)) a[++n] = b[i];
    rep(i, 1, n) if(a[i] > 0 && !pos) pos = i;
    if(!pos) pos = n + 1;
    l = -Inf, r = Inf;
    while(l < r){
        int Mid = (l + r) >> 1;
        if(check(Mid)) r = Mid;
        else l = Mid + 1;
    }
    printf("%lld", r);
	return 0;
}


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

using namespace std;

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

  int n, a; cin >> n;
  vector<pair<int, int>> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> a;
    vec[i] = {i+1, a};
  }
  sort(vec.begin(), vec.end(), [](pair<int, int> x, pair<int,int> y) {return x.second < y.second;});
  for (int i = 0; i < n; ++i) {
    cout << vec[i].first << " ";
  }
  cout << endl;

  return 0;
}



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

#define int long long

int a[100010], n, A, B;

bool check (int x)
{
    int sum=0, k=A-B;
    for (int i=0; i<n; i++) {
        int r=a[i]-B*x;
        
		if (r > 0){
            sum += r / k; 
            sum += (r % k != 0);
        }
    }
    
    if (sum > x)	
		return false;
    
	return true;
}

signed main()
{
	scanf ("%lld%lld%lld", &n, &A, &B);
	
	for (int i=0; i<n; i++)	
		scanf ("%lld", a+i);
		
	int l=0, r=1e9, ans=INT_MAX;
	while (l<=r){
		int mid=(l+r)>>1;
		if (check(mid))	
			r = mid - 1, ans = min (mid, ans);
		else			
			l = mid + 1;
    }
    
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int m = 0;
	rep(i, n - 1) chmax(m, a[i + 1] - a[i]);
	chmax(m, a[0] + k - a[n - 1]);
	cout << k - m << endl;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool check_prime(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int setbits(int n)
{
    int count=0;
    while(n)
    {
        if(n%2==1)
            count++;
        n>>=1;
    }
    return count;
}

int lcm(int a,int b)
{
    return (a*b)/__gcd(a,b);
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(a<b){
    int x=(a+(v*t));
    int y=(b+(w*t));

    if(x>=y)
        cout<< "YES";
    else
        cout<< "NO";}
    else
    {
        int x=(a-(v*t));
        int y=(b-(w*t));

        if(x<=y)
            cout<< "YES";
        else
            cout<< "NO";
    }


    return 0;
}


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

typedef long long ll;



int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    int a[300000];
    int max=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>max){
            max=a[i];
        }
    }
    int max1=0;
    for(int i=0;i<n;i++){
        if(abs(2*a[i]-max)<abs(2*max1-max)){
            max1=a[i];
        }
    }
    cout<<max<<" "<<max1;
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n; cin >> n; vector<string> s(n); for(int i = 0; i < n; i++){cin >> s[i]; sort(s[i].begin(), s[i].end());}
    map<string, ll> st;
    for(int i= 0; i < n; i++)st[s[i]]++;
    ll sum = 0;
    for(auto i : st) {
        sum += i.second * (i.second - 1) / 2;
    }
    cout << sum << endl;
}

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

using namespace std;

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

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int H, W;
int dp[2][1<<19][2][2] = {0};
vector<string> m(H);
bool inRange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}
char getM(int x, int y) {
	if ( !inRange(x, y) ) return 0;
	switch (m[y][x]) {
		case 'J': return 0;
		case 'O': return 1;
		case 'I': return 2;
	}
	return -1;
}
bool check(int x, int y, int c) {
	if ( getM(x, y) < 0 ) return true;
	return c == getM(x, y);
}
ll mod = 1e5;
int add(ll a, ll b) { return a+b > mod ? a+b-mod : a+b; }
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> H >> W;
	if (W == 1 || H == 1) {
		cout << 0 << endl;
		return 0;
	}
	m.resize(H);
	cin >> m;
	reverse( ALL(m) );
	REP(i, m.size()) reverse( ALL(m[i]) );
	fill(dp[0][0][0], dp[1][(1<<19)-1][2], 0); dp[0][0][0][0] = 1;
	REP(i, W*H) {
		fill(dp[i+1&1][0][0], dp[i+1&1][(1<<19)-1][2], 0);
		int x = i%W, y = i/W;
		REP(j, (1 << (W-1))) REP(m, 3) {
			if ( !check(x, y, m) ) continue;
			if (x == 0) {
				REP(k, 2) REP(l, 2) {
					int nj = j;
					int nk = m == 1 ? 1 : 0;
					dp[i+1&1][nj][nk][l] = add(dp[i+1&1][nj][nk][l], dp[i&1][j][k][l]);
				}
			}
			else {
				REP(k, 2) REP(l, 2) {
					int nj = j>>1; if (m == 2) nj |= (1<<(W-2));
					int nk = m == 1 ? 1 : 0;
					int nl = l == 1 || (m == 0 && (j&1) && k == 1) ? 1 : 0;
					dp[i+1&1][nj][nk][nl] = add(dp[i+1&1][nj][nk][nl], dp[i&1][j][k][l]);
				}
			}
		}
	}
	ll ans = 0;
	REP(i, (1 << (W-1))) REP(j, 2) {
		ans = add(ans, dp[(W*H)&1][i][j][1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 19564
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  if(s.substr(0,7)=="keyence"||s.substr(n-7,7)=="keyence"){
  cout << "YES" << endl;
  return 0;
  }
  
  repo(i,n-1){
    for(int j=i;j<n-1;j++){
      string t=s.substr(0,i)+s.substr(j+1,n-j);
      if(t=="keyence"){
      cout << "YES" << endl;
      return 0;
      }
    }
  }
  
  cout << "NO" << endl;
  
}


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

ac_check = [False for i in range(n)]
wa_count = [0 for i in range(n)]

clear = 0
error = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1

    if s == 'AC' and ac_check[p] == False:
        ac_check[p] = True
        error += wa_count[p]
    elif s == 'WA' and ac_check[p] == False:
        wa_count[p] += 1

for i in range(n):
    if ac_check[i]:
        clear += 1

print(clear, error)


Measured memory_bytes: 4760
#include <stdio.h>
#define N 45

void makeFibonacci(int);

int F[N];

int main() { 

  int n;

  scanf("%d", &n);

  makeFibonacci(n);

  printf("%d\n", F[n]);

  return 0;
}

void makeFibonacci(int n) {

  int i;

  F[0] = 1;
  F[1] = 1;
  
  for( i = 2; i <= n; i++ ) {
    F[i] = F[i-1] + F[i-2];
  }

  return ;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  if(a<b)ou("<");
  if(a==b)ou("=");
  if(a>b)ou(">");
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  const ll INF = 1e18;
  rep(i, n) {
    if (a[i] > INF) {
      cout << -1 << endl;
      return 0;
    }
    if (INF / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  if (ans > INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n, m;
    cin >> n >> m;
    map<int, ll> card;
    set<ll> ca;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ca.insert(a);
        card[a]++;
    }
    for(int i = 0; i< m; i++){
        int b, c;
        cin >> b >> c;
        card[c] += b;
        ca.insert(c);
    }
    ll ans = 0;
    ll num = n;

    for(auto itr = ca.end(); itr != ca.begin(); itr--){
        if(itr == ca.end()) itr--;
        ll tmp = *itr;
        if(num >= card[tmp]){
            num -= card[tmp];
            ans += tmp*card[tmp];
        }else{
            ans += tmp*num;
            num = 0;
            break;
        }
    }
    if(num != 0) ans += num * (*ca.begin());
    cout << ans << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  while(1){
    if(s.substr(0,7)=="dreamer" && s.substr(0,10)!="dreamerase") s.erase(0,7);
    else if(s.substr(0,6)=="eraser" && s.substr(0,9)!="eraserase") s.erase(0,6);
    else if(s.substr(0,5)=="dream") s.erase(0,5);
    else if(s.substr(0,5)=="erase") s.erase(0,5);
    else{
      cout << "NO" << endl;
      break;
    }
    if(s.empty()){
      cout << "YES" << endl;
      break;
    }
  }
  return 0;
}


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

int main(){
    //入力
    int a,b,c;
    cin >> a >> b >> c;
    if((a==b)&&(b==c)){
        cout << 1 << endl;
    }else if((a==b)||(b==c)||(a==c)){
        cout << 2 << endl;
    }else{
        cout << 3 <<endl;
    }
}

Measured memory_bytes: 256
import java.util.*
import java.math.*
fun main(args: Array<String>) {

//    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var ans=0
    var A = 0
    var B = 0
    var sep = false
    //ABA BA BA BA
    for (i in 0 until N) {
        val S = readLine()!!
        if (S.last() == 'A') A++
        if (S.first() == 'B') B++
        if (!sep && A != B) sep = true

        var isA = false
        for (c in S) {
            if (isA && c == 'B') ans++
            isA = c == 'A'
        }
    }
    var min = Math.min(A,B)
    if (!sep && min > 0) min--
    println(ans+min)
}


Measured memory_bytes: 34396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    priority_queue<double,vector<double>,greater<double>> pq;
    REP(i,N){
        double v;
        cin >> v;
        pq.push(v);
    }
    while(pq.size() != 1){
        double x = pq.top(); pq.pop();
        double y = pq.top(); pq.pop();
        pq.push((x+y)/2);
    }
    double ans = pq.top();
    printf("%.8lf\n",ans);

}


Measured memory_bytes: 256
import java.util.*;

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

		int n=s.nextInt();
		int[]a=new int[n];
		for(int i=0;i<n;++i)
			a[i]=s.nextInt();
		Arrays.sort(a);

		ArrayList<String>r=new ArrayList<>();

		for(int i=n-2;i>0;--i) {
			if(a[i]<=0)
				break;
			r.add(a[0]+" "+a[i]);
			a[0]-=a[i];
			a[i]=Integer.MAX_VALUE;
		}
		for(int i=0;i<n-1;++i) {
			if(a[i]==Integer.MAX_VALUE)
				break;
			r.add(a[n-1]+" "+a[i]);
			a[n-1]-=a[i];
		}
		System.out.println(a[n-1]);
		r.forEach(System.out::println);
	}
}

Measured memory_bytes: 68940
import sys, bisect
input = sys.stdin.readline

n = int(input())
m = 200000
y_r = [[] for _ in range(m+1)]
y_l = [[] for _ in range(m+1)]
x_u = [[] for _ in range(m+1)]
x_d = [[] for _ in range(m+1)]
xy_r = [[] for _ in range(2*m+1)]
xy_l = [[] for _ in range(2*m+1)]
xy_u = [[] for _ in range(2*m+1)]
xy_d = [[] for _ in range(2*m+1)]
yx_r = [[] for _ in range(2*m+1)]
yx_l = [[] for _ in range(2*m+1)]
yx_u = [[] for _ in range(2*m+1)]
yx_d = [[] for _ in range(2*m+1)]

for _ in range(n):
    x, y, u = input().split()
    x, y = int(x), int(y)
    if u == 'U':
        x_u[x].append(y)
        xy_u[x+y].append(x)
        yx_u[y-x+m].append(x)
    if u == 'D':
        x_d[x].append(y)
        xy_d[x+y].append(x)
        yx_d[y-x+m].append(x)
    if u == 'R':
        y_r[y].append(x)
        xy_r[x+y].append(x)
        yx_r[y-x+m].append(x)
    if u == 'L':
        y_l[y].append(x)
        xy_l[x+y].append(x)
        yx_l[y-x+m].append(x)

    

ans = 10 ** 9
for i in range(m+1):
    x_u[i].sort()
    x_d[i].sort()
    y_l[i].sort()
    y_r[i].sort()

    for yu in x_u[i]:
        idx = bisect.bisect_left(x_d[i], yu)
        if idx < len(x_d[i]):
            ans = min(ans, (x_d[i][idx] - yu) * 5)

    for xr in y_r[i]:
        idx = bisect.bisect_left(y_l[i], xr)
        if idx < len(y_l[i]):
            ans = min(ans, (y_l[i][idx] - xr) * 5)

for i in range(2*m+1):
    xy_u[i].sort()
    xy_d[i].sort()
    xy_l[i].sort()
    xy_r[i].sort()

    for xr in xy_r[i]:
        idx = bisect.bisect_left(xy_u[i], xr)
        if idx < len(xy_u[i]):
            ans = min(ans, (xy_u[i][idx] - xr) * 10)
    
    for xd in xy_d[i]:
        idx = bisect.bisect_left(xy_l[i], xd)
        if idx < len(xy_l[i]):
            ans = min(ans, (xy_l[i][idx] - xd) * 10)

    yx_u[i].sort()
    yx_d[i].sort()
    yx_l[i].sort()
    yx_r[i].sort()

    for xr in yx_r[i]:
        idx = bisect.bisect_left(yx_d[i], xr)
        if idx < len(yx_d[i]):
            ans = min(ans, (yx_d[i][idx] - xr) * 10)
    
    for xu in yx_u[i]:
        idx = bisect.bisect_left(yx_l[i], xu)
        if idx < len(yx_l[i]):
            ans = min(ans, (yx_l[i][idx] - xu) * 10)


print(ans if ans < 10 ** 9 else 'SAFE')

Measured memory_bytes: 250420
while True:
	n,m = map(int,input().split())
	if n+m == 0:break
	lst = []
	for _ in range(n):
		d,v = map(int,input().split())
		lst.append((d,v))
	lst.sort()
	ans = 0
	for i,a in enumerate(lst):
		if i == len(lst)-1:
			ans += a[1]
			continue
		if lst[i+1][0] != a[0]:
			ans += a[1]
	print(ans)


Measured memory_bytes: 5608
package main

import (
	"fmt"
)

type Item struct {
	Value  int
	Weight int
}

func main() {
	var ItemNumber int
	var MaxWeight int
	sack := []Item{}

	fmt.Scanln(&ItemNumber, &MaxWeight)

	dp := make([]int, MaxWeight+1)
	fill(dp, -1)
	dp[0] = 0

	for i := 0; i < ItemNumber; i++ {
		X := Item{}
		fmt.Scanln(&X.Weight, &X.Value)
		sack = append(sack, X)
	}
	value := Knapsack(sack, dp,ItemNumber,MaxWeight)
	fmt.Print(int64(value))
}

func Knapsack(sacks []Item,dp []int, N int, W int) int{
	for i := 0; i < N; i++ {
		w := sacks[i].Weight
		v := sacks[i].Value
		for j := W - w; j >= 0; j-- {
			if dp[j] == -1 {
				continue
			}
			dp[j+w] = max(dp[j+w], dp[j]+v)
		}
	}
	return reduce(max, dp)
}


func reduce(f func(x, y int) int, a []int) int {
	result := a[0]
	for i := 1; i < len(a); i++ {
		result = f(result, a[i])
	}
	return result
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, z,sum, mn = 999999999, avg, pos, dif,k, mx, xi, yi;
const int MXN=1e5+7;
ll pre[MXN];
bool prime[MXN];

bool PE ( ll x )
{
    for ( ll i = 2; i * i <= x; i+=1+(i&1))
    if ( x % i == 0 )
    return false;
    return true;
}
ll dist[MXN];
void sieve()
{
    memset(prime , 1 , sizeof prime);

    for ( ll i = 2; i * i <= MXN; i+=1+(i&1))
    if (prime[i])
    {
          for (ll j = i * i; j < MXN; j +=i)
         prime[j] = false;
    }
}
bool vis [MXN], talked[MXN];

bool PR ( string s )
{
    int n = s.length();
    for ( ll i = 0; i < n / 2; i++ )
    if ( s[i] != s[n - i - 1] )
    return false;
    return true;
}
ll dsu[MXN];
int FindRoot (int i )
{
    if (dsu[i] == i)
    return i ;
    return dsu[i] = FindRoot(dsu[i]);
}
int main (void){
    SpeeD;
    
cin >> n >> m >> t;
for (int i = n ; i <= m ;i++)
if (i % t ==0)
c++;
cout << c;




}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define REP(i,n) for(int i = 0 ; i < n ; i ++) 
#define ms(a,c) memset(a,c,sizeof a)
int n , *a ;
int dp[100001] ;
int f(int i) {
    if(i==n-1){
        return 0;
    }
    int &ret = dp[i] ;
    if(ret!=-1)return ret;
    int op1 = INT_MAX , op2 = INT_MAX;
    if(i+1 < n) op1 = abs(a[i] - a[i+1]) + f(i+1) ;
    if(i+2 < n) op2 = abs(a[i] - a[i+2]) + f(i+2) ;
    return ret = min(op1,op2);
}
int32_t main() {
    cin >> n;
    a = new int[n] ;
    REP(i,n) {
        cin >> a[i] ;
    }
    ms(dp,-1);
    cout << f(0) << endl ;
    return 0;
}

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

int main() {
    int n, ans;
    cin >> n;
    if (n % 1000 == 0) {
        ans = 0;
    } else if (n == 10000) {
        ans = 0;
    } else {
        ans = 1000 - (n % 1000);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string S, T;
  cin >> S >> T;
  if (T.substr(0, T.size()-1)==S) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
n,x = gets.split(" ").map{|v| v.to_i}
total = 0
min = x
c = 0
n.times{|t|
  v = gets.to_i
  total += v
  c += 1
  min = [min, v].min
}
rest = x - total
c = c + rest / min
puts c


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<500000; i++){
		if(!num[i]){
			for(int j=i*2; j<1000000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

bool is(string str)
{
    auto t=str;
    reverse(begin(t),end(t));
    return str==t;
}

main()
{
    int n; cin>>n;
    int a[1<<18];
    long long cnt[1<<18]={};
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    long long ans=0;
    for(int i=1;i<=n;++i)
    {
        ans+=cnt[i]*(cnt[i]-1)/2;
    }
    for(int i=0;i<n;++i)
    {
        cout << ans-cnt[a[i]]+1 << "\n";
    }
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/


ll n;
ll r[30010][10],ans=0;
string s;

int main(void){
	cin>>n>>s;
	s=" "+s;
	rep(i,10)r[n+1][i]=n+1;
	rep(j,10){
		ireg(i,0,n){
			r[i][j] = min(r[i+1][j],(s[i]=='0'+j ? (ll)i : (ll)1e18));
		}
	}
	reg(i,0,9){
		ll p = r[0][i];
		if(p+1>n)continue;
		reg(j,0,9){
			ll q = r[p+1][j];
			if(q+1>n)continue;
			reg(k,0,9){
				ll t = r[q+1][k];
				if(t<=n){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, M;
int K[100];
int A[100][100];
int like[100];

int main()
{
    cin >> N >> M;
    repe(i, 1, N)
    {
        cin >> K[i];
        repe(j, 1, K[i])
        {
            cin >> A[i][j];
            like[A[i][j]]++;
        }
    }
    int ans = 0;
    repe(i, 1, M)
    {
        if (like[i] == N)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

string s;

map<char, long long> mp;

long long f(long long x) {
    return (x * (x - 1)) / 2;
}

int main() {
    cin >> s;
    long long n = s.size();
    long long ans = 1 + f(n);
    for (auto it : s) {
        mp[it]++;
    }
    for (char a = 'a'; a <= 'z'; ++a) {
        ans -= f(mp[a]);
    }
    cout << ans;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define fr first
#define sc second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N, ans=1;
	string A;

	cin >> A;
	N = A.length();

	ll cnt[255]={};
	rep(i,N) cnt[A[i]]++;
	ans += N*(N-1)/2ll;
	for(char i='a'; i<='z'; i++){
		if(cnt[i] > 1){
			ans -= cnt[i]*(cnt[i]-1)/2ll;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, k = Is()
s = LS()
s[k-1] = s[k-1].lower()
print("".join(s))

Measured memory_bytes: 65388
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/dp/tasks/dp_g>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int memo[100005];
vector<int> G[100005];

int rec(int n){
    int& ret = memo[n];
    if(~ret) return ret;
    ret = 0;
    for(const int& next:G[n]){
        ret = max(ret,rec(next)+1);
    }
    return ret;
}
template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;
    for(int i = 0; i < M;i++){
        int x,y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }
    fill(memo,memo+N,-1);
    for(int i = 0; i < N;i++){
        res = max(res,rec(i));
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<int>() << endl;
    return 0;
}


Measured memory_bytes: 7552