akhauriyash/Code-Regression huggingface dataset:
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
int n;
vector<int> v;
int dp[3001][3001][2];
int func(int i,int j,int t) {
    if(i == j) return t==0 ? v[i]: -v[i];
    if(i>j) return 0;
    int ans = 0;
    int &res = dp[i][j][t];
    if(res == -1e15) {
    if(t == 0) {
         ans  = max(v[i] + func(i+1,j,1), v[j] + func(i,j-1,1));
    } else if(t == 1) {
        ans = min(func(i+1,j,0)-v[i],func(i,j-1,0)-v[j]);
    }
    res = ans;
    }
    return res;
    // debug(i,j,ans,t);
    return ans;
}
void solve(){
    cin>>n;
    v.resize(n);
    FOR(i,0,n) cin>>v[i];
    FOR(i,0,3001) FOR(j,0,3001) dp[i][j][0]=-1e15,dp[i][j][1] = -1e15;
    int ans = func(0,n-1,0);
    cout<<ans;
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 141184
# -*- coding: utf-8 -*-


def is_sosu(x):
    for i in range(2, x):
        if x % i == 0:
            return False
    return True

N = int(input())
sosu = []
for candidate in range(2, 55555):
    if is_sosu(candidate) and candidate % 5 == 1:
        sosu.append(candidate)
        if len(sosu) >= N:
            break
print(' '.join([str(s) for s in sosu]))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

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

const ll mod = 998244353;
ll fact[210200];
ll invfact[210200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll powMod(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return powMod(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[4100][4100];

int main(){
    string s;
    cin >> s;

    int red[4100], blue[4100];
    red[0] = 0;
    blue[0] = 0;

    int redNum = 0, blueNum = 0;
    int redTotal = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '0'){
            redNum += 2;
            redTotal += 2;
        }
        else if(s[i] == '1'){
            redNum++;
            redTotal++;
            blueNum++;
        }
        else{
            blueNum += 2;
        }
        if(redNum > 0){
            red[i+1] = red[i] + 1;
            redNum--;
        }
        else{
            red[i+1] = red[i];
        }

        if(blueNum > 0){
            blue[i+1] = blue[i] + 1;
            blueNum--;
        }
        else{
            blue[i+1] = blue[i];
        }
    }
    for(int i = s.length(); i < 2 * s.length(); i++){
        if(redNum > 0){
            red[i+1] = red[i] + 1;
            redNum--;
        }
        else{
            red[i+1] = red[i];
        }
        if(blueNum > 0){
            blue[i+1] = blue[i] + 1;
            blueNum--;
        }
        else{
            blue[i+1] = blue[i];
        }
    }

    for(int i = 0; i < 4100; i++){
        for(int j = 0; j < 4100; j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < 2 * s.length(); i++){
        for(int j = 0; j <= i; j++){
            if(red[i+1] >= j + 1){
                dp[i+1][j+1] = add(dp[i+1][j+1], dp[i][j]);   // 赤を渡す
            }
            if(blue[i+1] >= (i - j) + 1){
                dp[i+1][j] = add(dp[i+1][j], dp[i][j]);       // 青を渡す
            }
        }
    }

    cout << dp[2 * s.length()][redTotal] << endl;


    return 0;
}


Measured memory_bytes: 133376
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<set>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

//http://kmjp.hatenablog.jp/entry/2019/09/08/0930

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

    int N;
    int S[1<<18];
    cin>>N;

    for(int i=0;i<(1<<N);i++) cin>>S[i];
    sort(S,S+(1<<N));
    multiset<int> T;
    for(int i=0;i<(1<<N)-1;i++){
        T.insert(S[i]);
    }

    vector<int> V;
    V.push_back(S[(1<<N)-1]);
    for(int i=0;i<N;i++){
        vector<int> W=V;
        for(auto v:V){
            auto it=T.lower_bound(v);
            if(it==T.begin()){
                cout<<"No"<<endl;
                return 0;
            }
            it--;
            W.push_back(*it);
            T.erase(it);
        }
        sort(W.rbegin(),W.rend());
        swap(V,W);
    }
    cout<<"Yes"<<endl;
}


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

int p[100007] = {};
bool ac[100007] = {};

int main(){
    int n, m, a;
    cin >> n >> m;
    string s;
    int pen = 0, corr = 0;
    for(int i = 0; i < m; i++){
        cin >> a >> s;
        if(s == "AC"){
            if(!ac[a]){
                pen += p[a];
                ac[a] = 1;
                corr++;
            }
        } else {
            p[a]++;
        }
    }
    cout << corr << ' ' << pen << '\n';
}


Measured memory_bytes: 768
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
N = a[0]
X = a[1]
L = []
for i in range(len(b)):
    L.append(b[i])
list=[]
D=[]
D.append(0)
for l in range(1,N+1):
    c = D[l-1] + L[l-1]
    D.append(c)

for j in range(len(D)):
    if D[j] <= X:
        list.append(1)

print(len(list))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

	int n, m;
	int k[10], s[10][10], p[10];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 0; i < pow(2, n); i++) {
		bool on = true;
		for (int j = 0; j < m; j++) {
			int num = 0;
			for (int n = 0; n < k[j]; n++) {
				int tmp;
				tmp = i & (int)pow(2,s[j][n]);
				if (tmp != 0)num++;
			}
			if (num % 2 != p[j]) {
				on = false;
				break;
			}
		}
		if (on) ans++;
	}

	cout << ans << endl;

}

