akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,c,d,e,f;
    cin>> a >> b >> c >> d >> e >> f ;
    a = a * 100;
    b = b * 100;
    int tot=a,sugar=0;
    int TotalSugar,TotalWater;
    int range = 50;
    for(int i=0;i<=range;i++)
    {
        for(int j=0;j<=range;j++)
        {
            for(int k=0;k<=range;k++)
            {
                for(int l=0;l<=range;l++)
                {
                    TotalSugar = k*c + l*d;
                    TotalWater = i*a + j*b;
                    if(TotalSugar + TotalWater <= f)
                    {
                        if(TotalSugar * 100 <= TotalWater * e)
                        {
                            if((TotalSugar + TotalWater)*sugar <= tot*TotalSugar)
                            {
                                tot = TotalSugar + TotalWater;
                                sugar = TotalSugar;
                            }
                        }
                    }

                }
            }
        }
    }
    cout<< tot <<" "<<sugar<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

vector<int> par;
vector<int> ran;

void init(int n) {
  rep(i,n) {
    par.push_back(i);
    ran.push_back(0);
  }
}

int root(int n) {
  if(par[n]==n) return n;
  return par[n]=root(par[n]);
}

void unite(int x,int y) {
  x=root(x);
  y=root(y);
  if(ran[x]<ran[y]) {
    par[x]=y;
  } else {
    par[y]=x;
    if(ran[x]==ran[y]) ran[x]++;
  }
}

void coutAll(int n) {
  pr("par[i]","ran[i]");
  rep(i,n) {
    pr(par[i],ran[i]);
  }
}

int main(void) {
  int n,m;cin>>n>>m;
  vector<int> p(n);
  rep(i,n) cin>>p[i];
  vector<vector<int>> xy(n);
  int ans=0;

  init(n);

  int x,y;
  rep(i,m) {
    cin>>x>>y;
    --x;
    --y;
    unite(x,y);
    xy[x].push_back(y);
    xy[y].push_back(x);
  }

  // coutAll(n);

  rep(i,n) {
    if(root(i)==root(p[i]-1)) ans++;
    else if(i==p[i]-1) ans++;
    // pr(p[i],root(i),root(p[i]));
  }
  pr(ans);

  return 0;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, rt = 1;
bool incir[maxn], vis[maxn], insg[maxn];
int p[maxn], sg[maxn], fa[maxn];
vector<int> cir, E[maxn], G;
int top, e, cnt;
vector<int> ed[maxn];
int dfn[maxn], low[maxn], sta[maxn], belong[maxn], id[maxn][2];
inline void cmin(int& u, int& v)
{
	u = u > v ? v : u;
}
void tarjan(int u)
{
	dfn[u] = low[u] = ++e;
	sta[++top] = u;
	for(int i = 0; i < ed[u].size(); ++i)
	{
		int v = ed[u][i];
		if(!dfn[v])
			tarjan(v), cmin(low[u], low[v]);
		else if(!belong[v])
			cmin(low[u], dfn[v]);
	}
	if(low[u] == dfn[u])
		for(++cnt; sta[top + 1] ^ u; --top)
			belong[sta[top]] = cnt;
}
bool solve()
{
	int nn = cir.size() << 1 | 1;
	for(int i = 2; i <= nn; ++i)
		if(!dfn[i])
			tarjan(i);
	for(int i = 1; i <= cir.size(); ++i)
		if(belong[i << 1] == belong[i << 1 | 1])
			return 0;
	return 1;
}
void getsg(int x)
{
	G.clear();
	for(auto v : E[x])
		if(!incir[v])
			 G.push_back(sg[v]);
	fill(insg, insg + G.size() + 1, 0);
	for(auto v : G) insg[v] = 1;
	for(int i = 0; i <= G.size(); ++i)
		if(!insg[i])
		{
			sg[x] = i;
			break;
		}
}
void dfs(int x)
{
	vis[x] = 1;
	for(auto v : E[x])
	{
		if(!vis[v])
			dfs(v);
		if(incir[v])
		{
			incir[x] = 1;
			cir.push_back(x);
		}
	}
	getsg(x);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &p[i]);
		E[p[i]].push_back(i);
		fa[i] = p[i];
	}
	int rt = 1;
	for(int i = 1; i <= n; ++i) rt = fa[rt];
	incir[rt] = 1;
	dfs(rt);
	for(int i = 0; i < cir.size(); ++i) id[cir[i]][0] = (i + 1) << 1, id[cir[i]][1] = (i + 1) << 1 | 1;
	for(int i = 1; i <= cir.size(); ++i)
	{
		int u = cir[i - 1], v = cir[i == cir.size() ? 0 : i];
		if(sg[u] == sg[v])
		{
			ed[id[u][0]].push_back(id[v][1]);
			ed[id[u][1]].push_back(id[v][0]); 
			ed[id[v][0]].push_back(id[u][1]);
			ed[id[v][1]].push_back(id[u][0]); 
		}
		else if(sg[u] == sg[v] - 1)
		{
			ed[id[u][0]].push_back(id[v][0]);
			ed[id[u][1]].push_back(id[v][1]); 
			ed[id[v][0]].push_back(id[u][0]);
			ed[id[v][1]].push_back(id[u][1]); 
		}
		else
		{
			ed[id[v][1]].push_back(id[v][0]);
		}
	}
	if(solve()) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 56948
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;
bool flag[301][301][301];
double p[301][301][301];

