akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
  int n;

  cin >> n;
  for(int i = 0; i < n; i++){
    int y,m ,d;
    cin >> y >> m >> d;

    int ans=0;
    while( y != 1000 ){

      while(m != 11){
	int x;
	if(m % 2 == 0) x = 19;
	else x = 20;
	if(y % 3 == 0) x = 20;
	while(d != x+1){
	  d++;
	  ans++;
	}
	d = 1;
	m++;
      }
      m = 1;
      y++;
    }
    cout << ans <<endl;
 
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int const MAX = 1e5 + 100;

int main() {
    bool isPrime[MAX];
    fill(isPrime, isPrime + MAX, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 2; i * i < MAX; i++) {
        if (isPrime[i]) {
            for (int j = 2; i * j < MAX; j++) {
                isPrime[i * j] = false;
            }
        }
    }
    int vec[MAX];
    fill(vec, vec + MAX, 0);
    vec[3] = 1;
    int cnt = 1;
    for (int i = 4; i < MAX; i++) {
        vec[i] = cnt;
        if (isPrime[i]) {
            if (isPrime[(i + 1) / 2]) {
                cnt++;
                vec[i] = cnt;
            }
        }
    }
    int q;
    cin >> q;
    int l[q], r[q];
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
    }
    for (int i = 0; i < q; i++) {
        OUT(vec[r[i]] - vec[l[i] - 1]);
    }
}

Measured memory_bytes: 2048
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 405
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],pre[N],dp[N][N];
string s,s1;
//Variables End
ll sum(ll a,ll b)
{
	return pre[b]-pre[a-1];
}

ll compute(ll l,ll r)
{
	if(l==r)return 0;
	if(dp[l][r]!=-1)return dp[l][r];
	ll ret=inf;

	rep(i,l,r)
	{
		ret=min(ret,compute(l,i)+compute(i+1,r)+sum(l,r));
	}

	return dp[l][r]=ret;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		cin>>n;
		rep(i,1,n+1)cin>>ar[i];
		rep(i,1,n+1)pre[i]=pre[i-1]+ar[i];
		rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=-1;

		cout<<compute(1,n);        
    }
    return 0;
        
}

Measured memory_bytes: 1536
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  n <- getLine
  if maximum (map length $ group n) >= 3
    then putStrLn "Yes"
    else putStrLn "No"


Measured memory_bytes: 380
N = int(input())
data = []
for _ in range(N):
	A = int(input())
	items = []
	for __ in range(A):
		x, y = map(int, input().split())
		items.append((x - 1, y))
	data.append(items)
 
best = 0
 
def check(i):
    for j in range(N):
        if ((i >> j) & 1) == 1:           
            for x, y in data[j]:
                if y !=((i >> x) & 1):return False						
    return True
 
for i in reversed(range(0, 2**N)):
    count=0
    for j in range(N):count += ((i >> j) & 1)
    if count>best:
        if check(i):best = count
	
print(best)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > P;
int main()
{
  ll x,y;
  cin>>x>>y;

  ll cnt=0;
  while(x<=y)
  {
    x*=2;
    cnt++;
  }

  cout<<cnt<<endl;
}

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

