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

int main() {
    int m,f,u;
    do{
        cin >> m >> f >> u ;
        if (!((m==-1)&&(f==-1)&&(u==-1))){
            if (m==-1||f==-1){
                cout << 'F' << endl;
                continue;
            }
            if ((m+f)>=80){
                cout << 'A' << endl;
                continue;
            }
            if ((m+f)>=65){
                cout << 'B' << endl;
                continue;
            }
            if ((m+f)>=50){
                cout << 'C' << endl;
                continue;
            }
            if ((m+f)>=30){
                if (u>=50)
                    cout << 'C' << endl;
                else cout << 'D' << endl;
                continue;
            }
            cout << 'F' << endl;
        }
    }while (!((m==-1)&&(f==-1)&&(u==-1)));
    return 0;
}


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

bool isValid(vector<int> array, int add, int pairNum){
	array[add]++;
	// cannot use same number over 4 times
	for (int i = 1; i < 10; i++) {
		if (array[i] > 4) {
			return false;
		}
	}
	if(array[pairNum] < 2) return false;
	else array[pairNum] -= 2;
	// main
	for (int i = 1; i < 10; i++) {
		if (array[i] < 3 && i < 8) { // find straight
			if(array[i+1] < array[i] || array[i+2] < array[i]) return false;
			array[i+2] -= array[i];
			array[i+1] -= array[i];
			array[i] = 0;
		}else if(array[i] >= 3){ // find 3 same numbers
			array[i] -= 3;
			i--;
		}else if (array[i] > 0) {
			return false;
		}
	}
	return true;
}

bool solve(vector<int> array, int add){
	// setPair
	for (int i = 1; i < 10; i++) {
		if(isValid(array, add, i)) return true;
	}
	return false;
}