double saiki(int a,int b,int c){
    if(a==0&&b==0&&c==0)return 0.0;
    if(flag[a][b][c])return p[a][b][c];
    double tmp = 0.0;
    double sm = (double)n;
    double sss = 0.0;
    if(a>0)tmp += (double)(a)/sm * saiki(a-1,b,c);
    if(b>0)tmp += (double)(b)/sm * saiki(a+1,b-1,c);
    if(c>0)tmp += (double)(c)/sm * saiki(a,b+1,c-1);
    sss = (double)(n-a-b-c)/sm;
    tmp += 1.0;
    flag[a][b][c] = 1;
    return p[a][b][c] = tmp/(1.0-sss);
}


int main(){
    cin >> n;
    vector<int>a(n);
    int q[4]={};
    rep(i,n){
        cin >> a[i];
        q[a[i]]++;
    }
    p[0][0][0] = 0.0;
    // rep(i,n){
    //     rep(j,n){
    //         rep(k,n){
    //             p[i][j][k]
    //         }
    //     }
    // }
    cout.precision(20);
    cout << saiki(q[1],q[2],q[3]) << endl;
    return 0;
}

Measured memory_bytes: 239872
#include <string>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    vector<string> ts(4);
    ts[0] = "dream";
    ts[1] = "dreamer";
    ts[2] = "erase";
    ts[3] = "eraser";
    
    int index=str.size()-1;
    bool flag=true;
    while(index>=0) {
        if(str[index]=='m') {
            if(index<ts[0].size()-1) {
                flag=false;
                break;
            }
            for(int i=ts[0].size()-2; i>=0; i--) {
                if(ts[0][i]!=str[index-(ts[0].size()-1-i)]) {
                    flag=false;
                    break;
                }
            }
            index -= ts[0].size();
        } else if(str[index]=='e') {
            if(index<ts[2].size()-1) {
                flag=false;
                break;
            }
            for(int i=ts[2].size()-2; i>=0; i--) {
                if(ts[2][i]!=str[index-(ts[2].size()-1-i)]) {
                    flag=false;
                    break;
                }
            }
            index -= ts[2].size();
        } else if(str[index]=='r') {
            if(index<ts[3].size()-1) {
                flag=false;
                break;
            }
            
            if(str[index-1]=='e') {
                if(str[index-2]=='m') {
                    if(index<ts[1].size()-1) {
                        flag=false;
                        break;
                    }
                    for(int i=ts[1].size()-2; i>=0; i--) {
                        if(ts[1][i]!=str[index-(ts[1].size()-1-i)]) {
                            flag=false;
                            break;
                        }
                    }
                    index -= ts[1].size();
                } else if(str[index-2]=='s') {
                    for(int i=ts[3].size()-2; i>=0; i--) {
                        if(ts[3][i]!=str[index-(ts[3].size()-1-i)]) {
                            flag=false;
                            break;
                        }
                    }
                    index -= ts[3].size();
                } else {
                    flag=false;
                    break;
                }
            } else {
                flag=false;
                break;
            }
        } else {
            flag=false;
            break;
        }
    }
    
    if(flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long v[111111];
int main()
{
	int n;
	cin>>n;
	int ind = 0;
	for(ind =1;ind<10;ind++)
		v[ind]=ind;
	for(int i=1;;i++)
	{
		if(v[i]%10) v[ind++]=v[i]*10+v[i]%10-1;
		v[ind++]=v[i]*10+v[i]%10;
		if(v[i]%10!=9)v[ind++]=v[i]*10+v[i]%10+1;
		if(ind>n) break;
	}
	cout<<v[n];
	return 0;
 } 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200200;
int n;
int a[N];
int na[N];
int nxt[N];
LL k;
bool in[N];
int s[N];
int st=0;
int main(){
	scanf("%d",&n);
	cin>>k;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=n-1;i>=0;i--){
		na[a[i]]=n+i;
	}
	for(int i=n-1;i>=0;i--){
		nxt[i]=na[a[i]];
		// cerr<<i<<" "<<nxt[i]<<endl;
		na[a[i]]=i;
	}
	int t=0;
	for(int i=0;;){
		// cerr<<i<<endl;
		i=nxt[i]+1;
		while(i>=n){
			i-=n;
			t++;
		}
		if(i==0){
			break;
		}
	}
	// cerr<<"t = "<<t<<endl;
	k%=t;
	int i=0;
	for(;k>5;){
		i=nxt[i]+1;
		while(i>=n){
			i-=n;
			k--;
		}
	}
	while(k>0){
		if(in[a[i]]){
			while(in[a[i]]){
				in[s[--st]]=false;
			}
		}
		else{
			in[a[i]]=true;
			s[st++]=a[i];
		}
		i++;
		if(i==n){
			i=0;
			k--;
		}
	}
	for(int i=0;i<st;i++){
		printf("%d ",s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.length();
    reverse(s.begin(), s.end());
    for (int i=0;i<n;){
        if(s[i]=='m'&&s[i+1]=='a'&&s[i+2]=='e'&&s[i+3]=='r'&&s[i+4]=='d') i+=5;
        else if(s[i]=='e'&&s[i+1]=='s'&&s[i+2]=='a'&&s[i+3]=='r'&&s[i+4]=='e') i+=5;
        else if(s[i]=='r'&&s[i+1]=='e'&&s[i+2]=='m'&&s[i+3]=='a'&&s[i+4]=='e'&&s[i+5]=='r'&&s[i+6]=='d') i+=7;
        else if(s[i]=='r'&&s[i+1]=='e'&&s[i+2]=='s'&&s[i+3]=='a'&&s[i+4]=='r'&&s[i+5]=='e') i+=6;
        else {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long k;
	cin >> k;
	long long co = 0;
	for (long long i = 1; i < 20000000; i++) {
		co *= 10;
		co += 7;
		co %= k;
		if (co == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}


Measured memory_bytes: 3632
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()
    ans = 0
    for i in range(1, N):
        first = set(S[:i])
        second = set(S[i:])
        score = len(first & second)
        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62504
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>


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

using namespace std;
int main()
{
  string S;
  cin >> S;

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

Measured memory_bytes: 256
n,k=map(int,input().split())
ans=0
mod=1000000007
l=(k-1)*k//2
h=(n+n-k+1)*k//2
for i in range(k,n+2):
    if i==k:
        ans+=h-l+1
        if ans>=mod:
            ans%=mod
    else:
        l+=i-1
        h+=n-(i-1)
        ans+=h-l+1
        if ans>=mod:
            ans%=mod

print(ans)

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

int main() {
  int K,S;
  int ans = 0;
  cin >> K >> S;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <=K; y++) {
      int z = S -x -y;
      if ((z >= 0) && (z <= K)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
    
  
  
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Buffet
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N], cs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;
  for (int i = 0; i < n; i++) scanf("%d", bs + i);
  for (int i = 0; i + 1 < n; i++) scanf("%d", cs + i);

  int sum = 0;
  for (int i = 0; i < n; i++) {
    int &ai = as[i];
    sum += bs[ai];
    if (i < n - 1 && as[i + 1] == ai + 1) sum += cs[ai];
  }

  printf("%d\n", sum);
  return 0;
}


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

main() {
 ll a, b, x; cin >> a >> b >> x;
 ll ans = b / x + 1;
 ans -= (a == 0) ? 0 : (a - 1) / x + 1;
 cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    vector<pair<ll, pair<ll, ll>>> A(N);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        A[i].first = a + b;
        A[i].second = { a, b };
    }

    RSORT(A);
    ll Sa = 0, Sb = 0;
    REP(i, N) {
        if (i % 2 == 0) {
            Sa += A[i].second.first;
        } else {
            Sb += A[i].second.second;
        }
    }

    cout << Sa - Sb << endl;

    return 0;
}

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

int x1, y1, x2, y2;

int main(){
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1, dy = y2 - y1;
  int x3 = x2 - dy, y3 = y2 + dx;
  int x4 = x3 - dx, y4 = y3 - dy;
  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
    internal class Program {
        public static void Main(string[] args) { new Program().solve(); }
        void solve() {
            var N = int.Parse(Console.ReadLine());
            var tPoint = 0;
            var hPoint = 0;
            for(int i = 0; i < N; ++i) {
                var str = Console.ReadLine().Split(' ');
                var taro = str.First();
                var hana = str.Last();
                if(taro == hana) {
                    tPoint++;
                    hPoint++;
                } else if(taro.CompareTo(hana) > 0) { tPoint += 3; } else { hPoint += 3; }
            }
            Console.WriteLine(tPoint+" "+hPoint);
        }
        
    }
}



Measured memory_bytes: 10228
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,h[999],i=0;
	long long a=1;
	cin>>n;
	for(;i<n;i++)cin>>h[i];
	sort(h,h+n);
	for(i=0;i<n;i++)a+=max(h[n-i-1]-i/4,0);
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define foriter(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define endl '\n'
#define INF (ll)(1e9)
#define EPS 1e-9
#define MOD (ll)(1e9+7)
#define PI 3.1415926535897932384626433832795
#define set set
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
#define map map
#define mmap multimap
#define umap unordered_map
#define ummap unordered_multimap

using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vll;
typedef vector<vll> vvll;
typedef pair<i64, i64> pll;

int inp(){
  int x; 
  cin>>x;
  return x;
}

//=============================================================================//

void solve() {
    ll d,t,s; cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No");
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);

    int T=1;
    //cin >> T;
    while (T--) {
        solve();
        cout<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
char line[100000];
int min(int a, int b)
{
	if (a <= b)
		return a;
	else
		return b;
}
int main()
{
	long n,k;
	long i;
	long sum;
	cin >> n;
	cin >> k;
	for (i = 0; i < n; i++)
	{
		cin >> line[i];
	}
	int m = 0;
	for (i = 0; i < n - 1; i++)
	{
		if (line[i] != line[i + 1])
			m++;
	}
		if (m == 1)
			sum = n - 2 - m + 2 * k;
		else
			sum = n - 1 - m + 2 * k;
		sum = min(sum, (n - 1));
	cout << sum;
	return 0;
}


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

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

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

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

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

	return result;
}

static size_t searchHIdx(const size_t N,  size_t *x, size_t *y, size_t *h, const size_t cx, const size_t cy)
{
	for (size_t idx = 0; idx < N; idx++) {
		if (h[idx] != 0) {
			return idx;
		}
	}

	return 0;
}

int main(void) {
	size_t N;
	size_t x[100], y[100], h[100];

	scanf("%zu\n", &N);
	for (size_t idx = 0; idx < N; idx++) {
		scanf("%zu %zu %zu", &x[idx], &y[idx], &h[idx]);
		if (idx < N - 1) {
			scanf("\n");
		}
	}

	for (size_t cx = 0; cx <= 100; cx++) {
		for (size_t cy = 0; cy <= 100; cy++) {
			const size_t HIdx = searchHIdx(N, x, y, h, cx, cy);
			const size_t H = ABSS(cx, x[HIdx]) + ABSS(cy, y[HIdx]) + h[HIdx];
			bool matched = true;

			for (size_t idx = 0; idx < N; idx++) {
				if (idx != HIdx) {
					if (h[idx] == 0) {
						if (ABSS(cx, x[idx]) + ABSS(cy, y[idx]) < H) {
							matched = false;
							break;
						}
					}
					else {
						if (ABSS(cx, x[idx]) + ABSS(cy, y[idx]) + h[idx] != H) {
							matched = false;
							break;
						}
					}
				}
			}
			if (matched) {
				printf("%zu %zu %zu\n", cx, cy, H);
				return 0;
			}
		}
	}

	return 0;
}

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

#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void Merge(struct Card A[],int left , int mid , int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1 ; i++) L[i] = A[left + i];
    for(int i = 0; i < n2 ; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    int i = 0 ,  j = 0;
    for(int k = left ;k < right; k++){
        if(L[i].value <= R[j].value)
            A[k] = L[i++];
        else
            A[k] = R[j++];
    }
}

void mergesort (struct Card A[], int left , int right){
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        mergesort(A,left,mid);
        mergesort(A,mid,right);
        Merge(A,left,mid,right);
    }
}

int Partition(struct Card A[],int p , int r){
    int i , j ;
    struct Card t,x;
    i = p - 1;
    x = A[r];
    for(j = p ; j < r ; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
    return i + 1;
}

void Quicksort(struct Card A[],int p , int r){
    int q;
    if( p < r){
        q = Partition(A , p , r);
        Quicksort(A , p , q-1);
        Quicksort(A , q+1 , r);
    }
}
int main()
{
    int Stable  =  1;
    int v, n;
    char s[10];
    struct Card A[MAX],B[MAX];
    scanf("%d", &n);

    for(int i = 0 ; i < n ; i++){
        scanf("%s %d", s , &v);
        A[i].suit = B[i].suit = s[0];
        A[i].value = B[i].value = v;
    }

    mergesort(A,0,n);
    Quicksort(B,0,n-1);

    for(int i = 0; i < n ;i++){
        if(A[i].suit != B[i].suit)  Stable = 0;
    }

    if(Stable) printf("Stable\n");
    else  printf("Not stable\n");

    for(int i = 0 ; i < n ; i++){
        printf("%c %d\n",B[i].suit,B[i].value);
    }

    return 0;
}



Measured memory_bytes: 4116
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
x,y=p[0]
for i in range(len(p)-2):
 a,b=p[i+1];c,d=p[i+2]
 s+=((a-x)*(d-y)-(b-y)*(c-x))/2
print(abs(s))


Measured memory_bytes: 5592
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
  int c[3][3];
  for (int i = 0; i < 3; ++i){
    for (int j = 0; j < 3; ++j){
      scanf("%d",&c[i][j]);
    }
  }
  if(((c[0][1]-c[0][0])==(c[1][1]-c[1][0])) && ((c[0][1]-c[0][0])==(c[2][1]-c[2][0]) && (c[0][2]-c[0][1])==(c[1][2]-c[1][1])) && ((c[0][2]-c[0][1])==(c[2][2]-c[2][1]) ) ){
    printf("Yes\n");
  }else{
    printf("No\n");
  } 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
	int a,b,c,d,e,f;
	float x,y;
	while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF){
		/*if((b>=0&&e>=0)||(b<0&&e<0)){
			x=(c*abs(e)-f*abs(b))/(a*abs(e)-d*abs(b));
			y=(d*abs(c)-f*abs(a))/(b*abs(d)-e*abs(a));
		}
		else{
			x=(c*abs(e)+f*abs(b))/(a*abs(e)+d*abs(b));
			y=(d*abs(c)+f*abs(a))/(b*abs(d)+e*abs(a));
		}*/
		x=(float)(c*e-f*b)/(a*e-d*b);
		y=(float)(d*c-f*a)/(b*d-e*a);
		if(-0.0005<x && x<=0)x=0;
		if(-0.0005<y && y<=0)y=0;
		printf("%1.3f %1.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    string ans = "No";
    if (N % 2 == 0) {
        ans = "Yes";
        for (int i = 0; i < N/2; ++i) {
            if (S[i] != S[N/2+i]) {
                ans = "No";
            }
        }
    }
    printf("%s\n", ans.c_str());
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&a<c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	a_b := a * b
	var c = [3]int{1, 2, 3}
	for i := 0; i < len(c); i++ {
		if (a_b*i)%2 != 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll N = il();
  vector<vector<ll> > abs;
  rep(i,N){
    ll a = il();
    ll b = il();
    abs.p_b(vector<ll>{a+b, a, b});
  }
  sort(abs.begin(), abs.end());
  reverse(begin_end(abs));

  ll ans;
  rep(i, N){
    if (i % 2 == 0) ans += abs[i][1];
    else ans -= abs[i][2];
  } 
  
  cout << ans << endl;


  
}

Measured memory_bytes: 8776
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    int ans = 0;
    int t=0;
    REP(i,n){
        if(a[i]==b[i]&&a[i]==c[i]){
            //
        }else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
            ans++;
        }else{
            ans+=2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll path[500][500];
int main(void){
    ll n, m, q;
    cin >> n >> m >> q;

    rep(i, 0, m){
        ll l, r;
        cin >> l >> r;
        path[l - 1][r - 1]++;
    }

    ll qu1[q], qu2[q];
    rep(i, 0, q){
        cin >> qu1[i] >> qu2[i];
        qu1[i]--;
        qu2[i]--;
    }

    ll sum_r[n][n];
    rep(i, 0, n){
        sum_r[i][0] = path[i][0];
        rep(j, 1, n){
            sum_r[i][j] = sum_r[i][j-1] + path[i][j];
        }
    }

    rep(i, 0, q){
        ll ans = 0;
        rep(j, qu1[i], qu2[i]+1){
            if(qu1[i] == 0){
                ans += sum_r[j][qu2[i]];
            }else{
                ans += sum_r[j][qu2[i]] - sum_r[j][qu1[i]-1];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 6400
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    char a; cin >> a;
    if(a == 'A') cout << 'T' << endl;
    if(a == 'T') cout << 'A' << endl;
    if(a == 'G') cout << 'C' << endl;
    if(a == 'C') cout << 'G' << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *


# 1行複数
n = list(map(int, input().split()))

d = defaultdict(int)
for i in n:
    d[i] = 1

if (d[1] == 1 and d[9] == 1 and d[7] == 1 and d[4] == 1):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 7744
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
struct Mino{
  Int h,w;
  vector<string> vs;
};
vector<Mino> ms(4);

const Int H=4,W=10;
set< vector<string> > cs;
vector<string> bs(H,string(W,'#')),st;

void fill(Mino m,Int k){
  Int y=k/W,x=k%W;
  if(y+m.h>H||x+m.w>W) return;
  for(Int i=0;i<m.h;i++)
    for(Int j=0;j<m.w;j++)
      if(m.vs[i][j]=='#') st[y+i][x+j]='.';
}

void solve(){
  for(Int i=0;i<4;i++){
    for(Int j=0;j<i;j++){
      for(Int k=0;k<j;k++){
        for(Int a=0;a<40;a++){
          for(Int b=0;b<40;b++){
            for(Int c=0;c<40;c++){
              st=bs;
              fill(ms[i],a);
              fill(ms[j],b);
              fill(ms[k],c);

              //for(int p=0;p<H;p++) cout<<st[p]<<endl;
              //cout<<endl;

              cs.emplace(st);
            }
          }
        }
      }
    }
  }
}

signed main(){
  for(Int i=0;i<4;i++){
    cin>>ms[i].h>>ms[i].w;
    ms[i].vs.resize(ms[i].h);
    for(Int j=0;j<ms[i].h;j++)
      cin>>ms[i].vs[j];

    if(0){
      for(Int j=0;j<ms[i].h;j++)
        cout<<ms[i].vs[j]<<endl;
      cout<<endl;
    }
  }
  solve();

  Int n;
  cin>>n;
  for(Int i=0;i<n;i++){
    vector<string> st(4);
    for(Int j=0;j<4;j++) cin>>st[j];
    if(cs.count(st)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 18296
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    int n; cin >> n;
    int ans = 1;
    while(n/(2*ans)){
        ans <<= 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;

  cout << (A - 1) * (B - 1) << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int N=50;

ll K;
ll x[N];
ll a[N];

void run() {
	scanf("%lld",&K);
	REP(i,N) x[i]=K/N+(i<K%N?1:0);
	REP(i,N) a[i]=N-1+x[i]*N-K+x[i];
	printf("%d\n",N); REP(i,N) { if(i!=0) printf(" "); printf("%lld",a[i]); } puts("");
}

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


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))

x = [0] * (10**5+5)
for a in A:
    x[a] += 1
s = sum(A)
Q = int(readline())
for _ in range(Q):
    b, c = map(int, readline().split())
    s += (c - b) * x[b]
    print(s)
    x[c] += x[b]
    x[b] = 0


Measured memory_bytes: 85620
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int main()
{
    int n;
    cin >> n;
    vector<P> R(n);
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        R[i] = make_pair(b, a);
    }
    vector<P> B(n);
    for (int i = 0; i < n; i++)
    {
        int c, d;
        cin >> c >> d;
        B[i] = make_pair(c, d);
    }
    sort(B.begin(), B.end(), greater<P>());
    sort(R.begin(), R.end());
    int ans = 0;
    vector<bool> rvec(n,true);
    while (B.size() > 0)
    {
        P b = B[B.size()-1];
        for(int i = R.size()-1; i >= 0; i--)
        {
            if (R[i].second < b.first && R[i].first < b.second && rvec[i]) {
                ans++;
                rvec[i] = false;
                break;
            }
        }
        B.pop_back();
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';

ll MOD = 1e9 + 7;

ll i, j, le;

int sv(int x)
{
    int n = 200000;
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
    {
       
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    if (prime[x])
        return 1;
    else
        return 0;
}

int main()
{
    IOS;
    int t;
    //cin >> t;
 t=1;
    while (t--)
    {
        ll n;
        cin>>n;
        vl v(n,0),v1(n,0);
        flu(i,0,n)cin>>v[i];
        ll c= INT_MIN;
        flu(i,0,n)
        {
         c= max(v[i],c);
         v1[i]=c;
        }
        ll ans=0;
        flu(i,0,n)
        {
            ans+=v1[i]-v[i];
        }
        cout<<ans<<e;
    }
    return 0;
}

Measured memory_bytes: 6352
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define next Next
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005;
int n,m;
vector <int> e[N];
struct Edge{
	int x,y;
}ed[N];
map <int,int> g[N];
int depth[N];
int vis[N];
int v[N];
void dfs(int x,int d){
	depth[x]=d;
	vis[x]=1;
	vector <int> id;
	for (auto y : e[x])
		if (!vis[y]){
			dfs(y,d+1);
			if (v[y])
				g[y][x]=1;
			else
				g[x][y]=1,v[x]^=1;
		}
		else if (depth[y]<depth[x]-1)
			id.pb(y);
	for (auto y : id)
		g[x][y]=1,v[x]^=1;
}
int main(){
	n=read(),m=read();
	if (m&1)
		return puts("-1"),0;
	For(i,1,m){
		int x=read(),y=read();
		ed[i].x=x,ed[i].y=y;
		e[x].pb(y),e[y].pb(x);
	}
	dfs(1,0);
	For(i,1,m)
		if (g[ed[i].x][ed[i].y])
			printf("%d %d\n",ed[i].x,ed[i].y);
		else
			printf("%d %d\n",ed[i].y,ed[i].x);
	return 0;
}

Measured memory_bytes: 37760
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//入力
ll n;
int s[220][220];

//UnionFind
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int n) : par(n, -1) { }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool merge(int x, int y) {//xの木とyの木を結合する
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {//sizeの取得
        return -par[root(x)];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//Warshall-floyd
ll dp[220][220];//dpテーブルには辺がないところにはINF、i==jには０を入れておく
void warshallfloyd(){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
}


int main(){
    cin >> n;
    rep(i,n)rep(j,n){
        char c;
        cin >> c;
        s[i][j]=c-'0';
    }
    //二部グラフ判定
    UnionFind u(2*n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i][j]){
                u.merge(i,j+n);
                u.merge(j,i+n);
            }
        }
    }
    rep(i,n){
        if(u.same(i,i+n)){
            cout << -1 << endl;
            return 0;
        }
    }
    //ワーシャルフロイド
    rep(i,n){
        rep(j,n){
            if(i==j){
                dp[i][j]=0;
                continue;
            }
            if(s[i][j]==1)dp[i][j]=1;
            else dp[i][j]=INF;
        }
    }
    warshallfloyd();

    ll d = 0;
    rep(i,n){
        rep(j,n){
            if(dp[i][j]==INF)continue;
            chmax(d,dp[i][j]);
        }
    }
    cout << d+1 << endl;
    return 0;
}


Measured memory_bytes: 4132
# -*- coding: utf-8 -*-       

n, m = map(int, raw_input().split())
island = [[] for i in range(n+1)]
ans = 'IMPOSSIBLE'
for i in range(m):
    a, b = map(int, raw_input().split())
    island[a].append(b)
    island[b].append(a)
for i in island[1]:
    if(n in island[i]):
        ans = 'POSSIBLE'
        break
print(ans)


Measured memory_bytes: 42848
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    string s, t; cin >> s >> t;
    int ans = INF;
    int n = SZ(s), m = SZ(t);
    REP(k, n - m + 1){
        int tmp = 0;
        REP(i, m){
            if(s[i + k] != t[i]) tmp++;
        }
        chmin(ans, tmp);
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 3644
# -*- coding: utf-8 -*-

k = input().split(" ")

num_sunuke = int(k[0])
kind = int(k[1])

counter = [False for i in range(num_sunuke)]

for i in range(kind):
    d = int(input())
    a = input().split(" ")
    for j in range(d):
        counter[int(a[j])-1] = True
        
print(counter.count(False))

Measured memory_bytes: 9220
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s1, s2, s3; cin >> s1 >> s2 >> s3;
    char S1 = s1[0]-32;
    char S2 = s2[0]-32;
    char S3 = s3[0]-32;
    cout << S1 << S2 << S3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n,m;
    cin>>n>>m;
    vector<int > p(m);//(int,int)のpair型の配列pを作る
    vector<string> s(m);
    for(int i = 0;i< m; i++){
        cin >> p[i] >> s[i];
    }
    map<int,bool> pro;
    for(int i=0;i<m;i++){
        pro[p[i]]=false;
    }
    int ans=0,pen=0;
    vector<int> pena(n,0);

    rep(i,m){
        if(s[i]=="WA"&&pro[p[i]]==false){//WAでまだ正解してない
            pena[p[i]]++;
        }
        else if(s[i]=="AC"&&pro[p[i]]==false){
            ans++;
            pro[p[i]]=true;
            pen += pena[p[i]];
        }
        //これ以外の場合はペナも正解数も増えないはず
    }
    cout <<ans<<" "<<pen<<endl;
}

Measured memory_bytes: 11136