akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n), b(n), c(n-1);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n-1) cin >> c[i];
    int ans = 0;
    REP(i,n) {
        ans += b[a[i]-1];
        if(i>0) ans += (a[i]-a[i-1] == 1 ? c[a[i-1]-1] : 0);
    }
    cout << ans << endl;
    return 0;
}

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

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

    vector<long long> a(n);
    for (int i=0; i<n; i++) cin >> a.at(i);

    for (int i=n-1; i>=0; i--) {
        for (int j=2; j*(i+1)-1<n; j++) a.at(i) ^= a.at(j*(i+1)-1);
    }

    long long m=0;

    for (int i=0; i<n; i++) if (a.at(i)) m++;

    cout << m << endl;

    for (int i=0; i<n; i++) {
        if (a.at(i)) cout << i+1 << ' ';
    }

    cout << endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
const ll MAX = 2100000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}

int main()
{
ll k ;
cin >> k ;
string ss ;
cin >> ss ;
ll s=ss.size();
COMinit();
rep(i,k+1){
  ans+=mod(COM(s-1+k-i,s-1)*mod(mypow(25,k-i)*mypow(26,i)));
  ans=mod(ans);
}
cout << ans << endl;
return 0;
}

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

bool compair(const pair<int, int> &x, const pair<int, int> &y){
	return x.second > y.second;
}

