akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	ll n; cin >> n;
	vll a(n);
	ll len = 0;
	rep(i, n){
		cin >> a[i];
		len += a[i];
	}

	ll ans = LONG_MAX;
	//if(len % 2 == 1) ans += 1;
	ll r = 0;
	ll l = len;
	rep(i, n){
		r += a[i];
		l -= a[i];
		ans = min(ans, abs(r-l));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    bool p=true;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            if(a[i]%3==0 || a[i]%5==0)
            {
                continue;
            }
            else
            {
                p=false;
            }
        }
    }
    if(p)
    {
        cout<<"APPROVED";
    }
    else
    {
        cout<<"DENIED";
    }
    return 0;
}









Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, d, s, t;

	cin >> a >> b >> c >> d;

	s = a + b + c + d;

	cin >> a >> b >> c >> d;

	t = a + b + c + d;

	if (s >= t)
		cout << s << endl;
	else
		cout << t << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;

  REP(i,n){
    bool ok = true;
    if((i+1)%2 == 0) ok = false;
    if(a[i] % 2 == 0) ok = false;

    if(ok) ++cnt;

  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int n, m;
int a[50], b[50];
bool seen[50];

int G[50][50];

void dfs(int now) {
    seen[now] = true;
    rep(i, n) {
        if (!G[now][i])continue;
        if (seen[i]) continue;
        dfs(i);
    }
}

void solve() {
    int ans = 0;
    rep(i, m) {
        G[a[i]][b[i]] = G[b[i]][a[i]] = false;
        fill(seen, seen + n, false);
        dfs(0);
        rep(j, n) if (!seen[j]) {
                ans++;
                break;
            }
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }
    cout << ans << endl;
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        int ta, tb;
        cin >> ta >> tb;
        ta--, tb--;
        G[ta][tb] = G[tb][ta] = true;
        a[i] = ta, b[i] = tb;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main() {
	int n;
	cin  >> n;
	vector<int64_t> v(n);
	int64_t ans = 1000;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		//if (i) {
			//if (v[i] > v[i - 1]) {
				//int64_t x = ans / v[i - 1];
				//ans = ans % v[i - 1];
				//ans += x * v[i];
			//}
		//}
	}
	for (int i = 0; i + 1 < n; ++i) {
		if (v[i + 1] > v[i]) {
			int64_t x = ans / v[i];
			ans = ans % v[i];
			ans += x * v[i + 1];
		}
	}
	cout << ans;
}













Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111


int main(void) {
  ll n;
  cin >> n;
  FOR(i, 0, n) {
	cin >> tmp;
	if (tmp % 2 == 1) cnt++;
  }
  if (cnt % 2 == 0) {
	cout << "YES" << endl;
  }
  else {
	cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, long long R){
    cout<<R+100*(max(0LL, 10-N))<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long R;
    scanf("%lld",&R);
    solve(N, R);
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int ans = 1;
  if (s == "RRR")
    ans = 3;
  else if (s == "SRR" || s == "RRS")
    ans = 2;
  else if (s == "SSS")
    ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        for(int i = 0;i<m;i++){
            int a = sc.nextInt();
            sum += a;
        }
         if(n<sum){
             System.out.print("-1");
         }else{
             System.out.print(n-sum);
         }
    }
}

Measured memory_bytes: 46416
#include <numeric>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<pair<int, int> > all(n);
    for (int i = 0; i < n; i++)
        cin >> all[i].second >> all[i].first;
    sort(all.rbegin(), all.rend());
    long long sum = 0, count = 0;
    int used[n+1];
    fill(used, used+n+1, 0);
    for (int i = 0; i < k; i++) {
        sum += all[i].first;
        if (used[all[i].second] == 0) count++;
        used[all[i].second]++;
    }
    long long ans = sum + count * count;
    for (int i = k, j = k-1; i < n && count < k; i++) {
        if (used[all[i].second] == 0) {
            while (used[all[j].second] <= 1) j--;
            sum += all[i].first - all[j].first;
            used[all[i].second]++;
            used[all[j].second]--;
            count++;
            ans = max(ans, sum + count * count);
            j--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()

signed main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a=0,b=0,c=0;
  fo(i,n){
    if(s[i]=='R')
      a++;
    else if(s[i]=='G')
      b++;
    else
      c++;
  }
  int ans=a*b*c;
  fo(i,n-2){
    for(int j=i+1; j<n-1; j++){
      int d=2*j-i;
      if(n<=d)
        continue;
      if(s[i]!=s[j]&&s[j]!=s[d]&&s[d]!=s[i])
        ans--;
    }
  }
  cout<<ans<<endl;
}

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  int k,x;
  cin >> k >> x;
  if(500*k >= x) cout << "Yes";
  else cout << "No";
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



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

int main (){
  vector<int> dish (5),first (5);
  int sum = 0;
  for (int i = 0;i < 5;i++){
    cin >> dish.at(i);
    if(dish.at(i)%10 == 0){
      sum+=dish.at(i);
      dish.at(i) = 0;
    }else{
      first.at(i) = dish.at(i)%10;
      dish.at(i) = dish.at(i)/10 + 1;
    }
  }
  sort(dish.begin(),dish.end());
  reverse(dish.begin(),dish.end());
  if (dish.at(0) == 0) {
    cout<< sum << endl;
    return 0;
  }
  for (int i = 0;i < 5;i++)
    sum += dish.at(i)*10;
  sum-=10;
  sort(first.begin(),first.end());
  if(first.at(0) != 0)
    sum += first.at(0);
  else if(first.at(1) != 0)
    sum += first.at(1);
  else if(first.at(2) != 0)
    sum += first.at(2);
  else if(first.at(3) != 0)
    sum += first.at(3);
  else if(first.at(4) != 0)
    sum += first.at(4);
  cout << sum << endl;
}

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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;
    cin>>a>>b;

    if(b*2>=a){
        cout<<0<<endl;
    }

    else{
        cout<<a - b*2<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
 
int main(void){
    int i,j,n,graph[MAX][MAX]={{0},{0}},u[2]={0},judge;
    scanf("%d",&n);
   
	for(i=1;i<n+1;i++){
		scanf("%d %d",&u[0],&u[1]);
		for(j=1;j<=u[1];j++){
			scanf("%d",&judge);
			graph[i][judge]=1;
			}
		}
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            printf("%d",graph[i][j]);
            if(j!=n)printf(" ");
            }
            printf("\n");
        }
    return 0;
    }

Measured memory_bytes: 652
def main():
    n = int(input())
    ps = list(map(int, input().split()))
    res = 0
    for i in range(1, n - 1):
        if ps[i - 1] < ps[i] < ps[i + 1] or ps[i - 1] > ps[i] > ps[i + 1]:
            res += 1
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)

