akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define ll long long

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

void call(int n) {
    int i = 0;
    while (i < n) {
        ++i;
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }
        while (x) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << "\n";
}
int main() {
    int n;
    cin >> n;
    call(n);

    return 0;
}



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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4564
#include<cstdio>
#define re register
#define int long long
using namespace std;
int n,a,b,c,d;
signed main(){
scanf("%lld",&n);
if(n&1)puts("0");
else{
for(re int i=5;i<=n;i*=5){
	b+=n/(i*2);
}
printf("%lld",b);}
}


Measured memory_bytes: 128
function main(input) {
        var args = input.split('\n');
        var k = args[0].split(' ')[1];
        var s = args[1].split('');

        s[k - 1] = s[k - 1].toLowerCase();
        s = s.join('');
        console.log(s);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())

#define INF INT_MAX/3
#define mod 1000000007

int n;
vector<int> g[100010];
int deg[100010];
int bcnt[100010],cnt[100010],sum[100010];
int p[100010];
bool dame[100010];
string s;

void predfs(int v,int pre){
  cnt[v]=1;
  if(s[v]=='B')bcnt[v]++;
  for(int nv : g[v]){
    if(nv==pre)continue;
    predfs(nv,v);
    cnt[v]+=cnt[nv];
    bcnt[v]+=bcnt[nv];
  }
  for(int nv : g[v]){
    if(nv==pre)continue;
    if(cnt[nv]==bcnt[nv]){
      dame[nv]=true;
      deg[v]--;
    }
  }
}

void predfs2(int v,int pre){
  if((s[v]=='W'&&deg[v]%2==0)||(s[v]=='B'&&deg[v]%2==1))sum[v]++;
  for(int nv : g[v]){
    if(nv==pre||dame[nv])continue;
    predfs2(nv,v);
    sum[v]+=2;
    sum[v]+=sum[nv];
  }
}


P dfs(int v,int pre){
  P res=P(p[v],v);
  for(int nv : g[v]){
    if(nv==pre||dame[nv])continue;
    P tmp=dfs(nv,v);
    maxch(res,P(tmp.fi+p[v],tmp.se));
  }
  return res;
}

