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

template<typename T> struct BIT {
    int max_n;
    vector<T> data;
    const bool zi;
    const T unit;
    BIT<T>(int n, bool zi = true, T u = T(0)) : max_n(n), zi(zi), unit(u) {
        data.assign(max_n + 1, u);
    }
    void add(int i, T x) {
        if ( zi ) i++;
        assert( i > 0 );
        while ( i <= max_n ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        if ( zi ) i++;
        assert( i > 0 );
        T s = unit;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
    vector<T> get_sum_list(int l, int r) {
        vector<T> ret;
        for ( int i = l; i <= r; i++ ) {
            ret.push_back(sum(i));
        }
        return ret;
    }
};

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }

    vector<ll> xs1(A);
    sort(xs1.begin(), xs1.end());
    xs1.erase(unique(xs1.begin(), xs1.end()), xs1.end());
    for ( int ii = 0; ii < A.size(); ii++ ) {
        A[ii] = lower_bound(xs1.begin(), xs1.end(), A[ii]) - xs1.begin();
    }
    
    BIT<ll> bit(N+1);
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        ans += i - bit.sum(A[i]);
        bit.add(A[i], 1);
    }

    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 7588
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

def main():
    n = I()
    d = collections.defaultdict(int)
    pr = Prime(10000)
    r = 0

    for i in range(2,n+1):
        t = pr.division(i)
        for k,v in t:
            d[k] += v
    c = collections.defaultdict(int)
    for k,v in d.items():
        if v >= 74:
            c[75] += 1
        if v >= 24:
          c[25] += 1
        if v >= 14:
          c[15] += 1
        if v >= 4:
          c[5] += 1
        if v >= 2:
            c[3] += 1

    r += c[75]
    r += c[25] * (c[3]-1)
    r += c[15] * (c[5]-1)
    if c[5] > 1:
        r += c[5] * (c[5]-1) // 2 * (c[3]-2)


    return r


print(main())


Measured memory_bytes: 7880
import java.util.Scanner;

public class Main {
	static int min;
	static boolean odd;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		int ans = gcd(a[0], a[1]);
		for (int i = 2; i < a.length; i++) {
			ans = gcd(ans, a[i]);
		}
		System.out.println(ans);
	}

	public static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b,a%b);
	}
}