{

int a,b,c,x;

scanf("%d %d %d",&a,&b,&c);

if(a>b){


x=a;


a=b;


b=x;


}if(a>c){


x=a;


a=c;


c=x;


}if(b>c){


x=b;


b=c;


c=x;


}


printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

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

const int N=2e6+5;
const int oo=1e9+7;

int n;
string s,t;

int h[N];


int Tree [N+10];

void update(int idx, ll x,int n)
{
    // Let, n is the number of elements and our queries are
    // of the form query(n)-query(l-1), i.e range queries
    // Then, we should never put N or MAX in place of n here.
    assert(idx>=1);
    while(idx<=n)
    {
        Tree[idx]+=x;
        idx+=(idx&-idx);
    }
}

int query(int idx)
{
    ll sum=0;
    while(idx>0)
    {
        sum+=Tree[idx];
        idx-=(idx&-idx);
    }
    return sum;
}

int val(int idx)
{
    return query(N ) - query(idx-1);
}

int now  = 1 ;


int solve()
{
    if(s==t)
        return 0;
    s="#"+s;
    t="#"+t;

    vector<int > x;
    for(int i=1; i<=n; i++)
    {
        if(i>1 and t[i]==t[i-1])
            continue ;
        x.push_back(i);
    }
    reverse(ALL(x));



    int ss = n;
    int ret =1;

    for(int tt: x)
    {
        while(ss >=1 )
        {
            if(ss<=tt and s[ss] == t[tt])
                break;
            else
            {
                ss--;
                now++;
            }
        }
        if(ss>=1)
        {
            if(ss!=tt)
            {
//                for(int i= ss; i<tt; i++)
//                    h[i] =h[i+1] + 1;
//                h[tt]++;
//                ret = max(ret,  h[tt] + 1);

                int old = val(now-(tt-ss));
                now--;
                update(now , 1 , N);
//                assign_index( now - (tt-ss), old + 1 );
                ret =max(ret, old + 2);

//                assert(old+2 == h[tt]+1);

            }
            ss--;
            now++;
        }
        else
            return -1;
    }
    return ret;
}

int32_t main()
{
    FastIO;
    cin>>n>>s>>t;
    cout<<solve()<<"\n";
}


Measured memory_bytes: 13680
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define int long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

int A,B,n,ans,sum;

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	A=read();B=read();n=read();
	/*Tf(x,n,1) 
		if(floor(A*x/B)-A*floor(x/B)>ans) {
			ans=floor(A*x/B)-A*floor(x/B);
			cout<<x<<endl;
		}*/
			
	sum=sum=floor(A*n/B)-A*floor(n/B);
	int x=n/B*B-1; //cout<<x<<endl;
	if(x>0)
		if(floor(A*x/B)-A*floor(x/B)>sum) 
			sum=floor(A*x/B)-A*floor(x/B);
//	write(ans);puts("");
	write(sum);
	
    return 0;
}
//984521 526541 523232

