akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<61)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))

//ワーシャルフロイド
//頂点数（と隣接行列）を引いて全点間最短距離を返す
//O(V^3)
//*
ll cost[110][110];
ll dddd[110][110];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)dddd[i][j]=cost[i][j];//辺が無いところはINFにする前処理が必要
	rep(k,0,n)rep(i,0,n)rep(j,0,n)dddd[i][j]=min(dddd[i][j],dddd[i][k]+dddd[k][j]);
}
//*/

int main(){
	int n,m,s,g1,g2;
	while(scanf("%d%d%d%d%d",&n,&m,&s,&g1,&g2),n){
		s--,g1--,g2--;
		rep(i,0,n)rep(j,0,n)cost[i][j]=(i==j?0:INF);
		rep(_,0,m){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			x--,y--;
			cost[x][y]=z;
		}
		waasharuhuroido(n);
		ll ans=INF;
		rep(i,0,n)ans=min(ans,dddd[s][i]+dddd[i][g1]+dddd[i][g2]);
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
const int N = 2*1e5;
int n;
int Find(int *f, int x)
{
    if(f[x] == x)
        return x;
    else
    {
        f[x] = Find(f, f[x]);
        return f[x];
    }
}
void Merge(int *f, int x, int y)
{
    x = Find(f, x);
    y = Find(f, y);
    if(x != y)
        f[y] = x;
}
int f[N], g[N], vis[N];
vector<int> vec[N];
map<int, int> q;
void init()
{
    for(int i = 0; i <= n; i++)
        f[i] = g[i] = i;
}
int main()
{
    int k, l, u, v;
    scanf("%d %d %d", &n, &k, &l);
    init();
    while(k--)
    {
        scanf("%d %d", &u, &v);
        Merge(f, u, v);
    }
    while(l--)
    {
        scanf("%d %d", &u, &v);
        Merge(g, u, v);
    }
    memset(vis, 0, sizeof(vis));
    for(int i = 1; i <= n; i++) vec[Find(f, i)].push_back(i);
    for(int i = 1; i <= n; i++)
    {
        q.clear();
        for(int j = 0; j < vec[i].size(); j++)
        {
            q[Find(g, vec[i][j])]++;
        }
        for(int j = 0; j < vec[i].size(); j++)
        {
            vis[vec[i][j]] += q[Find(g, vec[i][j])];
        }
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%d", vis[i]);
        if(i == n) printf("\n");
        else printf(" ");
    }
    return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 3e2;
int n, a, b, c;
double dp[nsz + 5][nsz + 5][nsz + 5];

double dfs(int a, int b, int c) {
    if (dp[a][b][c] != -1)  return dp[a][b][c];
    if (a + b + c == 0)  return 0;
    double &val = dp[a][b][c], tmp = (double) (n - a - b - c) / n;
    val = (double) n / (a + b + c);
    if (a >= 1) {
        val += (double) a / (a + b + c) * dfs(a - 1, b, c);
    }
    if (b >= 1) {
        val += (double) b / (a + b + c) * dfs(a + 1, b - 1, c);
    }
    if (c >= 1) {
        val += (double) c / (a + b + c) * dfs(a, b + 1, c - 1);
    }
    return val;
}

int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    cont (i, n) {
        int cnt;
        cin >> cnt;
        a += cnt == 1;
        b += cnt == 2;
        c += cnt == 3;
    }
    fill(dp[0][0], dp[0][0] + sizeof(dp) / sizeof(double), -1);
    cout << fixed << setprecision(12) << dfs(a, b, c) << ln;
}

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

#define PI 3.14159265359

int main()
{
    int d, a;
    char c;
    int r = 90;
    double x, y;

    while (cin >> d >> c >> a) {
        if (d == 0 && a == 0) {
            break;
        }
        else {
            double ans = r * (PI / 180.0);
            x += d * cos(ans);
            y += d * sin(ans);
            r += a;
        }
    }
    cout << -1 * (int)x << endl;
    cout << (int)y << endl;

    return (0);
}

Measured memory_bytes: 3344
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>

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

using namespace std;
using p = pair<int, int>;
using ll = long long;



int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	vector<int> count(n);
	rep(i, n)cin >> h[i];
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		
		if (h[a-1] > h[b-1]) count[b - 1]++;
		else if (h[b - 1] > h[a - 1])count[a - 1]++;
		else {
			count[a - 1]++;
			count[b - 1]++;
		}
	}

	int ans = 0;
	rep(i, n)if (count[i] == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		int num = 31;
		cout << num << endl;
		int k = 0;
		while (num!=1) {
			num -= as[k];
			cout << num << endl;
			num -= 5 - as[k];
			cout << num << endl;
			k++;
			k %= N;
		}
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a;cin>>a;
    int h=a/3600;
    int m=(a-h*3600)/60;
    int s=a-3600*h-60*m;
    cout<<h<<":"<<m<<":"<<s<<endl;
   
}




Measured memory_bytes: 3092
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 5050, mod = 1e9 + 7;
int s[maxn][maxn], q[maxn][maxn], bp[15][maxn], res[maxn], tmp[maxn], n;
void add(int &a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
void mul(int *a, int *b, int *c) {
	for(int i = 0; i <= n; i++)
		for(int j = 0; i + j <= n; j++)
			add(c[i+j], a[i]*1ll*b[j]%mod);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	string st; cin >> st;
	s[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= i; j++) {
			add(s[i+1][j+1], s[i][j]*2ll%mod);
			add(s[i+1][max(0, j-1)], s[i][j]);
		}
	}
	q[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= i; j++) {
			add(q[i+1][j+1], q[i][j]*2ll%mod);
			if(j) add(q[i+1][j-1], q[i][j]);
		}
	}
	for(int i = 0; i <= n; i++) bp[0][i] = q[i][0];
	for(int i = 1; i < 15; i++) mul(bp[i-1], bp[i-1], bp[i]);
	res[0] = 1;
	for(int x = st.size(),i = 0; i < 13; i++) {
		if(!((x>>i)&1)) continue;
		memset(tmp, 0, sizeof tmp);
		mul(res, bp[i], tmp);
		for(int i = 0; i <= n; i++) swap(res[i], tmp[i]);
	}
	int ans = 0;
	for(int i = 0; i <= n-st.size(); i++) {
		add(ans, res[i]*1ll*s[n-st.size()-i][0]%mod);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 197632
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a_list = list(list(map(int, input().split())) for _ in range(n))
ans = 0

for i in range(n):
    s = 0
    for j in range(m):
        s += a_list[i][j] * b[j]
    if s + c > 0:
        ans += 1
print(ans)


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


int main() {

  int K,N;
  cin >> K >> N;
  vector<int> outi(N);
  vector<int> kyori(N);

  cin >> outi.at(0);

  for(int i=1; i<N; i++){
    cin >> outi.at(i);
    kyori.at(i-1) = outi.at(i) - outi.at(i-1);
  }

  kyori.at(N-1) = (K-outi.at(N-1))+outi.at(0);

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

  int ans = K-kyori.at(N-1);
  
  cout << ans << endl;
  
  return 0;

}


Measured memory_bytes: 1792
input = raw_input

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: # choufuku
                divisors.append(n//i)
    # divisors.sort()
    return divisors

def f(x, d):
    out = (x+d) ** 5 - x ** 5
    return out

ds = make_divisors(x)
#ds = ds1 + [-d for d in ds1]
#print("ds", ds)

found = False
for d in ds:
    if found:
        break

    d0 = d
    if d0 % 2 == 0:
        b = -d0 // 2
    else:
        b = -d0 // 2 + 1

    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b += 1

    if found:
        break

    #b = -1
    if d0 % 2 == 0:
        b = -d0 // 2
    else:
        b = d0 // 2 - 1

    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret > x:
            break
        b -= 1

    if found:
        break

    d0 = d
    d = -d
    
    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 + 1

    while True:
        aa = b+d
        bb = b
        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b += 1

    if found:
        break

    if d0 % 2 == 0:
        b = d0 // 2
    else:
        b = d0 // 2 - 1
    while True:
        aa = b+d
        bb = b

        ret = f(b, d)
        #print(aa, bb, d, ret)
        
        if x == ret:
            found = True
            a = b+d
            b = b
            break
        elif ret < x:
            break
        b -= 1


assert found
print("%d %d" % (a, b))

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

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

using namespace std;

int main(){
	int n,m; cin>>n>>m;
	int a[50],b[50],c[50],d[50];
	rep(i,n) cin>>a[i]>>b[i];
	rep(i,m) cin>>c[i]>>d[i];

	rep(i,n){
		int j=0;
		rep(k,m) if(abs(a[i]-c[k])+abs(b[i]-d[k])<abs(a[i]-c[j])+abs(b[i]-d[j])) j=k;
		cout<<j+1<<'\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(unsigned ll i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define M 1000000007LL
vi r,g,b;
void solve()
{
    ll n; cin>>n;
    ll ans=0;
    rep(i,1,n+1)
    {
        if(i%3==0 || i%5==0) continue;

        ans+=i;
    }
    cout<<ans;

}

int main()
{
    SPEED;
    ll t = 1;

   //cin>>t;

    while(t--) solve();

   return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int dx = tx - sx;
	int dy = ty - sy;

	for (int i = 0; i < dx; i++)
	{
		cout << "R";
	}
	for (int i = 0; i < dy; i++)
	{
		cout << "U";
	}


	for (int i = 0; i < dx; i++)
	{
		cout << "L";
	}
	for (int i = 0; i < dy; i++)
	{
		cout << "D";
	}

	cout << "D";
	for (int i = 0; i < dx+1; i++)
	{
		cout << "R";
	}
	for (int i = 0; i < dy+1; i++)
	{
		cout << "U";
	}
	cout << "L";

	cout << "U";
	for (int i = 0; i < dx+1; i++)
	{
		cout << "L";
	}
	for (int i = 0; i < dy+1; i++)
	{
		cout << "D";
	}
	cout << "R";


}





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

using namespace std;

const int MAXN = 2005;

typedef long long llint;

llint n, x, sol;
llint a[MAXN * 2], mn[MAXN][MAXN];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        a[i + n] = a[i];
        mn[0][i] = a[i];
        sol += a[i];
    }
    for (int ofs = 1; ofs < n; ofs++) {
        llint res = ofs * x;
        for (int i=0; i<n; i++) {
            mn[ofs][i] = min(mn[ofs - 1][i], a[n + i - ofs]);
            res += mn[ofs][i];
        }
        sol = min(sol, res);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    int ans=0;
    int sum=0;
    cin>>a>>b>>c;
    while(sum<c){
        ans+=1;
        sum+=a;
        if(ans%7==0){
            sum+=b;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 1e5+5;
//int A[maxn];
int edges[maxn];
int N,M;

int main()
{
    scanf("%d %d",&N,&M);
    _rep(i,1,N){
        edges[i] = maxn;
    }
    _rep(i,1,M){
        int a,b;scanf("%d %d",&a,&b);
        edges[a] = min(edges[a],b);
    }
    int rr = -1;
    int ans = 0;
    _rep(i,1,N){
        int l = i;
        int r = edges[i];
        if(r == maxn) continue;
        if(l >= rr){
            ans++;
            rr = r;
        }
        if(rr > r){
            rr = r;
        }

    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
n=int(input())
s=input()
r=0
g=0
b=0
for i in range(n):
  if s[i]=="R":
    r+=1
  elif s[i]=="G":
    g+=1
  else:
    b+=1
ans=r*b*g
for i in range(n):
  for j in range(i,n):
    k=2*j-i
    if k>=n: break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans-=1

print(ans)

Measured memory_bytes: 68212
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    ll n, k; cin >> n >> k;
    vector<ll> A(n+10); A.push_back(-1);
    rep(i, n) cin >> A[i+1];

    vector<ll> visited(200200, -1);
    visited[1] = 0;
    vector<ll> pass; pass.push_back(1);

    ll rp = 0, nrp = 0, cur = 1;
    for(ll i=1; i<=n; i++){
        if(i > k) break;
        ll next = A[cur];
        if(visited[next] == -1){
            pass.push_back(next);
            visited[next] = i;
            cur = next;
        }else{
            rp = i - visited[next];
            nrp = pass.size() - rp;
            break;
        }
    }
    if(rp == 0) rp = pass.size();
    ll x = (k - nrp) % rp;
    cout << pass[nrp + x] << ln;
}


Measured memory_bytes: 9620
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;


int dp[3010][3010];
int main(){
    string s,t;
    cin >> s >> t;
    rep(i,3010){
        rep(j,3010){
            dp[i][j] = 0;
        }
    }

    int n,m;
    n = s.length();
    m = t.length();

    rep(i,n){
        rep(j,m){
            if(s[i] == t[j]){
                dp[i+1][j+1] = max(dp[i][j] + 1, dp[i][j+1]);
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]); 
            }else{
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }

    
    int len = dp[n][m];
    string ans = "";
    int i = n-1;
    int j = m-1;
    while(len > 0){
        if(s[i] == t[j]){
            ans += s[i];
            i--;
            j--;
            len--;
        }else if(dp[i+1][j+1] == dp[i][j+1]){
            i--;
        }else{
            j--;
        }
    }
    
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  string s;
  cin >> n >> s;
  rep(i, s.size()) {
    int x = s[i]-'A';
    x = (x+n)%26;
    s[i] = char('A'+x);
  }
  cout << s << endl;
}


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

int main()
{
	int ta,ji,sa,si,ha;

	cin >> ta;
	if (ta<40)
		ta=40;
	cin >> ji;
	if (ji<40)
		ji=40;
	cin >> sa;
	if (sa<40)
		sa=40;
	cin >> si;
	if (si<40)
		si=40;
	cin >> ha;
	if (ha<40)
		ha=40;




	cout << (ta+ji+sa+si+ha)/5 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>                                                                
using namespace std;                                                               
                                                                                   
int main(void) {                                                                   
  int n;                                                                           
  cin >> n;                                                                        
  for (int i=1; i<=n; i++) {                                                       
    if (i%3==0) {                                                                  
      cout << " " << i << flush;                                                   
      continue;                                                                    
    }                                                                              
    int x = i;                                                                     
    while (x!=0) {                                                                 
      if (x%10==3) {                                                               
        cout << " " << i << flush;                                                 
        break;                                                                     
      }                                                                            
      x /= 10;                                                                     
    }                                                                              
  }                                                                                
  cout << endl;                                                                    
  return 0;                                                                        
}                                                                                  
                  

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; string s; cin >> n >> s;
    int ans = 1;
    for (int i = 0; i < n-1; i++)
    {
        if (s[i] != s[i+1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define n_MAX 100001
int main(){
  int x,n,j,tmp1=0,tmp2=0,i;
  scanf("%d",&n);
  int A[n];
  for(i = 1;i<=n ;i++){
    scanf("%d",&A[i]);
  }
  
  x = A[n];
  i = 0;
  for(j = 1 ;j<=n-1;j++){
    if(A[j] <=x){
      i = i+1;
    tmp1 = A[j];
    A[j] =A[i];
    A[i] =tmp1;
    }
  }
    tmp2 = A[n];
    A[n] = A[i+1];
    A[i+1] = tmp2;
    
  for(j = 1 ;j<n+1 ;j++){
    if(j == n){
      printf("%d\n",A[j]);}
    else  if(j==i+1){ printf("[%d] ",A[j]);}
    else printf("%d ",A[j]);
  }
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

bool yaku(int n) {
	int i, j, k;

	k = sqrt(n);
	if (n <= 3) {
		return true;
	}
	for (i = 2; i <= k; i++) {
		if (n%i == 0)
			return false;
	}

	return true;
}

int main() {
	int n, i, j, k, x;
	lli ans, s;

	cin >> n;

	s = pow(10, 9) + 7;

	ans = 1;
	for (i = 2; i <= n; i++) {
		k = 0;
		for (j = 1; j <= n; j++) {
			x = j;
			if (yaku(i)) {
				while (x%i == 0) {
					k++;
					x /= i;
				}
			}
		}
		ans *= (k + 1);
		ans %= s;

	}

	cout << ans;

	return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=2e5+1, mod= 1e9+7;


int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,res=0;  string s;
	cin>>n>>s;
	int i=0;
	while(i<n){
		int j=i;
		while(s[i]==s[j])j++;
		i=j;
		res++;
	}
	cout<<res;
	
    yogeshk972();
}


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

int main(void){
    string s; cin >> s;
    vector<bool>exist('z',false);
    for(int i=0;i<s.length();i++){
        exist[s[i]] = true;
    }
    for(int i='a';i<='z';i++){
        if(exist[i]==false){
            cout << char(i) << endl;
            return 0;
        } 
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
def find_mine_num(H, W, S, current_H, current_W):
    if S[current_H][current_W] == '#':
        return '#'
    mine_count = 0
    # 左斜め上、上、右斜め上
    find_H_position = current_H - 1
    for i in range(-1, 2):
        find_W_position = current_W + i
        if 0 <= find_H_position < H and 0 <= find_W_position < W:
            if S[find_H_position][find_W_position] == '#':
                mine_count += 1
    # 左、右
    if 0 <= current_W - 1 < W:
        if S[current_H][current_W - 1] == '#':
            mine_count += 1
    if 0 <= current_W + 1 < W:
        if S[current_H][current_W + 1] == '#':
            mine_count += 1
    # 左斜め下、下、右斜め下
    find_H_position = current_H + 1
    for i in range(-1, 2):
        find_W_position = current_W + i
        if 0 <= find_H_position < H and 0 <= find_W_position < W:
            if S[find_H_position][find_W_position] == '#':
                mine_count += 1
    return mine_count


H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
S_mine = []
for i in range(H):
    mine = []
    for j in range(W):
        mine.append(find_mine_num(H, W, S, i, j))
    S_mine.append(mine)
for s in S_mine:
    print(*s, sep='')


Measured memory_bytes: 3572
#! python3
import math
def main():
    a, b, n =map(int, input().split())
    if b > n:
        ans = (math.floor(a*n/b) -a*math.floor(n/b))
    else :
        c = b-1
        ans = (math.floor(a*c/b) -a*math.floor(c/b))

    print(ans)

main()

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MAXN 200000
#define DEBUG true

/*
sz[u] -> Size of subtree rooted at node u
cnt[c] -> Number of nodes below a subtree rooted at node with color c
sum[c] -> Number of paths which doesn't go through a node with color c
*/

int N, c[MAXN + 3], cnt[MAXN + 3], sz[MAXN + 3];
LL sum[MAXN + 3];
vector<int> adj[MAXN + 3];

LL numWays(int n) {
    return ((LL) n * n + n)/2;
}

void DFS(int u, int prv) {
    sz[u] = 1;
    for (auto v: adj[u]) {
        if (v == prv) continue;

        int prvCnt = cnt[c[u]];

        DFS(v, u);

        int cntOther = sz[v] - (cnt[c[u]] - prvCnt); //Number of nodes below u whose color is not c[u].

        sum[c[u]] += numWays(cntOther);
        cnt[c[u]] += cntOther;

        sz[u] += sz[v];
    }

    cnt[c[u]] += 1;
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> c[i];

    for (int i = 1; i < N; i++) {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    memset(sz, 0, sizeof(sz));
    memset(cnt, 0, sizeof(cnt));
    memset(sum, 0, sizeof(sum));

    DFS(1, 1);

    for (int c = 1; c <= N; c++) {
        LL all = numWays(N);

        //Using DFS above, we only count number of paths below a node. We also need to count number of path above it.
        LL aboveCnt = (sz[1] - cnt[c]);

        cout << all - (sum[c] + numWays(aboveCnt)) << endl;
    }
}


Measured memory_bytes: 34072
#include<stdio.h>

int main(void){
	int a, b, c, d;

	while (scanf("%d %d", &a, &b) != EOF) {
		c = a + b;
		d = 0;

		while (c > 0) {
			c = c / 10;
			d++;
		}

		printf("%d\n", d);
	}

	return 0;
}

Measured memory_bytes: 0
main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    as <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    bs <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    print $ maximum $ solve as (reverse bs) k

solve [] [] km = []
solve [] _ km = []
solve _ [] km = []
solve (a:as) (b:bs) km | (sum . map snd) [a,b] <= km = [(sum . map fst) [a,b]] ++ solve as (b:bs) km
                       | otherwise = solve (a:as) bs km


Measured memory_bytes: 124596
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
   



int main(){
   IOS

   int l, r, d; cin>>l>>r>>d;
   
   int cnt = 0;

   for(int i = 0; i <= 200; i+=d){
      if(i >= l and i <= r)cnt++;
   }
   cout<<cnt<<"\n";




}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
   if(b&1) res = res * a % mod;
        a = a * a % mod;
   b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3600
def main():
    import numpy as np
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    X=np.array(X)
    Xp,Xz,Xm=X[X>0],X[X==0],X[X<0]
    lp,lm=len(Xp),len(Xm)

    if 0 in Xz:
        k-=1
    if k==0:
      print(0)
      exit()
      
    ans=10**9
    if k<=lp:
        ans=min(ans,Xp[k-1])
    if k<=lm:
        ans=min(ans,-Xm[-k])

    for i in range(lp):
        j=k-i-1
        if 0<j<=lm:
            ans=min(ans,Xp[i]*2-Xm[-j])
        else:
            continue
        
    for i in range(lm,0,-1):
        j=k-i-1
        if 0<=j<lp:
            ans=min(ans,Xm[-i]*(-2)+Xp[j])
        else:
            continue
    print(ans)
   
if __name__=='__main__':
    main()

Measured memory_bytes: 23096
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

fn solve() {
	let n = read!(usize);
	println!("{}", (n+1)/2);
}

fn run() {
    solve();
}


Measured memory_bytes: 8572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		//fill In first line
		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		//fill in second line
		String[] t = scanner.nextLine().split(" ");
		int[] list = new int[n];

		for(int i = 0; i < n; i++) {

			list[i] = Integer.parseInt(t[i]);

		}

		//easy sort
		int minimum = list[0];
		int times = 0;
		for(int i = 1; i < n; i ++) {
			if(minimum == list[i]) {
				times++;
			}
			if(minimum > list[i]) {
				times = 0;
				minimum = list[i];
			}
		}

		//control
		int ans = 0;
		n -= times;
		while(n > 0) {
			if(n <= k) {
				n -= n;
				ans++;
			}else {
				n -= k - 1;
				ans++;
			}
		}
		System.out.println(ans);

	}

}

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

// --- MOD begin --- cut here ---

ll MOD = 1e9 + 7;
// ll MOD = 998244353;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

constexpr ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(a, b, dummy1, dummy2);
}

struct Fp {
  ll val;

  Fp(ll t = 0) :
    val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {}

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

class Comb {
  int nMax;
  vector<Fp> vFact;
  vector<Fp> vInvFact;
public:
  Comb(int nm) : nMax(nm), vFact(nm+1), vInvFact(nm+1) {
    vFact.at(0) = 1;
    for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i-1);
    vInvFact.at(nMax) = vFact.at(nMax).inv();
    for (int i = nMax; i >= 1; i--) vInvFact.at(i-1) = i * vInvFact.at(i);
  }
  Fp fact(int n) { return vFact.at(n); }
  Fp comb(int n, int r) {
    return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n-r);
  }
  // The number of permutation extracting r from n.
  Fp perm(int n, int r) {
    return vFact.at(n) * vInvFact.at(n-r);
  }
};

/* 
   Power function    power(a, b) == a^b
   Speed is O(log b).
   The same source code can be used for integers by replacing
   Fp with int etc.  Unfortunately, replacing Fp with auto does not
   make the function generic for int and Fp.
 */
Fp power(Fp a, int b) {
  Fp twoPow = a;
  Fp rv = 1;
  while (b > 0) {
    if (b & 1) rv *= twoPow;
    twoPow *= twoPow;
    b >>= 1;
  }
  return rv;
}

// --- MOD end --- cut here ---



int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll H, W, A, B; cin >> H >> W >> A >> B;
  Comb cb(H+W);
  Fp tot = cb.comb((H-1) + (W-1), H-1);
  Fp ng = 0;
  for (int i = 0; i < B; i++) {
    ng += cb.comb(i+H-A-1, i) * cb.comb(W-i-1+A-1, A-1);
  }
  cout << (ll)(tot - ng) << endl;

  return 0;
}



Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;


using ll = long long int;

/// <summary>
/// GCDを計算します
/// </summary>
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
	if (a < b) {
		NumType tmp = a;
		a = b;
		b = tmp;
	}

	NumType r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

/// <summary>
/// 約数を数えます
/// </summary>
template <typename NumType>
NumType cntDivisor(const NumType& num) {
	NumType cnt = 0;
	for (NumType i = 1; i * i <= num; ++i) {
		if (num % i == 0) {
			cnt++;
			if (i * i != num) cnt++;
		}
	}

	return cnt;
}

/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"





int main() {
	ll N, Y;
	cin >> N >> Y;

	Y /= 1000;

	for (ll x = 0; x * 10 <= Y; ++x) {
		for (ll y = 0; y * 5 <= Y - x; ++y) {
			ll z = N - x - y;

			if ((10 * x + 5 * y + z != Y)) {
				continue;
			}
			if (z < 0 || x + y + z != N) {
				break;
			}
			cout << x << " " << y << " " << z << endl;
			return 0;
		}
	}

	cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  
  int x=s;
  
  
  vector<int> vec(1000000);
 
  vec.at(1)=x;
  
  int N;
  
 bool flag=false;
  
  for(int i=2;i<1000000;i++){
if(x%2==0){
  x=(x/2);
  
  vec.at(i)=x;
 
}
    else{
      x=(3*x+1);
      
      vec.at(i)=x;
      
     
    }
    
  
  for(int j=1;j<i;j++){
    if(vec.at(j)==vec.at(i)){
      cout<<i<<endl;
      
      flag=true;
      break;
    
  }
  }
  
    
    
    if(flag){
      break;
    
  }
    
}
}

  

    
    
  
  
  
  


 


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    vector< long long int > v;

    for ( long long int i = 0; i < n; i++ ) {

      long long int in;
      cin >> in;
      v.push_back( in );

    }

    double ans;
    long long int ans_s = -1, ans_a, ans_c;

    for ( long long int s = 0; s <= 15; s++ ) {
      for ( long long int a = 0; a <= 15; a++ ) {
	for ( long long int c = 0; c <= 15; c++ ) {

	  long long int r = s;
	  long long int x[256] = {};
	  for ( long long int i = 0; i < n; i++ ) {

	    r = ( a * r + c ) % 256;
	    long long int o = ( v[i] + r ) % 256;
	    x[o]++;

	  }
	  double h = 0.00;
	  for ( long long int i = 0; i < 256; i++ ) {
	    if ( x[i] == 0 ) continue;
	    double b = 1.00 * x[i] / n;
	    h -= b * log( b );
	  }
	  if ( ans_s == -1 || ans - h > 1e-10 ) {
	    ans = h;
	    ans_s = s;
	    ans_a = a;
	    ans_c = c;
	  }

	}
      }
    }

    cout << ans_s << " " << ans_a << " " << ans_c << endl;

  }

  return 0;

}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    Cout(a-b+1);
    return 0;
}


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

void fnInput(vector<int> &rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
} 

void fnTrace(const vector<int> &cnrvnSort)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int> &rvnSort)
{
  for (int nSorting = 1; nSorting < rvnSort.size(); nSorting++)
  {
    int nTrg = rvnSort[nSorting];
    int nSorted = nSorting - 1;

    while (nSorted >= 0          &&
           nTrg  < rvnSort[nSorted])
    {
      rvnSort[nSorted + 1] = rvnSort[nSorted];
      nSorted--;
    }
    rvnSort[nSorted + 1] = nTrg;
    fnTrace(rvnSort);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnSort;

  fnInput(vnSort);
  fnTrace(vnSort);
  fnInsertionSort(vnSort);

  return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll V,E;
    cin >>V>>E;
    vector<vector<ll>> dp(V,vector<ll>(V,INF));
    vector<ll>a(E);
    vector<ll>b(E);
    vector<ll>c(E);
    rep(i,E){
        ll s,t,d;
        cin >> s>> t>>d;
        //s--;
        //t--;
        s--;t--;
        a[i]=s;
        b[i]=t;
        c[i]=d;

        dp[s][t] = d;
        dp[t][s] = d;

    }
    rep(i,V){
        dp[i][i] = 0;
    }

    rep(k,V){
        rep(i,V){
            rep(j,V){
                chmin(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    ll ans=0;
    rep(i,E){
        if(dp[a[i]][b[i]]<c[i]){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,x;
map<int,int> mp;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(mp[x]){
			cout<<"NO";
			return 0;
		}
		mp[x]++;
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 9600
n = int(input())
lis =[0]+list(map(int, input().split()))

b = [0]*(n+1)

for i in reversed(range(1,n+1)):
    ball = 0
    base = i+1

    for j in range(i,n+1,i):
        ball += b[j]
    
    if ball % 2 != lis[i]:
        b[i] = 1

print(sum(b))
print(*[i for i ,b in enumerate(b) if b == 1], sep=' ')

Measured memory_bytes: 17876
package main

import (
	"fmt"
)

func main() {
	var s string
	var r string

	fmt.Scan(&s)

	for _, l := range s {
		switch l {
		case '0':
			r += "0"
		case '1':
			r += "1"
		case 'B':
			if len(r) > 0 {
				r = r[0 : len(r)-1]
			}
		}
	}

	fmt.Println(r)

}


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

int main(){
  string s;
  cin >> s;
  
  string ans;
  if(s[5]=='1') ans = "TBD";
  else if(s[6] > '4') ans = "TBD";
  else ans = "Heisei";
  
  cout << ans << 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 Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  int n;cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(all(v));
  ld now=v[0];
  rep(i,n){
    now=(now+v[i])/2.0;
  }
  cout<<fixed<<setprecision(10);
  cout<<now<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    
    ll sum = 0;
    rep3(i, 1, n) {
        ll add = max(0, a[i - 1] - a[i]);
        sum += add;
        a[i] += add;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3968