Measured memory_bytes: 384
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord

--import qualified Data.IntSet as S
import qualified Data.Sequence as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    n <- readLn
    as <- replicateM n readLn :: IO [Int]
    let sl = scanl max 0 as
    let sr = scanr max 0 as
    mapM_ print $ zipWith max sl (tail sr)


Measured memory_bytes: 94972
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
    string x;
    cin >> x;

    int min_diff = 1000000000;
    for(int i=0;i<=x.size()-3;i++){
        int num = (x[i]-'0')*100+(x[i+1]-'0')*10+(x[i+2]-'0')*1;
        int diff = abs(753 - num);

        if(diff < min_diff){
            min_diff = diff;
        }
    }

    cout << min_diff << endl;
    return 0;
}

Measured memory_bytes: 256
import math
r = float(input())
a = math.pi
area = r * r * a
circle = r * 2 * a
area = "{0:.6f}".format(area)
circle = "{0:.6f}".format(circle)
ac_list = [area, circle]
for j in range(1):
    print(ac_list[j],end = ' ')

print(ac_list[1])



Measured memory_bytes: 5644
n, u, v = map(int,input().split())
edges = [[] for i in range(n)]


for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)


ha = [0 for i in range(n)]
def dfs(v):
    d= [0] * n
    q=[v]
    visited = [0] * n
    while q:
        v=q.pop()
        visited[v] = 1
        visited.append(v)
        c = True
        for i in edges[v]:
            if not visited[i]:
                d[i] = d[v] + 1
                q.append(i)
                c = False
        if c:
            ha[v] = 1
    return d,ha

df_nige , ha= dfs(u-1)
df_oi ,ha =dfs(v-1)

moku = -1
dfsa_mo = []
for i in range(n):
    kos =  df_oi[i] - df_nige[i] 
    dfsa_mo.append(kos)

#print(dfsa_mo)

ako = []

for i in range(n):
    dfsa = dfsa_mo[i]
    moku = i
    if dfsa > 0 and ha[i] == 1:
        if dfsa%2 == 0:
            if dfsa > 3:
                ans = df_nige[moku] + dfsa - 2 + 1
            elif dfsa == 2:
                ans = df_nige[moku] + 1
            else:
                ans = df_nige[moku]
        else:
            if dfsa == 1:
                ans = df_nige[moku]
            else:
                ans = df_nige[moku] + dfsa - 3 + 2
        #print(ans)
        ako.append(ans)

    else:
        ako.append(-1)

#print(ako)
gege = max(ako)
print(gege)

Measured memory_bytes: 74780
class TreasuerHunt
  def initialize
    @angle = deg_to_rad(90)
    @x = 0.0
    @y = 0.0
  end

  def move(dist, deg)
    @x += Math.cos(@angle) * dist
    @y += Math.sin(@angle) * dist
    rad = deg_to_rad(deg)
    @angle -= rad
  end

  def deg_to_rad deg
    deg * (Math::PI / 180)
  end

  def x
    @x
  end

  def y
    @y
  end

end

pos = TreasuerHunt.new

while line = gets do
  dist, deg = line.chomp.split(',')
  break if dist.to_i == 0 && deg.to_i == 0
  pos.move(dist.to_i, deg.to_i)
end
puts pos.x.to_i
puts pos.y.to_i

