akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 P = 998244353;
const i64 maxn = 11000;
i64 dp[maxn / 2][maxn];
i64 fact[maxn], tcaf[maxn];

i64 deg(i64 x, i64 d) {
    if (d < 0) d += P - 1;
    i64 y = 1;
    while (d) {
        if (d & 1) (y *= x) %= P;
        (x *= x) %= P;
        d /= 2;
    }
    return y;
}

void add(i64 &x, i64 y) {
    x += y;
    x %= P;
}

i64 cnk(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * tcaf[k] % P * tcaf[n - k] % P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    fact[0] = tcaf[0] = 1;
    for1(i, maxn - 1) fact[i] = i * fact[i - 1] % P, tcaf[i] = deg(fact[i], -1);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0;
    forn(i, s.size()) if (s[i] == '1') ++(t[i] == '1' ? b : a);
    dp[0][0] = 1;
    forn(i, a + 1) forn(j, b + 1) {
        if (!i) {
            continue;
        }
        add(dp[i][j], dp[i - 1][j] * i * i + (j == 0 ? 0LL : dp[i][j - 1]) * i * j);
    }
    i64 ans = 0;
    forn(k, b + 1) add(ans, cnk(a + b, k) * cnk(b, k) % P * dp[a][b - k] % P * fact[k] % P * fact[k] % P);
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 428544
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N;
	int a[100];
	cin >> N;
	for(int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N);
	reverse(a, a + N);
	int suma = 0, sumb = 0;
	for(int i = 0; i < N; i += 2) suma += a[i];
	for(int i = 1; i < N; i += 2) sumb += a[i];
	cout << suma - sumb << endl;
	return 0;
}


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

struct uftree {
    vector<int> par, height, size;

    uftree(int64_t n): par(n), height(n, 0), size(n, 1) {
        for(int64_t i = 0; i < n; i++) par[i] = i;
    }

    int64_t find(int64_t x) {
        return par[x] == x ? x : par[x] = find(par[x]);
    }