signed main(){
	int N, M, i, j, k;
	scanf("%lld%lld", &N, &M);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	sort(A.begin(), A.end());
/*	for(i = 0; i < N; i++){
		printf("%lld ", A[i]);
	}
	printf("\n");
*/	vector<pair<int, int>> BC(M);
	for(i = 0; i < M; i++){
		scanf("%lld%lld", &BC[i].first, &BC[i].second);
	}
	sort(BC.begin(), BC.end(), compair);
	for(i = 0, j = 0; i < M; i++){
//		printf("BC[%lld] = (%lld, %lld)\n", i, BC[i].first, BC[i].second);
		for(k = 0; k < BC[i].first && j + k < N; k++){
			A[j + k] = max(A[j + k], BC[i].second);
		}
		j += k;
	}
/*	for(i = 0; i < N; i++){
		printf("%lld ", A[i]);
	}
	printf("\n");
*/	int ans = 0;
	for(i = 0; i < N; i++){
		ans += A[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
int main(){

long long a,b,n,answer;cin>>n>>a>>b;
vector<long long> ans(4);
if ((b-a)%2==0)
{
    answer = (b-a)/2;
}
else{
    ans[0] = b-1;ans[1] = n-a;ans[2] = (b+a-1)/2;ans[3] = n+(1-a-b)/2;
    answer = *min_element(ans.begin(),ans.end());
}
cout << answer;
return 0;
}




Measured memory_bytes: 256
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r*g*b
for i in range(n):
    for d in range(n):
        j = i+d
        k = j+d
        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: 9200
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;

int main() {
    string s,t;
    cin >> s >> t;
    int ans = 0,len = s.size();
    for(int i = 0;i < len;i++) {
        if(s.at(i) != t.at(i)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  vector<int> v(3);
  rep(i,3)cin>>v[i];
  sort(v.begin(),v.end());
  if(v[2]%2==0){
    cout<<0<<endl;
  }else{
    int a=v[2]/2;
    int b=v[2]-a;
    cout<<(v[0]*v[1]*(abs(a-b)))<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
*d=0;eval"N,_,*A="+`dd`.split*?,;p d[N.times{|i|d[i]&&A.map{|x|d[t=i+[6,7,3,6,5,4,5,5,2][-x]]=[d[t]||0,d[i]*10+x].max}}]

Measured memory_bytes: 27900
import java.util.Scanner;

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

            boolean is = true;
            for (int i = 0; i < S.length(); i++) {
                char c = S.charAt(i);
                if (i % 2 == 0) {
                    if (!(c == 'R' || c == 'U' || c == 'D')) {
                        is = false;
                    }
                } else {
                    if (!(c == 'L' || c == 'U' || c == 'D')) {
                        is = false;
                    }
                }
            }

            System.out.println(is ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 27000
#include <stdio.h>
#include <limits.h>

int main(void)
{
	int pasta = 2000;
	int juice = 2000;
	int i, n;
	
	for (i = 0; i < 3; i++){
		scanf("%d", &n);
		
		if (n < pasta){
			pasta = n;
		}
	}
	
	for (i = 0; i < 2; i++){
		scanf("%d", &n);
		
		if (n < juice){
			juice = n;
		}
	}
	
	printf("%d\n", pasta + juice - 50);
	
	return (0);
}

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

int main()
{
	int a,b,c;
	int count;
	
	cin>>a>>b>>c;
	count=0;
	for( int i=a; i<=b; i++ ) {
		if( 0==(c%i) ) {
			count++;
		}
	}
	cout <<count<<endl;
    
    return 0;
}

Measured memory_bytes: 1164
//


#include <stdio.h>

int main(void){
    int n,i,j,m,ans;
    int t[100],p[100],x[100];
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&t[i]);
    }
    scanf("%d",&m);
    for(i=1;i<=m;i++){
        scanf("%d %d",&p[i],&x[i]);
    }
    for(j=1;j<=m;j++){
        ans=0;
    for(i=1;i<=n;i++){
        if(i==p[j])ans+=x[j];
        else ans+=t[i];
    }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 128
def gcd(x, y):
    if x * y == 0:
        return (x+y)
    x, y = max(x, y), min(x, y)
    while y > 0:
        r = x % y
        x, y = y, r
    return x

n = int(input())
a = [int(i) for i in input().split()]
l_list = [0]
r_list = [0]
for i in range(n):
    l = gcd(l_list[i], a[i])
    l_list.append(l)
    r = gcd(r_list[-1], a[-i-1])
    r_list.append(r)
r_list = list(reversed(r_list))
r_list = r_list[1:]
l_list = l_list[:n]
c_list = []
for i in range(n):
    c_list.append(gcd(l_list[i], r_list[i]))
print(max(c_list))

Measured memory_bytes: 14436
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位


int main(void){
    vector<ll> c(100010);
    ll n;
    cin >> n;
    for(ll i = 1; i <= 50000; i++){
        double check = (double)i*1.08;
        c[i] = (ll) check;
    }
    bool ok = false;
    for(ll i = 0; i <= 50000; i++){
        if(c[i]==n){
            cout << i << endl;
            ok = true;
        }
    }
    if(ok==false)
        cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD 1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){
   int a,b;
   cin>>a>>b;
   int x = min(a,b);
   int y = max(a,b);
   REP(i,y){
       cout<<x;
   }cout<<endl;
}

int main(){   
  
 solve();

 return 0;
}


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


int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！

    string str;
    long N, M;
    priority_queue<long> A;
    long count = 0;
    while(getline(cin, str)){
        stringstream ss;
        ss << str;
        if(count == 0){
            ss >> N;
            ss >> M;
        }
        else{
            for (long i = 0; i < N; ++i) {
                long temp;
                ss >> temp;
                A.push(temp);
            }
            break;

        }


        count++;
    }



    for (long i = 0; i < M; ++i) {
        long MaxElement = A.top();
        A.pop();
        A.push(MaxElement / 2);
    }


    long MinAmount = 0;

    for (long i = 0; i < N;++i) {
        MinAmount += A.top();
        A.pop();
    }


    cout << MinAmount << endl;
    return 0;
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

vector<ll> r(101);
vector<ll> c(101);
vector<vector<ll>> DP(101,vector<ll> (101,-1));

ll inf=1e18;



ll dp(ll l,ll h) {
  if(DP[l][h]>-1) {
    return DP[l][h];
  }
  ll res=inf;
  if(l+1==h) {
    res=0;
  }
  else {
    for(ll i=l+1;i<h;i++) {
      res=min(res,dp(l,i)+dp(i,h)+r[i]*r[l]*c[h-1]);
    }
  }
  return DP[l][h]=res;
}

int main() {
  ll n;
  cin >> n;
  for(ll i=0;i<n;i++) {
    cin >> r[i] >> c[i];
  }
  cout << dp(0,n) << endl;
}


Measured memory_bytes: 3264
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
 
int main(void){
	int n;
	int a[55];

	int c=0;

	bool f=false;

	cin >> n;

	for (int i=2; i < 55555; i++){
		if (c == n){
			break;
		}

		for(int j=2; j < i; j++){
			if (i % j == 0){
				f = true;
				break;
			}
		}

		if(!f){
			if (c >= 1){
				if ( (i - a[c-1]) % 5 == 0){
					a[c] = i;
					c++;
				}
			}
			else{
				a[c] = i;
				c++;
			}
		}

		f = false;
	}



	for (int i=0; i < n; i++)
		cout << a[i] << " ";
 
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll a, b; cin >> a >> b;
  string result;
  if (a*b<=0) result = "Zero";
  else if (a<0 && (b-a+1)%2==1) result = "Negative";
  else result = "Positive";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>

using namespace std;


int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<int>ans(N);
	for (int i = 0; i < N; i++)ans[i] = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			int a = j - i;
			int b = abs(X - 1 - i) + 1 + abs(Y - 1 - j);
			int c = abs(Y - 1 - i) + 1 + abs(X - 1 - j);
			int cost = min(a, b);
			cost = min(cost, c);
			ans[cost]++;
		}
	}
	for (auto it = ans.begin() + 1; it != ans.end(); it++) {
		cout << *it << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll N;
	cin >> N;

	vector<ll> X(N + 1);

	repn(i, N) cin >> X[i];

	ll ans = INF;

	repn(P, 100) {
		ll v = 0;
		repn(i, N) { v += (X[i] - P)*(X[i] - P); }

		ans = min(ans, v);
	}

	cout << ans;
	
	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 200050;

int f[N], head[N], to[N], nex[N], tot, siz[N], n;
void addedge(int u, int v){
	tot ++; to[tot] = v, nex[tot] = head[u], head[u] = tot;
	tot ++; to[tot] = u, nex[tot] = head[v], head[v] = tot;
}
void dfs(int x, int fa){
	int i, emp = 0;
	for(i = head[x]; i; i = nex[i]){
		if(to[i] != fa){
			dfs(to[i], x);
			if(f[to[i]] == 0)
				emp = to[i];
		}
	}
	for(i = head[x]; i; i = nex[i])
		if(to[i] != fa && to[i] != emp)
			f[x] += max(f[to[i]], 1);
}
int main()
{

	int i, j, k;
	scanf("%d", &n);
	for(i = 1; i < n; i ++){
		scanf("%d%d", &j, &k), j ++, k ++;
		addedge(j, k), siz[j] ++, siz[k] ++;
	}
	for(i = 1; i <= n; i ++){
		if(siz[i] >= 3){
			dfs(i, 0);
			break;
		}
	}
	if(i <= n)printf("%d", f[i]);
	else puts("1");

	return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int k = 10001,N = 2000001;
int main(){
  int n;
  cin >> n;
  vector < int > A(N),B(N),C(k,0);
  for(int i = 1 ; i <= n ; i++ ) cin >> A[i];
  for(int j = 1 ; j <= n ; j++ ){
    C[A[j]]++;
  }
  for(int i = 1 ; i <= k ; i++ ){
    C[i] = C[i] + C[i-1];
  }
  for(int j = n ; j >= 1 ; j-- ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(int i = 1 ; i <= n-1 ; i++ ){
    cout << B[i]<<" ";
  }
  cout<<B[n]<<endl;
  return 0;
}


Measured memory_bytes: 18416
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

int main()
{
  int h,n;
  cin>>h>>n;
  vector<P> p(n);
  REP(i,n){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(a,b);
  }

  vector<ll> dp(h+1,INF);
  dp[0]=0;
  REP(i,n){
    REP(j,h){
      int nj=min(h,j+p[i].first);
      dp[nj]=min(dp[nj],dp[j]+p[i].second);
    }
  }
  cout<<dp[h]<<endl;
  
  return 0;
}


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

int main() {
    int H, W, K;
    int black;

    cin >> H >> W >> K;

    char a[H][W];
    int ans = 0;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }

    for (int m_i = 0; m_i < (1 << H); m_i++) {
        for (int m_j = 0; m_j < (1 << W); m_j++) {
            black = 0;

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (((m_i >> i) & 1) == 0 && ((m_j >> j) & 1) == 0 && a[i][j] == '#') {
                        black += 1;
                    }
                }
            }

            if (K == black) {
                ans++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            long iK = long.Parse(sS[1]);
            List<ClsAtoB> lstX = new List<ClsAtoB>();
            for (int i = 0; i < iN; i++)
            {
                sS = Console.ReadLine().Trim().Split(' ');
                int ia = int.Parse(sS[0]);                              // 何が
                int ib = int.Parse(sS[1]);                              // 何個
                lstX.Add(new ClsAtoB() { iA = ia, iB = ib, });
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long lOut = 0L;
            lstX.Sort(delegate (ClsAtoB mca1, ClsAtoB mca2) { return (int)(mca1.iA - mca2.iA); });       // iAの昇順
            long lNow = 0L;
            for (int i = 0; i < lstX.Count; i++)
            {
                lNow += lstX[i].iB;
                if (lNow >= iK) { lOut = lstX[i].iA; break; }
            }

            //出力
            Console.WriteLine("{0}", lOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
        private class ClsAtoB
        {
            public long iA { get; set; } = 0;
            public long iB { get; set; } = 0;
        }

}


Measured memory_bytes: 21968
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  string S;
  cin >> N;
  cin >> S;
  ll ans = 0;

  ll left = 0;
  ll right = (N / 2) + 1;
  vector<string> sub(N);

  while (abs(right - left) > 1) {
    ll mid = left + (right - left) / 2;
    // iは開始位置
    bool ok = false;
    REP(i, N - mid + 1) { sub[i] = S.substr(i, mid); }
    REP(i, N - mid + 1) {
      FOR(j, i + mid, N - mid + 1) {
        if ((i + mid <= j || j + mid <= i) && sub[i] == sub[j]) {
          ok = true;
          break;
        }
      }
      if (ok)
        break;
    }
    if (ok)
      left = mid;
    else
      right = mid;
  }

  cout << left << endl;
  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int an = 0;
    while (n) {
        n /= k;
        an++;
    }
    cout << max(1, an) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

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

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
static const int N=114514;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  int n,m,k;
  cin>>n>>m>>k;
  int x=max(n,m);
  int y=min(n,m);
  rep(i,x+1){
    rep(j,y+1){
      if(y*i+x*j-i*j*2==k){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

class ProblemB{
  ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();//graph
  ArrayList<ArrayList<Integer>> rg = new ArrayList<ArrayList<Integer>>();//greverse graph
  ArrayList<Integer> vs = new ArrayList<Integer>();
  boolean visited[] = null;
  int cmp[] = null;

  void solve(){
    Scanner scan = new Scanner(System.in);
    int v = scan.nextInt();
    int e = scan.nextInt();

    visited = new boolean[v];
    cmp = new int[v];

    for(int i=0 ; i<v ; ++i){
      g.add(new ArrayList<Integer>());
      rg.add(new ArrayList<Integer>());
    }

    int s=-1, t=-1;
    for(int i=0 ; i<e ; ++i){
      s = scan.nextInt();
      t = scan.nextInt();
      g.get(s).add(t);
      rg.get(t).add(s);
    }

    if(scc(v)<v) System.out.println("1");
    else System.out.println("0");

  }

  void dfs(int v){
    visited[v] = true;
    for(int i=0 ; i<g.get(v).size() ; ++i){
      if(!visited[g.get(v).get(i)]) dfs(g.get(v).get(i));
    }
    vs.add(v);
  }

  void rdfs(int i, int k){
    visited[i] = true;
    cmp[i] = k;
    for(int j=0 ; j<rg.get(i).size() ; ++j){
      if(!visited[rg.get(i).get(j)]) rdfs(rg.get(i).get(j), k);
    }
  }

  int scc(int v){
    visitedClear();
    vs.clear();

    for(int i=0 ; i<v ; ++i){
      if(!visited[i]) dfs(i);
    }

    visitedClear();
    int k = 0;
    for(int i = vs.size()-1 ; i>=0 ; --i){
      if(!visited[vs.get(i)]) rdfs(vs.get(i), ++k);
    }
    return k;
  }

  void visitedClear(){
    for(int i=0 ; i<visited.length ; ++i) visited[i] = false;
  }
}

public class Main{
  public static void main(String[] args){
    new ProblemB().solve();
  }
}



Measured memory_bytes: 31548
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long


int max(int a, int b){
	if(a>b)return a;
	else	return b;
}

signed main(){
	int n;
	int c[61]={};
	int a[300000];
	cin >> n;
	LOOP(i,n){
		cin >> a[i];
		int b = a[i];
		int cnt = 0;
		while(b){
			c[cnt]+=b%2;
			cnt++;
			b/=2;
		}
	}

	int an = 0;
	// LOOP(j,4)cerr << c[j] << " ";
	cerr << endl;
	LOOP(i,n){
		int ans[61]={};
		int b = a[i]; //cerr << b;
		int cnt = 0;
		LOOP(j,61){
			ans[cnt] = max(0,c[cnt])*(!(b%2));
			// cerr << "works";
			// cerr << ans[cnt] << " ";
			cnt++;
			b/=2;
		}
		// cerr << ":";
		LOOP(j,4)cerr << ans[j] << " ";
		int db = 1;
		LOOP(j,61){
			an += ans[j]*db;
			an %= MOD;
			db*=2;
			db %= MOD;
		}
		cerr << an << endl;
	}
	cout << an << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int>&add,vector<vector<int>>&g,vector<int>&ans,vector<bool>&find,int s){
    ans[s] += add[s];
    find[s] = 1;
    for(int i = 0;i < g[s].size();i++){
        if(find[g[s][i]])
            continue;
        ans[g[s][i]] = ans[s];
        dfs(add,g,ans,find,g[s][i]);
    }
}

int main() {
    int n,q;
    cin >> n >> q;
    vector<vector<int>>v(n + 1);
    for(int i = 0;i < n - 1;i++){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<int>ans(n + 1,0);
    vector<int>add(n + 1,0);
    vector<bool>find(n + 1,false);
    for(int i = 0;i < q;i++){
        int p,x;
        cin >> p >> x;
        add[p] += x;
    }
    dfs(add,v,ans,find,1);
    for(int i = 1;i < n + 1;i++){
        cout << ans[i] << " ";
    }
}

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


using namespace std;


int main()
{
    int N, K;
    char A[70];
    string S;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        S += A[i];
    }
    transform(S.begin(), S.begin()+K, S.begin(), ::tolower);
    transform(S.begin(), S.begin()+(K-1), S.begin(), ::toupper);
    cout << S << endl;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	if (s == "ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;
}

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

class Point3d{
public:
  double x,y,z;
  Point3d(double a=0,double b=0,double c=0):x(a),y(b),z(c){}
};

double norm(Point3d a,Point3d b){
  return pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);
}

double abs(Point3d a,Point3d b){ 
 return sqrt(norm(a,b));
}

int main()
{
  vector<Point3d> v;
  int n,m;
  int ans;
  double eps=0.000000001;
  bool st[501];

  while(1){
    cin>>n;
    if(n==0)break;
    double a,b,c,d;
    for(int i=0;i<501;i++)st[i]=false;
    v.clear();
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      v.push_back(Point3d(a,b,c));
    }
    cin>>m;

    Point3d origin(0.0,0.0,0.0);
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      Point3d p3(a,b,c);
      double x,y,z,r;
      for(int j=0;j<n;j++){
	x=abs(v[j],origin);
	y=abs(p3,origin);
	z=abs(v[j],p3);
	//	printf("%.10f %.10f %.10f\n",x,y,z);
     	r=acos((x*x+y*y-z*z)/(x*y*2));
	
	//	printf("%.10f %.10f\n",r,d);
	if((r-d)<eps)st[j]=true;
      }
    }
    ans=0;
    for(int i=0;i<n;i++)if(st[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1332
#include<cstdio>  
#include<iostream>  
#define min(a, b) a < b ? a : b 
using namespace std;  
  
const int INF = 0x7f7f7f7f;  
const int MAXN = 1e5 + 111;  
  
int p[MAXN];  
int qt[MAXN], qv[MAXN], mark[MAXN];  
int t;  
  
int find(int x) {  
    return mark[x] < t ? x : p[x] = find(p[x]); // ?°?????????´?????¨??\??¢???????????????????¢????  
}  
  
int main()  
{  
    int n, q, i;  
    while (~scanf("%d%d", &n, &q) && (n | q)) {  
        for (i = 2; i <= n; ++i) {  
            scanf("%d", p + i);  
            mark[i] = INF;  
        }  
  
        int cnt = 0, x;  
        char op[2];  
        for (i = 1; i <= q; ++i) {  
            scanf("%s%d", op, &x);  
            if (op[0] == 'M') mark[x] = min(mark[x], i); // ??°?????????????????¶??´  
            else {  
                qt[cnt] = i;  
                qv[cnt++] = x;  
            }  
        }  
  
        long long ans = 0;  
        while (cnt --) {  
            t = qt[cnt]; // ??\??¢???????????¶??´  
            ans += find(qv[cnt]);  
        }  
        printf("%lld\n", ans);  
    }  
    return 0;  
}  

Measured memory_bytes: 2524
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	vs S(3);
	REP(i, 3)cin >> S[i];
	string ans;
	REP(i, 3) {
		ans += S[i][0];
	}
	transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
	OUT(ans);
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
	for (int i = 0; i < N; i++) {
  		cin >> A.at(i);
	}
  vector<int> B(N);
  	for (int i = 0; i < N; i++){
      cin >> B.at(i);
    }
  vector<int> C(N);
  	for (int i = 0; i < N-1; i++){
      cin >> C.at(i);
    }
  int sum =0;
  for (int i = 0; i < N; i++){
    sum += B.at(i);
  }
  
  for (int i= 0;i < N-1;i++) {
    if(A.at(i) == A.at(i+1) -1){
      sum += C.at(A.at(i) -1);
    }
  }
    
    cout << sum <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cont=0;
  char n=s[0];
  for(int i=1;s[i]!='\0';i++){
    if(n!=s[i]){
      cont++;
      n=s[i];
    }
  }
  cout<<cont<<endl;
  return(0);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;

template<class type> struct WeightedUnionFind{
  vector<int> par;
  vector<int> treerank;
  vector<type> wdiff;
  
  WeightedUnionFind(int n){
    par.resize(n); treerank.resize(n); wdiff.resize(n);
    rep(i, n) par[i] = i, treerank[i] = 0, wdiff[i] = 0;
  }
  
  int find(int x){
    if(par[x] == x) return x;
    int r = find(par[x]);
    wdiff[x] += wdiff[par[x]];
    return par[x] = r;
  }
  
  type weight(int x){
    find(x);
    return wdiff[x];
  }
  
  void unite(int x, int y, type w){
    w += weight(x); w -= weight(y);
    x = find(x); y = find(y);
    if(x == y) return;
    if(treerank[x] < treerank[y]) swap(x, y), w = -w;
    if(treerank[x] == treerank[y]) treerank[x]++;
    par[y] = x;
    wdiff[y] = w;
    return;
  }
  
  type diff(int x, int y){
    return weight(y) - weight(x);
  }
  
  bool same(int x, int y){
    return find(x) == find(y);
  }
};

int main(){
    int n, q; cin >> n >> q;
    WeightedUnionFind<int> uf(n);
    rep(i, q){
        int c; cin >> c;;
        if(c){
            int x, y; cin >> x >> y;
            if(!uf.same(x, y)) cout << '?' << endl;
            else cout << uf.diff(x, y) << endl;
        }
        else{
            int x, y, z; cin >> x >> y >> z;
            uf.unite(x, y, z);
        }
    }
}


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

main(){
  int r;
  int n;
  while(cin >> r){
    cin >> n;
    for(int i=0;i<n;i++){
      int x, y;
      cin >> x >> y;
      if(r%2==1){
	int m=r/2;
	int cx, cy;
	cx=2*(m-x);
	cy=2*(m-y);
	if(cx<0) cx*=-1;
	if(cy<0) cy*=-1;
	int ans;
	if(m-cy/2<=y && m+cy/2>=y && m-cx/2<=x && m+cx/2>=x){
	  ans=x%3;
	  if(ans==0) ans=3;
	  cout << ans << endl;
	}
	else if(m-cy/2<=y && m+cy/2>=y){
	  ans=x%3;
	  if(ans==0) ans=3;
	  cout << ans << endl;
	}
	else if(m-cx/2<=x && m+cx/2>=x){
	  ans=y%3;
	if(ans==0) ans=3;
	cout << ans << endl;
	}
	else{
	  printf("!\n");
	}
      }
      else{
	int dx, ux;
	int dy, uy;
	if(x<=r-x){
	  dy=x;
	  uy=r-x+1;
	}
	else{
	  dy=r-x+1;
	  uy=x;
	}
	if(y<=r-y){
	  dx=y;
	  ux=r-y+1;
	}
	else{
	  dx=r-y+1;
	  ux=y;
	}
	//printf("@%d %d\n", x, y);
	//printf("@%d %d %d %d\n", dx, ux, dy, uy);
	int ans;
	if(dx<=x && ux>=x && dy<=y && uy>=y){
	  if(x<=y){
	    if(x>r/2) x=r-x+1;
	    ans=x%3;
	  }
	  else{
	  if(y>r/2) y=r-y+1;
	    ans=y%3;
	  }
	  if(ans==0) ans=3;
	  cout << ans << endl;
	}
	else if(dx<=x && ux>=x){
	  if(y>r/2) y=r-y+1;
	  ans=y%3;
	  if(ans==0) ans=3;
	  cout << ans << endl;
	}
	else if(dy<=y && uy>=y){
	  if(x>r/2) x=r-x+1;
	  ans=x%3;
	  if(ans==0) ans=3;
	  cout << ans << endl;
	}
	else{
	  printf("!\n");
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int a[n + 2];
    a[0] = 0,a[n + 1] = 0;
    for(int i = 1;i < n + 1;i++)
    {
        cin >> a[i];
        sum += fabs(a[i] - a[i - 1]);
    }
    sum += fabs(a[n + 1] - a[n]);
    for(int i = 1;i < n + 1;i++)
    {
        int temp = sum;
        temp = temp + fabs(a[i - 1] - a[i + 1]);
        temp = temp - fabs(a[i - 1] - a[i]) - fabs(a[i] - a[i + 1]);
        cout << temp << "\n";
    }

    return 0;
}

Measured memory_bytes: 1664
n, m = map(int, input().split())
a, b = [0] * m, [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())

#union-find
#初期化 par:親の番号
#par = [i for i in range(n)]
#木の根を求める
def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x] 
#xとyが同じ集合に属するか否か
def same(x, y):
    return root(x) == root(y)
#xとyの属する集合を併合
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    par[x] = root(y)

cnt = 0
for i in range(m):
    par = [k for k in range(n+1)]
    for j in range(m):
        if i == j:
            continue
        unite(a[j], b[j])
    if not same(a[i], b[i]):
        cnt += 1
print(cnt)

Measured memory_bytes: 74036
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n), b(n);
    REP(i,n) b[n-i-1] = a[i] = 1 + i*(n+1);
    REP(i,n){
        int p;
        scanf("%d", &p);
        p--;
        b[p] += i;
    }
    REP(i,n) printf("%d ", a[i]);
    cout << endl;
    REP(i,n) printf("%d ", b[i]);
    cout << endl;

    return 0;
}

Measured memory_bytes: 768
def ABC099C():
    N = int(input())
    res = N
    for i in range(N + 1):
        cnt = 0
        t = i
        while t > 0:
            cnt += t % 6
            t //= 6
        t = N - i
        while t > 0:
            cnt += t % 9
            t //= 9
        if res > cnt:
            res = cnt
    print(res)
ABC099C()

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

int main() {
  int N,flag=1,ans=0,exit=0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N;i++){
    cin >> A.at(i);
  }

   for (int j = 0; j < N; j++){
      if (A.at(j)==flag){
        ans++;
        flag++;
        //cout << j;
      }
      if(j==N-1 && ans==0){
        ans = -1;
      } 
  }
  if(ans==-1){
    cout << ans;
  }else{
    cout << N - ans;
  }  
}

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

int main() {
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

void solve() {
	
    int n;
    cin >> n;

    vector<ll>a(n);

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

    ll ans = 0;
    ll mx = a[0];
    for(auto &i : a){
        mx = max(mx,i);
        ans += mx - i;
    }
    cout << ans;
}
int main() {
    
    ios_base::sync_with_stdio(false);cin.tie(NULL); 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif



    solve();
    
   

     cerr<<"\ntime taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
   return 0; 
}

Measured memory_bytes: 4732
import sys
a = [[0] * 3 for i in range(3)]
ans = [[0] * 3 for i in range(3)]
for i in range(3):
    a[i][0],a[i][1],a[i][2] = map(int, input().split())
N = int(input())
b = [input() for i in range(N)]
for i in range(3):
    for j in range(3):
        if ans[i][j] == 1:
            break
        for k in range(N):
            if a[i][j] == int(b[k]):
                ans[i][j] = 1
                break
for i in range(3):
    if ans[i][0] == 1 and ans[i][1] == 1 and ans[i][2] == 1:
        print('Yes')
        sys.exit()
for j in range(3):
    if ans[0][j] == 1 and ans[1][j] == 1 and ans[2][j] == 1:
        print('Yes')
        sys.exit()
if ans[0][0] == 1 and ans[1][1] == 1 and ans[2][2] == 1:
    print('Yes')
    sys.exit()
if ans[0][2] == 1 and ans[1][1] == 1 and ans[2][0] == 1:
    print('Yes')        
    sys.exit()
print('No')


Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    double a, b;
    int C;
    double S, L, h;
    double rad;
    scanf("%lf %lf %d", &a, &b, &C);
    
    rad = C * M_PI / 180;
    S = a * (b * sin(rad)) / 2;
    L = a + b + sqrt((a*a + b*b) - 2*a*b*cos(rad));
    h = 2 * S/a;
    
    printf("%lf\n%lf\n%lf\n", S, L, h);
    return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<int> v(m+1, 0);
    rep (n) {
        int k;
        cin >> k;
        rep (k) {
            int f;
            cin >> f;
            ++v[f];
        }
    }
    int ans = 0;
    repeat_from_to (i, 1, m) {
        if (v[i] == n) ++ans;
    }
    cout << ans << endl;
}

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

int main(){
string s;
cin>>s;
if(s.size()<4) cout<<"No"<<endl;
else{
  if(s.substr(0,4)=="YAKI") cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

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


void solve(long long N, std::vector<std::string> s, long long M, std::vector<std::string> t){
vector<int> kazu(N);
for(int i=0;i<N;i++){
    int count=0;
    for(int j=0; j<N; j++){
        if(s.at(i)==s.at(j)){
            count++;
        }
    }
    for(int k=0; k<M; k++){
        if(s.at(i)==t.at(k)){
            count--;
        }
    }
    kazu.at(i) = count;
}
sort(kazu.begin(),kazu.end());
int maxn;
maxn = kazu.at(N-1);
if(maxn>=0)cout<<maxn<<endl;
else cout<<"0"<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    long long M;
    scanf("%lld",&M);
    std::vector<std::string> t(M);
    for(int i = 0 ; i < M ; i++){
        std::cin >> t[i];
    }
    solve(N, std::move(s), M, std::move(t));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		int max = 1;
		for (int i = 2; i * i <= x; i++) {
			int num = i;
			while (num <= x) {
				max = Math.max(max, num);
				num *= i;
			}
 		}
		
		System.out.println(max);
		sc.close();
	}
}




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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ll long long

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

	bool flag = false;
	rep(i, S.size() - 1)
	{
		if (S[i] == S[i + 1])
		{
			flag = true;
		}
	}

	if (flag)
	{
		cout << "Bad" << endl;
	}
	else
	{
		cout << "Good" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll l,r;
int main(){
	cin>>l>>r;
	if(r-l>=2018){
		cout<<0<<endl;
		return 0;
	}
	int ans=2018;
	for(ll i=l;i<=r-1;i++){
		for(ll j=i+1;j<=r;j++){
			ll tans=(i*j)%2019LL;
			ans=min(ans,tans);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<int> idx(N);
    rep(i, N) idx[A[i] - 1] = i;

    int ls = 1, cs = 1;
    rep(i, 1, N) {
        if (idx[i] > idx[i - 1]) cs++;
        else cs = 1;
        ls = max(ls, cs);
    }

    write(N - ls);
}

Measured memory_bytes: 1792
import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Created by Harry on 4/6/20.
 */

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        long[] A = new long[n];
        for(int i=0; i<n; i++){
            A[i] = scanner.nextLong();
        }
        long[] preSum = new long[n+1];
        long[][] dp = new long[n][n];
        long sum = 0;
        for(int i=0; i<n; i++){
            preSum[i+1] = preSum[i]+A[i];
        }

        for(int j=0; j<n; j++){
            for(int i=j; i>=0; i--){
                if(i==j){
                    dp[i][j] = A[i];
                }
                else{
                    dp[i][j] = Math.max(preSum[j+1]-preSum[i]-dp[i+1][j], preSum[j+1]-preSum[i]-dp[i][j-1]);
                }
            }
        }
        long x = dp[0][n-1];
        long y = preSum[n]-x;
        System.out.print(x-y);
    }
}


Measured memory_bytes: 129856
def p(n):
    if n == 1:
        return 300000
    elif n == 2:
        return 200000
    elif n == 3:
        return 100000
    else:
        return 0

x, y = map(int, input().split())
ans = 0
if x == y == 1:
    ans += 400000
ans += p(x) + p(y)
print(ans)


Measured memory_bytes: 9116