Measured memory_bytes: 9000
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+100;
int a[maxn];
int main()
{
    memset(a,0,sizeof(a));
    int n;
    scanf("%d",&n);
    int x;
    int st=0;
    while(n--){
        scanf("%d",&x);
        if(x==0){
            st++;
            a[x]++;
            a[x+1]++;
        }
        else{
            a[x-1]++;
            a[x]++;
            a[x+1]++;
        }
    }
    for(int i=0;i<100000;i++)
        st=max(st,a[i]);
    printf("%d\n",st);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

struct Data{
    int c, t;
};

void warshallFloyd(Data d[105][105], int m){
    range(k,1,m + 1){
        range(i,1,m + 1){
            range(j,1,m + 1){
                d[i][j].c = min(d[i][j].c, d[i][k].c + d[k][j].c);
                d[i][j].t = min(d[i][j].t, d[i][k].t + d[k][j].t);
            }
        }
    }
}

int main(){
    int n, m;
    Data d[105][105];

    while(cin >> n >> m, n||m){
        rep(i,105) rep(j,105) d[i][j].t = d[i][j].c = INF;
        rep(i,n){
            int a, b, e, f;
            cin >> a >> b >> e >> f;
            d[a][b].c = d[b][a].c = e;
            d[a][b].t = d[b][a].t = f;
        }

        warshallFloyd(d, m);

        int k;
        cin >> k;
        rep(i,k){
            int a, b, c;
            cin >> a >> b >> c;
            if(c) cout << d[a][b].t << endl;
            else cout << d[a][b].c << endl;
        }
    }
}

Measured memory_bytes: 1240
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
	
	int N;
	
	cin >> N;
	
	string str;
	
	cin >> str;
	
	int count1 = 0;
	int max1 = 0;
	int count2 = 0;
	int max2 = 0;
	
	for(int i = 0; i < N; i++){
		if(str[i] == ')'){
			count1++;
		}else{
			count1--;
		}
		max1 = max(max1, count1);
	}
	
	for(int i = N - 1; i >= 0; i--){
		if(str[i] == '('){
			count2++;
		}else{
			count2--;
		}
		max2 = max(max2, count2);
	}
	
	for(int i = 0; i < max1; i++){
		str = "(" + str;
	}
	
	for(int i = 0; i < max2; i++){
		str = str + ")";
	}
	
	cout << str << endl;
	
	return 0;
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
//#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

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

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N;
	cin >> N;

	int ans = 0;
	int ten = 10;
	bool cancel = false;

	while(ten<=100000) {
		if (N >= ten) ans += 9 * ten / 10;
		else {
			if (N >= (ten / 10)) cancel = true;
			break;
		}
		ten *= 100;
	}

	if(cancel) ans += N - (ten / 10) + 1;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
ll a[100000];
ll dom[100001];
 
ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}
 
int main(){
  int a,b,x;
  cin>>a>>b>>x;
  float ans;
  if(x==a*a*b/2) ans=45.0000000;
  else if(x==a*a*b) ans=0.00000000;
  else if(x>a*a*b/2){
    ans=atan((float)(2*a*a*b-2*x)/(float)(a*a*a))*(float)180/(float)M_PI;
  }else{
    ans=atan((float)(a*b*b)/(float)(2*x))*(float)180/(float)M_PI;
  }
  printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A int
  	fmt.Scan(&A)
  
	if A == 25 {
		fmt.Println("Christmas")
	} else if A == 24 {
		fmt.Println("Christmas Eve")
	} else if A == 23 {
		fmt.Println("Christmas Eve Eve")
	} else if A == 22 {
		fmt.Println("Christmas Eve Eve Eve")
	}
}

Measured memory_bytes: 512
// Problem : D - Wall
// Contest : AtCoder - AtCoder Beginner Contest 079
// URL : https://atcoder.jp/contests/abc079/tasks/abc079_d
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int c[10][10];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int t=1;
	while(t--)
	{
		int h,w,ans=0;
		cin>>h>>w;
		loop(i,10)
			loop(j,10)
				cin>>c[i][j];
		int a[h][w];
		loop(k,10)
			loop(j,10)
				loop(i,10)
				if(c[i][j]>c[i][k]+c[k][j])
					c[i][j]=c[i][k]+c[k][j];
		loop(i,h)
			loop(j,w)
			{
				int n;
				cin>>n;
				if(n!=-1)
				ans+=c[n][1];
			}
			cout<<ans<<nl;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3668
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o A.exe A.cpp 
Execute: ./A
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int x;
	cin >> x;
	
	if(x >= 30) 
		cout << "Yes" << endl; 
	else 
		cout << "No" << endl; 
	
	return 0; 
} 


Measured memory_bytes: 3620
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
D = sorted([X[i + 1] - X[i] for i in range(M - 1)])
print(X[-1] - X[0] - sum(D[-(N - 1):]) if N > 1 else X[-1] - X[0])


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