    void unite(int64_t x, int64_t y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (height[x] < height[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if(height[x] == height[y]) height[x]++;
        }
    }

    bool issame(int64_t x, int64_t y) {
        return find(x) == find(y);
    }

    int64_t treesize(int64_t x) {
        return size[find(x)];
    }    
};

int main() {
    int64_t n, m;
    cin >> n >> m;
    vector<pair<int64_t, int64_t>> ab(m);
    for(auto& e : ab) {
        cin >> e.first >> e.second;
        e.first--;
        e.second--;
    }
    uftree t(n);
    vector<int64_t> ans(m);
    ans[m-1] = n * (n - 1) / 2;
    for(size_t i = m - 1; i > 0; i--) {
        ans[i-1] = ans[i] - (t.issame(ab[i].first, ab[i].second) ? 0 : t.treesize(ab[i].first) * t.treesize(ab[i].second));
        t.unite(ab[i].first, ab[i].second);
    }
    for(size_t i = 0; i < m; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4864
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

int main() {
	ll n, a, b; cin >> n >> a >> b;
	ll t1 = 0, t2 = 0, t3 = 0;
	repe(i, 1, n) {
		ll p;	cin >> p;
		if (p <= a) {
			t1++;
		}
		else if (p <= b) {
			t2++;
		}
		else {
			t3++;
		}
	}
	cout << min(t3, min(t1, t2)) << endl;

	return 0;
}

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

int count(ll n){
    int digits=0;
    while(n){
        n/=10;
        digits++;
    }
    return digits;
}

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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ll N;
    cin>>N;

    int ans=12;

    for(ll i=1ll;i*i<=N;i++){
        if(N%i !=0) continue;

        int cur=max(count(i),count(N/i));

        if(ans>cur){
            ans=cur;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3644
//#pragma GCC optimize("03,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb           push_back
#define ff           first
#define ss           second
#define gcd(a, b)    __gcd(a, b)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define lllim        2147483648
#define Pi           2*acos(0.0)
#define pii          pair<int,int>
#define pll 	     pair<ll,ll>
#define mem(a,b)     memset(a, b, sizeof(a))
#define fill_(a,b)   fill(a,a+n,b);
//#define mod          1000000007
#define fast_cin     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define filein       freopen("input.txt","r", stdin)
#define D(x)         cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define case		 int t,cas=1;cin>>t;while(t--)
#define rep(i,a,n)   for(int i=a;i<n;i++)
#define rev(i,n,a)   for(int i=n;i>=a;i--)
#define sim 		 template<class T

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};  // Kings Move
//const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

sim > void ckmin(T& a, const T& b) {
    a= b < a? b:a;
}
sim > void ckmax(T& a, const T& b) {
    a= b > a? b:a;
}

///.............................input.................................///
sim > void readvec( std::vector<T>& v, const int n) {
    rep(i,0,n) {
        T p;
        std::cin>>p;
        v.pb(p);
    }
}
///...........................input end...............................///


using namespace std;
using namespace __gnu_pbds;

const int maxn=2e6+2;

ll mod=1e9+7;

ll bigmod(ll a, ll b, ll m)
{
    if(b==0) return 1;
    if(b==1) return a;

    if(b%2)
    {
        ll res=bigmod(a,b/2,m)%m;
        return ((((res%m)*(res%m))%m)*(a))%m;
    }
    else
    {
        ll res=bigmod(a,b/2,m)%m;
        return (((res%m)*(res%m))%m);
    }
}


void solve()
{
	ll ans=0,n;
	cin>>n;
	
	
	ans= bigmod(10,n,mod)-2*(bigmod(9,n,mod))+(bigmod(8,n,mod));
	ans%=mod;
	ans+=mod;
	ans%=mod;
	cout<<ans<<endl;
	
	
	
}


int main()
{
	
    fast_cin;
   //calc();
   // case
    {
      //  cout<<"Case "<<cas++<<": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string s;
  cin >> s;

  string ans = "";
  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (!ans.empty()) {
        ans.erase(ans.size() - 1);
      }
    } else {
      ans += s[i];
    }
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3600
s = list(map(int,list(input())))[::-1]
n = len(s)
chk = [0]*2019
chk[0] = 1
t,m,ans = 1,0,0
for i in s:
    m = (m+t*i)%2019
    ans += chk[m]
    chk[m] += 1
    t = t*10%2019
print(ans)


Measured memory_bytes: 11972
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

int main(){
    int n,q;
    cin >> n;
    vector<int> S(n+1);
    for(int i=0;i<n;i++) cin >> S[i];
    cin >> q;
    int cur,ans=0;
    for(int i=0;i<q;i++){
        cin >> cur;
        S[n] = cur; //番兵
        int j=0;
        while(S[j] != cur) j++;
        if(j != n) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3156
sx,sy,tx,ty=map(int,input().split())
y=ty-sy
x=tx-sx
ans=[]
for i in range(y):
  ans.append("U")
for i in range(x):
  ans.append("R")
for i in range(y):
  ans.append("D")
for i in range(x):
  ans.append("L")
ans+="L"
for i in range(y+1):
  ans.append("U")
for i in range(x+1):
  ans.append("R")
ans+="D"
ans+="R"
for i in range(y+1):
  ans.append("D")
for i in range(x+1):
  ans.append("L")
ans+="U"

print("".join(ans))

Measured memory_bytes: 3188
#include <iostream>
#include<math.h>
using namespace std;

int main() {
int h,w,d;
cin>>h>>w>>d;
int a;
int masu[h*w+1][2];

for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a;
masu[a-1][0]=i;
masu[a-1][1]=j;
}
}

int k=(h*w)/d+1;
int ruiseki[d][k];
for(int i=0;i<d;i++){
for(int j=0;i+j*d<h*w;j++){
if(j==0)ruiseki[i][j]=0;
else{
ruiseki[i][j]=ruiseki[i][j-1]+abs(masu[i+j*d][0]-masu[i+j*d-d][0])+abs(masu[i+j*d][1]-masu[i+j*d-d][1]);
}
}
}
int q;
cin>>q;
for(int i=0;i<q;i++){
int a,b;
cin>>a>>b;
a--;
b--;
cout<<ruiseki[b%d][b/d]-ruiseki[a%d][a/d]<<endl;
}
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int a[10000],b[1000],p,n,m;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>a[i],b[a[i]]++;
	for(int i=0;i<=100;i++){
		if(!b[n-i]){
			p=n-i;break;
		}
		else if(!b[n+i]){
			p=n+i;break;
		}
	}
	printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;

#define pi 3.141592653589

void cut(void);

int main(){
	int room[4][3][10] = { 0 };	//4棟3階建10部屋
	int b, f, r, v;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		room[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				cout << " " << room[i][j][k];
			}
			cout << endl;
		}
		if (i != 3){
			cut();
			cout << endl;
		}
	}
	return 0;
}

void cut(){
	for (int i = 0; i < 20; i++){
		cout << "#";
	}
	return;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define inf 1<<29
using namespace std;
 
class State{
public:
  int a,time,cost;
  State(int a,int b,int c):a(a),time(b),cost(c){}
  bool operator<(State s)const{
    return s.cost<cost;
  }
};
 
int n,m,h,k,a,b,c,r,s,t,p,l,d,lim;
int R[101][101],C[101][101],H[101][101],D[(1<<8)+1];
 
void init(){
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      R[i][j]=inf;
      C[i][j]=inf;
      H[i][j]=inf;
    }
  }
  for(int i=0;i<(1<<8)+1;i++)D[i]=inf;
}
 
int Dijkstra(int bits){
  int dp[101][25],ans=inf;
  for(int i=0;i<101;i++){
    for(int j=0;j<25;j++)dp[i][j]=inf;
  }
  dp[s][0]=0;
  priority_queue<State> pq;
  pq.push(State(s,0,0));
 
  while(!pq.empty()){
    State u=pq.top();
    pq.pop();
 
    if(dp[u.a][u.time]<u.cost)continue;
    if(u.a==t){
      ans=min(ans,u.cost);
      continue;
    }
 
    for(int i=0;i<n;i++){
      if(H[u.a][i]==inf)continue;
      int time=u.time+H[u.a][i],cost=u.cost+C[u.a][i];
      if(((bits>>R[u.a][i])%2)&1)cost=u.cost;
 
      if(lim<time)continue;
      if(cost<dp[i][time]){
    dp[i][time]=cost;
    pq.push(State(i,time,cost));
      }
    }
  }
  return ans;
}
 
int main()
{
 
  while(1){
    cin>>n>>m>>lim>>k;
    if(n+m+lim+k==0)break;
 
    init();
 
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>h>>r;
      a--;b--;r--;
      C[a][b]=c;C[b][a]=c;
      H[a][b]=h;H[b][a]=h;
      R[a][b]=r;R[b][a]=r;
    }
    cin>>s>>t>>p;
    s--;t--;
    for(int i=0;i<p;i++){
      cin>>l>>d;
      int sum=0;
      for(int j=0;j<l;j++){
    cin>>a;
    sum+=1<<(a-1);
      }
      D[sum]=d;
    }
   
    D[0]=0;
    for(int i=0;i<(1<<8);i++){
      if(D[i]==inf)continue;
      for(int j=i+1;j<(1<<8);j++){
    D[(i|j)]=min(D[(i|j)],D[i]+D[j]);
      }
    }
    int ans=inf;
    for(int i=0;i<(1<<8);i++){
      if(D[i]==inf)continue;
      ans=min(ans,Dijkstra(i)+D[i]);
    }
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3320
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.annotation.tailrec
import scala.collection.mutable
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val n = get[Int]
    val ws = Array.fill(n) {
      get[String]
    }

    out.println(
      if (mutable.HashSet(ws: _*).size == n && ws.zip(ws.tail).forall { case (a, b) => a.last == b.head }) {
        "Yes"
      } else {
        "No"
      }
    )

    out.flush()
  }
}

Measured memory_bytes: 25416
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;

int main(){
	int a[5];
	for(int i = 0;i < 5;i++)cin >> a[i];
	int b[5];
	for(int i = 0;i < 5;i++){
		if(a[i] % 10 == 0)b[i] = 0;
		else b[i] = 10 - a[i] % 10;
	}
	int sum = 0;
	for(int i = 0;i < 5;i++)sum += a[i] + b[i];
	cout << sum - *max_element(b,b+5) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> can;
    rep(i,n) if(s[i] == 'o') can.pb(i);
    vector<int> plan;
    int last = -inf;
    rep(i,n) {
        if(s[i] == 'x') continue;
        if (last+c < i) {
            plan.pb(i);
            last = i;
        }
    }
    if(plan.size() > k) {
        return 0;
    }
    vector<pair<bool,int>> alt(plan.size());
    vector<int> ans;
    rrep(i,plan.size()) {
        auto it = upper_bound(all(can),plan[i]);
        if(it == can.end() || *it > plan[i]+c) {
            ans.pb(plan[i]+1);
            alt[i].first = false;
        } else {
            auto nit = upper_bound(all(plan),*it);
            if(nit != plan.end() && *nit <= *it+c && (!alt[nit-plan.begin()].first || alt[nit-plan.begin()].second <= *it+c)) {
                ans.pb(plan[i]+1);
                alt[i].first = false;
            } else {
                alt[i].first = true;
                alt[i].second = *it;
                while(true) {
                    it++;
                    if(it == can.end() || *it > plan[i]+c) break;
                    auto nnit = upper_bound(all(plan),*it);
                    if(nnit != plan.end() && *nnit <= *it+c && (!alt[nnit-plan.begin()].first || alt[nnit-plan.begin()].second <= *it+c)) {
                        break;
                    } else {
                        alt[i].second = *it;
                    }
                }
            }
        }
    }
    sort(all(ans));
    for(int i : ans) cout << i << endl;
}


Measured memory_bytes: 5772
#include <iostream>

using namespace std;
int Field[14][14];
int move_x[] = {-1, 0, 1,  0, -1,  1,  1, -1, -2, 0, 2,  0};
int move_y[] = { 0, 1, 0, -1,  1,  1, -1, -1,  0, 2, 0, -2};


void solve()
{
	int ax, ay, at;
	while(~scanf("%d%*c%d%*c%d", &ax, &ay, &at))
	{
		int size = at * 4;
		Field[ax + 2][ay + 2]++;
		for(int i = 0; i < size; ++i)
		{
			int X = ax + move_x[i] + 2;
			int Y = ay + move_y[i] + 2;
			Field[X][Y]++;
		}
	}
	int count = 0;
	int deepest = 0;
	for(int i = 2; i < 12; ++i)
	{
		for(int j = 2; j < 12; ++j)
		{
			if(Field[i][j] > 0)
			{
				if(deepest < Field[i][j])
				{
					deepest = Field[i][j];
				}
			}
			else
			{
				count++;
			}
		}
	}
	cout << count << endl << deepest << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e3 + 5;
int book[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n , k;  cin >> n >> k;
    for (int i = 1 ; i <= k ;  i ++){
        int d; cin >> d;
        for (int i = 1 ; i <= d ; i++){
            int v ; cin >> v;
            book[v] = 1;
        }
    }
    int ans = 0;
    for (int i = 1 ; i <= n ; i++)
        ans += (!book[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
int main() {
	long long d, n;
	cin >> d >> n;
	long long ans = 1;
	for (int i = 0; i < d; i++) {
		ans *= 100;
	}
	if (n == 100) {
		cout << ans * 101 << endl;
	}
	else cout << ans * n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ld a,b,c; cin >>a >> b >> c ;
    if(sqrt(a)+sqrt(b)+1e-15<sqrt(c)){
        cout << "Yes" ;
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

void Main(){
	string s, t; cin >> s >> t;
	vector<vector<int>> sc(26, vector<int>());
	rep(i, s.size()){
		sc[s[i] - 'a'].push_back(i);
	}
	int loop = 0;
	int head = -1;
	for(char a: t){
		auto sp = sc[a-'a'];
		if(sp.empty()){
			cout << "-1\n";
			return;
		}
		auto ub = upper_bound(all(sp), head);
		if(ub == sp.end()){
			loop++;
			ub = sp.begin();
		}
		head = *ub;
	}
	cout << (ll)loop * s.size() + head + 1 << endl;
}


Measured memory_bytes: 4412
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,i,j,k;
	char z[10];
	while(scanf("%s %d %d",z,&a,&s)!=EOF){
		d=a*200+s*300;
		f=a+s;
		printf("%s %d %d\n",z,f,d);
	}
	return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    string s;
    int k;
    cin >> s >> k;
    rep(i, 0, s.size()){
        if(s[i] == 'a') continue;
        int tmp = 'z' - s[i] + 1;
        if(k >= tmp){
            k -= tmp;
            s[i] = 'a';
        }
    }
    k %= 26;
    repb(i, s.size() - 1, 0){
        if(k == 0) break;
        int tmp = 'z' - s[i];
        if(tmp <= k){
            s[i] = 'z';
            k -= tmp;
        }else{
            s[i] += k;
            k = 0;
        }
    }
    o(s);
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int a,b,c,d,tmp;
int ff(int a,int k){
	cout << a;
	if(k==0) cout << "+";
	else cout << "-";
	return 0;
}
int pf(int e,int f,int g){
	ff(a,e);
	ff(b,f);
	ff(c,g);
	cout << d << "=7";
	return 0;
}
int t1(int e,int k){
	if(e==0) tmp+=k;
	else tmp-=k;
	return 0;
}
int t2(int e,int k){
	if(e==0) tmp-=k;
	else tmp+=k;
	return 0;
}
int main(int argc, char *argv[]) {
	int e,f,g,sum;
	cin >> sum;
	d=sum%10;
	c=(sum%100-d)/10;
	b=(sum%1000-10*c-d)/100;
	a=sum/1000;
	for(e=0;e<2;e++){
		tmp=a;
		t1(e,b);
		for(f=0;f<2;f++){
			t1(f,c);
			for(g=0;g<2;g++){
				t1(g,d);
				if(tmp==7){
					pf(e,f,g);
					return 0;
				}
				else t2(g,d);
			}
			t2(f,c);
		}
		t2(e,b);
	}
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>

using iarrN = int[2003];

constexpr int inf = 0x3f3f3f3f;

char c[2003];
int tot, ans = inf;
iarrN mn, mx, siz, head;

struct Edge {
	int nxt, to;
} e[4003];

inline void addEdge(int u, int v) {
	e[++tot] = {head[u], v};
	head[u] = tot;
}

void dfs(int u, int f) {
	mx[u] = mn[u] = 0, siz[u] = c[u] == '1';
	int son = 0;
	for (int i = head[u], v; i; i = e[i].nxt) {
		if ((v = e[i].to) == f) continue;
		dfs(v, u);
		siz[u] += siz[v], mx[u] += mx[v];
		if (mx[v] > mx[son]) son = v;
	}
	if (mn[son] > mx[u] - mx[son])
		mn[u] = mn[son] + mx[son] - mx[u] + siz[u];
	else mn[u] = siz[u] + (mx[u] & 1);
	mx[u] += siz[u];
}

int main() {
	int N;
	scanf("%d%s", &N, c + 1);
	for (int i = 1, u, v; i < N; ++i) {
		scanf("%d%d", &u, &v);
		addEdge(u, v), addEdge(v, u);
	}
	for (int i = 1; i <= N; ++i) {
		dfs(i, 0);
		if (mn[i] - siz[i] == 0)
			ans = std::min(ans, (mx[i] - siz[i]) >> 1);
	}
	printf("%d", ans == inf ? -1 : ans);
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,e,k;cin >> a >> b >> c >> d >> e >> k;
	if(e-a>k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

main(){
  char a, b;
  while(cin >> a >> b){
    if(a == '0' && b == 'U') cout << "nn";
    else{
      if(a == '2') cout << 'k';
      if(a == '3') cout << 's';
      if(a == '4') cout << 't';
      if(a == '5') cout << 'n';
      if(a == '6') cout << 'h';
      if(a == '7') cout << 'm';
      if(a == '8') cout << 'y';
      if(a == '9') cout << 'r';
      if(a == '0') cout << 'w';
      if(b == 'T') cout << 'a';
      if(b == 'L') cout << 'i';
      if(b == 'U') cout << 'u';
      if(b == 'R') cout << 'e';
      if(b == 'D') cout << 'o';
    }
  }
  cout << endl;
}

Measured memory_bytes: 1140
def calc_divisor(n):
    div = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.append(i)
            if n // i != i:
                div.append(n//i)
    div.sort()
    return div


n, m = map(int,input().split())
k = (m+1) // n

div = calc_divisor(m)
for i in div:
    if i <= k:
        ans = i
print(ans)

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

int main(){
	string ss, t;
	cin >> ss >> t;
	int n = (int)ss.size() - (int)t.size() + 1, len = t.size();
	bool ok = false;
	int first;
	for(int i = n-1; i >= 0; i--)
	{
		string sss = ss.substr(i, len);
		for(int j = 0; j < len; j++)
		{
			if(sss[j] != t[j] && sss[j] != '?') break;
			if(j == len - 1) ok = true;
		}
		if(ok){
			first = i;
			break;
		}
		
	}
	
	if(ok){
		for(int i = 0; i < (int)ss.size(); i++)
		{
			if(i >= first && i <= first+len-1) cout << t[i-first];
			else if(ss[i] == '?') cout << 'a';
			else cout << ss[i];
		}
	}
	else
	{
		cout << "UNRESTORABLE";
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll e[N+1], C[N];
    rep(i, N) cin >> C[i];
    sort(C, C+N);
    e[0] = 1;
    rep2(i, 1, N) e[i] = (2*e[i-1])%MOD;
    ll inv2 = (MOD+1)/2;
    ll ans = 0;
    rep(i, N){
        ll tmp = e[N-1]*e[N-1];
        tmp %= MOD;
        tmp *= C[i];
        tmp %= MOD;
        tmp *= (N+1-i);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    if (a < b && a < c && b > c)
    {
        cout << "Yes" << endl;
    }
    else if (a > b && a > c && b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S;cin >> S;
    int N = S.size();

    bool ok = true;
    bool ok1 = true;
    bool ok2 = true;
    rep(i,N){
        if(S[i] != S[N-1-i])ok = false;
    }
    rep(i,(N-1)/2){
        if(S[i] != S[(N-1)/2 -1 -i])ok1 = false;
    }
    int lim = N - (N+3)/2 + 1;

    rep(i,lim){
        if(S[i+(N+3)/2 -1] != S[N-1-i])ok2 = false;
    }

    if(ok && ok1 && ok2)cout << "Yes" << endl;
    else cout << "No" << endl;

}

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


int main(){
    
    // INPUT
    char l1[3];
    char l2[3];
    cin >> l1 >> l2;

    if(l1[0]==l2[2]
        && l1[1] == l2[1]
        && l1[2] == l2[0]) 
      cout << "YES" << endl;
    else 
      cout << "NO" << endl;

}

Measured memory_bytes: 256
# E

class UnionFind():
    def __init__(self, n):
        # 根なら-size, 子なら親のIDを持つ配列
        # 最初は全て根(size:-1)として初期化する
        self.par = [-1]*n

    # 親のIDを検索する再帰関数
    def Find(self, x):
        # 親の場合、IDを返す
        if self.par[x] < 0:
            return x
        # 子の場合、その親IDで再帰呼出しする
        # 経路縮約のため、呼び出した結果で辺を張り直す
        self.par[x] = self.Find(self.par[x])
        return self.par[x]

    def Union(self, x, y):
        # 根を見つける
        x = self.Find(x)
        y = self.Find(y)

        # 同じ木だったら結合しない
        if (x==y): 
            return False
        # 常に大きい方に小さい方の木を繋げる
        if (self.par[x]>self.par[y]):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        return True
    
    def isSameGroup(self, x, y):
        return self.Find(x)==self.Find(y)
    
    def Size(self, x):
        return self.par[self.Find(x)]*-1

    def Show(self):
        return self.par

n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.Union(x, y)

ans = 0
for i in uf.Show():
    if i<0:
        ans += 1

print(ans)

Measured memory_bytes: 5432
#include <iostream>
#include <vector>

using namespace std;

int a, b, k;

int main(){
        cin >> a >> b >> k;

        vector<int> s;
        for (int i=1; i<=min(a,b); i++) {

                if (a%i == 0 && b%i ==0)
                        s.push_back(i);
        }

        cout << s[s.size()-k] << endl;

        return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  putStrLn $ if solve n m as then "Yes" else "No"


solve :: Int -> Int -> [Int] -> Bool
solve n m as = (length $ filter (choosable total m) as) >= m
  where
    total = sum as

choosable :: Int -> Int -> Int -> Bool
choosable total m a = 4*m * a >= total

test :: IO ()
test = do
  print $ solve 4 1 [5, 4, 2, 1] == True
  print $ solve 3 2 [380, 19, 1] == False
  print $ solve 12 3 [4, 56, 78, 901, 2, 345, 67, 890, 123, 45, 6, 789] == True
  putStrLn "test finished"


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll dp[100100][3];
ll N,K,R,S,P,ans;
string T;
bool pre;

int main(){
    cin>>N>>K>>R>>S>>P>>T;
    rep(i,K){
        if(T[i]=='r')ans+=P;
        if(T[i]=='s')ans+=R;
        if(T[i]=='p')ans+=S;
    }
    for(int i=0;i<K;i++){
        pre=true;
        for(int j=i+K;j<N;j+=K){
            if(T[j]==T[j-K]&&pre){
                pre=false;
            }
            else{
                if(T[j]=='r')ans+=P;
                if(T[j]=='s')ans+=R;
                if(T[j]=='p')ans+=S;
                pre=true;
            }
        }
    }
    out(ans);

}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
tmpmonster =0
tmphuman = 0
killnum = 0
for i in range(n):
  #step1
  if b[i] >= a[i]:
    killnum += a[i]
    b[i] -= a[i]
  else:
    killnum += b[i]
    b[i] = 0
  #step2
  if b[i] >= a[i+1]:
    killnum += a[i+1]
    a[i+1] = 0
  else:
    killnum += b[i]
    a[i+1] -= b[i]
print (killnum)

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

int main(){
    string X, Y;
    cin >> X >> Y;
    if(X > Y){
        cout << ">" << endl;
    }
    else if(X == Y){
        cout << "=" << endl;
    }
    else{
        cout << "<" << endl;
    }
}

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

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a <= 0 && 0 <= b) {
		printf("Zero\n");
	}
	else if (a < 0) {
		int cnt = min(b, -1) - a + 1;
		if (cnt % 2 == 0) {
			printf("Positive\n");
		}
		else {
			printf("Negative\n");
		}
	}
	else {
		printf("Positive\n");
	}
	return 0;
}

Measured memory_bytes: 128
x=[]

n=int(input())
d1={}
for i in range(n):
  s=input()
  x.append(s)
  if s in d1:
    d1[s]+=1
  else:
    d1[s]=1
    
m=int(input())
d2={}
for i in range(m):
  t=input()
  x.append(t)
  if t in d2:
    d2[t]+=1
  else:
    d2[t]=1

ans=0
for s in x:
  cnt=0
  if s in d1:
    cnt+=d1[s]
  if s in d2:
    cnt-=d2[s]
  if ans<cnt:
    ans=cnt

print(ans)


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,h,m; cin>>a>>b>>h>>m;
  
  double d1=360.0/12*h+360.0/12/60*m;
  double d2=360.0/60*m;
  // cout<<d1<<' '<<d2<<endl;
  
  double r1 = d1 * PI / 180.0; // hour
  double r2 = d2 * PI / 180.0; // mi
  
  double x1=sin(r1)*a;
  double x2=sin(r2)*b;
  double x=abs(x1-x2);
  
  
  double y1=cos(r1)*a;
  double y2=cos(r2)*b;
  double y=abs(y1-y2);
  
  
  // coutd(x);
  // coutd(y);
  
  double ans=sqrt(x*x+y*y);
  coutd(ans);
  
}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int root=0;
	for(int i=0;i<=(int)sqrt((double)n);++i){
		root=max(root,i*i);
	}
	printf("%d\n",root);
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("03")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"

const int mod=100000007;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	ll sum=0;
	for(int i=1;i<n;i++) {
		if(a[i]<a[i-1]) {
			sum+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout << sum;
}



Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> b = a;
	sort(all(a));
	auto r = unique(all(a));
	a.erase(r, a.end());
	dunk(a.size() == b.size() ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const ll mod = 1e9+7;
int main(){
    int n, m; cin >> n >> m;
    ll xsum = 0, ysum = 0;
    vector<ll> x(n),y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    rep(i,n){
        xsum += ((2*i-n+1)*x[i]) % mod;
        xsum %= mod;
    }
    rep(i,m){
        ysum += ((2*i-m+1)*y[i]) % mod;
        ysum %= mod;
    }
    cout << (xsum*ysum) % mod << endl;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const long long MOD = 1000000007;

ll modPow(int a, int p) {
    if (p == 0) return 1;
    if (p%2==0) {
        ll half = modPow(a, p/2);
        return half * half % MOD;
    }
    else return a * modPow(a, p-1) % MOD;
}

ll calcComb(int a, int b) {
    if (b > a-b) return calcComb(a, a-b);
    ll num = 1, den = 1;
    rep(i, b) num = num * (a-i) % MOD;
    rep1(i, b) den = den * i % MOD;
    return num * modPow(den, MOD-2) % MOD;
}

int main(){
    int n, m;
    cin >> n >> m;
    vi b;
    for (int i=2; i*i<=m; ++i) {
        int cnt = 0;
        while (m%i==0) {
            m /= i;
            ++cnt;
        }
        if (cnt > 0) b.pb(cnt);
    }
    if (m!=1) b.pb(1);
    ll ans = 1;
    /*
    rep(i, sz(b)) printf("%d ", b[i]);
    cout << endl;
    return 0;
    */
    for (int a : b) {
        ans = ans * calcComb(a+n-1, n-1) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
      using namespace std;
      #define ll long long
      #define pb push_back
      #define pll  pair <long long,long long>
      #define mp make_pair
      #define ss second
      #define ff first
      #define maa 1000000007
      #define endl '\n'
      #define ld long double
      #define all(x) x.begin(),x.end()
      ll  power(ll  i,ll  j)
      {
        if(j==0)
        return 1 ;
        ll t=power(i,j/2)%maa ;
        if(j%2==0)
        return (t%maa*t%maa)%maa ;
        else
        return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
      }
      bool is(ll  i)
      {
        if(i==1)
            return 0 ;
        ll  f=0 ;
        for(ll  j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                f=1 ;
                break ;
            }
        }
        return !f ;
      }
      ll n,k ;
      ll r[100001] ;
      ll dp[100001];
      ll fun(ll i)
      {
          if(i==0)
          {
              return 0 ;
          }
          else if(dp[i]!=-1)
          return dp[i] ;
          else
          {
              ll ans=1 ;
              for(ll j=1;j<=n;j++)
              {
                  if(r[j]<=i)
                  {
                      ans&=fun(i-r[j]) ;
                  }
              }
              ans=!ans ;
              return dp[i]=ans ;
          }
      }
      int main()
      {

        /// 50-4
        /// freopen("input.txt","r",stdin);
        /// freopen("output.txt","w",stdout);
        cin>>n>>k ;
        for(ll i=1;i<=n;i++)
        cin>>r[i] ;
        
        for(ll i=0;i<100001;i++)
        {
           dp[i]=-1  ;
        }
        ll ans=fun(k) ;
        if(ans==1)
        cout<<"First"<<endl ;
        else
        cout<<"Second"<<endl ;
       
        
        

      }








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

int main()
{
	int x,y;
	cin>>x>>y;
	int cnt1,cnt2;
	cnt1=(y-2*x)/2;
	cnt2=x-cnt1;
	if(cnt1>=0&&cnt2>=0&&cnt1*4+cnt2*2==y)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,m;
  cin >> m >> k;
  ll ma = 1;
  for(i=0;i<m;i++)ma*=2;
  if(k==0){
    for(i=0;i<ma;i++){
      cout << i << " " << i << " ";
    }
    cout << endl;
    return 0;
  }
  if(ma-1<k){
    cout << -1 << endl;
    return 0;
  }else{
    ll x=0;
    for(i=1;i<ma;i++){
      if(i!=k)x^=i;
    }
    if(x!=k){
      cout << -1 << endl;
      return 0;
    }else{
      cout << 0 << " " << k << " " << 0 << " ";
      for(i=1;i<ma;i++){
        if(i!=k)cout << i << " ";
      }
      cout << k << " ";
      for(i=ma-1;i>=1;i--){
        if(i!=k)cout << i << " ";
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  ll ans;
  if(abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  ll sumn = 1;
  ll summ = 1;
  FOR(i, 1, n + 1) {
    sumn = (sumn * i) % mod;
  }
  FOR(i, 1, m + 1) {
    summ = (summ * i) % mod;
  }

  if(n == m) sumn = sumn * 2 % mod;
  ans = (sumn * summ) % mod;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int K;
    cin >> K;
    
    if (K % 2 == 0) {
        cout << K * K / 4 << endl;
    } else {
        cout << (K + 1) * (K - 1) / 4 << endl;
    }
    return 0;
}


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

ll power(ll a, ll b)
{
  ll res=1;
  while(b>0)
  {
    if(b%2!=0)
    {
      res*=a;
    }
    a*=a;
    b/=2;
  }
  return res;
}
int main()
{
  ll h;
  cin>>h;
  ll x=(log2(h));
  x++;
  //cout<<x<<"\n";
  ll res=power(2,x)-1;
  cout<<res;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
main()
{
	int d;cin>>d;
	while(d--)
	{
		int N;
		cin>>N;
		vector<string>ans(N,string(N,' '));
		int r=0;
		int x=N-1,y=0;
		int id=0,pre=-114514;
		while(true)
		{
			ans[x][y]='#';
			bool flag=false;
			int pr=r;
			for(int i=0;i<4;i++,r=(r+1)%4)
			{
				int tx=x+dx[r]*2,ty=y+dy[r]*2;
				if(tx>=0&&ty>=0&&tx<N&&ty<N)
				{
					if(ans[tx][ty]!='#')break;
				}
				else
				{
					tx-=dx[r];ty-=dy[r];
					if(!(tx<0||ty<0||tx>=N||ty>=N))break;
				}
				if(i==3)
				{
					flag=true;
					break;
				}
			}
			if(flag)break;
			id++;
			if(pr!=r)
			{
				if(id==pre+1)break;
				pre=id;
			}
			x+=dx[r],y+=dy[r];
		}
		for(int i=0;i<N;i++)cout<<ans[i]<<endl;
		if(d)cout<<endl;
	}
}



Measured memory_bytes: 3056