int main(){
	string str;
	bool hasAns;
	vector<int> array;
	while(cin >> str){
		// initialize
		hasAns = false;
		array.clear();
		for (int i = 0; i < 10; i++) {
			array.push_back(0);
		}
		for (int i = 0; i < str.size(); i++) {
			array[str[i] - '0']++;
		}
		for (int i = 1; i < 10; i++) {
			if (solve(array, i)) {
				if (hasAns) {
					cout << " " << i;
				}else {
					hasAns = true;
					cout << i;
				}
			}
		}
		if (hasAns) {
			cout << endl;
		}else {
			cout << "0" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    vector<pair<ll,ll> > kabu(n+1);
    vector<pair<ll,ll> > kane(n+1);
    kabu[0] = make_pair(1000,0);
    kane[0] = make_pair(1000,0);
    REP(i,n){      
        if(kabu[i].se+kabu[i].fi/a[i]==kane[i].se+kane[i].fi/a[i]){
            kabu[i+1].se = kabu[i].se+kabu[i].fi/a[i];
            kabu[i+1].fi = max(kabu[i].fi%a[i],kane[i].fi%a[i]);
        }else if(kabu[i].se+kabu[i].fi/a[i]>kane[i].se+kane[i].fi/a[i]){
            kabu[i+1].se = kabu[i].se+kabu[i].fi/a[i];
            kabu[i+1].fi = kabu[i].fi%a[i];
        }else{
            kabu[i+1].se = kane[i].se+kane[i].fi/a[i];
            kabu[i+1].fi = kane[i].fi%a[i];
        }
        if(kabu[i].fi+kabu[i].se*a[i]>kane[i].fi+kane[i].se*a[i]){
            kane[i+1].se = 0;
            kane[i+1].fi = kabu[i].fi+kabu[i].se*a[i];
        }else{
            kane[i+1].se = 0;
            kane[i+1].fi = kane[i].fi+kane[i].se*a[i];
        }

        
    }
    cout << kane[n].fi << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

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


int main(){
    int count;
    ll N;
    ll D;
    count = 0;

    cin >> N >> D;
    REP(i, N){
        ll xi;
        ll yi;
        cin  >> xi >> yi;
        if( sqrt(xi*xi+yi*yi) <= D ){count += 1;}

    }
    cout << count << endl;



    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <queue>

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

    std::priority_queue<int> pq;
    for(int i=0; i<10; ++i){
        int input;
        std::cin >> input;
        pq.push(input);
    }
    for(int i=0; i<3; ++i){
        std::cout << pq.top() << "\n"; pq.pop();
    }
    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	bool ymflag = true, myflag = true;
	int s,s1,s2;
	cin >> s;
	s2 = s % 100;
	s1 = (s - s2)/100;
	//cout << s1 << "," << s2 << endl;
	if (s1 >= 13)myflag = false;
	if (s2 >= 13)ymflag = false;
	if (s1 == 0)myflag = false;
	if (s2 == 0)ymflag = false;
	if (ymflag && myflag)cout << "AMBIGUOUS";
	else if (ymflag)cout << "YYMM";
	else if (myflag)cout << "MMYY";
	else cout << "NA";

}

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

int main() {
	ll x=0,ans=0,a;
	string s;
	cin>> a>>s;
	for(int i=0;i<a;i++){
		if(s[i]=='I'){
			x++;
		}
		else{
			x--;
		}
		ans=max(x,ans);
	}
	cout <<ans<<endl;
 	return 0;
}



Measured memory_bytes: 256
lst = list(map(int,input().split()))
_max = max(lst)
lst2 = list(map(lambda x: _max - x, lst))
lst2.remove(0)

if lst2[0] % 2 == 0 and lst2[1] % 2 == 0:
    print(sum(lst2) // 2)
elif lst2[0] % 2 != 0 and lst2[1] % 2 != 0:
    _sum = (lst2[0] - 1) + (lst2[1] - 1)
    print(_sum // 2 + 1)
else:
    print((sum(lst2) + 1) // 2 + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   ll A, B, N; cin >> A >> B >> N;
   if (N < B) cout << A * N / B << endl;
   else cout << A * (B - 1) / B << endl;
 }


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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    while (A >= B) {
        K--;
        B = B*2;
    }
    while (B >= C) {
        K--;
        C = C*2;
    }
    if (K >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;


int main() {
	int n;
	long long k;
	cin>>n;
	cin>>k;

	long long arr[100001]= {0};

	int a;
	int b;
	for (int i = 0; i < n; i++) {
		cin>>a;
		cin>>b;
		arr[a] += b;
	}

	long long count = 0;
	int answer = 0;
	int number = 1;
	while (count < k) {
		answer = number;
		count += arr[number];
		number++;
	}

	cout<<answer<<endl;


	return 0;
}

Measured memory_bytes: 1024
import collections


def run(s, t):
    ss = sorted(list(collections.Counter(s).values()))
    tt = sorted(list(collections.Counter(t).values()))
    if ss == tt:
        return 'Yes'
    else:
        return 'No'


def main():
    s = input()
    t = input()
    print(run(s, t))


if __name__ == '__main__':
    main()

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

int T,N,K,X[100000+10],A[100000+10];

int main() {
  cin >> T;
  for (int t=0; t<T; t++) {
    cin >> N >> K;
    for (int i=0; i<N; i++) {
      cin >> X[i];
    }
    for (int i=0; i+1<N; i++) {
      A[i] = X[i+1] - X[i];
    }
    sort(A,A+N-1);
    int sum=0;
    int I = max(0,N-1-(K-1));
    for (int i=0; i<I; i++) {
      sum += A[i];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1948
use std::io;
use std::str::FromStr;

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let(x, a) = input_int_tuple();
    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;

int a[200000],b[200000];
ll d[200000];
vector<P>E[200000];

int main(){
	int n;cin>>n;
	vector<P>A,B;
	rep(i,n)scanf("%d",&a[i]),A.push_back(P(a[i],i));
	rep(i,n)scanf("%d",&b[i]),B.push_back(P(b[i],i));
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	rep(i,n-1){
		E[A[i+1].second].push_back(P(A[i+1].first-A[i].first,A[i].second));
		E[A[i].second].push_back(P(A[i+1].first-A[i].first,A[i+1].second));
		E[B[i+1].second].push_back(P(B[i+1].first-B[i].first,B[i].second));
		E[B[i].second].push_back(P(B[i+1].first-B[i].first,B[i+1].second));
	}
	memset(d,0x3f,sizeof(d));
	priority_queue<P,vector<P>,greater<P>>que;
	d[0]=0;que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();que.pop();
		if(d[p.second]!=p.first)continue;
		for(auto u:E[p.second]){
			if(p.first+u.first<d[u.second]){
				d[u.second]=p.first+u.first;
				que.push(P(d[u.second],u.second));
			}
		}
	}
	rep(i,n){
		printf("%lld\n",d[i]);
	}
}


Measured memory_bytes: 23492
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int t, n;
	cin >> t >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	int mx = 0;
	rep(i,n) mx = max(mx, v[i]);
	int k = t - mx;
	cout << max(0, mx - k - 1) << endl;
}

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

const int N=2e5+20;
int n,m,u,v,p[N],sz[N],ans;

void init() {for(int i=1;i<=n;i++) p[i]=i,sz[i]=1;}

int root(int i) {return p[i]==i?i:p[i]=root(p[i]);}

bool cycle(int a,int b) {return root(a)==root(b);}

void join(int a,int b)
{
	a=root(a),b=root(b);
	if(sz[a]<sz[b]) swap(a,b);
	p[b]=p[a],sz[a]+=sz[b];
}

int main()
{
	scanf("%d%d",&n,&m);

	init();
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&u,&v);
		if(not cycle(u,v)) join(u,v);
	}

	for(int i=1;i<=n;i++) ans=max(ans,sz[root(i)]);
	cout<<ans;
}

Measured memory_bytes: 5296
#include <iostream>
#include <vector>
#include <boost/optional.hpp>
auto const none = boost::none;


template<class T> struct Graph {
  using size_t = std::size_t;
  size_t n; std::vector<std::vector<boost::optional<T>>> dat;
  Graph() {}
  Graph(size_t n) : n(n), dat(n, std::vector<boost::optional<T>>(n)) {}
  void init(size_t n) { this->n = n; dat.resize(n); for(size_t i=0;i<n;++i) dat[i].assign(n, none); }
  auto& operator[](size_t i) { return dat[i]; }
  void de(size_t i, size_t j, T v) { dat[i][j] = v; }
  void e(size_t i, size_t j, T v) { de(i, j, v); de(j, i, v); }
  auto begin() { return dat.begin(); }
  auto end() { return dat.end(); }
  size_t size() const { return n; }
  void wf() {
    for(size_t k=0; k<size(); ++k) for(size_t i=0; i<size(); ++i) for(size_t j=0; j<size(); ++j) {
      if(!dat[i][k] || !dat[k][j]) continue;
      T v = *dat[i][k] + *dat[k][j];
      if(!dat[i][j] || v < *dat[i][j]) dat[i][j] = v;
    }
  }
};


void abc143_e() {
  int N, M; long long L;
  std::cin >> N >> M >> L;
  Graph<long long> g(N);
  for(int i=0;i<M;++i) {
    int A, B, C;
    std::cin >> A >> B >> C;
    g.e(--A, --B, C);
  }

  g.wf();
  for(auto& v : g) for(auto& e : v) if(e && *e <= L) e = 1; else e = none;
  g.wf();

  int Q;
  std::cin >> Q;
  for(int i=0;i<Q;++i) {
    int s, t;
    std::cin >> s >> t;
    --s; --t;
    std::cout << (g[s][t] ? *g[s][t]-1 : -1) << '\n';
  }
}

signed main() {

  abc143_e();

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define MAXN 105
using namespace std;
long long val[MAXN],wt[MAXN];

long long knapSack(int W,int n)
{
   int i, w;
   long long K[n+1][W+1];


   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}

int main(){

    int n,C;
    cin>>n>>C;

    for(int i=0;i<n;i++)
        cin>>wt[i]>>val[i];

    cout<<knapSack(C,n);



}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
struct pref{
    int num,p,y;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n,x;
    cin >> n >> x;
    vector<ll> A(n);
    REP(i,n){
        cin >> A[i];
        
    }
    ll cnt=0;
    // ll cnt2= 0;
    FOR(i,1,n){
        ll p=((A[i-1]+A[i]-x>0)?A[i-1]+A[i]-x:0);
        cnt+= p;
        if(A[i]>=p) A[i]-= p;
        else {
            A[i]=0;
            A[i-1]-=p-A[i];
        }
    }


    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int h,w,k;

int sum_matrix(const vector<vector<int>>& vv){
    int count=0;
    for(const auto& v : vv){
        for(const auto& e : v){
            count += e;
        }
    }
    return count;
}

int main(){
    cin >> h >> w >> k;
    vector<vector<int>> data(6, vector<int>(6,0));
    // read data
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char c; cin >> c;
            if(c=='#') data[i][j] = 1;
        }
    }
    // make index
    // for h
    vector<vector<int>> lst_h(1<<h);
    for (int bit = 0; bit < (1<<h); ++bit) {
        for (int i = 0; i < h; ++i) {
            if (bit & (1<<i)) {
                lst_h[bit].push_back(i);
            }
        }
    }
    // for w
    vector<vector<int>> lst_w(1<<w);
    for (int bit = 0; bit < (1<<w); ++bit) {
        for (int i = 0; i < w; ++i) {
            if (bit & (1<<i)) {
                lst_w[bit].push_back(i);
            }
        }
    }
    // check
    int ans=0;
    for(int bit_h = 0; bit_h < (1<<h); ++bit_h) {
        for(int bit_w = 0; bit_w < (1<<w); ++bit_w){
            vector<vector<int>> dmy=data;
            for(auto i : lst_h[bit_h]) for(int j=0; j<6; j++) dmy[i][j]=0;
            for(int i=0; i<6; i++) for(auto j : lst_w[bit_w]) dmy[i][j]=0;
            if(sum_matrix(dmy)==k) ans++;
        }
    }
   cout << ans << "\n";
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

int h,w;
vs board;

bool dfs(int y, int x, int cnt)
{
  if(y<0||h<=y||x<0||w<=x||board[y][x]!='#') return false;
  if(cnt>=2) return true;
  if(dfs(y+1,x,cnt+1)||dfs(y-1,x,cnt+1)||dfs(y,x+1,cnt+1)||dfs(y,x-1,cnt+1)) 
    return true;
}

signed main() 
{
  cin>>h>>w;
  rep(i,h)
  {
    string s; cin>>s;
    board.pb(s);
  }
  rep(y,h) rep(x,w)
  {
    if(board[y][x]=='#')
      if(!dfs(y,x,0)) 
      {
        print("No");
        return 0;
      }
  } 
  print("Yes");

  return 0;
}

Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int r, g;
  scanf("%d%d", &r, &g);
  printf("%d\n", 2 * g - r);
  return 0;
}


Measured memory_bytes: 128
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    std::ios_base::sync_with_stdio(false); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return true;
}();

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

/* BFS + backtrack.
 * ans[i] indicates
 * one next room on shortest
 * path to first room. */
void solve() {
    cini(n);
    cini(m);
    vvi adj(n);

    for(int i=0; i<m; i++) {
        cini(a);
        cini(b);
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    vector<pii> dp(n, { -1, 0});
    queue<int> q;
    q.push(0);
    dp[0]={0,0};
    while(q.size()) {
        int node=q.front();
        q.pop();
        for(int chl : adj[node]) {
            if(dp[chl].first<0) {
                dp[chl].first=dp[node].first+1;
                dp[chl].second=node;
                q.push(chl);
            }
        }
    }

    bool posi=true;
    for(int i=0; i<n; i++) {
        if(dp[i].first<0) {
            cout<<"No"<<endl;
            return;
        }
    }
    
    cout<<"Yes"<<endl;
    for(int i=1; i<n; i++)
        cout<<dp[i].second+1<<endl;
}

signed main() {
    solve();
}

// DO NOT JUMP BETWEEN PROBLEMS


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

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

	int ans=0;

	for(int i=0; i<s.size()/2; i++)
		if(s[i]!=s[s.size()-1-i])
			ans++;

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

	return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
if 2 * K > B - A:
	for x in range(A, B + 1):
		print(x)
else:
	for x in range(A, A + K):
		print(x)
	for x in range(B - K + 1, B + 1):
		print(x)

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

int main(void)
{
    char s[5];
    scanf("%s", s);
    int i;
    for(i=0; i<3; i++)
    {
        if(strncmp(&s[i], &s[i+1], 1)==0)
        {
            printf("Bad");
            return 0;
        }
    }
    printf("Good");
    return 0;
}

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

using namespace std;

typedef long long ll;

ifstream fin ("hps.in");
ofstream fout ("hps.out");

#define f first
#define s second
#define pb push_back

ll h, ans, p = 1;


int main()
{
  cin >> h;
  while (h > 0) {
    ans += p;
    h /= 2;
    p *= 2;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cctype>

using namespace std;

#define ll long long

int n, m;
int a[1000001];

int main() {
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (1LL * i * j >= n) break;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3196
#include <cstdio>
#include <complex>
#include <vector>

using namespace std;
typedef complex<double> P;
int main(){
  int n;
  P p1(0.0,1.0),p2(0.0,-1.0);
  while(scanf("%d",&n)&&n){
    P p[n];
    double x,y;
    for(int i=0;i<n;++i){
      scanf("%lf,%lf",&x,&y);
      p[i].real()=x;p[i].imag()=y;
    }
    int a=1;
    for(int i=0;i<n;++i){
      for(int j=i+1;j<n;++j){
	vector<P> v;
	v.clear();
	P c((p[i].real()+p[j].real())/2,(p[i].imag()+p[j].imag())/2);
	if(abs(p[i]-p[j])==2.0)  v.push_back(c);
	else if(abs(p[i]-p[j])<2.0){
	  P va=p[i]-p[j];
	  P x1=(va*p1)/abs(va);
	  P x2=(va*p2)/abs(va);
	  double l=sqrt(1-abs(va)*abs(va)/4);
	  P c1=c+x1*l;
	  P c2=c+x2*l;
	  v.push_back(c1);v.push_back(c2);
	}
	if(v.empty()) continue;
	int m1=2;
	int m2=2;
	for(int k=0;k<n;++k){
	  if(i!=k&&j!=k&&abs(v[0]-p[k])<=1.0) m1++;
	  if(i!=k&&j!=k&&abs(v[1]-p[k])<=1.0) m2++;
	  a=max(a,max(m1,m2));
	}
      }
    }
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 1096
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;

    if(S == "Sunny") cout << "Cloudy" << endl;
    if(S == "Cloudy") cout << "Rainy" << endl;
    if(S == "Rainy") cout << "Sunny" << endl;

    return 0;

}

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

using namespace std;

int ans,n;
long long dp[100005];
long long jump(int a[],int i)
{
    if(i>=n)
        return 1001001001;

    if(i==n-1)
        return 0;

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

    dp[i]= min(abs(a[i]-a[i+1])+jump(a,i+1),abs(a[i]-a[i+2])+jump(a,i+2));
    return dp[i];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    cout<<jump(a,0);

    return 0;
}


Measured memory_bytes: 8672
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := iScan(), iScan()
	c, d := iScan(), iScan()
	x := larger(a, c)
	y := smaller(b, d)
	fmt.Println(larger(0, y-x))
}


Measured memory_bytes: 1772
import java.util.Scanner;

public class Main{
	public static int bubbleSort(int A[], int N) {
		int a;
		int b;
		int count = 0;
		for (int i =0; i <N-1; i++) {
			for (int j = N - 1; j >i; j--) {
				if ( A[j-1]>A[j]) {
					b = A[j-1];
					A[j-1] = A[j];
					A[j] = b;
					count++;
				} 
			}
		}
		return count;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
		}
		int count = bubbleSort(A, N);
		for (int i = 0; i < N; i++) {
			if (i != N - 1) {
				System.out.print(A[i] + " ");
			} else {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}

}



Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main(){
    int a,b;
    cin>>a>>b;
    int cnt=0;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    for (int i = 1; i <= 30; i++)
    {
        cnt++;
        if(i*a-(i-1)>=b) break;
        
    }
    cout<<cnt<<endl;
    
    
   
    return 0;
}

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

int main(void) {
    int N,K,a,ans = 0;
    cin >> N >> K;

    map<int64_t,int> mp;
    for(int i=0;i<N;i++) {
        cin >> a;
        mp[a]++;
    }
    vector<int> ball(mp.size());
    a = 0;
    for(auto m:mp) {
        ball[a] =m.second;
        a++;
    }

    sort(ball.begin(), ball.end());
    for(int i=K;i<ball.size();i++) {
        ans += ball[i-K];
    }

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


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[4];
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    if((a[2]-a[1])==(a[3]-a[2]))
    {
        cout<<"YES"<<endl;
        return 0;
    }
    else
    cout<<"NO"<<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 FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	int n, c;
	cin >> n >> c;
	VVI v(100010, VI(c, 0));
	REP(i, n) {
		int s, t, cc;
		cin >> s >> t >> cc;
		cc--;
		v[s][cc]++;
		v[t][cc]--;
	}
	REP(i, 100009) {
		REP(j, c) {
			v[i + 1][j] += v[i][j];
		}
	}
	REP(i, 100009) {
		REP(j, c) {
			if (v[i][j] == 0 && v[i + 1][j] == 1)v[i][j] = 1;
		}
	}
	int ans = 0;
	REP(i, 100005) {
		int res = 0;
		REP(j, c) {
			res += v[i][j];
		}
		ans = max(ans, res);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <climits>
#include <stdio.h>

void insertionSort(int A[], int N)
{
  for (int i = 0; i <= N - 1; i++)
  {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v)
    {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;

    for (int k = 0; k < N; k++)
    {
      std::cout << A[k];
      if (k != N - 1)
      {
        std::cout << " ";
      }
    }
    std::cout << std::endl;
  }
}

int main(int argc, char *argv[])
{
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i = 0; i < N; i++)
    scanf("%d", &A[i]);

  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 3156
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n,x,c=0;
	cin>>n;
	for1(i,n){
		cin>>x;
		if(x!=i) c++;
		}
	pf(c<=2? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(int argc, char *argv[]){
  int n, m;
  cin >> n >> m;
  vector<vector<lli> > g(n, vector<lli>(n, 1LL<<40));
  int from, to, cost;
  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> from >> to >> cost;
    g[from][to] = cost;
  }
  //???????????§?????????
  //???????????????????????£???????????????
  bool neg_cycle = false;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if(//g[i][j] == 1LL<<40 &&
           (g[i][k] == 1LL<<40 || g[k][j] == 1LL<<40))continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if(g[i][i] < 0)neg_cycle = true;
  }
  if(neg_cycle){
    std::cout << "NEGATIVE CYCLE" << std::endl;
    return 0;
   }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if(g[i][j] >= 1LL<<40)std::cout << "INF ";
      else std::cout << g[i][j] << " ";
    }
    if(g[i][n - 1] >= 1LL<<40)std::cout << "INF" << std::endl;
    else std::cout << g[i][n - 1] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    ll k, a, b, c;
    cin >> a >> b >> c >> k;

    ll res= 0;
    if(k%2 == 0) res = a - b;
    else res = b - a;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000009
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s,t,p;
    cin>>s>>t;
    s += s;
    bool ans=false;
    for (int i=0;i<t.size() && !ans;i++) {
        p = s.substr(i,t.size());
        if (p==t) ans=true;
    }
    if (ans) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
n, k = [int(x) for x in input().split(' ')]
exist = []
storage = [0 for x in range(10 ** 5+1)]
for i in range(n):
    a, b = [int(x) for x in input().split(' ')]
    storage[a] += b
sum = 0
for i in range(1, 10**5+1):
    sum += storage[i]
    if sum >= k:
        print(i)
        break
    else:
        continue


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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

ll dp[3003][3003][4];

void solve(){
    long int r,c;
    cin>>r>>c;
    ll k;
    cin>>k;
    ll a[r+1][c+1];
    memset(a,0,sizeof(a));
    while(k--){
    	ll x,y;
    	cin>>x>>y;
    	cin>>a[x][y];
    }

    // for(long int i=1;i<=r;i++){
    // 	for(long int j=1;j<=c;j++)
    // 		cout<<a[i][j]<<" ";
    // 	cout<<endl;
    // }
    for(long int i=1;i<=r;i++){
    	for(long int j=1;j<=c;j++){

    		dp[i][j][1]=max(dp[i][j-1][1],a[i][j]+max({dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]}));
    		dp[i][j][2]=max(dp[i][j-1][2],a[i][j]+dp[i][j-1][1]);
    		dp[i][j][3]=max(dp[i][j-1][3],a[i][j]+dp[i][j-1][2]);

    		// debug(dp[i][j][1]); debug(dp[i][j][2]); debug(dp[i][j][3]); cout<<endl;


    	}
    }

    cout<<max({dp[r][c][1],dp[r][c][2],dp[r][c][3]})<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 355412
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
vector<T> sumup(const vector<T>& a, ll K) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = (res[i] + a[i]) % K;
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (auto& x : A) cin >> x;
    auto S = sumup(A, K);
    for (int i = 0; i < S.size(); i++) S[i] = (S[i] - i % K + K) % K;
    map<ll, int> mp;
    ll res = 0;
    for (int i = 0; i < S.size(); i++) {
      if (i - K >= 0) --mp[S[i - K]];
      res += mp[S[i]];
      ++mp[S[i]];
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 15872
#include<iostream>
using namespace std;
#include<algorithm>
#define REP(i,a) for(int  i=a-1;i>=0;i--)
int A[100000];
int main(){


	int a,b=0,c,n,j,k;	
	cin>>n;
	while(n!=-1){
	a=n;
		while(1){
			if(a<4) {
				A[b]=a;
				break;
			}
			A[b]=a%4;
			a=a/4; 
			b++;
		}
		REP(i,b+1){
			cout<<A[i];

		}
		cout<<endl;
		b=0;
		cin>>n;
	}
	return 0;
}

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

main(){
  int h, i;
  int *A;

  scanf("%d", &h);
  A = malloc(sizeof(int) * (h+1));
  for(i=1; i<=h; i++) scanf("%d", A+i);

  for(i=1; i<=h; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(i!=1) printf("parent key = %d, ", A[(i)/2]);
    if(i*2 <= h) printf("left key = %d, ", A[i*2]);
    if(i*2 < h) printf("right key = %d, ", A[i*2+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int64_t> A;
  int64_t tmp;
  int64_t judge=0;
  int64_t result = 0;
  for(int64_t i=0; i<N; i++){
    cin >> tmp;
    A.push_back(tmp);
    if(i==0) {
      judge = A.at(0);
      continue;
    }
    if(judge <= tmp) judge = tmp;
    else result += (judge - tmp);
//    cout << judge - tmp << endl;
  }
  cout << result << endl;
  return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  int N;
  int ans = 0;
  cin>>N;
  vec A(N);
  rep(i,N){
    cin>>A.at(i);
  }
  vec T;
  int bef_j = 0;
  int flag = 0;
  rep(i,N){

    flag = 0;
    REP(j,i,N){
    if(A.at(j)==i+1){
      T.push_back(j);
      bef_j = j+1;
      flag = 1;
      break;
    }
    }

    if(flag == 0){
      if(T.size()==0){
        ans = -1;
      }
      break;
    }else if(T.size()>1&&*(T.end()-1)<*(T.end()-2)){
        T.pop_back();
        break;
    }
  }


  if(ans!=-1)ans = N-T.size();
  cout<<ans<<endl;

}


Measured memory_bytes: 2168
#include<stdio.h>
int main()
{
    int n,a,b;
    int sum=0;
    int j;
    long long int ans=0;
    scanf("%d %d %d",&n,&a,&b);
    for(int i=1;i<=n;i++){
        sum=0;
        j=i;
        while(j!=0){
            sum+=j%10;
            j/=10;
        }
        if(sum<=b && sum>=a){
            ans+=i;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
  int A, B ,C ,D;
  cin >> A >> B >> C >> D;
  if ( (A+B) > (C+D) ){
    cout << "Left" << endl;
  }else if ( (A+B) < (C+D) ){
    cout << "Right" << endl;
  }else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<set>
using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;

    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++)
        cin >> s[i] >> c[i];

    for (int i = 0; i < M; i++)
        s[i]--;

    //for (int i = 0; i < M; i++)
    //    cout << s[i] << " " << c[i] << endl;

    const char init = '*';
    string ans(N, init);
    //cout << ans << endl;
    for (int i = 0; i < M; i++) {
        int index = s[i];
        char ch = c[i] + '0';

        if (ans[index] == init)
            ans[index] = ch;
        else if(ans[index] != ch){
            cout << -1 << endl;

            return 0;
        }
    }
    if (N > 1 && ans[0] == '0') {
        cout << -1 << endl;

        return 0;
    }

    for (int i = 0; i < N; i++) {
        if (ans[i] == init)
            ans[i] = '0';
    }

    if (N > 1) {
        if (ans[0] == '0')
            ans[0]++;
        
        cout << ans << endl;
    }
    else {
        cout << ans << endl;
    }

    //vector<set<int>> digit(N);
    //for (int i = 0; i < M; i++)
    //    digit[s[i]].insert(c[i]);

    //for (int i = 0; i < N; i++) {
    //    if (digit[i].size() > 1) {
    //        cout << -1 << endl;

    //        return 0;
    //    }
    //}

    //vector<int> ans(N, 0);
    //for (int i = 0; i < N; i++) {
    //    if (digit[i].empty())
    //        continue;

    //    ans[i] = *digit[i].begin();
    //}

    //if (N > 1 && ans[0] == 0) {
    //    cout << -1 << endl;

    //    return 0;
    //}

    //for (int i = 0; i < N; i++)
    //    cout << ans[i];
    //cout << endl;

    return 0;
}


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

struct Request{
	size_t first,second;
	Request(size_t i_first,size_t i_second):first(i_first),second(i_second){}
	bool operator<(const Request &otherobj)const{
		//ソートしたいので用意する
		if(first<otherobj.first){
			return true;
		} else if(first>otherobj.first){
			return false;
		}
		return (second<otherobj.second);
	}
};

int main(){
	//入力機構
	size_t N;//島の個数
	size_t M;//要望の個数
	std::cin>>N>>M;
	std::vector<Request> req(M,Request(0,0));//要望の内容。a,bの順番に意味はないのでまとめて管理。
	for(size_t i=0;i<M;i++){
		std::cin>>req[i].first>>req[i].second;
	}

	//処理機構
	//まず、処理をしやすいようにreqを加工。配列番号と「西からi(i=1,2,...)番目」という番号は1ずれているので直しておくと良い。更に、昇順にソートもしておきたい。
	for(size_t i=0;i<M;i++){
		req[i].first--;
		req[i].second--;
		if(req[i].first>req[i].second){
			//初期の数値の制約からこの処理必要ないのが分かる
			size_t tmp=req[i].first;
			req[i].first=req[i].second;
			req[i].second=tmp;
		}
	}
	//解法方針はこの通り
	/*
		この問題はグルーピングの問題
		「(ai,bi)が同じ組に入らないように、1,2,3,....,Nをこの順番通りに区切る場合、何個のグループに区切る事ができるか？」
		こういうアルゴリズムで解けるんじゃないかな？
		(1)reqをfirstが小さい順にソートする。
		(2)reqの先頭から次のように区切り位置を決めていく。
		(2-1)req[i]があれば、req[i].first<=p<req[i].secondなるpの右の位置に区切り位置がある。left=req[i].first,right=req[i].second。
		(2-2)req[i+1]について、req[i+1].first<rightなら、leftはreq[i+1].firstに持っていくことで効率化できる。
		(2-3)(2-2)ができるなら、req[i+1].second<rightなら、rightはreq[i+1].secondに持っていかないといけない。req[i+1]の要望を満たせない。
		(2-4)(2-2)ができなくなるまで(2-2),(2-3)を繰り返す。
		(3)left<=p<rightなるpの右の位置に区切りを置く。この処理でreq[index1]~req[index2]まで探索をしていれば、この区切りによってreq[index1]~req[index2]までの要望は満たされていることになる。
		(4)rightの位置から(2)を行っていくことでまた探索していく。
	*/
	//(1)
	std::sort(req.begin(),req.end());
	//(2)
	size_t count=0;
	size_t researchnum=0;//現在の区間で探索をした回数。itの探索をし終わった時にこれが0より大きくなってたら、区切りを1つ置かないといけない。
	size_t left=0,right=N-1;
	for(std::vector<Request>::const_iterator it=req.begin(),ite=req.end();it!=ite;it++){
		researchnum++;
		//(2-1),(2-2)
		if(it->first<right){
			//区切り位置を狭める処理をする((2-3)をできる)
			left=it->first;
			//(2-3)
			if(it->second<right){
				right=it->second;
			}
		} else{
			//(2-2)ができなくなった時
			//(3)
			count++;//仕切りを置く。どこに置くかは記憶しなくて良いので、カウンターを1つ増やしとけば良い。この仕切りは、現在のitより前のreq[i]を区切る仕切りである。このit自身はこの仕切りでは区切られない。
			//(4)
			left=it->first;
			right=it->second;
			researchnum=1;//探索回数のリセット。このit自身の探索回数を含めないといけないので1にする。
		}
	}
	if(researchnum>0){
		count++;
	}
	
	//出力機構
	std::cout<<count<<std::endl;

	return 0;
}


Measured memory_bytes: 1920
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	char c;

	scanf("%c", &c);

	puts((c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? "vowel" : "consonant"));

	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int i = 0;
            int[] H = new int[1000];
            int[] W = new int[1000];
            while(true){
                String line = reader.readLine();
                String[] str = line.split(" ");
                H[i] = Integer.parseInt(str[0]);
                W[i] = Integer.parseInt(str[1]);
                if(H[i] == 0 && W[i] == 0){
                    break;
                }
                i++;
            }
            for(int j = 0; j < i; j++){
                for(int k = 0;k < H[j];k++){
                    for(int l = 0; l < W[j]; l++){
                        if((k%2 ==0 && l%2 == 0 )||(k%2 != 0 && l%2 != 0)){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        } catch (IOException e) {
    
        }
    }
   
}


Measured memory_bytes: 35496