Measured memory_bytes: 3640
/* Filename: ABC074A.java
 * Author: Mushiyo
 */
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			int A = input.nextInt();
			
			System.out.println(N * N - A);
		}

	}

}


Measured memory_bytes: 22740
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());

    bool ans=false;
    for(int i=0;i<s.size();i++){
        if(s[i]<t[i]){
            ans=true;
            break;
        }else if(s[i]>t[i]){
            break;
        }else{
            if(s.size()<t.size()){
                if(i==s.size()-1){
                    ans=true;
                    break;
                }
            }else{
                if(i==t.size()-1){
                    break;
                }
            }
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) {
            String[] values = reader.readLine().split(" ");
            double xa = Double.parseDouble(values[0]);
            double ya = Double.parseDouble(values[1]);
            double ra = Double.parseDouble(values[2]);
            double xb = Double.parseDouble(values[3]);
            double yb = Double.parseDouble(values[4]);
            double rb = Double.parseDouble(values[5]);
            double x = xb - xa;
            double y = yb - ya;
            double d = Math.sqrt(x * x + y * y);
            int result = 0;
            if (d <= ra + rb) {
                if (d < ra - rb) {
                    result = 2;
                } else if (d < rb - ra) {
                    result = -2;
                } else {
                    result = 1;
                }
            }
            out.println(result);
        }
    }
}

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


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

    int num = ( a + b + 1) / 2;
    cout << num << endl;

}


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
int n,m;
int fa[100005];
int finde(int x)
{
	if(fa[x] == x) return fa[x];
	else return fa[x] = finde(fa[x]); 
}
void unio(int x,int y)
{
	int xx = finde(x);
	int yy = finde(y);
	if(xx != yy)
	{
		fa[xx] = yy;
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n;i++) fa[i] = i;
	for(int i=0,a,b,c;i<m;i++)
	{
		cin>>a>>b>>c;
		unio(a,b);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++)
	{
		if(fa[i] == i) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define re register
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;
inline int read(){
	int x=0,w=0;char ch=getchar();
	while (!isdigit(ch))w|=ch=='-',ch=getchar();
	while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return w?-x:x;
}
int a[100007],c[100007],v[100007],t[100007],n;
inline void ksm(int p){
	while (p){
		if (p&1){
			for (int i=1;i<=n;++i)t[i]=c[v[i]];
			for (int i=1;i<=n;++i)c[i]=t[i];
		}
		for (int i=1;i<=n;++i)t[i]=v[v[i]];
		for (int i=1;i<=n;++i)v[i]=t[i];
		p>>=1;
	}
}
signed main(){
    n=read();
    for(int i=1;i<=n;i++)a[i]=read(),c[i]=a[i]-a[i-1],v[i]=i;
    int m=read(),k=read();
    for(int i=1;i<=m;i++){
        int x=read();
        swap(v[x],v[x+1]);
    }
    ksm(k);
    double sum=0;
	for (int i=1;i<=n;++i){
		sum+=c[i];
		printf("%.1lf\n",sum);
	}
	return 0;
}


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

struct Card { char suit, value; };

void bubbleSort(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j >= i; j--) {
            if (A[j].value < A[j - 1].value) {
                struct Card tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
            }
        }
    }
}