int main(){
    int N;
    cin >> N;
    int A[N],B[N];
    for(int i = 0; i <= N; i++)
        cin >> A[i];
    for(int i = 0; i < N; i++)
        cin >> B[i];
    
    ll ans = 0;
    
    for(int i = 0; i < N; i++){
        if(A[i] <= B[i]){
            ans += A[i];
            B[i] -= A[i];
            A[i] = 0;
            if(B[i] > 0){
                ans += min(B[i], A[i+1]);
                A[i+1] = max(0,A[i+1] - B[i]);
            }
        }else{
            ans += B[i];
        }
    }
    
    cout << ans << "\n";
}


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

import cmath


def outer_product(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real


def area_polygon(n, points):
    s = sum(outer_product(points[i], points[(i + 1) % n])
            for i in range(n)) / 2.0
    return s


def main():
    n = int(input())
    ps = [complex(*map(float, input().split())) for _ in range(n)]
    s = area_polygon(n, ps)
    print("{:.1f}".format(s))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7804
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int a, b;
    while (cin >> a >> b, a) {
        int cnt = 0;
        if (a < b) swap(a, b);
        while (b) {
            cnt++;
            swap(a = a % b, b);
        }
        cout << a << " " << cnt << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL M,D;
  cin>>M>>D;
  LL cnt  = 0;
  FOR(i,1,M+1){
    FOR(j,1,D+1){
      if(j<=9){
        continue;
      }
      if((j%10)*(j/10)==i&&(j%10)>=2&&(j/10)>=2){
        cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

int n;
int k;
int w[100000];

bool check(int x) {
  int c = 1;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (w[i] > x)
      return false;
    if (sum + w[i] > x) {
      ++c;
      sum = 0;
    }
    sum += w[i];
  }
  return c <= k;
}

int solve() {
  int lo = -1;
  int hi = 1010101010;
  while (hi - lo > 1) {
    int mi = (lo + hi) / 2;
    if (check(mi))
      hi = mi;
    else
      lo = mi;
  }
  return hi;
}

int main(int argc, char *argv[])
{
  scanf(" %d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf(" %d", w+i);
  printf("%d\n", solve());
  return 0;
}

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

#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
typedef vector<int> vi;
typedef vector<vi> vii;
#define ALL(a) a.begin(),a.end()

int mynot(int n){
	switch(n){
	case 0:return 2;
	case 1:return 1;
	case 2:return 0;
	default:assert(0);
	}
}
int myand(int x,int y){
	switch(x){
	case 0:
		return 0;
	case 1:
		return (y==0?0:1);
	case 2:
		return y;
	default:
		assert(0);
	}
}
int myor(int x,int y){
	switch(x){
	case 0:
		return y;
	case 1:
		return (y==2?2:1);
	case 2:
		return 2;
	default:
		assert(0);
	}
}
int n;
int go(string s,int p,int q,int r){
	int a,b,sign,v;
	switch(s[n]){
	case '0':
	case '1':
	case '2':
		v=s[n];
		n++;
		return v-'0';
	case 'P':
		n++;
		return p;
	case 'Q':
		n++;
		return q;
	case 'R':
		n++;
		return r;
	case '-':
		n++;
		return mynot(go(s,p,q,r));
	case '(':
		n++;
		a=go(s,p,q,r);
		sign=s[n];
		n++;
		b=go(s,p,q,r);
		n++;
		switch(sign){
		case '*':
			return myand(a,b);
		case '+':
			return myor(a,b);
		}
	case ')':
	default:
		assert(0);
	}
}

int main(){
	string s;
	while(cin>>s,s!="."){
		int ans=0;
		REP(p,3)REP(q,3)REP(r,3){
			n=0;
			if(go(s,p,q,r)==2){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) rep(j, N) {
        int a;
        cin >> a;
        A[i] |= a << j;
    }

    vector<int> dp(1 << N);
    dp[0] = 1;
    rep(bit, 1, 1 << N) {
        int pc = 0;
        rep(i, N) pc += bit >> i & 1;
        rep(i, N) {
            if (bit >> i & 1 && A[pc - 1] >> i & 1) dp[bit] = (dp[bit] + dp[bit ^ (1 << i)]) % MOD;
        }
    }

    write(dp[(1 << N) - 1]);
}

Measured memory_bytes: 8448
#include<stdio.h>
#include<cstdlib>

#define MAX 20000

void culc_N(int); // line[]の要素数を引数に、くぼみの個数を数える
int culc_S(int, int); // くぼみの開始、終了matrixを引数に、その面積を計算する

int N = 0; // くぼみの個数
int S[MAX/2]; // くぼみの面積
int Ssum = 0; // くぼみの総面積

typedef struct{
    int inc; // inclination
    int y; // 始点のy座標
}Line;

Line line[MAX];

int main(){
    int i = 0,j,coor_y = 0;
    char c;
    while(1){
        if(scanf(" %c",&c) == EOF){
            break;
        }
        if(c == '\\'){
           line[i].inc = -1;
           }else if(c == '_'){
               line[i].inc = 0;
           }else{
               line[i].inc = 1;
           }
        line[i].y = coor_y;
        coor_y += line[i].inc;
        //printf("inc:%d y:%d\n",line[i].inc,line[i].y);
        i++;
    }
    
    culc_N(i);
    printf("%d\n%d",Ssum,N);
    if(N == 0){
        printf("\n");
    }else{
        printf(" ");
        for (j = 0; j < N; j++) {
            printf("%d",S[j]);
            if (j == N-1) {
                printf("\n");
                break;
            }
            printf(" ");
        }
    }
    
    return 0;
}


void culc_N(int n){
    int i,j,k=0;
    
    for (i = 0; i < n; i++) {
        //printf("i:%d\n",i);
        if (line[i].inc == -1) {
            for (j = i+1; j < n; j++) {
                //printf("   j:%d\n",j);
                if(line[j].inc == 1 && line[i].y == line[j].y + 1){
                    N++;
                    S[k] = culc_S(i,j);
                    k++;
                    i = j;
                    break;
                }
            }
        }
    }
}


int culc_S(int start, int end){
    int i;
    float Sk = 0;
    
    for (i = start; i <= end; i++) {
        /*if (line[i].inc == 1) {
            Sk += line[start].y - line[i].y - 0.5;
        }else if(line[i].inc == 0){
            Sk += line[start].y - line[i].y;
        }else{
            Sk += line[start].y - line[i].y + 0.5;
        }*/
        
        Sk += line[start].y - line[i].y - line[i].inc * 0.5;
    }
    
    Ssum += Sk;
    return (int)Sk;
}













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

mul_5 = 0
ans = 0
while n > 2 * 5**mul_5:
    mul_5 += 1
if n % 2 == 0 and mul_5 > 0:
    for i in range(mul_5):
        ans += n // (2 * 5**(i+1))

print(ans)

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

vector<int> input(int N) {
	 vector<int> vec(N);
	for (int i = 0; i < N; i++){
		cin >> vec.at( i );
	}
	return vec;
	}

int main(){
	int N;
	cin >> N;
	vector<int>  a = {0, 0, 0};
	int TorF = 1;
	
	for ( int i = 0; i < N; i++){
	vector<int> b, c, diff;	
	b = input(3);
	c = {b.at(0) - a.at(0), b.at(1) - a.at(1), b.at(2) - a.at(2)};
	diff = { c.at(0), abs( c.at(1) ) + abs( c.at(2) ) };
		
	if ( diff.at(0)%2 == 0){
		if ( diff.at(1) <= diff.at(0) && diff.at(1)%2 ==0){
			TorF *= 1;
		}
		else {
			TorF *= 0;
		}
	}
	else if (diff.at(0)%2 == 1){
		if ( diff.at(1) <= diff.at(0) && diff.at(1)%2 == 1){
			TorF *= 1;
		}
		else {
			TorF *= 0;
		}
	}
	
	a = b;
	}// for文終わり
	
	if (TorF == 1){
	cout << "Yes" << endl;
	}
	else if (TorF == 0){
	cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,l[200005],r[200005],a[200005];
long long ans;
stack<pair<int,int> > stk;
int main()
{
	scanf("%d",&n);
	fz1(i,n){
		scanf("%d",&a[i]);
	}
	fz1(i,n){
		while(!stk.empty()&&stk.top().second>a[i]){
			r[stk.top().first]=i-1;
			stk.pop();
		}
		stk.push(make_pair(i,a[i]));
	}
	while(!stk.empty()){
		r[stk.top().first]=n;
		stk.pop();
	}
	fd1(i,n){
		while(!stk.empty()&&stk.top().second>a[i]){
			l[stk.top().first]=i+1;
			stk.pop();
		}
		stk.push(make_pair(i,a[i]));
	}
	while(!stk.empty()){
		l[stk.top().first]=1;
		stk.pop();
	}
	fz1(i,n){
		ans+=1ll*a[i]*(i-l[i]+1)*(r[i]-i+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;

struct Edge
{
	int from, to;
	long long cost;
};

struct BellmanFord
{
	int V, E;
	int s;
	const vector<Edge> &edges;
	vector<long long> dist;
	vector<int> previous;
	bool negative_loop;
	vector<bool> negative;

	BellmanFord(int V, int start, const vector<Edge> &edges) : V(V), s(start), edges(edges) {
		E = edges.size();
	}

	void calc() {
		dist.assign(V, INF);
		dist[s] = 0;
		previous.assign(V, -1);
		negative.assign(V, false);
		negative_loop = true;
		for (int i = 0; i < V; i++) {
			bool update = false;
			for (Edge e : edges) {
				if (dist[e.from] >= INF) continue;
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					previous[e.to] = e.from;
					update = true;
				}
			}
			if (!update) {
				negative_loop = false;
				return;
			}
		}
		for (int i = 0; i < V; i++) {
			for (Edge e : edges) {
				if (dist[e.from] >= INF) continue;
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					negative[e.to] = true;
				}
				if (negative[e.from]) negative[e.to] = true;
			}
		}
	}

	bool calc_shortest_path() {
		dist.assign(V, INF);
		dist[s] = 0;
		previous.assign(V, -1);
		negative_loop = true;
		for (int i = 0; i < V; i++) {
			bool update = false;
			for (Edge e : edges) {
				if (dist[e.from] >= INF) continue;
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					previous[e.to] = e.from;
					update = true;
				}
			}
			if (!update) {
				negative_loop = false;
				break;
			}
		}
		return negative_loop;
	}

	bool find_negative_loop() {
		dist.assign(V, 0);
		for (int i = 0; i < V; i++) {
			for (Edge e : edges) {
				if (dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from] + e.cost;
					if (i == V-1) return true;
				}
			}
		}
		return false;
	}
};

int main() {
	int n, m;
	long long p;
	cin >> n >> m >> p;
	vector<Edge> es(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		long long c;
		cin >> a >> b >> c;
		a--; b--;
		es[i] = {a, b, p-c};
	}
	BellmanFord bf(n, 0, es);
	bf.calc();
	if (bf.negative[n-1]) {
		cout << -1 << endl;
		return 0;
	}
	long long ans = max(-bf.dist[n-1], 0ll);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3300
#include <stdio.h>
//#include <string.h>

int main() {
    int w, h, i, j;

    while (1) {
        scanf("%d %d", &h, &w);

        if (w == 0 && h == 0)
            break;

        for (i = 0; i < h; ++i) {
            for (j = 0; j < w; ++j) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,c=0;
  cin>>n>>k;
  int aa[n];
  for(int i=0;i<n;i++)
  {
    cin>>aa[i];
    if(aa[i]>=k)
    c++;
  }
  cout<<c;
}

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

int main()
{
   int days,assign,i,day,t=0;
   scanf("%d %d",&days,&assign);
   for(i=0;i<assign;i++)
   {
       scanf("%d",&day);
       t+=day;
   }
   if(days>=t)
   {
       printf("%d",days-t);
   }
   else printf("-1");
    return 0;
}

Measured memory_bytes: 1732
local h,w=io.read("n","n","l")
local s={}
local dp={}
for i=1,h do
    local t=io.read()
    s[i]={}
    dp[i]={}
    for j=1,w do
        s[i][j]=t:sub(j,j)
        dp[i][j]=10000000000000000
    end
end

local dx={1,0}
local dy={0,1}

local function solve()
    if s[1][1]=="#" then
        dp[1][1]=1
    else
        dp[1][1]=0
    end

    for i=1,h do
        for j=1,w do
            for k=1,2 do
                local ni=i+dx[k]
                local nj=j+dy[k]
                if h>=ni and w>=nj then
                    local add=0
                    if s[ni][nj]=="#" and s[i][j]=="." then
                        add=1
                    end
                    if dp[ni][nj]>dp[i][j]+add then
                        dp[ni][nj]=dp[i][j]+add
                    end
                end
            end
        end
    end
    return dp[h][w]
end

print(solve())

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

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

int main() {
  ll n , m ;
  cin  >> n >> m ;
  cout << lcm(n,m) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>

using namespace std;

int main()
{
    string a;
    int n;
    for(;;){
        int s=0;
        cin >> a;
        if(a[0]=='-'&&(int)a.size()==1)return 0;
        else{
            cin >> n;
            int p[n];
            for(int i=0;i<n;i++){
                cin >> p[i];
                s+=p[i];
            }
            queue<char> q;
            for(int i=0;i<(int)a.size();i++){
                q.push(a[i]);
            }
            for(int i=0;i<s;i++){
                q.push(q.front());
                q.pop();
            }
            for(int i=0;i<(int)a.size();i++){
                cout << q.front();
                q.push(q.front());
                q.pop();
            }
            cout << endl;
        }
    }
}



Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int n;
int main()
{
	long long ans=0;
	long long a,b;
	read(n);
	long long mx=122321313213ll;
	bool df=1;
	while(n--)
	{
		read(a);
		read(b);
		df&=(a==b);
		if(a>b)
			mx=min(mx,b);
		ans+=b;
	}
	if(df)
	{
		printf("0\n");
		return 0;
	}
	printf("%lld\n",ans-mx);
	return 0;
}

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

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

using namespace std;

int main(){
	
	int n;
	long long int input, po, count, ans;
	
	cin >> n;
	
	vector<long long int> s(n+1);
	s[0] = 0;
	
	REP(i,n){
		cin >> input;
		s[i+1] = input + s[i];
	}
	
	/*
	REP(i,n+1) cout << s[i] << " ";
	cout << endl;
	*/
	
	sort(s.begin(), s.end() );
	
	/*
	REP(i,n+1) cout << s[i] << " ";
	cout << endl;
	*/
	
	count = 1;
	ans = 0;
	po = s[0];
	
	REP(i,n){
		if (po == s[i+1]){
			ans += count;
			count++;
		}else{
			count = 1;
			po = s[i+1];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

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

const ll mod = 1e9 +7;

int main() {

    
    while (true)
    {
        ll n, x;
        cin >> n >> x;
        
        if (n == 0 && x == 0)
        {
            break;
        }
        ll ret = 0;
        for (int i = 1; i < n; ++i)
        {
            for (int j = i + 1; j < n; ++j)
            {
                ll k = x - i - j;
                if (k > n)
                {
                    continue;
                }
                if (k <= j)
                {
                    break;
                }
                ret++;
            }
        }
        cout << ret << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main() {
    int k;
    cin>>k;
    string n;
    cin>>n;
    if(k>=n.length())
    cout<<n<<endl;
    else 
    {
        for(int i=0;i<k;i++)
        cout<<n[i];
        cout<<"..."<<endl;
    }
    
}

Measured memory_bytes: 3624
#import 
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

sum = 0
for i in range(1,n):
    if a[i - 1] > a[i]:
        sum += a[i - 1] - a[i]
        a[i] = a[i - 1]
print(sum)

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

int main() {
    ll n, k;
    ll p[1000];
    cin >> n >> k;
    rep(i, n) cin >> p[i];
    sort(p, p + n);
    ll count = 0;
    rep(i, k) count += p[i];
    cout << count << endl;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
  int n; cin>>n;
  int us=0, sm=0;
  for(us=1;;us++) {
    sm+=us;
    if (sm >= n) break;
  }
  for(int i=1;i<=us;i++) {
    if (sm - i == n) continue;
    cout<<i<<endl;
  }
}


Measured memory_bytes: 256
_, _, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

xmax = max(x)
ymin = min(y)
if xmax >= ymin:
    print("War")
else:
    for z in range(xmax+1, ymin+1):
        if X < z <= Y:
            print("No War")
            break
    else:
        print("War")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n, m, i, j, k, a[55], c[55];
int main(){
	scanf("%lld%lld", &n, &k);
	a[0] = c[0] = 1;
	for(i=1; i<=n; i++){
		a[i] = a[i-1] * 2 + 1;
		c[i] = c[i-1] * 2 + 3;
	}
	while(k > 0){
		if(k >= c[n]){
			m += a[n], k = 0;
		}
		else if(k > c[n-1]){
			k -= c[n-1] + 1;
			m += a[n-1];
			if(k) m++, k--;
		}
		else k--;
		n--;
	}
	printf("%lld\n", m);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		var a = read().GroupBy(x => x).Select(g => new[] { g.Count(), g.Key }).Concat(new int[h[1]].Select(_ => read()))
			.GroupBy(x => x[1]).OrderByDescending(g => g.Key).Select(g => new { c = g.Key, b = g.Sum(x => x[0]) });

		var M = 0L;
		foreach (var _ in a)
		{
			var b = Math.Min(_.b, h[0]);
			M += _.c * b;
			if ((h[0] -= b) == 0) break;
		}
		Console.WriteLine(M);
	}
}


Measured memory_bytes: 63348
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define mod 1000000007
using namespace std;

void Onigiri()
{
  int a[5];
  int ans;
  rep(i,0,5)
  {
   cin>>a[i];if(a[i]==0)
   ans=i;
   }
   cout<<ans+1;

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("in", "r", stdin);freopen("out", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

Measured memory_bytes: 3792
n,m,X,Y = map(int,input().split())
ans = "War"
if X < Y:
    x = list(map(int,input().split()))
    y = list(map(int,input().split()))
    if max(x) < min(y) and X < min(y) <= Y :
        ans = "No War"
print(ans)

Measured memory_bytes: 3060
#include <iostream>
        #include <string>
        #include <math.h>
#include<stdio.h>
        #include<algorithm>
        using namespace std;
         
        int main(){
          long double n,m,d;
          cin >> n >> m >> d;
          if(d!=0){
           printf("%.10Lf\n",2*(m-1)/(n*n)*(n-d));
          }
          else{
           printf("%.10Lf\n",(m-1)/n);
          }
          return 0;}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int m, k;
	cin >> m >> k;
	if(!k){
		rep(i, (1 << m)) cout << i << " " << i << " ";
		cout << endl;
		return 0;
	}
	deque<int> ans;
	int f = 0;
	map<int, int> vis;
	pi gd;
	rep(i, (1 << m)){
		int j = k ^ i;
		if(j >= 0 && j < (1 << m) && i != k && j != k && i != j){
			ans.pb(i);
			ans.pb(j);
			vis[i] = 1;
			vis[j] = 1;
			vis[k] = 1;
			ans.push_front(k);
			ans.pb(k);
			f = 1;
			gd = mp(i, j);
			break;
		}
	}
	//for(int x : ans) cout << x << " ";
	//cout << endl;
	if(!f){
		cout << -1 << endl;
		return 0;
	}
	else{
		rep(i, (1 << m)){
			if(!vis[i]){
				ans.push_front(i);
				ans.pb(i);
			}
		}
		ans.pb(gd.se);
		ans.push_front(gd.fi);
		//verify(ans, k, m);
		for(int x : ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 9088
#include <iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	int N = 999999;
	int M = 999999;
	for(int i = 0 ; i < 3 ; i++){
		int in; cin >> in;
		N = min(in,N);
	}
	for(int i = 0 ; i < 2 ; i++){
		int in; cin >> in;
		M = min(in,M);
	}
	cout << N + M - 50 << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
typedef long long ll;
 
string s, t;
int dp[3300][3300];
int main(){
    cin >> s >> t;
    int n = s.size(), m = t.size();
 
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= m;j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]){
                dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j]);
            }
        }
    }
 
    string rewsna = "";
 
    while(n > 0 && m > 0){
        if(dp[n][m] == dp[n-1][m])n--;
        else if(dp[n][m] == dp[n][m-1])m--;
        else {
            rewsna += s[n-1];
            n--;
            m--;
        }
    }
    int l = rewsna.size();
    for(int i = 0;i < l;i++){
        cout << rewsna[l-i-1];
    }cout << endl;
    
    return 0;
}

Measured memory_bytes: 42228
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

int main()
{
	int X;
	cin>>X;
	while(true){
		bool safe = true;
		REP(p, 2, X)if(X%p==0){
			safe=false;
		}
		if(safe) break; 
		X++;
	}
	cout<<X<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;
const double eps = 1e-9;
int ab[20005],bc[20005],ac[20005];
string a, b, c;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> c;
    for (int i = 0 ; i < a.size() ; i++) {
        for (int j = 0 ; j < b.size() ; j++) {
            if (a[i] != b[j] && a[i] != '?' && b[j] != '?') {
                ab[j - i + 10000] = 1;
            }
        }
    }
    for (int i = 0 ; i < a.size() ; i++) {
        for (int j = 0 ; j < c.size() ; j++) {
            if (a[i] != c[j] && a[i] != '?' && c[j] != '?') {
                ac[j - i + 10000] = 1;
            }
        }
    }
    for (int i = 0 ; i < b.size() ; i++) {
        for (int j = 0 ; j < c.size() ; j++) {
            if (b[i] != c[j] && b[i] != '?' && c[j] != '?') {
                bc[j - i + 10000] = 1;
            }
        }
    }
    int ans = 1e9;
    for (int i = -4000 ; i <= 4000 ; i++) {
        for (int j = -4000 ; j <= 4000 ; j++) {
            if (ab[-i + 10000] || ac[-j+10000] || bc[i-j+10000])continue;
            int mx = max({(int)a.size(),i+(int)b.size(),j+(int)c.size()});
            int mi = min({0,i,j});
            ans = min(ans,mx - mi);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int N;
  cin >> N;
  int P[N];
  rep(i,N) cin >> P[i];

  int ans = N;
  int mn = INF;
  rep(i,N) {
    if (mn < P[i]) ans--;
    mn = min(mn, P[i]);
  }

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


Measured memory_bytes: 1024