Measured memory_bytes: 50616
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int d,n;
    cin >> d >> n;
    if(n==100) n+=1;
    for(int i=0;i<d;i++){
        n*=100;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	string S,T;
	cin >> S >> T;
	bool ans = false;
	for (int i = 0; i < S.size(); i++) {
		if(S==T) {
			ans=true;
			break;
		}
		S=S.back()+S.substr(0,S.size()-1);
	}
	if (ans) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    string ans = "";
    REP (i, N) {
        ans.push_back (S[i]);
        ans.push_back (T[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> IntegerToVector(ll bit, ll N) {
    vector<ll> S;
    for (ll i = 0; i < N; ++i) {
        if (bit & (1 << i)) S.push_back(1);
        else S.push_back(0);
    }
    return S;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll> > s;
    rep1(i, m){
        ll k;
        cin >> k;
        vector<ll> res;
        rep1(j, k){
            ll _s;
            cin >> _s;
            _s--;
            res.push_back(_s);
        }
        s.push_back(res);
    }
    vector<ll> p(m);
    rep1(i, m) cin >> p[i];
    ll ans = 0;
    for (ll bit = 0; bit < (1<<n); ++bit) {
        vector<ll> S = IntegerToVector(bit, n);
        ll res = 0;
        rep1(i, m){
            ll sum = 0;
            for (ll x: s[i]) sum += S[x];
            if (sum%2 == p[i]) res++;
        }
        if (res==m) ans++;
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3600
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
 
int32_t main()
{
	IOS;
	cin>>n;
	v32 sub[n+1];
	forsn(i,1,n){
		cin>>x;
		sub[x].pb(i);
	}
	forsn(i,1,n+1) cout<<sub[i].size()<<ln;
	// cout<<ln;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)((x).size()))

typedef long long ll;

const ll mod = 1000000007;
const double pi = 3.1415926535897932384626;

ll powmod(ll a, ll b) {ll res = 1; ll rem = a % mod; for (; b; b >>= 1) {if (b & 1) res = (res * rem) % mod; rem = (rem * rem) % mod;} return res;}

const int N = 18;

ll G[N][N];
ll A[N];
ll dis[N];

ll gao(int s)
{
	memset(dis, -1, sizeof(dis));
	priority_queue< pair<ll, int>, vector< pair<ll, int> >, greater< pair<ll, int> > > Q;
	Q.push(mp(0ll, s));
	dis[s] = 0ll;

	while (!Q.empty()) {
		ll d = Q.top().fi;
		int u = Q.top().se;
		dis[u] = d;

		Q.pop();

		if (u == 1) return dis[u];

		for (int i = 0; i <= 9; ++i) {
			int v = i;
			ll _d = d + G[u][v];			
			if (dis[v] == -1 || _d < dis[v]) {
				dis[v] = _d;
				Q.push(mp(_d, v));
			}
		}
	}

	return 0ll;
}		

int main()
{	
#ifdef hannibal_08
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
    
	int n = 0;
	int m = 0;
	scanf("%d %d", &n, &m);

	for (int i = 0; i <= 9; ++i) {
		for (int j = 0; j <= 9; ++j) {
			scanf("%lld", &G[i][j]);
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			ll x = 0ll;
			scanf("%lld", &x);
			if (x != -1 && x != 1) ++A[x];
		}
	}

	ll ret = 0ll;

	for (int i = 0; i <= 9; ++i) {
		if (i == 1) continue;
		ll ss = gao(i);
		ret += (ss * A[i]);
	}

	printf("%lld\n", ret);
	
	return 0;
}


Measured memory_bytes: 256
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
var arr2=readLine()!
 let characters = arr2.characters

var c = 1
var o  = "";
var p : String = "" 
for var s in characters {
  	
  	if( arr[1] == c ) { 
    	p = String(s).lowercaseString
    } else {
 		p = String(s)
	}
	
    o += p
	c += 1
}

print( o )

Measured memory_bytes: 4080
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
int dp[100100];
int cnt = 0;
signed main() {
  int x,a,b;
  cin >> x >> a >> b;
  int ans = x - a;
  ans -= ans/b*b;
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int main(){
	int n;
	cin>>n;
	vi d(n);
	rep(i,n)cin>>d[i];
	sort(all(d));
	cout<<d[n/2]-d[n/2-1]<<endl;
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))

#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;
bool f[100000];
   	int n,m;
	vector<int> v[100000];
	vector<int> w[100000];
	int ans[100000];
bool cca = false;
void searchm(int p, int mark){
	f[p] = true;
	ans[p] = mark;
	//cout << "tttt"<<endl;
	for(auto &a:(v[p])){
		if(f[a]==false)searchm(a, mark);
	}
	for(auto &a:(w[p])){
		if(f[a]==false)searchm(a, (mark+1)%2);
		cca = true;
	}
}
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	   cin>>n;
	rep(i, n-1){
		int a,b;cin>>a>>b;
		ul c;cin>>c;
		if(c%2==0){
			v[a-1].push_back(b-1);
			v[b-1].push_back(a-1);
		}else{
			w[a-1].push_back(b-1);
			w[b-1].push_back(a-1);
		}
	}
	/*rep(i, n){
		for(auto &a:(v[i])){
			cout<<a<<endl;
		}
		cout<<"   "<<endl;
	}*/
	int sw = 0;
	int ccc = 0;
	//cout<<"test"<<endl;
	/*rep(i, n){
		if(f[i]==false){
			//cout<<i<<endl;
			searchm(i, sw);
			sw = (sw+1)%2;
			ccc++;
		}
	}*/
	//cout<<"test"<<endl;
	searchm(0, 0);
	if(!cca){
		rep(i, n-1){
			cout<<"0"<<endl;
		}
		cout<<"1"<<endl;
	}else{
		rep(i, n){
			cout << ans[i] << endl;
		}
	}
	
	return 0;
}


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

vector<vector<int>> graph;
vector<bool> visit;
int ans = 0;
int n;

void dfs(int v){
    visit[v] = true;
    int flag = true;
    rep(i, n){
        if(!visit[i]){
            flag = false;
            break;
        }
    }
    if(flag){
        ans++;
    }
    
    for(auto u : graph[v]){
        if(visit[u]){
            continue;
        }
        dfs(u);
    }
    visit[v] = false;
}

int main() {

    int m;
    cin >> n >> m;
    graph.resize(n);
    visit.resize(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	FOR(i,1,9+1){
		FOR(j,1,9+1){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
}

Measured memory_bytes: 1116
n=int(input())
s=int(input())
ans="-1"
def f(b,n):
    if n<b:
        return n
    else:
        return f(b,n//b)+n%b
if n==s:
    ans=n+1
for b in range(2,int(n**(1/2)+1)):
    if f(b,n)==s:
        ans=b
        break
if ans=="-1":
    for p in range(int(n**(1/2)+1),0,-1):
        b=int((n-s)/p)+1
        if b>=2:
            if f(b,n)==s:
                ans=b
                break
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    ll A[2][101], dp[2][101];
    cin>>N;
    rep(i, 2) rep(j, N) cin>>A[i][j];
    dp[0][0]=A[0][0];
    rep1(i, N-1) dp[0][i]=dp[0][i-1]+A[0][i];
    dp[1][0]=dp[0][0]+A[1][0];
    rep1(i, N-1) dp[1][i]=max(dp[1][i-1], dp[0][i])+A[1][i];
    cout<<dp[1][N-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    d, t, s = i_map()

    print('Yes' if d <= t * s else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 72664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);


ll gcd(ll a, ll b){  if(b==0){  return a; }   return gcd(b , a%b); }

ll sum_digit(ll n){
  ll value = 0;

  while(n!=0){
    value += n%10;
    n = n/10;
  }

  return value;
}


int main() {


int n;
cin>>n;

ll a[n];
ll maxx = INT_MIN;
ll sum = 0;
for(int i=0;i<n;i++){
  ll x;
  cin>>x;
  a[i] = x - (i+1);
  maxx = max(maxx,a[i]);
}
sort(a,a+n);

for(int i=0;i<n;i++){
  sum += abs(a[i] - a[n/2]);
}

cout<<sum<<"\n";

  
  return 0;
}


Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	int n;
	cin >> n;
	Vec h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	bool f = true;
	for (int i = n-2 ; i >= 0; i--) {
		if (h[i] <= h[i+1])
			continue ;
		if (h[i] == h[i+1] + 1)
		{
			h[i]--;
			continue ;
		}
		f = false;
		break ;
	}
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int k,n,i;
	std::string s;
	std::cin >> k;
	std::cin >> s;
	n = s.l_ength();
	for(i=0; i<std::min(n,k); ++i){
		std::cout << s[i];
	}
	if(n>k){
		std::cout << "...";
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

#include <algorithm>
#include <vector>
#define MAX_W 200010
using namespace std;

int n,m;

vector<int> adj[MAX_W];
int dp[MAX_W];
bool vis[MAX_W];

int rec(int cur){
    if(dp[cur] != -1)
        return dp[cur];
    vis[cur] = true;

    int mymax = 0;
    for(auto i : adj[cur]){
        mymax = max(mymax,rec(i)+1);
    }

  //  dp[cur] = mymax + 1;
    return dp[cur] = mymax;

}


int main(int argc,char* argv[]){

    
    scanf("%d %d\n",&n,&m);

    for(int i = 0; i < MAX_W ; i++)
    {
        vis[i] = false;
        dp[i] = -1;
    }

    for(int i = 0; i < m; i++)
    {
        int a,b;
        scanf("%d %d\n",&a,&b);
        adj[a].push_back(b);
    }
    
    int cnt = 0;
    int i = 0;
    int mymax = 0;
    while(cnt != n){
        if(!vis[++i]){
            cnt++;
            mymax = max(mymax,rec(i));
        }
    }

    printf("%d",mymax );
    return 0;
}



Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long h,n,b=1,ans=0;
  cin>>h;
  while(h!=1){
	h/=2;
  	ans+=b;
    b=b*2;
  }
  cout<<ans+b<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

string s, t;
set<int>st[30];
signed main() {
	cin >> s >> t;
	rep(i, s.size()) {
		st[s[i] - 'a'].insert(i);
	}
	int ans = 0;
	int now = 0;
	rep(i, t.size()) {
		if (st[t[i] - 'a'].empty()) {
			cout << -1 << endl; return 0;
		}
		if (st[t[i] - 'a'].lower_bound(now) == st[t[i] - 'a'].end()) {
			ans++;
			now = *st[t[i] - 'a'].begin() + 1;
		}
		else {
			now = *st[t[i] - 'a'].lower_bound(now) + 1;
		}
	}
	cout << ans * s.size() + now << endl;
}


Measured memory_bytes: 5120
# 上から貪欲

N, K = map(int, input().split())
a = list(map(int, input().split()))

b = [0 for _ in range(40)]
for aa in a:
    for j in range(40):
        b[j] += (aa >> j) & 1

x = 0
for j in sorted(range(40), reverse=True):
    # reverseしないと低い桁が全て1になり、高い桁が0になってしまう
    if x | (1 << j) <= K:
        if 2 * b[j] < N:
            x += (1 << j)
res = 0
for j in range(40):
    if (x >> j) & 1 == 1:
        res += (N - b[j]) * (1 << j)
    else:
        res += (b[j]) * (1 << j)

print(res)


Measured memory_bytes: 14620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll l[1000006], r[1000006], a[1000006], n;
ll solve()
{
	stack<ll> s;
	for (int i = 0; i < n; ++i)
	{
		while (!s.empty() && a[i] <= a[s.top()])
		{
			r[s.top()] = i - 1;
			s.pop();
		}
		s.push(i);
	}
	while (!s.empty())
	{
		r[s.top()] = n - 1;
		s.pop();
	}
	for (int i = n - 1; i >= 0; --i)
	{
		while (!s.empty() && a[i] <= a[s.top()])
		{
			l[s.top()] = i + 1;
			s.pop();
		}
		s.push(i);
	}
	while (!s.empty())
	{
		l[s.top()] = 0;
		s.pop();
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ll mul = (r[i] - i + 1) * (i - l[i] + 1);
		ans += mul * a[i];
	}
	return ans;
}
int main(int argc, char const *argv[])
{
	fast;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	ll ans = solve();
	
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 11064
import java.util.Scanner;

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

    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      int K = Math.min(A, B) + Math.abs(A - B) / 2;

      if (Math.abs(A - K) == Math.abs(B - K)) {
        System.out.println(K);
      } else {
        System.out.println("IMPOSSIBLE");
      }
    }
  }
}

Measured memory_bytes: 21844
n = int(input())
w = [int(e) for e in input().split(" ")]
w_sum = sum(w)
s_diff = []
s1 = 0
s2 = w_sum
for i in range(n+1):
    s_diff.append(abs(s2 - s1))
    if (i == n):
        break
    s1 += w[i]
    s2 -= w[i]

print(min(s_diff))


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<utility>
#include<queue>

typedef long long lli;
using namespace std;

int main() {

	lli i, n, ans = 0, x;
	lli a[100000],b[100000], c[100000];
	scanf("%lld", &n);
	for (i = 0;i < n;i++) {
		scanf("%lld %lld", &a[i], &b[i]);
		c[i] = b[i] - (a[i]%b[i]);
		if (a[i] % b[i] == 0)c[i] = 0;
	}
	for (i = n - 1;i >= 0;i--) {
		x = c[i] - ans;
		if (x < 0) {
			x = b[i] - ((-x) % b[i]);
			if (x%b[i] == 0)x = 0;
		}
		if (b[i] == 1)x = 0;
		if (ans == 0 && a[i] == 0)x = 0;
		ans += x;
	}
	printf("%lld\n", ans);


	return 0;
}


//改行注意


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    map<string, int> a, b;
    int n, m;
    string str;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> str; 
        a[str]++;
    }
    cin >> m;
    for(int i=0; i<m; i++){
        cin >> str; 
        b[str]++;
    }

    int best = 0;
    for(map<string, int>::iterator it=a.begin(); it!=a.end(); it++){
        best = max(best, it->second-b[it->first]);
    }
    cout << best << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
even = A[0::2]
odd = A[1::2]
EC = defaultdict(int)
EC[0] = 0
OC = defaultdict(int)
OC[0] = 0
for e in even:
  EC[e] += 1
for o in odd:
  OC[o] += 1
E = sorted([[v, k] for k, v in EC.items()], reverse=True)
O = sorted([[v, k] for k, v in OC.items()], reverse=True)
if E[0][1] != O[0][1]:
  print(n - E[0][0] - O[0][0])
elif E[1][0] >= O[1][0]:
  print(n - E[1][0] - O[0][0])
else:
  print(n - E[0][0] - O[1][0])

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


int N, a[1000], max_a = -1e9, max_a_idx;
long long ans = 0;

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(max_a < a[i]){
            max_a_idx = i;
            max_a = a[i];
        }
    }

    if(max_a < 0){
        cout << max_a << endl;
        cout << N - 1 << endl;
        for(int i = 0; i < max_a_idx; i++){
            cout << 1 << endl;
        }
        for(int i = max_a_idx + 1; i < N; i++){
            cout << N - i + 1<< endl;
        }
        return 0;
    }

    long long sums[2] = {};
    for(int i = 0; i < N; i++){
        sums[i%2] += (a[i] > 0) ? a[i] : 0;
    }
    int target = 0;
    if(sums[1] > sums[0]){
        target = 1;
    }
    bool needed[1000] = {};
    int min_needed = 1000, max_needed = 0;
    for(int i = 0; i < N; i++){
        if(i % 2 == target && a[i] > 0){
            needed[i] = true;
            min_needed = min(min_needed, i);
            max_needed = max(max_needed, i);
        }
    }
    vector<int> ops;
    for(int i = 0; i < min_needed; i++){
        ops.push_back(1);
    }
    for(int i = 0; i < N - max_needed - 1; i++){
        ops.push_back(N - min_needed - i);
    }
    int i = min_needed, removed_cnt = min_needed;
    while(i < max_needed){
        if(needed[i]){
            i++;
        }else if(!needed[i] && needed[i+1]){
            ops.push_back(i + 1 - removed_cnt);
            removed_cnt += 2;
            i++;
        }else if(!needed[i] && !needed[i+1]){
            ops.push_back(i + 2 - removed_cnt);
            removed_cnt += 2;
            i += 2;
        }
    }
    cout << sums[target] << endl;
    cout << ops.size() << endl;
    for(int i = 0; i < ops.size(); i++){
        cout << ops[i] << endl;
    }    
}


Measured memory_bytes: 256
#B - Frog 2
#TLE
#

n,k=map(int,input().split())
h = list(map(int,input().split()))
#h[i]は足場[i+1]の高さ

dp = [0]*n

#dp[n-1]まで埋めれば良い

for i in range(1,n):
    c_min=float("inf")
    c_kh=float("inf")
    for j in range(1,k+1):
        #足場i+1までにたどり着くためのコストを考える
        #i~i-k（c[i-1]~c[i-k-1]）の足場からの飛び移り方を考える
        if i-j >= 0:
            c_kh = dp[i-j]+abs(h[i]-h[i-j])
            if c_kh < c_min:
                c_min = c_kh
        dp[i] = c_min
print(dp[n-1])

Measured memory_bytes: 52576
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var numbers = new List<int>();
        numbers.AddRange(Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList());
        numbers.AddRange(Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList());
        numbers.AddRange(Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList());

        var N = long.Parse(Console.ReadLine());
        var calles = new List<int>();
        for (int i = 0; i < N; i++)
        {
            calles.Add(int.Parse(Console.ReadLine()));
        }

        foreach (var n in calles)
        {
            for (int i = 0; i < numbers.Count; i++)
            {
                if (numbers[i] == n) numbers[i] = 0;
            }
        }

        var bingo = false;
        if (numbers[0] + numbers[1] + numbers[2] == 0) bingo = true;
        if (numbers[3] + numbers[4] + numbers[5] == 0) bingo = true;
        if (numbers[6] + numbers[7] + numbers[8] == 0) bingo = true;

        if (numbers[0] + numbers[3] + numbers[6] == 0) bingo = true;
        if (numbers[1] + numbers[4] + numbers[7] == 0) bingo = true;
        if (numbers[2] + numbers[5] + numbers[8] == 0) bingo = true;

        if (numbers[0] + numbers[4] + numbers[8] == 0) bingo = true;
        if (numbers[2] + numbers[4] + numbers[6] == 0) bingo = true;

        Console.WriteLine(bingo ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main(void){
  int n;
  int a[1000];
  
  scanf("%d", &n);
  for(int i=0; i<n; i++){
    scanf("%d ", &a[i]);
  }
  
  for(int i=0; i<n; i++){
    if(a[i]%2 == 0){
      if(a[i]%3 != 0 && a[i]%5 != 0){
        printf("DENIED");
        return 0;
      }
    }
  }
  printf("APPROVED");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N,X;
    cin >> N >>X;
    int L[N+1];
    L[0] = 0;
    for(int i=1;i<=N;i++){
        cin >> L[i];
    }
    int ans = 0;
    int D = 0;
    for(int i=0;i<=N;i++){
        D += L[i];
        if(D > X){
            break;
        }
        else{
            ans++;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3224
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int n;
vector<pii> ve[maxn];
ll dp[305][305][305];

bool check(int a, int b, int c) {
    int k = max(a, max(b, c));
    if (k > n) return false;
    for (auto element: ve[k]) {
        int cnt = 0;
        if (a >= element.Fi) cnt++;
        if (b >= element.Fi) cnt++;
        if (c >= element.Fi) cnt++;
        if (cnt != element.Se) return false;
    }
    return true;
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        ve[r].pb(pii(l, x));
    }
    ll ans = 0;
    dp[0][0][0] = 1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= n; k++) {
                if (!check(i, j, k)) {
                    dp[i][j][k] = 0;
                    continue;
                }
                int target = max(i, max(j, k));
                if (target == n) ans = (ans + dp[i][j][k]) % Mod;
                dp[target + 1][j][k] = (dp[target + 1][j][k] + dp[i][j][k]) % Mod;
                dp[i][target + 1][k] = (dp[i][target + 1][k] + dp[i][j][k]) % Mod;
                dp[i][j][target + 1] = (dp[i][j][target + 1] + dp[i][j][k]) % Mod;
            }
        }
    }
    printf("%lld\n", ans);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 224256
#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e6+10;
int main()
{
   ll n,m;
   cin>>n>>m;
   ll a=n*(n-1)/2;
   ll b=m*(m-1)/2;
   cout<<a+b<<endl;
   //system("pause");
   return 0;
   
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,n;
	while(cin >>a>>b>>n){
		int sum = 0;
		a=a%b;
		while(n--){
			sum+=(a*10)/b;
			a = (a*10)%b;
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
      	String t = sc.nextLine();
      	int count= 0;
     	for (int i = 0; i < s.length(); i++) {
        	if (s.charAt(i) != t.charAt(i))
        		count++;
     	}
     	System.out.println(count);
	}
}

Measured memory_bytes: 42488
n = gets.to_i
a, b = gets.chomp.split(' ').map(&:to_i)
p = gets.chomp.split(' ').map(&:to_i)
ans = [0]*3
p.each do |x|
  ans[0] += 1 if x <= a
  ans[1] += 1 if x > a && x <= b
  ans[2] += 1 if x > b
end
puts ans.min

Measured memory_bytes: 14268
def check(s,i):
    if s in l:
        return i
    if s % 2 == 0:
        l.append(s)
        ans = check(s//2, i+1)
    else:
        l.append(s)
        ans = check(3 * s + 1, i + 1)
    return ans
s = int(input())
l = [s]
ans = 0
if s % 2 == 0:
    ans = check(s//2,2)
else:
    ans = check(3 * s + 1,2)
print(ans)

Measured memory_bytes: 3060
#!/usr/bin/ruby
require 'prime'
h={};2.step(36){|i|h[i]=i.prime_division}
while(l=gets.chomp)!="0 0"
	l=l.split
	n=l[0].to_i;m=l[1].to_i(n)
	p h[n].map{|a,b|
		z=m;r=0
		while z>0 do r+=(z=z.div(a)) end
		r.div(b)
	}.min
end

Measured memory_bytes: 6260
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadLongArray(N);

            var total = a.Sum();
            var min = long.MaxValue;
            var s = 0L;
            for (int i = 0; i < N; ++i)
            {
                s += a[i];
                if (i + 1 < N) min = Min(Abs(total - s * 2), min);
            }

            WriteLine(min);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}


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

int main() {
    int n, m, l;
    int a[101][101], b[101][101];
    cin >> n >> m >> l;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin >> b[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            long long c=0;
            for(int k=0; k<m; k++){
                c += (long long)a[i][k] * b[k][j];
            }
            if(j>0){
                cout << " ";
            }
            cout << c;
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, D;

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

  ll ans = 0;

  rep( i, N ) {
    ll X, Y;
    std::cin >> X >> Y;

    if( X*X+Y*Y <= D*D )
      ++ans;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll cnt;

int main(){
	ll n;
	cin >> n;
	ll a[n];
	cinf(a,n);
	arep(1,i,n){
		if(a[i]<a[i-1]){
			cnt+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout << cnt << endl;
}

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

int main(){
	int N , arr[200003]; cin >> N;
	for(int i = 1 ; i <= 2 * N ; ++i) cin >> arr[i];
	sort(arr + 1 , arr + 2 * N + 1); long long sum = 0;
	for(int i = 1 ; i <= 2 * N ; i += 2) sum += arr[i];
	cout << sum; return 0;
}


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

#define ll         long long int
#define pb         push_back
#define mk         make_pair
#define vec        vector<int>
#define vp         vector<pair<int , int>>
#define iter       vector<int>:: iterator
#define f(n)       for(int i=0 ; i<n ; i++)
#define sz         size()
#define srtv(v)    sort(v.begin() , v.end())
#define rsrt(v)    sort(v.rbegin() , v.rend())
#define M          1e5+5
#define fast       ios_base::sync_with_stdio(false);cin.tie(NULL)




using namespace std;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int d = max(a,max(b,c));
  cout<<a+b+c-d;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#ifdef ONLINE_JUDGE
    #undef DBG
#endif
 
#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; ++i)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fr first
#define sc second
 
using ll = long long;
 
 
int n;
string s;

bool check(int ln) {
    unordered_map<string, vector<int>> mapik;
    for (int i = 0; i < n; ++i) {
        string cur = "";
        for (int j = i; j < i + ln; ++j) {
            cur += s[j];
        }
        mapik[cur].emplace_back(i);
    }
    for (auto& el : mapik) {
        int x = el.sc[0];
        auto it = lower_bound(all(el.sc), x + sz(el.fr));
        if (it != el.sc.end()) 
            return true;
    }
    return false;
}

 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    cin >> s;
    int l = 0;
    int r = n + 1;
    while (l < r) {
#ifdef DBG
        cout << "l = " << l << endl;
        cout << "r = " << r << endl;
#endif
        int mid = l + (r - l) / 2;
        if (check(mid)) {
            l = mid + 1;
        }
        else {
            r = mid;
        }
    }
    printf("%d\n", max(l - 1, 0));
    return 0;
}


Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS() std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
	IOS();

	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	int a[10];
	int b[10];
	int c[10];
	mem(a,0);
	for(int i=0; i<n; i++)
	{
		if(a[s[i]-'0']) continue;
		a[s[i]-'0']=1;
		mem(b,0);
		for(int j=i+1; j<n; j++)
		{
			if(b[s[j]-'0']) continue;
			b[s[j]-'0']=1;
			mem(c,0);
			for(int l=j+1; l<n; l++)
			{
				if(c[s[l]-'0']) continue;
				c[s[l]-'0']=1;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck psb&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

vl v;

int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll xx,yy,i,j,k,x,y,z,n,a,b,c;
	sc(n);
	for(i=0;i<n;i++){
		sc(j);
		v.pb(j);
	}
	xx=-1;
	x=-1;
	for(i=0;i<n;i++){
		if(v[i]>=x){
			x=v[i];
			xx=i+1;
		}
	}
	yy=-1;
	y=mod;
	for(i=0;i<n;i++){
		if(v[i]<=y){
			yy=i+1;
			y=v[i];
		}
	}
	if(abs(x)>=abs(y)){
		j=x;
		k=xx;
	}
	else{
		j=y;
		k=yy;
	}
	pr(2*n-1);
	for(i=0;i<n;i++){
		printf("%lld %lld\n",k,i+1);
	}
	if(k==xx){
		for(i=1;i<n;i++){
			printf("%lld %lld\n",i,i+1);
		}
	}
	else{
		for(i=n-1;i>0;i--){
			printf("%lld %lld\n",i+1,i);
		}
	}


}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	int ret=0;
	ret=max(ret,A*10+B+C);
	ret=max(ret,B*10+A+C);
	ret=max(ret,C*10+B+A);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N;
VI A;
int main() {
    std::cin >> N;
    A.resize(N);

    int min = 1e6, max = 0;
    REP(i, N) {
        std::cin >> A[i];
        min = std::min(min, A[i]);
        max = std::max(max, A[i]);
    }

    SORT(A);

    int ans = 0;
    FOR(X, min, max + 1) {
        int num = 0;

        num += (int)(std::upper_bound(ALL(A), X-1) - std::lower_bound(ALL(A), X-1));
        num += (int)(std::upper_bound(ALL(A), X)   - std::lower_bound(ALL(A), X));
        num += (int)(std::upper_bound(ALL(A), X+1) - std::lower_bound(ALL(A), X+1));

        ans = std::max(ans, num);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		long ans = 0;
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9;j++)
				ans += handstand(i,j,n)*handstand(j,i,n);
		}
		
		System.out.println(ans);

	}


	static int handstand(int l, int r, int n){
		int sum = 0;
		for(int i = 1; i <= n; i++){
			if(i%10 == l && Integer.parseInt(String.valueOf(i).substring(0, 1)) == r )
				sum++;
		}
		return sum;

	}
}

Measured memory_bytes: 108592
import java.util.*;

public class Main {
    public static void main(String[] args ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();

        int count = 0;
        for(int i = L;i <= R;i++){
            if(i % d == 0){
                count++;
            }
        }

        System.out.println(count);

    }
}


Measured memory_bytes: 26952