void selectionSort(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j].value < A[minj].value) {
                minj = j;
            }
        }
        struct Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i = 0; i < N; i++) {
        if (C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

void print(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        cout << A[i].suit << A[i].value;
        if (i == N - 1) cout << endl;
        else cout << ' ';
    }
}

int main(void) {
    int N, i;
    Card C1[50], C2[50];
    cin >> N;

    for (i = 0; i < N; i++) cin >> C1[i].suit >> C1[i].value;
    for (i = 0; i < N; i++) C2[i] = C1[i];

    bubbleSort(C1, N);
    selectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;

    print(C2, N);
    if (isStable(C1, C2, N)) cout << "Stable";
    else cout << "Not stable";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1156
class DisjointSet
  def initialize(size = nil)
    @rank = Array.new(size){0}
    @parent = []
    if size
      size.times do |i|
        @parent[i] = i
      end
    end
  end

  def same(x, y)
    return find(x) == find(y)
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    if @rank[x] > @rank[y]
      @parent[y] = x
    else
      @parent[x] = y
      @rank[y] += 1 if @rank[x] == @rank[y]
    end
  end

  def find(x)
    @parent[x] = find(@parent[x]) unless x == @parent[x]
    return @parent[x]
  end
end

v, e = gets.split.map(&:to_i)
tree = DisjointSet.new(v)

edges = {}
e.times{|i|
  s, t, w = gets.split.map(&:to_i)
  edges["#{s} #{t}"] = w
}

edges = edges.sort_by {|k, val| val}
sum = 0
edges.each{|edge|
  s, t = edge[0].split.map(&:to_i)
  unless tree.same(s, t) then
    sum += edge[1]
    tree.unite(s, t)
  end
}
puts sum

Measured memory_bytes: 27796
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	string s;
	cin>>s;
	string s1 = s;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return 0;
	}
	if(s.sz==26){
		vector<char> vc;
		rep(i,0,s.sz){
			vc.pb(s[i]);
		}
		next_permutation(all(vc));
		string ss;
		rep(i,0,vc.sz){
			ss += ctos(vc[i]);
		}
		rep(i,0,26){
			string s2;
			rep(j,0,i+1){
				s2 += ss[j];
			}
			if(s2>s){
				cout << s2 << endl;
				break;
			}
		}
		return 0;
	}
	ll d[26];
	clr(d,0);
	rep(i,0,s.sz){
		d[s[i]-'a']++;
	}
	rep(i,0,26){
		if(d[i]==0){
			string s2 = ctos('a'+i);
			s += s2;
			break;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let a: Vec<usize> = read_vec();
    let mut count = vec![0; 2 * 100_000 + 10];
    let mut ans = vec![];
    for i in 0..n {
      count[a[i]] += 1;
    }

    let mut tot: usize = 0;

    for i in 0..count.len() {
      let c = count[i];
      tot += (c-1)*c/2;
    }

    for i in 0..n {
      let now = a[i];
      let c = count[now];
      let t = tot - c * (c-1)/2 + (c-1)*(c-2)/2;
      ans.push(t);
    }

    for a in ans {
      println!("{}", a);
    }
}



Measured memory_bytes: 14576
C = [[int(i) for i in input().split()] for i in range(3)]
res = 'No'
for i in range(100) :
  a1 = i
  b1 = C[0][0] - a1
  b2 = C[0][1] - a1
  b3 = C[0][2] - a1
  a2 = C[1][0] - b1
  a3 = C[2][0] - b1
  if C[1][1] != a2 + b2 :
    continue
  if C[1][2] != a2 + b3 :
    continue
  if C[2][1] != a3 + b2 :
    continue
  if C[2][2] != a3 + b3 :
    continue
  res = 'Yes'
  break
print(res)

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

using namespace std;


int main(){

    // freopen("input.txt","r",stdin);

    string str;

    cin >> str;

    char cur;

    cur = str[0];

    int cnt = 0;
    int sum = 0;

    for(int i=1; i<str.length(); i++){

        if(str[i] == cur){

            continue;

        }else{

            cnt++;
            cur = str[i];
        }

    }

    cout << cnt <<endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k  = sc.nextInt();
		int count = 0;
		Map<Integer,Integer> p =  new LinkedHashMap<Integer,Integer>();

		for(int i = 1; i <= n; i++) {
			p.put(i,0);
		}

		for(int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for(int j = 0; j < d; j++) {
				int a = sc.nextInt();
				int temp = p.get(a)+1;
				p.put(a,temp);
			}
		}

		for(int i:p.keySet()) {
			if(p.get(i) == 0) {
				count++;
			}
		}
		System.out.println(count);


	}

}

Measured memory_bytes: 46668
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
long long a;
long double b;

signed main()
{
	scanf("%lld%llf", &a, &b);
	
	ll ans=floor((long double)a*b);
	printf("%lld",ans);
	 
	return 0;
} 

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,m,ans=0;cin>>n>>m;
  
  
  for(int i=0;i<n;i++)ans+=i;
  for(int i=0;i<m;i++)ans+=i;
  
  cout<<ans;
}
  
  