int main(){
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin>>s;

  int r=-1,wcnt=0;
  rep(i,n){
    deg[i]=g[i].size();
    if(s[i]=='W'){
      r=i;
      wcnt++;
    }
  }
  if(r==-1){
    cout<<0<<endl;
    return 0;
  }
  if(wcnt==1){
    cout<<1<<endl;
    return 0;
  }
  predfs(r,-1); predfs2(r,-1);
  int res=sum[r];
  rep(i,n){
    if((s[i]=='W'&&deg[i]%2==0)||(s[i]=='B'&&deg[i]%2==1)) p[i]=2;
    else p[i]=0;
  }
  P p1=dfs(r,-1);
  P p2=dfs(p1.se,-1);
  cout<<res-p2.fi<<endl;
  return 0;
}


Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	string s;
	cin>>s;
	ll x = 0;
	x+=((ll)(s[0] - '0'));
	x*=10;
	x+=((ll)(s[1] - '0'));
	ll y = 0;
	y+=((ll)(s[2] - '0'));
	y*=10;
	y+=((ll)(s[3] - '0'));
	if(x<=12 && y<=12){
		if(x==0 && y==0){
			cout<<"NA"<<endl;
			return 0;
		}
		if(x == 0){
			cout<<"YYMM"<<endl;
			return 0;
		}
		if(y == 0){
			cout<<"MMYY"<<endl;
			return 0;
		}
		cout<<"AMBIGUOUS"<<endl;
	}
	else if(x<=12){
		if(x == 0){
			cout<<"NA"<<endl;
			return 0;
		}
		cout<<"MMYY"<<endl;
	}
	else if(y<=12){
		if(y == 0){
			cout<<"NA"<<endl;
			return 0;
		}

		cout<<"YYMM"<<endl;
	}
	else {
		cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

string chipher(string tmp, int k){
	rep(i,tmp.size())if( 'a'<=tmp[i] && tmp[i]<='z' ){
		if( tmp[i]+k>'z' ){
			tmp[i] = (tmp[i]+k-'z'-1)+'a';
		}else{
			tmp[i] = tmp[i]+k;
		}
	}
	return tmp;
}
int main(){
	string in;
	while(getline(cin,in)){
		rep(i,26){
			string tmp = chipher(in,i);
			if( tmp.find("this")!=string::npos || tmp.find("the")!=string::npos ||
					tmp.find("that")!=string::npos ){
					
				cout << tmp << endl; break;
			}
		}
	}
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

signed main(){
    int L,R;scanf("%lld%lld",&L,&R);
    if(R-L>=2019){
        cout<<0<<endl;
        return 0;
    }

    int ans=2019;
    reps(i,L,R+1)reps(j,i+1,R+1)chmin(ans,(i*j)%2019);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

int main() {
    ll n,k; cin >> n >> k;
    multimap<ll,ll> p;
    for(int i = 0;i < n;i++){
        ll x,y; cin >> x >> y;
        p.insert(make_pair(x,y));
    }
    ll total = 0;
    for(auto a:p){
        total += a.second;
        if(total >= k){
            cout << (ll)a.first;
            break;
        }
    }
}



Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main(void) {
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for(int i=0; i<=K; i++) {
        for(int j=0; j<=K; j++) {
            int k = S - i - j;
            if(0 <= k && k <= K) {
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String args[]){
    Scanner youbi = new Scanner(System.in);
    String date = youbi.nextLine();

    switch (date){
      case "SUN":
        System.out.println("7");
        break;
      case "MON":
        System.out.println("6");
        break;
      case "TUE":
        System.out.println("5");
        break;
      case "WED":
        System.out.println("4");
        break;
      case "THU":
        System.out.println("3");
        break;
      case "FRI":
        System.out.println("2");
        break;
      case "SAT":
        System.out.println("1");
        break;
    }
  }
}


Measured memory_bytes: 22612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MAX 100
#define MAXI 1000
#define MIN 1
#define MID
int main(void){
  int M,N,a[MAX],count=0,sum=0;
  scanf("%d",&N);
  scanf("%d",&M);
  for(int i=0;i<N;i++){
   scanf("%d",&a[i]);
   sum=sum+a[i];
   }
  for(int i=0;i<N;i++){
   if(a[i]*(4*M)>=sum)count++;
   }
  if(count>=M)printf("Yes");
   else printf("No");
   exit(0);
   }

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define iter set<int>::iterator
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=2e5+7;
const int inf=1e18+5;
const int mod=1e9+7;

main ()
{
    ios;
    int n;
    cin>>n;
    ld sum=0;
    for (int i=1;i<=n;++i){
        ld x;
        cin>>x;
        sum+=(ld)1/(ld)x;
    }
    ld ans=(ld)1/sum;
    cout<<fixed<<setprecision(12);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;

int k, d[100005]; 

heap<ii, vector<ii>, greater<ii> > pq; 
signed main()
{
	cin >> k; 
	for(int i = 0; i < k; i++) 
		d[i] = (int)1e9; 
	for(int i = 1; i <= 9; i++) {	
		if(d[i % k] == (int)1e9) {
			pq.push({i, i % k}); 
			d[i % k] = i; 
		}
	}
	while(!pq.empty()) {
		ii T = pq.top(); pq.pop();
		int u = T.se, w = T.fi;
		if(w == d[u]) {	
			for(int i = 0; i <= 9; i++) {
				int v = (u * 10 + i) % k; 
				if(d[v] > d[u] + i) {
					d[v] = d[u] + i;  
					pq.push({d[v], v}); 	
				}
			}
		}
	}
	cout << d[0]; 
}

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

int main(){
    int X, Y;
    cin >> X >> Y;

    int ans = X;
    if(X%Y == 0){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input())

if a + b + c + d == 7:
	print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=' + str(7)) 
elif a + b + c - d == 7:
	print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=' + str(7))
elif a + b - c + d == 7:
	print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=' + str(7))
elif a - b + c + d == 7:
	print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=' + str(7))
elif a + b - c - d == 7:
	print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=' + str(7))
elif a - b + c - d == 7:
	print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=' + str(7))
elif a - b - c + d == 7:
	print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=' + str(7))
elif a - b - c - d == 7:
	print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=' + str(7))

Measured memory_bytes: 3064
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll
void solve() {
    int h, w;
    cin >> h >> w;
    if (h > w) swap(h, w);
    if (h == 1) {
        cout << 1 << endl;
        return;
    }
    int ans = h * w / 2LL;
    if (h % 2 == 1 && w % 2 == 1) {
        ans++;
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    cout << (n*(n-1)/2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
 #define int long long
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};



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

  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  double A, B, t = 0;

  if(x > a * b / 2.0) {
    A = a;
    B = b - (2.0 * x / a - b);
    t = atan2(B, A);
  } else {
    A = b;
    B = x * 2.0 / b;
    t = atan2(A, B);
  }

  // cout << x << " " << A << " " << B << " " << C << endl;
  // cout << t << endl;
  fcout << t * (180.0 / 3.1415926535897932) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private StringBuffer letter;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		
		String[] s = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
		
		while (scan.hasNext()) {
			String str = scan.nextLine();
			
			for (int p = 0; p < s.length; p++) {
				letter = new StringBuffer();
				for (int i = 0; i < str.length(); i++) {
					String c = str.substring(i, i + 1);
					if (c.equals(" ") || c.equals(".")) {
						letter.append(c);
					}else {
						for (int j = 0; j < s.length; j++) {
							if (c.equals(s[j])) {
								if (j + p >= s.length) {
									letter.append(s[j + p - s.length]);
								}else {
									letter.append(s[j + p]);
								}
							}
						}
					}
				}
				
				if (letter.indexOf("this") != -1 || letter.indexOf("the") != -1 || letter.indexOf("that") != -1) {
					break;
				}
			}
			System.out.println(letter);
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 20148
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll gcd(ll a, ll b){
	return (b?gcd(b,a%b):a);
}

int x[4][50][50];

int main(void){
	int n,i,j,k,p,q,s,t;
	ll a,b,g,ans=0ll,tmp=0ll;
	bool flag;
	std::string str;
	std::cin >> n;
	for(i=0; i<n; ++i){
		flag = false;
		b = MOD-7; k = 0; a = 0ll;
		p = 0; q = 0; s = 0; t = 0;
		std::cin >> str;
		for(j=0; j<str.l_ength(); ++j){
			if(str[j]=='.'){
				flag = true;
				continue;
			}
			a *= 10;
			a += (str[j]-'0');
			if(flag){
				++k;
			}
		}
		while(k<9){
			a *= 10;
			++k;
		}
		g = gcd(a,b);
		a /= g; b /= g;
		while(!(a%2)){
			++p; a /= 2;
		}
		while(!(a%5)){
			++q; a /= 5;
		}
		while(!(b%2)){
			++s; b /= 2;
		}
		while(!(b%5)){
			++t; b /= 5;
		}
		++x[2*(p>=s)+(q>=t)][abs(p-s)][abs(q-t)];
	}
	for(p=0; p<50; ++p){
		for(q=0; q<50; ++q){
			tmp += x[3][p][q];
			for(s=0; s<50; ++s){
				for(t=0; t<50; ++t){
					if(p>=s && q>=t){
						ans += 1ll*x[3][p][q]*x[0][s][t];
						ans += 1ll*x[2][p][t]*x[1][s][q];
					}
					if(p>=s){
						ans += 1ll*x[3][p][q]*x[1][s][t];
					}
					if(q>=t){
						ans += 1ll*x[3][p][q]*x[2][s][t];
					}
				}
			}
		}
	}
	ans += (tmp*(tmp-1))/2;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

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

bool is_prime(ll x) {
  for (ll i = sqrt(x); i >= 2; i--) {
    if (x % i == 0) return false;
  }
  return true;
}

int a[1000005];

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return;
  }

  int ans = 0;
  for (ll i = 2; i*i <= 10e12; i++) {
    if (n % i != 0) continue;
    ll e = 0;
    while(n % i == 0) {
      // i の e 乗を因数に持つ
      e++;
      n /= i;
    }
    ll j = 1;
    while(e >= j) {
      // i の j = 1, 2, 3..乗で割ることができるか
      e -= j;
      j++;
      ans++;
    }
  }
  if (n != 1) ans++;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

const ll INF = 1e18;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    ll s[a+2], t[b+2], u[2][2], ans[q];
    s[0] = t[0] = -INF;
    for(int i = 1; i <= a; i++) {
        cin >> s[i];
    }
    for(int i = 1; i <= b; i++) {
        cin >> t[i];
    }
    s[a+1] = t[b+1] = INF;
    rep(i, q) {
        ans[i] = INF;
    }

    rep(h, q) {
        ll x;
        cin >> x;

        ll* sepos = lower_bound(s, s+a+2, x);
        u[0][1] = *sepos;
        ll* swpos = sepos - 1;
        u[0][0] = *swpos;
        ll* tepos = lower_bound(t, t+b+2, x);
        u[1][1] = *tepos;
        ll* twpos = tepos - 1;
        u[1][0] = *twpos;

        rep(i, 2) {
            rep(j, 2) {
                rep(k, 2) {
                   ll dist = 0;
                   dist += abs(u[i][j] - x) + abs(u[i][j] - u[i^1][k]);
                   ans[h] = min(ans[h], dist);
                }
            }
        }
    }

    rep(i, q) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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 int INF = 100000; 

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

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

   int min_p = p[1];
   int cnt = 0;
   for(int i = 1; i <= n; i++){
       if(min_p >= p[i]){
           cnt++;
           min_p = p[i];
       }else{
           continue;
       }
   }

   cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
N, M = map(int,input().split())
A=[]
for _ in range(M):
    s, c = map(int,input().split())
    A.append([s,c])

ans = -1
for i in range(10**N):
    f=len(str(int(i)))==N
    for s, c in A:
        if c != (i // (10**(N-s))) % 10:
            f = False
    if f:
        ans = i
        break

print(ans)

Measured memory_bytes: 9152
#include <stdio.h>
int main(){
  int x,y;
  while(1){
    scanf("%d%d",&x,&y);
    if(x==0 && y==0){break;
    }
    if(x>y){
      printf("%d %d\n",y,x);
    }
    else{
      printf("%d %d\n",x,y);
    }
  }
  return 0;
}

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

for i in range(m):
    a[i],b[i] = map(int,input().split())

go = []
goal = []

for i in range(len(a)):
    if a[i] == 1:
        go.append(b[i])
    if b[i] == n:
        goal.append(a[i])

count = [0 for i in range(n)]
for i in range(len(go)):
    count[go[i]-1] = 1
for i in range(len(goal)):
    count[goal[i]-1] += 1
for i in range(len(count)):
    if count[i] > 1:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 20528
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int N;
  double tmp1, tmp2; 
  
  cin >> N;

  tmp1 = (N+1)/2;
  tmp2 = tmp1/N; 
  
  printf("%10f\n",tmp2); 

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007
#define EPS 1e-7

int n,m;
double x[15],y[15];
int dp[1<<15];

bool ok(double r){
  rep(i,1<<n)dp[i]=INF;
  dp[(1<<n)-1]=0;
  for(int S=(1<<n)-1;S>0;S--){
    rep(i,n){
      if(((S>>i)&1)==0)continue;
      minch(dp[S^(1<<i)],dp[S]+1);
      rep(j,i){
        if(((S>>j)&1)==0)continue;
        double dx=x[i]-x[j],dy=y[i]-y[j];
        double d=sqrt(dx*dx+dy*dy)/2.0;
        if(d>r)continue;
        double mx=(x[i]+x[j])/2.0;
        double my=(y[i]+y[j])/2.0;
        double h=sqrt(r*r-d*d);
        double ex=-dy,ey=dx;
        double l=sqrt(ex*ex+ey*ey);

        if(l>0){
          ex/=l; ey/=l;
        }

        {
          double cx=mx+ex*h,cy=my+ey*h;
          int T=S^(1<<i)^(1<<j);
          rep(k,n){
            if(k==i||k==j)continue;
            if(((S>>k)&1)==0)continue;
            double ddx=x[k]-cx;
            double ddy=y[k]-cy;
            if(ddx*ddx+ddy*ddy<r*r+EPS){
              T^=(1<<k);
            }
          }
          minch(dp[T],dp[S]+1);
        }
        {
          double cx=mx-ex*h,cy=my-ey*h;
          int T=S^(1<<i)^(1<<j);
          rep(k,n){
            if(k==i||k==j)continue;
            if(((S>>k)&1)==0)continue;
            double ddx=x[k]-cx;
            double ddy=y[k]-cy;
            if(ddx*ddx+ddy*ddy<r*r+EPS){
              T^=(1<<k);
            }
          }
          minch(dp[T],dp[S]+1);
        }
      }
    }
  }
  return dp[0]<=m;
}

int main(){
  cin>>n>>m;
  rep(i,n)cin>>x[i]>>y[i];
  double lb=1e-6,ub=1e7;
  rep(hoge,50){
    double mid=(ub+lb)/2.0;
    if(ok(mid))ub=mid;
    else lb=mid;
  }
  printf("%.10f\n", (lb+ub)/2.0);
  return 0;
}



Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7 ;
int main(){
    long long n , m ;
    cin >> n >> m ;
    if ( abs(n-m) >= 2 ){
        cout << 0 << endl;
        return 0 ;
    }
    if ( m > n ) swap(n,m) ;
    long long ans = 1;
    if ( n > m ) {
        for(long long i=n;i>=2;i--){
            ans = (((ans % mod * i % mod) % mod) * (i-1) % mod) % mod ;
        }
        cout << ans << endl;
        return 0 ;
    }
    for(long long i=n;i>=2;i--){
        ans = (((ans % mod * i % mod) % mod) * i % mod) % mod ;
    }
    ans = (ans % mod + ans % mod) % mod;
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n;
  cin >> n;
  n%=10;
  if(n==3) {
    cout << "bon" << endl;
  } else if(n==0||n==1||n==6||n==8) {
    cout << "pon" << endl;
  } else {
    cout  << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D,a,b;
  cin>> A >> B >> C >> D;
  a=A/D+1;
  if(A%D==0){
    a=A/D;
  }
  b=C/B+1;
  if(C%B==0){
    b=C/B;
  }
  if(a>b){
    cout<< "Yes" <<endl;
  }else if(a==b){
    cout<< "Yes" <<endl;
  }else if(a<b){
    cout<< "No" <<endl;
  }
  return 0;
}


Measured memory_bytes: 3112
//39
#include<iostream>
#include<cstdlib>
#include<sstream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  for(string s;cin>>s,s!="0000";){
    int c=0;
    while(s!="6174"){
      sort(s.begin(),s.end());
      if(s[0]==s[3]){
	cout<<"NA"<<endl;
	goto next;
      }
      stringstream ss;
      ss.fill('0');
      ss.width(4);
      ss<<atoi(string(s.rbegin(),s.rend()).c_str())-atoi(s.c_str());
      s=ss.str();
      c++;
    }
    cout<<c<<endl;
  next:
    ;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
using namespace std;
int main(void)
{
	double date[7]={0,165,170,175,180,185,2000};
	int n;
	cin >> n;
	int freq[7]={0};
	while(n--){
		double height;
		cin >> height;
		for(int i=1;i<7;i++){
			if(date[i-1]<=height&&height<date[i]){
				freq[i]++;
				break;
			}
		}
	}
	for(int i=1;i<7;i++){
		cout << i << ":";
		for(int j=0;j<freq[i];j++){
			cout << "*";
		}
		cout << "\n";
	}
	return 0;
}

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

using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    printf("%lf\n", d);
}

Measured memory_bytes: 3288
#include <iostream>
#include <string>
using namespace std;
int main()
{
	while(true)
	{
		int n1, n2;
		cin >> n1 >> n2;

		if (n1 > 0 || n2 > 0)
		{
			if (n1 < n2)
				cout << n1 << " " << n2 << endl;
			else
				cout << n2 << " " << n1 << endl;
		}
		else break;
	}
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)

int main(void){

  int p,q,r;
  cin>>p>>q>>r;
  cout<<min((p+q),min(q+r,r+p))<<endl;


  return 0;
}


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

int main () {
  int a , b , c ;
  cin >> a >> b >> c ;
  
  int x , y ;
  x = b - a ;
  y = c - a ;
  
  if(x<=0) x *= -1;
  if(y<=0) y *= -1;
  
  if( x >= y ) {
    cout << "B" << endl ;
  } else {
    cout << "A" << endl ;
  }
}


Measured memory_bytes: 256
#include <iostream>
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
#include <stdio.h>

int
main(void)
{
	int x, y, v = 0;

	scanf("%d %d", &x, &y);

	for (;;) {
		if (!(x >= y)) {
			v = x;
			x = y;
			y = v;
		}
		if ((v = x % y)) {
			x = y;
			y = v;
		} else {
			break;
		}
	}

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

	return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	lint N, M;
	cin >> N >> M;
	for (int i = M; i > 0; i--) {
		if (N * i <= M && M % i == 0) {
			cout << i << endl;
			return 0;
		}
	}
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin>>s;
  int n=s.size();
  int sum=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0')sum++;
  }
  int ss=n-sum;
  cout<<min(ss,sum)*2<<endl;
}

Measured memory_bytes: 512
#include  <stdio.h>
#include <string.h>

int main(){

char text[50];
int count1 = 0,count2 = 0,count;
int leng = 0;
int i=0;
int num = 0;

scanf("%s",text);
leng = strlen(text);

if(text[0]==text[1]){
        if(text[2]==text[3]&&text[0]!=text[2]){
                num = 1;
        }
}

if(text[0]==text[2]){
        if(text[1]==text[3]&&text[0]!=text[1]){
                num = 2;
        }
}

if(text[0]==text[3]){
        if(text[1]==text[2]&&text[0]!=text[1]){
                num = 3;
        }
}

if(num>0){
        printf("Yes\n");
}else{
        printf("No\n");
}

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<double, double> > p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    /*
    for (int i = 0; i < n; i++) {
        cout << p[i].first << " " << p[i].second << endl;
    }
    cout << endl;
    */

    double ans = 0.0;
    do {
        /*
        for (int i = 0; i < n; i++) {
            cout << p[i].first << " " << p[i].second << endl;
        }
        cout << endl;
        */

        for (int i = 0; i < n - 1; i++) {
            double c = 0.0;
            c += (p[i].first - p[i + 1].first) * (p[i].first - p[i + 1].first);
            //cout << c << endl;
            c += (p[i].second - p[i + 1].second) * (p[i].second - p[i + 1].second);
            c = pow(c, 1 / 2.0);
            ans += c;
            //cout << ans << endl;
        }
        //cout << ans << endl;
    }while(next_permutation(p.begin(), p.end()));
    
    double d = 1.0;
    for (double i = 1.0; i <= n; i += 1.0) d *= i;
    //cout << d << endl;

    //cout << ans << endl;
    ans /= (double)d;
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

const int N = 3002;

ll a[N][N];

ll dp[N][N][4];

ll r,c,k;

int _runtimeTerror_()
{
    cin>>r>>c>>k;
    for(int i=1;i<=k;++i)
    {
        int x,y,w;
        cin>>x>>y>>w;
        a[x][y]=w;
    }
    for(int i=1;i<=r;++i)
    {
        for(int j=1;j<=c;++j)
        {
            if(a[i][j]==0)
            {
                for(int l=0;l<=3;++l)
                {
                    amax(dp[i][j][l],dp[i-1][j][3]);
                    amax(dp[i][j][l],dp[i][j-1][l]);
                }
                continue;
            }
            for(int l=0;l<=3;++l)
            {
                amax(dp[i][j][l],dp[i-1][j][3]);
                amax(dp[i][j][l],dp[i][j-1][l]);
                if(l>0)
                    amax(dp[i][j][l],dp[i-1][j][3]+a[i][j]);
            }
            for(int l=1;l<=3;++l)
                amax(dp[i][j][l],a[i][j]+dp[i][j-1][l-1]);
            for(int l=1;l<=3;++l)
                amax(dp[i][j][l],dp[i][j][l-1]);
        }
    }
    cout<<dp[r][c][3]<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 355340
/*
	https://www.youtube.com/watch?v=766qmHTc2ro
*/
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define ull unsigned long long
#define ll long long
#define ss string
#define vt vector
#define pii pair <int,int>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define pll pair <ll,ll>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define sz(x) (int) x.size()
#define bcc __builtin_popcount
#define bll __builtin_popcountll
void ___(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void data(){
	freopen("name.in","r",stdin);
	freopen("name.out","w",stdout);
}
const int N = 3e5 + 500;
const ll INF = 1e18;
const int mod = 1e9 + 7;


int main()
{
	//data();
	___();
	
	
	int n;
	cin >> n;
	int a[1 + n];
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int lst = a[1];
	ll s = 0;
	for(int i = 2; i <= n; i++){
		if(lst > a[i]){
			s += lst - a[i];
		}else{
			lst = a[i];
		}
	}
	cout << s;
	return 0;
}




Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  string w; cin >> w;
  int cnt[26] = {0};
  rep(i, w.size()) {
    cnt[w[i] - 'a']++;
  }
  bool flag = true;
  for (auto c : cnt) {
    if (c % 2 == 1) {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> student(N, vector<int>(2));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> student.at(i).at(j);
        }
    }
    vector<vector<int>> cp(M, vector<int>(2));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> cp.at(i).at(j);
        }
    }
    
    for (int i = 0; i < N; i++) {
        vector<pair<int, int>> key(M);
        for (int j = 0; j < M; j++) {
            int dst;
            dst = abs(student.at(i).at(0) - cp.at(j).at(0)) + abs(student.at(i).at(1) - cp.at(j).at(1));
            key.at(j) = make_pair(dst, j + 1);
        }
        sort(key.begin(), key.end());
        cout << key.at(0).second << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    if( a+b >= c ){
      std::cout << "Yes" << std::endl;
    }else{
      std::cout << "No" << std::endl;
    }
}
    

Measured memory_bytes: 256
//In the Name of ̲A̲l̲l̲a̲h̲

#define pb push_back
#define F first
#define S second
#define sz size()
#define ll long long
#define modulo(x,y) ((x+y)%y)
#include <bits/stdc++.h>

using namespace std;

const ll mx = 1e5+1, inf = 1e10;
ll n, w[101], v[101], W, dp[101][mx+10], ps[10001], ans;

int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> W;
	for (ll i = 1; i <= n; i++)
    {
        cin >> w[i] >> v[i];
    }
    for (ll i = 1; i <= n; i++)
    {
        ps[i] = ps[i-1] + v[i];
    }
    for (ll i = 0; i <= n; i++)
        for (ll j = 0; j <= mx; j++)
            dp[i][j] = inf;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= ps[i]; j++)
        {
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
        }
    }
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= mx; j++)
        {
            if (dp[i][j] <= W)
                ans = max(ans,j);
        }
    }
    cout << (1+ans);
}

/*𝐻𝒶𝒹𝒾*/


Measured memory_bytes: 79232
(declaim (inline read-line-into))
(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\Nul))
  (declare (optimize (speed 3) (safety 0))
	   (simple-base-string buf-str))
  (loop for ch of-type base-char =
           #-swank (code-char (read-byte in nil #\Newline))
           #+swank (read-char in nil #\Newline)
        for idx = 0 then (1+ idx)
        until (char= ch #\Newline)
        do (setf (aref buf-str idx) ch)
        finally (setf (aref buf-str idx) terminate-char)
                (return buf-str)))

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil
(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (declare (optimize (speed 3) (safety 0)))
  (let* ((n (read))
         (k (read))
         (table (make-array (list n) :element-type 'uint))
         (buf (make-string 11 :element-type 'standard-char :initial-element #\Newline)))
    (declare (uint k))
    (dotimes (idx n)
      (setf (aref table idx)
            (parse-integer (read-line-into buf *standard-input* #\Newline) :junk-allowed t)))
    (stable-sort table #'<)
    (println
     (loop for begin-idx from 0
           for end-idx from (- (min k (length table)) 1) below (length table)
           minimize (- (aref table end-idx) (aref table begin-idx))))))

#-swank(main)


Measured memory_bytes: 20580
import sys

input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


def solve():

    S = [0 for _ in range(N + 1)]

    comb = Combination(100001, mod)

    for i in range(N):
        S[i + 1] = S[i] + A[i]
        S[i + 1] %= mod

    ans = 0
    for i in range(K - 1, N):
        ans += (S[N] - S[i] - S[N - i]) * comb(i - 1, K - 2)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 24424
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n; long long a[1009], b[1009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	long long p = 1, q = 1;
	for (int i = 0; i < n; i++) {
		long long r1 = p, r2 = q;
		if (p % a[i] != 0) r1 = (p / a[i] + 1) * a[i];
		if (q % b[i] != 0) r2 = (q / b[i] + 1) * b[i];
		if (r1 / a[i] > r2 / b[i]) r2 = r1 / a[i] * b[i];
		else r1 = r2 / b[i] * a[i];
		p = r1, q = r2;
	}
	cout << p + q << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int total = 0;
    int[] array = new int[n];

    for(int i=0 ; i<n; i++){
      array[i] = sc.nextInt();
    }

    Arrays.sort(array);

    for(int i=0; i<k; i++){
      total += array[i];
    }

    System.out.println(total);
  }
}

Measured memory_bytes: 38804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main()
{
	int n;
	int c[500];
	int s[500];
	int f[500];
	int time=0;
	
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>c[i]>>s[i]>>f[i];
	}

	for(int i=0;i<n-1;i++)
	{
		time=s[i]+c[i];
		for(int j=i+1;j<n-1;j++)
		{
			if(time<s[j])
			{
				time=s[j];
			}else if(time%f[j]!=0){
				time=f[j]*(time/f[j]+1);
			}
			time+=c[j];
		}
		cout<<time<<endl;
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
c = [int(input()) for _ in range(N)]

dp = [0 for _ in range(N + 1)]
dp[0] = 1

d = defaultdict(lambda: -1)

for i, cc in enumerate(c, 1):
    if c[i - 1] == c[i - 2]:
        dp[i] = dp[i - 1]
    elif d[cc] == -1:
        # 初めて出現した色
        dp[i] = dp[i - 1]
    else:
        dp[i] = dp[i - 1] + dp[d[cc]]
    dp[i] %= MOD
    d[cc] = i
    # print(d)
    # print(dp)
print(dp[N])

Measured memory_bytes: 36832
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))

count = 0
for i in range(n - 1):
    dif = a[i] + a[i + 1] - x
    if dif > 0:
        if a[i + 1] >= dif:
            a[i + 1] -= dif
            count += dif
        else:
            a[i] -= dif - a[i + 1]
            a[i + 1] = 0
            count += dif
print(count)

Measured memory_bytes: 14592
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

int main(){
 
    int n;
    cin>>n;
    int i=0;
    
    while(1){
        if((n+i)/100==((n+i)%100)/10&&(n+i)/100==(n+i)%10){
            cout<<n+i<<endl;
            break;
        }
        i++;
         
    }
    
    return 0;
}


Measured memory_bytes: 256