int main(){
    long long int N, A, B;
    cin >> N >> A >> B;

    long long int k=0, c=0;
    if((A+B)!=0){
        k= N/(A+B);
        c= N%(A+B);
        // cout << k << ":" << c << endl;
        if(c<=A){
            cout << k*A+c << endl;
        }
        else{
            cout << k*A+A << endl;
        }
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    buf = input()
    buflist = buf.split()
    A = list(map(int, buflist))
    BC = []
    for i in range(M):
        buf = input()
        buflist = buf.split()
        BC.append((int(buflist[0]), int(buflist[1])))
    A = list(sorted(A))
    BC = list(sorted(BC, reverse=True, key=lambda x:x[1]))
    pointer = 0
    for bc in BC:
        remaining = bc[0]
        substitute_to = bc[1]
        if pointer >= N:
            break
        if A[pointer] >= substitute_to:
            break
        while remaining > 0 and pointer < N:
            if A[pointer] >= substitute_to:
                break
            A[pointer] = substitute_to
            pointer += 1
            remaining -= 1
    print(sum(A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 23280
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s;
  int i1, i2;
  cin >> s;
  size_t l = s.size();
  for (int i=l-2;0<i;i-=2) {
    size_t l_half = i/2;
    if (s.substr(l_half, l_half)==s.substr(0, l_half)) {
      cout << l_half*2 << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement

def main():
    n,m,q = (int(x) for x in input().split())
    A = list(combinations_with_replacement(range(1,m+1),n))
    query = [[int(x) for x in input().split()] for _ in range(q)]
    pmax = 0

    for i in A:
        Ai = list(i)
        if Ai != sorted(Ai): continue
        p = 0
        for j in query:
            if Ai[j[1]-1] - Ai[j[0]-1] == j[2]:
                p += j[3]
        pmax = max(p,pmax)

    print(pmax)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <ios>
#include <iomanip>
using namespace std;
#define int long long
const int mo = 1e9 + 7;
const int ma = 2010;
int c[ma][ma];
main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    for (int i = 0; i < ma; i++)
        c[i][0] = 1;
    for (int i = 1; i < ma; i++)
        for (int j = 1; j < ma; j++)
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j])%mo;
        
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; i++)
        printf("%d\n", c[n - k + 1][i] * c[k - 1][i - 1] % mo);
    return 0;
}

Measured memory_bytes: 31872
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 1e4+1;
string arr[N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,ans=0,sb=0,ea=0,both=0,sz;
    cin>>n;
    FOR(i, 0, n) {
    	cin>>arr[i]; sz = arr[i].size();
    	FOR(j, 0, sz-1) {
    		if(arr[i][j]=='A' && arr[i][j+1]=='B') ans++;
    	}
    	if(arr[i][sz-1] == 'A' && arr[i][0]=='B') both++;
    	else if(arr[i][sz-1] == 'A') ea++;
    	else if(arr[i][0] == 'B') sb++;
	}
	if(!both) {
		ans += min(ea, sb);
	}
	else if(ea + sb > 0) {
		ans += both + min(ea, sb);
	} else {
		ans += both - 1;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	REP(i, M) cin >> B[i];
	int ans = 0;
	REP(i, N) {
		int tmp = C;
		REP(j, M) {
			int a;
			cin >> a;
			tmp += B[j] * a;
		}
		if(tmp > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

class UnionFind {
public:
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ
    
    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
};
 
int main() {
    ll n, m;
    cin >> n >> m;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    UnionFind Uni(n);
    Uni.init(n);
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        Uni.unite(x, y);
    }

    vvl G(n);
    ll u = 0;  // 連結成分の個数
    rep(v, n) {
        if(v == Uni.root(v)) {
            u++;
        }
        G[Uni.root(v)].pb(a[v]);
    }

    if(u == 1) {
        out(0);
        re0;
    }

    if(n < 2*(u-1)) {
        out("Impossible");
        re0;
    }

    ll ans = 0;
    vl w;
    rep(v, n) {
        if(v == Uni.root(v)) {
            sort(all(G[v]));
            ans += G[v][0];
            rep(i, G[v].size()) {
                if(i > 0) {
                    w.pb(G[v][i]);
                }
            }
        }
    }
    
    sort(all(w));
    rep(i, u-2) {
        ans += w[i];
    }
    
    out(ans);
    re0;
}

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

    if 0 in A:
        print(0)
        return

    ans = 1
    for a in A:
        ans *= a
        if ans > 1000000000000000000:
            print(-1)
            return

    print(ans)


main()


Measured memory_bytes: 21784
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100100,oo=1000000000;
int i,j,k,n,m,ch,ff,x,y,v,En,fg;
ll ans;
int h[N],sz[N];
struct edge { int s,n,v;} E[N<<1];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void E_add(int x,int y,int v) {
	E[++En].s=y;E[En].v=v;
	E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].v=v;
	E[En].n=h[y];h[y]=En;
}
void dfs(int x,int F) {
	sz[x]=1;
	int ma=0;
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		dfs(E[k].s,x);
		sz[x]+=sz[E[k].s];
		ans+=2ll*min(sz[E[k].s],n-sz[E[k].s])*E[k].v;
		ma=max(ma,sz[E[k].s]);
	}
	ma=max(ma,n-sz[x]);
	if (ma<=n/2 && !fg) {
		fg=1;
		int mi=oo;
		for (int k=h[x];k;k=E[k].n) mi=min(mi,E[k].v);
		if (ma*2==n) {
			for (int k=h[x];k;k=E[k].n) {
				if (E[k].s!=F && sz[E[k].s]==ma) mi=E[k].v;
				if (E[k].s==F && n-sz[x]==ma) mi=E[k].v;
			}
		}
		ans-=mi;
	}
}
int main() {
	R(n);
	for (i=1;i<n;i++) {
		R(x);R(y);R(v);
		E_add(x,y,v);
	}
	dfs(1,0);
	W(ans);puts("");
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;

int main() {
	int n;
	cin >> n;
	vector<int> b(n);
	rep(i,n) cin >> b[i];
	vector<int> ans;
	int bn = b.size();
	rep(j,bn){
		for(int i=b.size()-1;i>=0;i--){
			if(b[i]==i+1){
				ans.push_back(b[i]);
				b.erase(b.begin()+i);
				break;
			}
		}
	}
	if(b.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int i=ans.size()-1;i>=0;i--){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include "cmath"
using namespace std;

int main(int argc, const char * argv[]) {
    string a;
    cin>>a;
    if (a[0]==a[1] && a[1]==a[2]) {
        cout<<"Yes"<<endl;
    }else if (a[1]==a[2] && a[2]==a[3]) {
        cout<<"Yes"<<endl;
    }else   cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
code = []
for i in range(n):
    tmp = list(map(int, input().split()))
    code.append(tmp)
re = 0
for i in range(n):
    ans = 0
    for j in range(m):
        ans += code[i][j] * b[j]
    if ans + c > 0:
        re += 1
print(re)


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val a = arrayListOf<ArrayList<ArrayList<Int>>>()
    for (i in 0 until 4) {
        a.add(ArrayList())
        for (j in 0 until 3) {
            a[i].add(ArrayList())
            for (k in 0 until 10) {
                a[i][j].add(0)
            }
        }
    }

    for (i in 0 until n) {
        val (b, f, r, v) = readLine()!!.split(" ").map { it.toInt() - 1 }
        a[b][f][r] += v + 1
    }

    for (i in 0 until 4) {
        if (i != 0) println("#".repeat(20))
        for (j in 0 until 3) {
            println(" " + a[i][j].joinToString(" "))
        }
    }
}



Measured memory_bytes: 32520
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);

	if(a>b)
		{
			d=a;
			a=b;
			b=d;
		}
	if(b>c)
		{
			d=b;
			b=c;
			c=d;
		}
	if(a>b)
		{
			d=a;
			a=b;
			b=d;
		}
	printf("%d %d %d\n",a,b,c);

return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
char a[204000];
char b[200];
int c[2000];
int i,n=0,m,j,k,l=0,x,y,z,sum=0;
int main()
{

    scanf("%d %d %d",&x,&y,&z);
    k=z%y;
    m=0;
    while(sum<100*x)
    {
        if(sum%y==k)
        {
            m=1;
            break;
        }
        sum+=x;
    }
    if(m==1)
    {
        printf("YES");

    }else
    {
        printf("NO");
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a,b,x,c;
    cin >> a >> b >> x;
    cout << fixed << setprecision(7);
    c= x*2.0000000/(a*b);
    if(c <= a){
        cout << atan(b/c)*180.000000/3.14159265 << endl;
    }
    else{
        c = (x * 2.0000000/(a*a))-b;
        double d;
        d=a*b/(b-c);
        cout << atan(b/d)*180.000000/3.14159265 << endl;
    }
}

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

int solve(int a,int  b,int c,int d){
    vector<int> n(4);
    n[0] = a;
    n[1] = b;
    n[2] = c;
    n[3] = d;

    sort(n.begin(), n.end());

    return (n[2] - n[1]);

}

int main(){
    int w,a,b;
    int ans;

     cin >> w >> a >> b;

    if((a + w >= b && b >= a) || (b + w >= a && a >= b)){
        ans = 0;
    }
    else{
        ans = solve(a, a + w, b, b + w);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(void) {
  unsigned long x;
  unsigned long y;

  cin >> x;
  cin >> y;

  unsigned long ans = x;
  unsigned long guard = pow(10, 18);

  if (x % y == 0) {
    cout << "-1" << endl;
    return 0;
  }


  while(ans <= guard) {
    if (ans % y != 0) {
      cout << ans << endl;
      return 0;
    }
    ans += x;
  }

  cout << "-1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

int main()
{
    int n; cin >> n;
    int a = 1; int cnt=0;
    while(a<=n){
        a *= 2;
        cnt++;
    }
    cout << 1*pow(2,cnt-1) << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

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

// Union-Find
vector<int> par(100010); //親の番号

// 初期化
void init(int n){
  for(int i=0; i<n; i++) par[i] = i;
}

// 頂点xに対応する木の根を見つける
int root(int x){
  if (par[x] == x) return x;
  else return par[x] = root(par[x]);
}

// 頂点xの木と頂点yの木を統合
void unite(int x, int y){
  x = root(x); y = root(y);
  if (x != y) par[x] = y;
}

bool same(int x, int y){
  return (root(x) == root(y));
}

struct edge {int u, v, cost;};

bool comp(edge e1, edge e2){
    return e1.cost < e2.cost;
}

int kruskal(vector<edge> G, int V){
    sort(G.begin(), G.end(), comp);

    init(V);

    int res = 0;
    rep(i,G.size()){
        edge e = G[i]; 
        if(!same(e.u, e.v)){
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main(){
    int V, E; cin >> V >> E;

    vector<edge> G;
    rep(i, E){
        int s, t, w; cin >> s >> t >> w;
        edge e = {s,t,w};
        G.push_back(e);
    }

    int ans = kruskal(G, V);
    
    cout << ans << endl;
}


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/

int n, m;
string s, t;
string an = "";
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    cin>>s>>t;
    n = s.length();
    m = t.length();
    int dp[n+1][m+1];
    memset(dp, 0, sizeof(dp));
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    int i = n, j = m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            an += s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>=dp[i][j-1])
            i--;
        else
            j--;
    }
    reverse(an.begin(), an.end());
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int a,b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
  }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

// RangeMinimumQuery
template <typename T>
struct SegTree {
	T init_val;
	int n;
	vector<T> dat;
	
	SegTree(int _n, T init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, T x) {
		i += n - 1;
		dat[i] = min(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	void set(int i, T x) {
		dat[i + n - 1] = x;
		update(i, x);
	}
	
	// ??¢?´¢??????[a,b), ?????¨????????????k?????????[l,r)
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return min( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
	
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

int main() {
	int n, q; cin >> n >> q;
	
	SegTree<ll> sg(n, (1ll<<31) - 1);
	
	while (q--) {
		int com, x, y;
		scanf("%d %d %d", &com, &x, &y);
		if (com == 0) sg.set(x, y);
		else printf("%lld\n", sg.query(x, y + 1));
	}
	return 0;
}

Measured memory_bytes: 4856
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var y1 = int.Parse(line[0]);
        var m1 = int.Parse(line[1]);
        var d1 = int.Parse(line[2]);
        line = Console.ReadLine().Trim().Split(' ');
        var y2 = int.Parse(line[0]);
        var m2 = int.Parse(line[1]);
        var d2 = int.Parse(line[2]);
        var a1 = new List<int>();
        var b1 = new List<int>();
        if ((m1 == 2 && d1 == 29) | (m2 == 2 && d2 == 29))
        {
            a1 = getAge(y1, m1, d1, 2996);
            b1 = getAge(y2, m2, d2, 2996);
        }
        else
        {
            a1 = getAge(y1, m1, d1, 3000);
            b1 = getAge(y2, m2, d2, 3000);
        }
        var ans = -1;
        for (int i = 0; i < a1.Count(); i++)
            ans = Max(ans, Abs(a1[i] - b1[i]));
        Console.WriteLine(ans);
    }
    public static List<int> getAge(int y, int m, int d, int yyyy)
    {
        var ans = new List<int>();
        var bd = new DateTime(y, m, d);
        var mo = new int[] { 1, 3, 5, 7, 8, 10, 12 };
        foreach (var x in mo)
        {
            for (int i = 1; i <= 31; i++)
            {
                var now = new DateTime(yyyy, x, i);
                var age = now.Year - bd.Year;
                if (bd > now.AddYears(-age)) age--;
                ans.Add(age);
            }
        }
        var mo2 = new int[] { 4, 6, 9, 11 };
        foreach (var x in mo2)
        {
            for (int i = 1; i <= 30; i++)
            {
                var now = new DateTime(yyyy, x, i);
                var age = now.Year - bd.Year;
                if (bd > now.AddYears(-age)) age--;
                ans.Add(age);
            }
        }
        var feb = yyyy == 3000 ? 28 : 29;
        for (int i = 1; i <= feb; i++)
        {
            var now = new DateTime(yyyy, 2, i);
            var age = now.Year - bd.Year;
            if (bd > now.AddYears(-age)) age--;
            ans.Add(age);
        }
        return ans;
    }
}






Measured memory_bytes: 18336
primeornot=[True]*(10**5*2)
for i in range(2,10**5):
    if primeornot[i]==True:
        j=2*i
        while j<10**5*2:
            primeornot[j]=False
            j+=i
x=int(input())
for i in range(x,10**5*2):
    if primeornot[i]==True:
        print(i)
        break

Measured memory_bytes: 10200
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	
	int n;
	cin >> n;
	map<int, int>t;
	for (int i = 0; i < n; i++) {
		int x;
		
		cin >> x;x--;
		t[x] = i+1;
	}

	for (int i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << t[i];
	}


	return 0;
	
}

Measured memory_bytes: 5504
import sys
import heapq

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    Am = [0] * N
    for i in range(N):
        Am[i] = -A[i]

    heapq.heapify(Am)

    for _ in range(M):
        a = heapq.heappop(Am)
        a = -a
        a = a // 2
        a = -a
        heapq.heappush(Am, a)

    print(-sum(Am))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14180
#include<iostream>
#include<vector>
#include<string>

int main(){
	std::string s;
	int x, y;
	std::vector<int> distXList;
	std::vector<int> distYList;

	std::vector<std::vector<bool>> dpTableX;
	std::vector<std::vector<bool>> dpTableY;

	bool isX= true;
	int distCount= 0;

	int distXsum=0;
	int distYsum=0;

	std::cin>> s;
	std::cin>> x>> y;

	for(int i=0; i<s.size(); i++){
		if(s[i]=='F')
			distCount++;
		
		if(s[i]=='T' || i==s.size()-1){
			if(isX){
				distXList.push_back(distCount);
				distXsum+= distCount;
			}
			else{
				distYList.push_back(distCount);
				distYsum+= distCount;
			}

			distCount=0;
			isX= !isX;
		}
	}

	dpTableX.resize(distXList.size());
	for(int i=0; i< distXList.size(); i++)
		dpTableX[i].resize(distXsum*2+ 1, false);
	
	dpTableY.resize(distYList.size());
	for(int i=0; i< distYList.size(); i++)
		dpTableY[i].resize(distYsum*2+ 1, false);

	if(!distXList.empty())
		dpTableX[0][distXsum+distXList[0]]=true;
	
	if(!distYList.empty()){
		dpTableY[0][distYsum+distYList[0]]=true;
		dpTableY[0][distYsum-distYList[0]]=true;
	}

	for(int i=1; i< distXList.size(); i++){
		for(int j=0; j<distXsum*2 +1; j++){
			if(dpTableX[i-1][j]==true){
				dpTableX[i][j+distXList[i]]=true;
				dpTableX[i][j-distXList[i]]=true;
			}
		}
	}

	for(int i=1; i< distYList.size(); i++){
		for(int j=0; j<distYsum*2 +1; j++){
			if(dpTableY[i-1][j]==true){
				dpTableY[i][j+distYList[i]]=true;
				dpTableY[i][j-distYList[i]]=true;
			}
		}	
	}

	if(dpTableY.empty()){
	if(dpTableX[distXList.size()-1][distXsum+x] && y==0)
		std::cout<<"Yes"<<std::endl;
	else
		std::cout<<"No"<<std::endl;

	return 0;

	}

	if(x>distXsum || x<-distXsum || y>distYsum || y<-distYsum){
		std::cout<<"No"<<std::endl;
		return 0;
	}


	if(dpTableX[distXList.size()-1][distXsum+x] && dpTableY[distYList.size()-1][distYsum+y])
		std::cout<<"Yes"<<std::endl;
	else
		std::cout<<"No"<<std::endl;

	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N;
char S[30303];
ll sa[30303][11];
ll i, j,ans;
int main(){
    scanf("%lld%s",&N,S);
    fornum(i,0,10){
        sa[N][i] = -1;
    }
    for (i = N - 1; i >= 0;i--){
        fornum(j,0,10){
            sa[i][j] = sa[i + 1][j];
        }
        sa[i][S[i] - '0'] = i+1;
    }
    fornum(i,0,1000){
        ll a = 0, b = i;
        fornum(j,0,3){
            if(sa[a][b%10]==-1)
                break;
            a = sa[a][b % 10];
            b /= 10;
        }
        if(j==3)
            ans++;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 2816
N=int(input())
tiai=[list(map(int,input().split())) for i in range(N)]

n1n2=[1,1]

for i in range(N):
  nn=max(n1n2[0]//tiai[i][0]+(0 if not n1n2[0]%tiai[i][0] else 1),n1n2[1]//tiai[i][1]+(0 if not n1n2[1]%tiai[i][1] else 1))
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]
print(sum(n1n2))

Measured memory_bytes: 3188
n,m = gets.chomp.split(" ").map(&:to_i)
require 'prime'
pr = [1]
if n == 1
  puts m
  exit
end
Prime.each(10**7) do |prime|
  pr.push(prime)
end
pr2 = Array.new(pr.length, 0)
for i in 1..pr.length - 1
  while m % pr[i] == 0
    m /= pr[i]
    pr2[i] += 1
  end
  if m == 1
    break
  end
end
if m != 1
  pr2.push(1)
end
ans = 1
for i in 1..pr2.length - 1
  if pr2[i] >= n
    ans *= (pr[i]**(pr2[i]/n))
  end
end
puts ans


Measured memory_bytes: 23856
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

const int Knapsack_Sup=114514;
int v[Knapsack_Sup],w[Knapsack_Sup];
int knap_dp[Knapsack_Sup]={};
int Knapsack(int U,int S){
    for(int i=0;i<U;i++){
        for(int j=S;j>=0;j--){
            if(j<v[i])continue;
            knap_dp[j]=max(knap_dp[j],knap_dp[j-v[i]]+w[i]);
        }
    }
    return knap_dp[U];
}


signed main(){
    int N,W;
    cin >> N >> W;
    REP(i,N){
        cin >> v[i] >> w[i];
    }
    Knapsack(N,W);
    cout << knap_dp[W] << endl;
    
    //REP(i,N*W){cout << knap_dp[i] << " ";}
    return 0;
}   


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, w;
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << "0\n";
	} else {
		ll ans = min(h, w), bl[3], bmax, bmin;
		rep (hh, h + 1) {
			bl[0] = hh * w;
			bl[1] = (h - hh) * (w / 2);
			bl[2] = (h - hh) * ((w - 1) / 2 + 1);
			bmax = max(max(bl[0], bl[1]), bl[2]);
			bmin = min(min(bl[0], bl[1]), bl[2]);
			chmin(ans, bmax - bmin);
		}
		rep (ww, w + 1) {
			bl[0] = h * ww;
			bl[1] = (w - ww) * (h / 2);
			bl[2] = (w - ww) * ((h - 1) / 2 + 1);
			bmax = max(max(bl[0], bl[1]), bl[2]);
			bmin = min(min(bl[0], bl[1]), bl[2]);
			chmin(ans, bmax - bmin);
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f
using namespace std;
const int N=2e3+10;
char s[N][N];
int tu[N][N];
int n,m;
struct node{
    int w,v;
    node(int a=0,int b=0){w=a;v=b;}
};
stack<node>S;
int h[N],l[N],r[N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]+1);
    }
    for(int i=1;i<n;i++)
    for(int j=1;j<m;j++){
        int a=s[i][j]=='.'?0:1,b=s[i+1][j]=='.'?0:1,c=s[i+1][j+1]=='.'?0:1,d=s[i][j+1]=='.'?0:1;
        tu[i][j]=!(a^b^c^d);
        if(tu[i][j])tu[i][j]+=tu[i-1][j];
    }
    int ans=max(n,m);
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(S.empty()){
                l[j]=1;S.push(node(j,tu[i][1]));
            }else{
                int mi=j;
                while(!S.empty()&&S.top().v>=tu[i][j]){
                    int id=S.top().w;r[id]=j;S.pop();
                }
                if(S.empty())mi=1;else mi=S.top().w+1;
                S.push(node(j,tu[i][j]));l[j]=mi;
            }
        }
        while(!S.empty()){int id=S.top().w;r[id]=m;S.pop();}
        for(int j=1;j<m;j++)ans=max(ans,(tu[i][j]+1)*(r[j]-l[j]+1));
    }
    cout<<ans<<endl;
}


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

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

    cout << s.substr(0, 5) << ' ' << s.substr(6, 7) << ' ' << s.substr(14)
         << endl;
    return 0;
}


Measured memory_bytes: 3580
def main():
    l = input().split(' ')

    s = []

    for el in l:
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define endl "\n"
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);  
    
     
      
  ll n;cin>>n;
  ll s[n];f(i,0,n)cin>>s[i];
  ll ans=0;
  f(i,1,n)
  {
    if(s[i-1]>s[i]){ans+=s[i-1]-s[i];
    s[i]=s[i-1];}
  }
  cout<<ans<<endl;
} 


Measured memory_bytes: 5192
#include <stdio.h>

int f(int X){
	if(X == 0){
		return 0;
	}
	else{
		return X % 10 + f(X / 10);
	}
}

int main(){
	int N;
	scanf("%d", &N);
	if(N % f(N) == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
    if(!(a % b))
        return b;
    return gcd(b, a % b);
}
int main(void) {
    int a,b;
    cin >> a >> b;
    cout << gcd(a,b) << endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
using namespace std;
int main(){
	vector<int> v(5);
	for(int i=0; i<5; i++){
		cin >> v[i];
	}
	int k;
	cin >> k;
	bool flag=false;
	for(int i=0; i<5; i++){
		for(int j=1; j<5; j++){
			if(abs(v[i]-v[j])>k){
				flag=true;
				break;
			}
		}
		if(flag){
			cout << ":(" <<endl;
			break;
		}
	}
	if(!flag)cout <<"Yay!"<<endl;
	return 0;
}


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


int main() {
  int n,m;
  cin >> n>>m;
  vector<int>a(n);
  int to=0;
  rep(i,n){
    cin>>a.at(i);
    to+=a.at(i);
  }
  int ans=0;
  rep(i,n){
    if(a.at(i)*4*m>=to){
      ans++;
    }
  }
  if(ans>=m){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m,a;
  while(cin>>n>>m>>a,n||m||a) {
    int yoko[n+1][1001];
    memset(yoko,0,sizeof(yoko));
    REP(i,m) {
      int h,p,q;
      cin>>h>>p>>q;
      yoko[p][h] = q;
      yoko[q][h] = p;
    }
    for (int i=1000; i>0; --i) {
      if (yoko[a][i]) {
        //  cout << a << " ";
        a = yoko[a][i];
        //  cout << a << endl;
      }
    }
    cout << a << endl;
  }
}

Measured memory_bytes: 1260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    bool c, f;
    c = f = false;
    for (int i=0; i<N; i++){
        if (S[i] == 'C')c = true;
        if (S[i] == 'F' and c)f = true;
    }
    if (c and f)cout <<"Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n,k,sum=0,tmp;
	cin >> n >> k;
	for(int i=0;i<k;++i){
		cin >> tmp;
		sum += tmp;
	}
	if(sum >= n)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

string in;
int pos;
bool over;

void check(PI&p){
  over|=p.F>10000 || p.S>10000 || p.F<-10000 || p.S<-10000;
}


PI operator*(const PI&l,const PI&r){
  PI ret=mp(l.F*r.S+r.F*l.S,l.S*r.S-l.F*r.F);
  check(ret);
  return ret;
}

PI operator+(const PI&l,const PI&r){
  PI ret=mp(l.F+r.F,l.S+r.S);
  check(ret);
  return ret;
}

PI operator-(const PI&l,const PI&r){
  PI ret=mp(l.F-r.F,l.S-r.S);
  check(ret);
  return ret;
}

void pr(const PI&ans){
  if(over)cout<<"overflow"<<endl;
  else{
    if(ans.S){
      cout<<ans.S;
      if(ans.F>0)cout<<'+';
    }
    if(ans.F){
      cout<<ans.F<<'i';
    }
    if(ans.F==0 && ans.S==0)cout<<0;
    cout<<endl;
  }
}

PI getnum(){
  if(in[pos]=='i'){
    ++pos;
    return mp(1,0);
  }
  PI ret=mp(0,0);
  while(pos<in.size() && isdigit(in[pos])){
    ret.S=ret.S*10+in[pos++]-'0';
    check(ret);
  }
  return ret;
}

PI expr(){
  PI ret;
  if(in[pos]=='('){
    ++pos;
    ret=expr();
  }else{
    ret=getnum();
  }
  deque<PI> st;
  st.pb(ret);
  deque<char> op;

  while(pos<in.size() && in[pos]!=')'){
    char cop=in[pos];
    ++pos;
    PI tt;
    if(in[pos]=='('){
      ++pos;
      tt=expr();
    }else tt=getnum();
    
    switch(cop){
    case '+':
      op.pb(cop);
      st.pb(tt);
      break;
    case '-':
      op.pb(cop);
      st.pb(tt);
      break;
    case '*':
      ret=st.back()*tt;
      st.pop_back();
      st.pb(ret);
      break;
    }
  }

  ret=st.front();st.pop_front();

  while(!st.empty()){
    char cop=op.front();op.pop_front();
    PI tt=st.front();st.pop_front();
    if(cop=='+')ret=ret+tt;
    else ret=ret-tt;
  }
  ++pos;
  return ret;
}


main(){
  while(cin>>in){
    over=pos=0;
    PI ans=expr();
    check(ans);
    pr(ans);
  }
}

Measured memory_bytes: 0
n = int(raw_input())
A = [0]
p = range(1, n)
a = [[0 for i in range(n)]for j in range(n)]

for i in range(n):
    a[i] = map(int, raw_input().split() )

l = 0

while p != []:
    a_min = 10000
    for i in A:
        for j in p:
            if 0 <= a[i][j] < a_min:
                a_min = a[i][j]
                add_A = j
    A.append(add_A)
    p.remove(add_A)
    l += a_min

print l

Measured memory_bytes: 6488
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int r, d, x;
  cin >> r >> d >> x;
  long long ans = x;
  for(int i = 1 ; i <= 10 ; i++){
    ans = r * ans - d;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int g[1002][1002];
bool f[1002][1002];
int main() {
	
	int w, h;
	cin >> h >> w;
	//h--; w--;
	vector<string>a(h);
	for (int i = 0; i < h; i++)cin >> a[i];
	
	queue<int>x, y;
	for(int i=0;i<h;i++)
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') { 
				x.push(j);
				y.push(i);
			g[i][j] = 0; f[i][j] = 1;
			
			}
			else g[i][j] = 9999999;

		}
	int ans = 0;

	while (x.size()) {
		int c = x.front();
		int d = y.front();
		x.pop(); y.pop();
		int m = g[d][c];
		if (c&&!f[d][c - 1]) {
			g[d][c - 1] = m + 1;
			x.push(c - 1);
			y.push(d);
			f[d][c - 1] = 1;
		}

		if (d&& !f[d-1][c] ) {
			g[d-1][c] = m + 1;
			x.push(c);
			y.push(d-1);
			f[d - 1][c] = 1;
		}

		if (c<w-1&& !f[d][c + 1] ) {
			g[d][c + 1] = m + 1;
			x.push(c + 1);
			y.push(d);
			f[d][c + 1] = 1;
		}

		if (d<h-1&& !f[d+1][c ] ) {
			g[d+1][c ] = m + 1;
			x.push(c );
			y.push(d+1);
			f[d + 1][c] = 1;
		}
		

	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(ans, g[i][j]);
		//	cout << g[i][j] << " ";
		}
	//	cout << endl;
	}
	cout << ans << endl;


	return 0;


}

Measured memory_bytes: 14336