Measured memory_bytes: 256
L, R = map(int, input().split())
mod = 2018
i = L
if R-L >= 2019:
    mod = 0
else:
    for i in range(L, R):
        for j in range(i+1, R+1):
            num = (i*j) % 2019
            mod = min(mod, num)
            if mod == 0:
                break
print(mod)

Measured memory_bytes: 3060
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 998244353

def ddprint(x):
  if DBG:
    print(x)



# # # # class Segtree # # # #

#      0
#   1     2
# 3   4  5  6
#       :
# leaf i - n-1+i
# parent   - (i-1)//2
# children - 2*i+1, 2*i+2

class Segtree:
    # modify UNIT and oper depending on the reduce operation

    #UNIT = 0  # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..

    #@classmethod
    #def oper(c,x,y):
    #    return x|y  # sum:+ or/and/min/max/gcd/lcm:(same)

    # call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))

    def __init__(s,l,unit,oper):
        s.unit = unit
        s.oper = oper
        s.n = 1
        while s.n<l:
            s.n *= 2
        s.ary = [s.unit for i in range(2*s.n-1)]

    def get(s,i):
        return s.ary[i+s.n-1]

    def set(s,i,v):
        k = i+s.n-1
        s.ary[k] = v
        while k>0:
            k = (k-1)//2
            s.ary[k] = s.oper( \
                        s.ary[2*k+1], s.ary[2*k+2])

    def setary(s,a):
        for i,v in enumerate(a):
            s.ary[i+s.n-1] = v
        for k in range(s.n-2,-1,-1):
            s.ary[k] = s.oper( \
                        s.ary[2*k+1], s.ary[2*k+2])

    def query(s,x,y):
        l = x+s.n-1
        r = y+s.n-1
        res = s.unit
        while l<r:
            if not l%2:
                res = s.oper(res,s.ary[l])
                l += 1
            if not r%2:
                r -= 1
                res = s.oper(res,s.ary[r])
            l >>= 1
            r >>= 1
        return res


# # # # class Segtree end # # # #

# # # #
from bisect import bisect_left
n = inn()
xd = []
for i in range(n):
    xx,dd = inm()
    xd.append((xx,dd))
xd.sort()
x = [xd[i][0] for i in range(n)]

#ddprint(xd)
#ddprint(x)

