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

void DBG() { cerr << endl; }
template<typename Head, typename... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#ifdef NAIM
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)
#else 
#define dbg(...)
#endif

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ll long long
#define ints(a...) int a; read(a)
#define IN(a) for (auto &it : a) cin >> it

const double PI = acos(-1);

long double dist(int a, int b, long double t) {
    return sqrt(a * a + b * b - 2 * a * b * cos(t * PI / 180));
}

void solve() {
    ints(a, b, h, m);
    long double angle = abs((h * 60 + m) * 0.5 - m * 6);
    angle = min(angle, 360 - angle);
    cout << fixed << setprecision(10) << dist(a, b, angle);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 4076
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

N, K = [int(i) for i in input().split()]
h = quick_sort([int(input()) for _ in range(N)])

answer = 10 ** 10
for i in range(N - K + 1): 
  answer = min(answer, h[i + K - 1] - h[i])

print(answer)

Measured memory_bytes: 10696
#include <iostream>
#include<vector>
using namespace std;
typedef long long ll;
const long long M = 1e9 + 7;
int main() {
	vector<vector<ll>>dp(2001, vector<ll>(2001));
	
	for (int i = 0; i <= 2000; i++){
		for (int j = 0; j <= i; j++){
			if (j == 0){
				dp[i][j] = 1;
				continue;
			}
			else{
				dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
				dp[i][j] %= M;
			}
		}
	}


	int n, k;
	cin >> n >> k;
	for (int i = 1; i<=k; i++){
		cout << dp[n - k + 1][i] * dp[k - 1][i - 1] % M << endl;
	}

	return 0;
}

Measured memory_bytes: 31616
#include <stdio.h>

int main() {
    int A,B,C,K,num,l=0,m=0;
    scanf("%d%d%d%d",&A,&B,&C,&K);
    if (A>=K) {
        num=1*K;
    }else{
        num=1*A;
        l=K-A;
    }
    if (B>=l) {
        num=num+0*K;
    }else{
        num=num+0*B;
        m=l-B;
    }
    num=num-1*m;
    printf("%d",num);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#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 SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int n;
    cin >> n;
    if(n%2){
        cout << double(n/2+1)/n << endl;
    }
    else{
        cout << 0.5 << endl;
    }
    return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = 0;i < 1000;i++){
        if((a + a * i) % b == c){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

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

int main(void)
{
	int N;
	cin >> N;

	string S;
	cin >> S;

	vector<int> w(N+1, 0), e(N+1, 0);
	for(int i=0; i<N; i++){
		w[i+1] += w[i];
		e[i+1] += e[i];

		if(S[i] == 'W')
			w[i+1]++;
		if(S[i] == 'E')
			e[i+1]++;
	}

	int ret = INT_MAX;
	for(int i=0; i<N; i++){
		ret = min(ret, w[i] + e[N]-e[i+1]);
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3076
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7

n = int(input())
A = list(map(int,input().split()))
ass = set()
def div(x):
    for i in range(1,int(x**0.5)+1):
        if x%i == 0:
            ass.add(i)
            ass.add(x//i)
    return ass
a0 = A[0]
a1 = A[1]
div(a0)
div(a1)
ans = 1
for i in ass:
    cnt = 0
    for a in A:
        if a%i == 0:
            cnt += 1
    if cnt >= n-1:
        ans = max(ans,i)
print(ans)

Measured memory_bytes: 14488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c; cin>>a>>b>>c;
    int f=0;
    if(a==5){
        if((b==7&&c==5)||(b==5&&c==7)){
        cout<<"YES"<<endl;
        f=1;
        }
    }else if(a==7){
        if(b==5&&c==5){
            cout<<"YES"<<endl;
            f=1;
        }
    }
    if(!f) cout<<"NO"<<endl;
}


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

using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<int> cnt(n, 0);
  vector<int> is_solve(n, false);

  int ac = 0, pena = 0;
  for (int i = 0; i < m; i++) {
    int p; string s;
    cin >> p >> s;
    if (s == "WA") {
      cnt[p-1]++;
    }
    if (s == "AC" && is_solve[p-1] == false) {
      ac++;
      pena += cnt[p-1];
      is_solve[p-1] = true;
    }
  }
  cout << ac << " " << pena << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b, __ = c; a < __; a++)

using namespace std;
typedef long long ll;
const ll mod = ll(1e9) + 7;

int n;
string s[2];
ll memo[60][60][8][8];

ll dp(int i, int j, int mi, int mj){
	if(i == j && i == n)
		return 1;
	ll &ans = memo[i][j][mi][mj];
	if(ans != -1)
		return ans;
	ans = 0;
	if(i == j && s[0][i] == s[1][j]){
		fr(k, 0, 3){
			if(!((mi >> k)&1) && !((mj >> k)&1)){
				ans += dp(i+1, j+1, 1 << k, 1 << k);
				ans %= mod;
			}
		}
	}
	else if(i == j){
		fr(k, 0, 3){
			if(!((mi >> k)&1)){
				ans += dp(i+2, j, 1 << k, mj | (1 << k));
				ans %= mod;
			}
		}
	}
	else{
		fr(k, 0, 3){
			if(!((mj >> k)&1)){
				ans += dp(i, j+2, mi, (1 << k));
				ans %= mod;
			}
		}
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	cin >> s[0] >> s[1];
	memset(memo, -1, sizeof memo);
	cout << dp(0, 0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int num;
    if(C>=A&&C<=B&&D>=B) num=B-C;
    else if(C>=A&&D<=B) num = D-C;
    else if(A>=C&&B<=D) num = B-A;
    else if(C<=A&&D>=A&&D<=B) num = D-A;
    else num = 0;

    cout << num;

    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
S=sorted([int(input()) for i in range(N)])
M=sum(S)

import sys
if M%10!=0:
    print(M)
    sys.exit()
    
R=0
for i in S:
    if i%10!=0:
        R=i
        break

if R==0:
    print(0)
else:
    print(M-R)

Measured memory_bytes: 3064
def m():
    n, m = map(int, input().split())
    g = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)

    ans = 0
    import itertools
    perm = list(itertools.permutations([j for j in range(1,n+1)]))
    for l in perm:
        if l[0] != 1:
            continue
        flag = 0
        for i in range(1, len(l)):
            if l[i] in g[l[i-1]]:
                pass
            else:
                flag = 1
                break
        if flag:
            continue
        ans+=1
    return ans

print(m())

Measured memory_bytes: 8052
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


struct BinaryIndexed {
  ll num;
  vll bit;

  BinaryIndexed(ll x = MAX) {
    num = x;
    bit.resize(x + 1, 0);
  }

  ll sum(ll i) {
    ll ret = 0;
    while (i > 0) {
      ret += bit[i];
      i -= i & -i;
    }
    return ret;
  }

  void add(ll i, ll x) {
    if (i == 0) cout << "access 0 index" << endl;
    while (i <= num) {
      bit[i] += x;
      i += i & -i;
    }
  }
};


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

  
  BinaryIndexed bit1(MAX), bit2(MAX);
  cin >> n;
  ll suma = 0, sumb = 0;
  vector<pair<ll, pll>> q;
  unordered_map<ll, ll> comp;
  vll v;
  rep(i, n) {
    cin >> tmp;
    if (tmp == 1) {
      ll a, b;
      cin >> a >> b;
      q.pb(make_pair(1, pll(a, b)));
      v.pb(a);
    }
    else q.pb(make_pair(2, pll(0, 0)));
  }
  sort(all(v));
  rep(i, v.size()) comp[v[i]] = i + 1;
  ll cnt = 0;
  rep(i, n) {
    if (q[i].first == 1) {
      suma += q[i].second.first;
      sumb += q[i].second.second;
      bit1.add(comp[q[i].second.first], 1);
      bit2.add(comp[q[i].second.first], q[i].second.first);
      cnt++;
    }
    else {
      ll le = 0, ri = v.size() - 1;
      if (bit1.sum(comp[v[0]]) >= (cnt + 1) / 2) {
        ri = le;
      }
      else {
        while (ri - le > 1) {
          ll mid = (ri + le) / 2;
          if (bit1.sum(comp[v[mid]]) >= (cnt + 1) / 2) ri = mid;
          else le = mid;
        }
      }
      ll num = bit1.sum(comp[v[ri]]);
      ans = suma - bit2.sum(comp[v[ri]]) - v[ri] * (cnt - num);
      ans += v[ri] * num - bit2.sum(comp[v[ri]]);
      cout << v[ri] << " " << ans + sumb << endl;
    }
  }



  return 0;
}

Measured memory_bytes: 16684
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll a, b, c, d;
	cin >>a >> b >> c >> d;
	if (min(b, d) - max(a, c) > 0) {
		cout << min(b, d) - max(a, c) << endl;
	}
	else {
		cout << "0" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvi;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

int main(){
    int n ;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    int ans = 0;
  	for (int i=0;i<n-2;i++){
      for (int j=i+1;j<n-1;j++){
        for (int k=j+1;k<n;k++){
          if (l[i]<l[j]+l[k] && l[j] < l[i]+l[k] && l[k]<l[i]+l[j]){
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int array[100005]={0};
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
    int left,right;
    cin>>left>>right;
    array[left]++;
    array[right+1]--;
  }
  
  int cnt=0;
  for(int i=1;i<=n;i++){
    array[i]=array[i-1]+array[i];
    if(array[i]==m){
      cnt++;
    }
  }
  
  cout<<cnt<<endl;
  return(0);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  long long n = S.size();
  vector<long long> num(26);
  for(int i = 0;i < n;i++) {
    char ch = S.at(i);
    num.at(ch-'a')++;
  }

  long long ans = n*(n-1)/2;
  for(int i = 0;i < 26;i++) {
    long long N = num.at(i);
    ans -= N*(N-1)/2;
  }

  cout << ans+1 << endl;
  

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long frek[200];
int main()
{
    char c;
    long long n,m,i,j;
    cin>>n>>m;
    for(i=0;i<n;++i)
    {
        for(j=0;j<m;++j)
        {
            cin>>c;
            frek[c]++;
        }
    }
    if((n%2==0)and(m%2==0))
    {
        for(i='a';i<='z';++i)
        {
            if(frek[i]%4!=0)
            {
                cout<<"No\n";
                return 0;
            }
        }
        cout<<"Yes\n";
    }
    else if((n%2==1)and(m%2==1))
    {
        long long z=0,yo=0;
        for(i='a';i<='z';++i)
        {
            if(frek[i]%2==1)
            {
                z++;
            }
            yo+=frek[i]/4;
        }
        if(z!=1)
        {
            cout<<"No\n";
                return 0;
        }
        if(yo<(n/2)*(m/2))
        {
            cout<<"No\n";
                return 0;
        }
        cout<<"Yes\n";
    }
    else
    {
        long long yo=0;
        for(i='a';i<='z';++i)
        {
            if(frek[i]%2==1)
            {
                cout<<"No\n";
                return 0;
            }
            yo+=frek[i]/4;
        }
        if(yo<(n/2)*(m/2))
        {
            cout<<"No\n";
                return 0;
        }
        cout<<"Yes\n";
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],head[maxn],tot,n,d[maxn],ans,mx[maxn];
using namespace std;
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void dfs(int u,int fa){
	int b,v,save,flag,l,r,mid;;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		save=ans,flag=0;
		if(d[ans]<a[v])d[++ans]=a[v];
		else{
			l=0,r=ans;
			while(l+1<r){
				mid=(l+r)/2;
				if(d[mid]<a[v])l=mid;
				else r=mid;
			}
			flag=d[r],d[r]=a[v];
		}
		mx[v]=ans;
		dfs(v,u);
		ans=save;
		if(flag)d[r]=flag;
	}
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
}
int main(){
	init();
	ans=1,d[1]=a[1],mx[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",mx[i]);
	return 0;
}

Measured memory_bytes: 21536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            int answer=0;
            switch(op) {
            case "+":
            	answer=a+b;
            	break;
            case "-":
            	answer=a-b;
            	break;
            case "*":
            	answer=a*b;
            	break;
            case "/":
            	answer=a/b;
            	break;
            case "?":
            	break;
            
            
            }
            if(op.equals("?"))break;
           System.out.printf("%d\n",answer);
           
        }
        sc.close();
        
    }
}


Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	if (a1*t1 + a2*t2 == b1*t1 + b2*t2) {
		put("infinity");
		return 0;
	}
	P p = P(a1 - b1, a2 - b2);
	if (p.first < 0) {
		p.first *= -1;
		p.second *= -1;
	}
	ll c1 = p.first * t1, c2 = p.second * t2;
	if (c1 + c2 > 0) {
		put(0);
		return 0;
	}
	using ld = long double;
	ld h1 = (ld)c2/ (c1 + c2);
	ld h2 = (ld)c1 / (c1 + c2);
	ll h3;
	ll res = 0;
	if (c1 % abs(c1 + c2) == 0) {
		h3 = c1 / abs(c1 + c2) + 1;
		res = h3 * 2 - 2;
	} else {
		h2 *= -1;
		h3= ceil(h2);
		res = h3 * 2 - 1;
	}
	
	put(res);
	return 0;
}


Measured memory_bytes: 256
def sum(n,k):
    sum = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            for c in range(1,n+1):
                if(a+b)%k == 0:
                    if(a+c)%k == 0:
                        if(b+c)%k == 0:
                            sum += 1

n,k = map(int,input().split())
t0 = 0
t5 = 0 
for a in range(1,n+1):
    #print(a,a/k)
    if(a%k == 0):
        t0 += 1
    elif(a/k)%(0.5)==0:
        t5 += 1
#print(t0,t5)
print(pow(t5,3)+pow(t0,3))

Measured memory_bytes: 3064
# tx = lcm(A[0],A[1], ..., A[N-1])
# B = [tx/A[0], tx/A[1], ..., tx/A[N-1]]
# 2X/A[i] = 2p + 1 となるようなpが存在する, が条件
# tx = 2Xとおくと, txは偶数 かつ すべてのi(<N)において, tx/A[i]は奇数である必要がある. 
# よって, Bの要素はすべて奇数 かつ txは偶数である, が条件
# そのような, txが存在するならば, x = tx/2が条件を満たす集合の最小元であり, 他の要素は,xの奇数倍として表される.
# というのも, xの偶数倍となると2p+1が奇数となる条件を反すから

import sys

N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return (a // gcd(a,b)) * b

tx = 1
for a in A:
    tx = lcm(tx, a)

if tx % 2 == 1:
    print(0)
    sys.exit()

B = []
for a in A:
    B.append(tx // a)

for b in B:
    if b % 2 == 0:
        print(0)
        sys.exit()

ans = ((M // (tx//2)) + 1) // 2
print(ans)

Measured memory_bytes: 22668
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double

#define pll pair<ll,ll>
#define ff first
#define ss second

#define pb push_back
#define all(x) x.begin(),x.end()

#define MOD  1000000007
const int N = 100005; 

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        cin >> a[i];
        if(i>0)
        {
            if(a[i]<a[i-1])   ans += (a[i-1] - a[i]),a[i] = a[i-1];
        }
    }
    cout<<ans;
}

int main()
{
    FAST;
    int t = 1;
 // cin >> t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 5176
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N; cin >> N;
	int num = 0;
	int n = 0;
	int an = mod;
	int min = 0;
	for (int i = 1; i < N; i++) {
		num = N - i;
		n = i;
		min = 0;
		while (num > 0) {
			min += num % 10;
			num /= 10;
		}
		while (n > 0) {
			min += n % 10;
			n /= 10;
		}
		if (min < an) an = min;
	}
	cout << an << endl;
}


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

int main() {
    int n, a, c = 1, t = 0, cnt = 0;

    cin >> n;
    int ans[200000];
    for (int i = 0; i < n; i++)
    {
        ans[i] = 0;
    }

    for (int i = 0; i < n - 1; i++)
    {
        cin >> a;

        if (a != c)
        {
            t = a - 1;
            c = a;
        }
        ans[t] += 1;
      
    }

    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }
}

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


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

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n;
    cin>>n;
    ll ans=1000-(n%1000);
    ans=ans%1000;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

int main(){
	int n; cin>>n; n*=3;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	sort(all(v));
	ll cnt=0;
	for(int i=n-2; i>=n/3; i-=2){
		cnt+=v[i];
	}
	cout<<cnt<<endl;
}

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

int main(){
	long long a,v,b,w,t;
	cin >> a >> v >> b >> w >> t;
	if(v <= w) cout << "NO\n";
	else{
		long long tt = (b-a+v-w-1)/(v-w);
		tt = abs(tt);
		if(tt > t) cout << "NO\n";
		else cout << "YES\n";
	}
}

Measured memory_bytes: 3632
n = int(input())
a=list(map(int,input().split()))
ans = 1

if any(a[j] == 0 for j in range(n)):
    ans = 0
else:
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            ans = -1
            break
print(ans)

Measured memory_bytes: 88148
#include <iostream>
#include <iomanip>
int main(void)
{
  int a, b, d, r;
  double f;
  std::cin >> a >> b;
  d = a / b;
  r = a % b;
  f = a / static_cast<double>(b);
  std::cout << d << " " << r << " " << std::fixed << std::setprecision(5) << f << std::endl;
}

Measured memory_bytes: 1244
n = int(input())
list1 = list(map(int,input().split()))
count = 1
the_lowrst = list1[0]
if n == 1:
    print(1)
    exit()
for i in range(1,n):
    if the_lowrst <= list1[i]:
        the_lowrst = list1[i]
        count += 1
print(count)

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

#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int mod=998244353;
int a,b,c,d;
int dp[3010][3010];
signed main()
{
	
		
  cin>>a>>b>>c>>d;
  dp[a][b]=1;
		for(int i=a;i<=c;i++)
		{
			for(int j=b;j<=d;j++)
			{
				if(i==a && j==b)
				{

				}else if(i==a)
				{
                  dp[i][j]=(dp[i][j-1]*i)%mod;
				}else if(j==b)
				{
					dp[i][j]=(dp[i-1][j]*j)%mod;
				}else
				{
					dp[i][j]=((dp[i-1][j]*(j))%mod+(dp[i][j-1]*(i))%mod-(dp[i-1][j-1]*((i-1)*(j-1)))%mod+mod)%mod;
				}
				//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
			}
		}
		cout<<dp[c][d];


	
}

Measured memory_bytes: 73980
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

const int INF = 1e9;

struct edge{
  int from,to,cost,cap,rev;
  edge(int a,int b,int c,int d,int e)
    :from(a),to(b),cost(c),cap(d),rev(e){}
};

struct FordFulkerson{
  int n;
  vector< vector<edge> > graph;
  vi use;

  FordFulkerson(int a=0):n(a){
    graph.resize(a); use.resize(a);
  }

  void init_use(void){fill(all(use),0);}

  void AddEdge(int s,int g,int c,int p){
    graph[s].pb( edge(s,g,c,p,graph[g].sz) );
    graph[g].pb( edge(g,s,-c,0,graph[s].sz-1) );
  }

  void DeleteEdge(int s, int g){
    int id = -1, rev = -1;
    rep(e,graph[s].sz){
      if(graph[s][e].to == g && graph[s][e].cost>0){
	id = e; rev = graph[s][e].rev; break;
      }
    }
    if(id<0)return;

    swap(graph[s][id],graph[s].back());
    swap(graph[g][rev],graph[g].back());

    edge e = graph[s][id];
    if(id+1!=(int)graph[s].size())graph[e.to][e.rev].rev = id;
    e = graph[g][rev];
    if(rev+1!=(int)graph[g].size())graph[e.to][e.rev].rev = rev;
    graph[s].pop_back(); graph[g].pop_back();
  }
  
  int dfs(int v, int t, int f){
    if(v==t)return f;
    use[v] = 1;
    rep(i,graph[v].sz){
      edge &e = graph[v][i];
      if(!use[e.to] && e.cap > 0){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d > 0){
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t){
    int res = 0;
    for(;;){
      init_use();
      int f = dfs(s,t,INF);
      if(!f)return res;
      res += f;
    }
  }
};

int main(){
  int n,E,q;
  cin >> n >> E >> q;
  FordFulkerson mf(n);
  rep(i,E){
    int f,t;
    cin >> f >> t; f--; t--;
    mf.AddEdge(f,t,1,1);
    mf.AddEdge(t,f,1,1);
  }

  int F = mf.max_flow(0,n-1);
  rep(i,q){
    int m,a,b;
    cin >> m >> a >> b; a--; b--;
    if(m==1){
      mf.AddEdge(a,b,1,1);
      mf.AddEdge(b,a,1,1);
      F += mf.max_flow(0,n-1);
    }else{
      int use = 0;
      for(edge e : mf.graph[a]){
	if(e.to == b && e.cost>0 && e.cap == 0){
	  use |= 1; break;
	}
      }
      for(edge e : mf.graph[b]){
	if(e.to == a && e.cost>0 && e.cap == 0){
	  use |= 2; break;
	}
      }
      mf.DeleteEdge(a,b);
      mf.DeleteEdge(b,a);

      if(use==1 || use==2){
	rep(i,n)mf.use[i] = 0;
	int another = 0;
	if(use==1)another = mf.dfs(a,b,1);
	if(use==2)another = mf.dfs(b,a,1);

	if(!another){
	  mf.init_use();
	  mf.dfs(use==1?a:b,0,1);
	  mf.init_use();
	  mf.dfs(n-1,use==1?b:a,1);
	  F--;
	}
      }
    }

    cout << F << endl;
  }
}

Measured memory_bytes: 3388
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int H, W;
char A[505][505], ans1[505][505], ans2[505][505];

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


  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      int now = min(min(i, j), min(H - 1 - i, W - 1 - j));
      if (now % 2 == 0) ans1[i][j] = '#';
      else ans1[i][j] = '.';
    }
  }
  

  for (int i = 0; i < min(H, W) / 2; i++){
    if (ans1[i + 1][i] == '#') ans1[i + 1][i] = '.';
    else ans1[i + 1][i] = '#';
  }
  

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (ans1[i][j] == '#'){
        ans1[i][j] = '#'; ans2[i][j] = '.';
      }else{
        ans1[i][j] = '.'; ans2[i][j] = '#';
      }
      if (A[i][j] == '#'){
        ans1[i][j] = '#'; ans2[i][j] = '#';
      }
    } 
  }
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cout << ans1[i][j];
    }
    cout << endl;
  }
  cout << endl;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cout << ans2[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList();
			var h = firstLine[0];
			var w = firstLine[1];

			var picture = new List<string>();

			for(int i = 0; i < h; i++)
			{
				picture.Add(Console.ReadLine());
			}

			var scaledPicture = new List<string>();

			foreach(var line in picture)
			{
				scaledPicture.Add(line);
				scaledPicture.Add(line);
			}

			foreach (var line in scaledPicture)
			{
				Console.WriteLine(line);
			}
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int hMin, hMax;
	int Min = INF;
	for (int i = 0; i < n - k + 1; i++) {
		hMin = h[i];
		hMax = h[i + k - 1];
		int t = hMax - hMin;
		if (t < Min) {
			Min = t;
		}
	}
	cout << Min << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int ans[1100][1100];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,a,b; cin>>h>>w>>a>>b;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if((i<b && j<a) || (i>=b && j>=a)){
                ans[i][j]=1;
            }
        }
    }

    for(int i=0; i<h;i++){
        for(int j=0;j<w;j++){
            cout<<ans[i][j];
        }
        cout<<endl;
    }

}

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

int n, a[20], x[20][20], y[20][20];

int counter(int rep) {
	return rep == 0 ? 0 : counter(rep >> 1) + (rep & 1);
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		for (int j = 1; j <= a[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}

	int ans = 0;
	for (int b = 1; b < (1 << n); b++) {
		bool ok = true;
		for (int i = 1; i <= n; i++) {
			if (!(b & (1 << i - 1)))continue;
			for (int j = 1; j <= a[i]; j++) {
				if ((b >> (x[i][j] - 1) & 1) ^ y[i][j])ok = false;
			}
		}
		if (ok)if (ans < counter(b))ans = counter(b);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y;//定义
    cin>>n;
    x=n*800;//根据n求出x
    y=(n/15)*200;//根据n求出y
    cout<<x-y<<endl;//最后输出答案
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, x, y = map(int, readline().split())

p1 = a * x + b * y
if y >= x:
    p2 = c * x * 2 + b * (y - x)
else:
    p2 = a * (x - y) + c * y * 2
p3 = c * max(x, y) * 2

print(min(p1,p2,p3))

Measured memory_bytes: 9180
import sys
input = sys.stdin.readline


def read():
    X = int(input().strip())
    return X,


def solve(X):
    t = 0
    x = 0
    while x < X:
        t += 1
        x += t
    return t


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 9168
import java.util.*

const val mInf = 1 shl 31
const val inf = mInf - 1
private val sc = Scanner(System.`in`)

fun readWord(): String = sc.next()
fun readLine(): String = sc.nextLine()
fun readInt(): Int = readLine().toInt()

fun readArray(): List<String> = readLine().split(" ").toList()
fun readStringList(size: Int): List<String> = (0 until size).map { readLine() }


fun readMultiRowToStringArray(size: Int, f: (String) -> Unit = {}): Array<String> =
    Array(size) { readLine().apply(f) }

fun readMultiRowToIntArray(size: Int, f: (Int) -> Unit = {}): IntArray =
    IntArray(size) { readLine().toInt().apply(f) }

fun readMultiRowToBooleanArray(size: Int, f: (String) -> Boolean): BooleanArray = BooleanArray(size) { f(readLine()) }

//
fun readRowSplitToStringArray(size: Int, f: (String) -> String = { it }): Array<String> =
    Array(size) { sc.next().apply { f } }

fun readRowSplitToIntArray(size: Int, f: (Int) -> Unit = { }): IntArray =
    IntArray(size) { sc.next().toInt().apply(f) }

fun readRowSplitToBooleanArray(size: Int, f: (String) -> Boolean): BooleanArray = BooleanArray(size) { f(sc.next()) }


fun main(args: Array<String>) {
    val (N, M) = readRowSplitToIntArray(2)
    readRowSplitToIntArray(N).run {
        val sum = sum().toDouble() / (4 * M).toDouble()
        filterNot { it.toDouble() < sum }.size
    }.let {
        if (it < M.toDouble()) println("No") else println("Yes")
    }
}

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

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

    int ans = 0;
    for(int i=0; i<n-1; i++) {
        for(int j=i+1; j<n; j++) {
            ans = max(ans, abs(a[i] - a[j]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
class UnionFind {
  constructor(n) {
    this.p = new Array(n).fill(null).map((_, i) => i)
    this.height = new Array(n).fill(0)
    this.size = new Array(n).fill(1)
  }

  unite(a, b) {
    this.link(this.findSet(a), this.findSet(b))
  }

  link(a, b) {
    if (a === b) return null

    if (this.height[a] > this.height[b]) {
      this.p[b] = a
      this.size[a] += this.size[b]
    } else {
      this.p[a] = b
      this.size[b] += this.size[a]

      if (this.height[a] === this.height[b]) {
        this.height[b]++
      }
    }
  }

  findSet(x) {
    if (this.p[x] === x) return x
    return this.findSet(this.p[x])
  }
}

const main = (input) => {
  input = input.trim().split('\n')
  const [n,] = input.shift().split(' ').map(Number)
  input = Array.from(new Set(input))

  const uf = new UnionFind(n+1)

  for (let i=0; i<input.length; i++) uf.unite(...input[i].split(' ').map(Number))
  
  return console.log(uf.size.reduce((a, b) => Math.max(a, (b || 0)), 0))
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 92568
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		boolean f = true;
		f &= str.charAt(0) == 'A';
		int cnt = 0;
		for (int i = 2; i < str.length() - 1; ++i) {
			if (str.charAt(i) == 'C')
				++cnt;
		}
		f &= cnt == 1;
		String str2 = str.toLowerCase();
		cnt = 0;
		for (int i = 0; i < str.length(); ++i) {
			if (str.charAt(i) != str2.charAt(i))
				++cnt;
		}
		f &= cnt == 2;
		System.out.println(f ? "AC" : "WA");
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 21972
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}
int lcm(long long a, long long b,long long gcmed) {
	return (a*b / gcmed);
}
int main(){
	long long a,b;
	while (cin >> a >> b) {
		long long c = gcd(a, b);
		printf("%lld %lld\n", c, lcm(a, b, c));
	}
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
long long p2;
long long getMax(vector<long long>& BTmax,int pos){
  int b = p2, e = pos;
  long long ret = 0;
  while(b < e){
    //cout << "getMax " << b << " " << e << " ";
    if(b&1){
      ret = max(ret,BTmax[b]);
      ++b;
    }
    if((e&1) == 0){
      ret = max(ret,BTmax[e]);
      --e;
    }
    b >>= 1;
    e >>= 1;
    //cout << ret << endl;
  }
  if(b == e) ret = max(ret,BTmax[b]);
  return ret;
}
void update(vector<long long>& BTmax,int pos,long long val){
  BTmax[pos] = val;
  pos >>= 1;
  while(pos > 0){
    BTmax[pos] = max(BTmax[2*pos],BTmax[2*pos+1]);
    pos >>= 1;
  }
}
int main(){
  int N;
  cin >> N;
  p2 = 1;
  while(p2 < N) p2 <<= 1;
  vector<long long> A(N),BTmax(2*p2);
  vector<int> H(N),Hpos(N),pH;
  for(int i = 0; i < N; ++i){
    cin >> H[i];
    pH.push_back(H[i]);
  }
  for(int i = 0; i < N; ++i) cin >> A[i];
  sort(begin(pH),end(pH));
  for(int i = 0; i < N; ++i) Hpos[pH[i]] = p2+i;
  for(int i = 0; i < N; ++i){
    //cout << i << " : ";
    int pos = Hpos[H[i]];
    long long val = getMax(BTmax,pos);
    update(BTmax,pos,val+A[i]);
    //for(long long i : BTmax) cout << i << ' ';
    //cout << endl;
  }
  cout << BTmax[1];
  return 0;
}

Measured memory_bytes: 8568
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int N = 328;
using Arr = array<array<ll, N>, N>;
const int MOD = int(1e9 + 7);

const int M = N * 2;

int a[M];
int ac;

int w[M];

void ad(ll& x, ll y) {
    x = (x + y) % MOD;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);

    int n;
    cin >> n;

    int free = 0;

    int one = 0;

    for (int i = 1; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        if (x > y) {
            swap(x, y);
        }

        if (x != -1 && y != -1) {
            w[x] = w[y] = 1;
        }

        if (x == -1 && y != -1) {
            ++a[y];
            w[y] = 2;
            ++one;
        }

        if (y == -1) {
            ++free;
        }

    }

    int m = 2 * n;

    for (int i = m; i > 0; --i) {
        a[i] += a[i + 1];
    }

    Arr f{};
    f[0][0] = 1;

    for (int i = 2 * n; i >= 1; --i) {
        if (w[i] == 1) {
            continue;
        }

        Arr g{};

        if (w[i] == 0) {
            for (int j = 0; j <= n; ++j) {
                for (int k = 0; k <= one; ++k) {
                    if (k) {
                        ad(g[j][k - 1], f[j][k] * k);
                    }

                    if (j) {
                        ad(g[j - 1][k], f[j][k]);   
                    }

                    ad(g[j + 1][k], f[j][k]);
                }
            }
        } else {
            for (int j = 0; j <= n; ++j) {
                for (int k = 0; k <= one; ++k) {
                    if (j) {
                        ad(g[j - 1][k], f[j][k]);
                    }

                    ad(g[j][k + 1], f[j][k]);
                }
            }
        }

        f = g;
    }

    ll ans = f[0][0];
    for (int i = 1; i <= free; ++i) {
        ans = ans * i % MOD;
    }

    cout << ans << "\n";
}



Measured memory_bytes: 1920
#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 n;
    cin >> n;
    int a[n];
    rep (i, n) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
using namespace std;
#define ll long long
const ll maxn = 1e18;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    bool exist = true;
    rep(i, n){
        ll a;
        cin >> a;
        if(maxn/ans < a){
            exist = false;
        }else{
            ans *= a;
        }
        if(a == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    if(exist){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  string s;
  cin >> s;
  s += "FFFFF";
  int res = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
      res++;
    }
  }
  cout << res;
}

Measured memory_bytes: 256
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n, k;
    cin >> n >> k;
    vector<ll> pi(n);
    forn(i, n) cin >> pi[i];
    vector<ll> pre(n);
    pre[0] = pi[0];
    for (int i = 1; i < n; i++) {
        pre[i] = pi[i] + pre[i - 1];
    }
    int ini = -1, last = -1;
    ll best = -1e18;
    for (int i = 0; i <= n - k; i++) {
        ll cur = pre[i + k - 1] - (i == 0 ? 0 : pre[i - 1]);
        // cout << cur << endl;
        if (cur > best) ini = i, last = i + k - 1, best = cur;
    }
    long double ans = 0;
    for (int i = ini; i <= last; i++) {
        ans += (pi[i] + 1) * 0.5;
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

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

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

    long long N, T;
    N = n / (a + b) * a;
    T = n % (a + b);
    if (T > a) {
        long long S;
        S = N + a;
        cout << S << endl;
    } else if (T <= a) {
        long long Z;
        Z = N + T;
        cout << Z << endl;
    }


    return 0;
}

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

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

    int ans = 0, temp = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A'||s[i] == 'T'||s[i] == 'C'||s[i] == 'G')
        {
            temp++;
        }
        else
        {
            if (temp > ans)
            {
                ans = temp;
            }
            temp = 0;
        }
    }
    if (temp > ans)
        ans = temp;
            
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

bool eval(vector<int> &table,string &s,int &i){
    if(isdigit(s[i])) return s[i++] == '1';
    if(s[i] == '-') return !eval(table,s,++i);
    if(isalpha(s[i])) return table[s[i++]-'a'];
    i++; // (
    bool e1 = eval(table,s,i);
    char op = s[i++];
    bool e2 = eval(table,s,i);
    i++; // )
    if(op == '^') return e1^e2;
    if(op == '*') return e1*e2;
    assert(false);
}

int feature(string &E){
    int k = 0;
    int f = 0;
    rep(a,2)rep(b,2)rep(c,2)rep(d,2){
        vector<int> table = {a,b,c,d};
        int i = 0;
        if(eval(table,E,i)){
            f |= 1<<k;
        }
        k++;
    }
    return f;
}

int main(void){
    vector<string> exps[17];
    exps[1] = {"a","b","c","d"};
    for(int m = 2; m <= 16; m++){
        for(string E : exps[m-1]){
            if(E[0] == '-') continue;
            exps[m].push_back("-"+E);
        }
        rep1(x,m-2){
            int y = m-3-x;
            if(x>y) continue;
            for(string E1 : exps[x]){
                for(string E2 : exps[y]){
                    bool ng = false;
                    for(char ch : {'a','b','c','d'}){
                        if(count(all(E1),ch)+count(all(E2),ch)>1){
                            ng = false;
                        }
                    }
                    if(ng) continue;
                    exps[m].push_back("("+E1+"^"+E2+")");
                    exps[m].push_back("("+E1+"*"+E2+")");
                }
            }
        }
    }
    exps[1].push_back("0");
    exps[1].push_back("1");


    vector<int> min_len(1<<16, 20);
    rep1(m,16){
        for(string E : exps[m]){
            int f = feature(E);
            min_len[f] = min(min_len[f], m);
        }
    }

    string E;
    while(cin>>E, E != "."){
        cout<<min_len[feature(E)]<<endl;
    }
    return 0;
}



Measured memory_bytes: 13356