r = [i for i in range(n)]
sgt = Segtree(n,0,max)
sgt.setary(r)
f = [0]*(n+1)
f[n] = 1
f[n-1] = 2
for i in range(n-2,-1,-1):
    xx,dd = xd[i]
    j = bisect_left(x,xx+dd)
    k = sgt.query(i,j)
    sgt.set(i,k)
    f[i] = (f[i+1] + f[k+1])%R
    #ddprint(f"i {i} x {xx} d {dd} j {j}")

#ddprint(f)
print(f[0])


Measured memory_bytes: 108068
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();

		int[] S = {A,B,C};
		Arrays.sort(S);

		int max = S[2];
		int second = S[1];
		int min = S[0];

		int count = 0;

		if(max%2 == second%2){
			count += (max-second)/2;
		}
		else{
			count += (max-(second+1))/2;
			count++;
			min++;
		}

		if(max%2 == min%2){
			count+= (max-min)/2;
		}
		else{
			count+=((max+1)-min)/2;
			count++;
		}

		System.out.println(count);
	}

}

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

    int N,M,Q;
    vector<int> a;
    vector<int> b;
    vector<int> c;
    vector<int> d;
    int ans = 0;


void cal(int n,vector<int> st){
    if(n == N){
        int tmp = 0;
        rep(i,Q){
            if(st[b[i]-1] - st[a[i]-1] == c[i])tmp += d[i];
        }
        ans = max(ans,tmp);
        return;
    }

    
    int start;
    if(n != 0)start = st[st.size()-1];
    else start = 1;

    for(int i = 1;i <= M;i++){
        if(i < start)continue;
        vector<int> v = st;
        v.push_back(i);
        cal(n+1,v);
    }

}


int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> v;

    cal(0,v);

    cout << ans << endl;

    
}

Measured memory_bytes: 3648
// atcoder/nikkei2019-2-qual/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 998244353;

namespace math {
  lli mod_pow(lli n, int p)
  {
    if (p == 0) return 1;
    if (p == 1) return n;
    lli m = mod_pow(n, p / 2);
    m *= m;
    m %= mod;
    if (p % 2) m = (m * n) % mod;
    return m;
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    map<int, int> m;
    each (i, v) ++m[i];

    lli x = (v[0] == 0 && m[0] == 1);

    sort(v.begin(), v.end());
    for (int i = 1; i <= v.back(); ++i) {
      if (m[i] == 0) x = 0;
      (x *= math::mod_pow(m[i - 1], m[i])) %= mod;
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 8172
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


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

        divisors.sort(reverse=True)
        return divisors

    n, m = ns()
    gcd = make_divisors(m)

    max_gcd = 1
    for d in gcd:
        if m // d >= n:
            max_gcd = d
            break

    print(d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5564
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
using namespace std;

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7


int main() {
	int D; cin >> D;
	if (D == 25) cout << "Christmas" << endl;
	if (D == 24) cout << "Christmas Eve" << endl;
	if (D == 23) cout << "Christmas Eve Eve" << endl;
	if (D == 22) cout << "Christmas Eve Eve Eve" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;

const int INF = 1<<28;
int c, n, m, s, d;
vector<pair<int, int> > g[100];
int dist[100][11];

typedef tuple<int, int, int> node;

int dijkstra() {
  priority_queue<node, vector<node>, greater<node> > Q;
  Q.push(make_tuple(0, s, c));
  dist[s][c] = 0;
  
  while (!Q.empty()) {
    int cost;
    int v;
    int t;
    tie(cost, v, t) = Q.top();
    Q.pop();
    for (auto &edge: g[v]) {
      int w = edge.first;
      int weight = edge.second;
      if (cost + weight < dist[w][t]) {
        dist[w][t] = cost + weight;
        Q.push(make_tuple(dist[w][t], w, t));
      }
      if (t > 0 && cost + weight/2 < dist[w][t-1]) {
        dist[w][t-1] = cost + weight/2;
        Q.push(make_tuple(dist[w][t-1], w, t-1));
      }
    }
  }

  int ret = INF;
  for (int i = 0; i < 11; i++)
    ret = min(ret, dist[d][i]);
  return ret;
}

void init() {
  for (int i = 0; i < 100; i++)
    g[i].clear();
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 11; j++)
      dist[i][j] = INF;
}

int main(int argc, char *argv[])
{
  for (;;) {
    cin >> c >> n >> m >> s >> d;
    if (!c && !n && !m && !s && !d)
      break;
    --s, --d;
    init();
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a, --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }
    int ret = dijkstra();
    printf("%d\n", ret);
  }
  
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll fact(ll x){
  ll y=1;
  for(ll i=1;i<=x;i++){
   y*=i;
   y%=1000000007;
  }
  return y;
}
ll lcm(ll x,ll y){
ll z=__gcd(x,y);
  return (x*y/z);
}
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll B=b-(b/c+b/d-b/lcm(c,d));
  if(a>0) {
  ll A=a-1-((a-1)/c+(a-1)/d-(a-1)/lcm(c,d));
  putout(B-A);
  }
  else putout(B);
}

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

double p[20][9];
int n;
char s, t, b;

vector<vector<int>> adj = {
    {1,3,0,0},
    {0,2,4,1},
    {1,5,2,2},
    {0,4,6,3},
    {1,3,5,7},
    {2,4,8,5},
    {3,7,6,6},
    {4,6,8,7},
    {5,7,8,8}
};

int main() {
    while (cin >> n, n) {
        cin >> s >> t >> b;
        for (int i=0; i<20; ++i) {
            for (int j=0; j<9; ++j) {
                p[i][j] = 0;
            }
        }
        p[0][s - 'A'] = 1;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<9; ++j) {
                for (int k=0; k<4; ++k) {
                    if (adj[j][k] == b - 'A') {
                        p[i+1][j] += p[i][j] / 4.0;
                    } else {
                        p[i+1][adj[j][k]] += p[i][j] / 4.0;
                    }
                }
            }
        }
        cout.width(8);
        cout << fixed << p[n][t - 'A'] << endl;
    }
    return 0;
}

Measured memory_bytes: 1268
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N+1)]
for i, v in enumerate(ABC):
  for j in range(3): # prev
    for k in range(3): # cand
      if j == k:
        continue
      dp[i][k] = max(dp[i-1][j] + v[k], dp[i][k])
print(max(dp[N-1]))

Measured memory_bytes: 74072
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 60;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

const int N = 256;

inline int round(int x){
    chmin(x, N - 1);
    chmax(x, 0);
    return x;
}

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

    for(int n, m; cin >> n >> m, n;){
        vi C(m); for(auto& e : C) cin >> e;
        vi x(n); for(auto& e : x) cin >> e;

        vector<vll> dp(n + 1, vll(N, inf));
        dp[0][128] = 0;

        rep(i, n){
            rep(j, N){
                ll cur = dp[i][j];

                if(dp[i][j] == inf) continue;
                for(auto& c : C){
                    int nj = round(j + c);
                    chmin(dp[i + 1][nj], cur + (int)pow(nj - x[i], 2));
                }
            }
        }

        cout << *min_element(_all(dp[n])) << endl;
    }

    return 0;
}

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

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> p(n);

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

    int count = 0;
    
    for(int i=0;i<n;i++){
        if(i != n-1){
            if(p[i] == i+1){
                count++;
                i++;
            }
        }else{
            if(p[i] == i+1)
                count++;
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>  // ver1.9
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  string s;
  cin >> s;
  while(s.size()<15) s.pb('o');
  int win =0;
  rep(i,0,15){
    if(s[i]=='o') win++;
  }
  if(win>=8) cYES;
  else cNO;
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
r = ''
i=0
j=1
while(i<len(s)):
    while(j<len(s) and s[i]==s[j]):
        j+=1
    r += s[j-1]
    #print(r)
    i=j
    j=i+1
print(len(r))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
using namespace std;

int main() {
	double r;
	cin >> r;
	double pi = 3.14159265358979;
	printf("%.8f %.8f\n", pi*r*r, pi*r*2);
	return 0;
}


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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		ll a[n];
		for (int i=0;i<n;i++) cin >> a[i];
		ll ans=0;
		ll ma = a[0];
		for (int i=1;i<n;i++) {
			if (a[i] < ma) ans += ma-a[i];
			ma = max(a[i],ma);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5212