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

const int maxn = 3e5 + 5;
const long long inf = 1e18;

int n, m;
long long a[maxn], f[maxn], g[maxn], y[maxn], q[maxn], sum[maxn], h[maxn], temp[maxn];

inline bool check1 (int a, int b, int k) {return y[b] - y[a] < 1LL * (b - a) * k;}
inline bool check2 (int a, int b, int k) {return 1LL * (k - b) * (y[k] - y[a]) - 1LL * (k - a) * (y[k] - y[b]) < 0;}
inline void shift (int a, int b, long long c[]) {c[a] = max (c[a], c[b] + 1LL * (a - b) * (a - b + 1) / 2 - sum[a] + sum[b]);}

void get_dp (long long f[])
{
    int st = 0, ed = 0;
    q[ed++] = 0;
    for (int i = 1; i <= n; i++)
    {
        sum[i] = sum[i - 1] + a[i];
        for (; st < ed - 1 && check1 (q[ed - 2], q[ed - 1], i); ed--);
        f[i] = f[i - 1];
        shift (i, q[ed - 1], f);
        y[i] = f[i] + 1LL * i * (i - 1) / 2 + sum[i];
        for (; st < ed - 1 && check2 (q[ed - 2], q[ed - 1], i); ed--);
        q[ed++] = i;
    }
}

inline void rev (long long f[]) {for (int i = 1; i <= n / 2; i++) swap(f[i], f[n - i + 1]);}

inline void divide_conquer (long long f[], long long g[], int l, int r)
{
    if (l == r)
    {
        h[l] = max (h[l], f[l - 1] + g[r + 1] - a[l] + 1);
        return ;
    }
    if (l > r) return;
    int mid = l + r >> 1;
    int st = 0, ed = 0;
    for (int i = l - 1; i <= r; i++)
    {
        for (; st < ed - 1 && check2 (q[ed - 2], q[ed - 1], i); ed--);
        if (i < mid) q[ed++] = i, temp[i] = f[i];
        else
        {
            temp[i] = -inf;
            temp[i] = max(temp[i] , f[q[ed - 1]] + 1LL * (i - q[ed - 1]) * (i - q[ed - 1] + 1) / 2 - sum[i] + sum[q[ed - 1]] + g[i + 1]);
        }
    }
    for (int i = r - 1; i >= mid; i--) temp[i] = max (temp[i], temp[i + 1]);
    for (int i = r; i >= mid; i--) h[i] = max (h[i], temp[i]);

    divide_conquer (f, g, l, mid);
    divide_conquer (f, g, mid + 1, r);
}

int main()
{
    //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", a + i);
    scanf("%d", &m);

    rev (a);
    get_dp (g); rev(g);
    rev (a);
    get_dp (f);

    for (int i = 0; i <= n + 1; i++) h[i] = -inf;
    divide_conquer (f, g, 1, n);
    rev(a); rev(g); rev(f); rev(h);
    for (int i = 1; i <= n; i++)
    {
        sum[i] = sum[i - 1] + a[i];
        y[i] = g[i] + 1LL * i * (i - 1) / 2 + sum[i];
    }
    divide_conquer (g, f, 1, n);
    rev(h); rev(g); rev(f); rev(a);

    while (m--)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        printf("%lld\n", max (f[u - 1] + g[u + 1], h[u] - (v - a[u])));
    }
    return 0;
}


Measured memory_bytes: 21376
#include<stdio.h>
int main()
{
	int i,flag = 0;
	char a,b[6] = {'a','i','e','o','u'};
	scanf("%c",&a);
	for(i = 0;i < 5;i++)
	{
		if(a == b[i])
		{
			flag = 1;
			break;
		}
	}
	if(flag == 1)
		printf("vowel\n");
	else
		printf("consonant\n");
	return 0;
}


Measured memory_bytes: 128
//be naame khodaa

#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <sstream>
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

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

int in(){ int x; scanf("%d", &x); return x; }

int main()
{
	ios::sync_with_stdio(false);
	int x = in(), y = in();
	if (x%y == 0)
		cout << -1 << endl;
	else
		cout << x << endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
  
int main(void){
  
  int r,c;
  int hyou[10000][100] = {0};
  register int i,j;
  int sum,total = 0;
  
  scanf("%d %d",&r,&c);
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      scanf("%d",&hyou[i][j]);
    }
  }
  for(i = 0;i < r;i++){
    sum = 0;
    for(j = 0;j < c;j++){
      printf("%d ",hyou[i][j]);
      sum += hyou[i][j];
    }
    printf("%d",sum);
    total += sum;
    printf("\n");
  }
  for(i = 0;i < c;i++){
    sum = 0;
    for(j = 0;j < r;j++){
      sum += hyou[j][i];
    }
    printf("%d ",sum);
  }
  printf("%d\n",total);
  return 0;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> S(N);
    rep(i, N) {
        if(!i) S[i] = a[i];
        else S[i] = a[i] + S[i-1];
    }

    ll ans = 1e18;
    rep(i, N-1){
        ll x = S[i], y = S.back() - S[i];
        ans = min(ans, abs(x - y));
    }
    print(ans);

    return 0;
}

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

int main(){
  string s;
  cin>>s;
  vector<int> d(26,0);
  
  int n = s.size();
  rep(i,n){
    if(d[s[i] - 'a'] == 1){
      cout<<"no"<<endl;
      return 0;
    }
    d[s[i] - 'a'] = 1;
  }
  cout<<"yes"<<endl;
}

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

int Array[200][200];

void DFS(int h,int w,int c){

    if(Array[h][w] != c || Array[h][w] == 0 || Array[h][w] == 6){
      return;
    }

    int tmp=Array[h][w];

    Array[h][w] = 6;

    DFS(h-1,w,tmp);
    DFS(h,w+1,tmp);
    DFS(h+1,w,tmp);
    DFS(h,w-1,tmp);


}

int main(){

    while(1){
      int H,W;
      int Start[2],Goal[2];
      int BlockNum;
      int color,dir,xpos,ypos;


      for(int i=0;i<200;i++){
        for(int j=0;j<200;j++){
          Array[i][j] = 0;
        }
      }

      cin >> H >> W;

      if(H == 0 && W == 0){
        break;
      }

      cin >> Start[0] >> Start[1];

      cin >> Goal[0] >> Goal[1];

      cin >> BlockNum;

      for(int i=0;i<BlockNum;i++){
        cin >> color >> dir >> xpos >> ypos;
        for(int i=0;i<4;i++){
          for(int j=0;j<2;j++){
            if(!dir){//?¨?
              Array[xpos+i][ypos+j] = color;
            }
            else{
              Array[xpos+j][ypos+i] = color;
            }
          }
        }
      }

      if(Array[Start[0]][Start[1]] != 0){
        DFS(Start[0],Start[1],Array[Start[0]][Start[1]]);
      }
      if(Array[Goal[0]][Goal[1]] == 6){
        cout << "OK" << endl;
      }
      else{
        cout << "NG" << endl;
      }

  }
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;
    sort(A.begin(), A.end());
    int count = 0;
    vector<pair<int, int>> ans;
    for (int i = 0; i < N; i++) count += abs(A[i]);
    if (N == 2) {
        int minValue = min(A[0], A[1]);
        int maxValue = max(A[0], A[1]);
        cout << maxValue - minValue << endl;
        cout << maxValue << " " << minValue << endl;
        return 0;
    }

    if (A[0] > 0) {
        count -= abs(A[0]) * 2;
        int base = A[0] - A[1];
        ans.emplace_back(A[0], A[1]);
        for (int i = 2; i < N - 1; i++) {
            ans.emplace_back(base, A[i]);
            base -= A[i];
        }
        ans.emplace_back(A[N - 1], base);
    } else if (A[N - 1] < 0) {
        count -= abs(A[N - 1]) * 2;
        int base = A[N - 1] - A[N - 2];
        ans.emplace_back(A[N - 1], A[N - 2]);
        for (int i = N - 3; i > 0; i--) {
            ans.emplace_back(base, A[i]);
            base -= A[i];
        }
        ans.emplace_back(base, A[0]);
    } else {
        for (int i = 1; i < N - 1; i++) {
            if (A[i] > 0) continue;
            ans.emplace_back(A[N - 1], A[i]);
            A[N - 1] -= A[i];
        }
        for (int i = 1; i < N - 1; i++) {
            if (A[i] <= 0) continue;
            ans.emplace_back(A[0], A[i]);
            A[0] -= A[i];
        }
        ans.emplace_back(A[N - 1] , A[0]);
    }

    cout << count << endl;
    for (auto temp : ans) {
        cout << temp.first << " " << temp.second << endl;
    }
}


Measured memory_bytes: 4336
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    int n, m, k, cnt = 0;
    cin >> n;
    vector<int> p(n);

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

    for (int i = 1; i < n - 1; i++)
    {
        if ((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] < p[i - 1] && p[i] > p[i + 1]))
            cnt++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll P, Q, R;
        cin >> P >> Q >> R;
        vll x{P+Q, Q+R, P+R};
        cout << *min_element(all(x)) << endl;
}

Measured memory_bytes: 256
from math import sqrt
import bisect


def is_prime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = sqrt(num)
    for i in range(3, int(sqrtNum) + 1, 2):
        if num % i == 0:
            return False

    return True


def solve(query):
    ans = []
    al = []
    for i in range(3, 10**5+1, 2):
        if is_prime(i) and is_prime((i+1)//2):
            al.append(i)

    for q in query:
        if is_prime(q[0]) and is_prime((q[0]+1)//2):
            l_ind = bisect.bisect_right(al, q[0]) - 1
        else:
            l_ind = bisect.bisect_right(al, q[0])
        if is_prime(q[1]) and is_prime((q[1]+1)//2):
            r_ind = bisect.bisect_left(al, q[1])
        else:
            r_ind = bisect.bisect_left(al, q[1]) - 1
        ans.append(r_ind-l_ind+1)

    return ans


if __name__ == "__main__":
    Q = int(input())
    query = [list(map(int, input().split())) for _ in range(Q)]

    ans = solve(query)

    for a in ans:
        print(a)


Measured memory_bytes: 29780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X,Y;
  cin>>X>>Y;
for(int i=0;i<=100;i++){
  for(int j=0;j<=100-i;j++){
    if(2*i+j*4==Y&&i+j==X){
      cout<<"Yes"<<endl;
      return 0;
      }
    }
  }
cout<<"No"<<endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

struct fig{
	int n;
	string str;
};
fig num[4];

bool inp(){
	cin>>num[0].n>>num[1].n>>num[2].n>>num[3].n;
	char buf[100];
	sprintf(buf,"%d",num[0].n);
	num[0].str=buf;
	sprintf(buf,"%d",num[1].n);
	num[1].str=buf;
	sprintf(buf,"%d",num[2].n);
	num[2].str=buf;
	sprintf(buf,"%d",num[3].n);
	num[3].str=buf;
	return num[0].n!=0;
}

bool f(fig nu[],int n){
	/*int y;
	for(y=0;y<n;y++){
		cout<<nu[y].n<<endl<<nu[y].str<<endl;
	}
	cout<<endl;
	*/if(n==1){
		if(nu[0].n==10){
			cout<<nu[0].str<<endl;
			return true;
		}else{
			return false;
		}
	}
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==j)continue;
			fig next[4];
			int k,t=1;
			next[0].n=nu[i].n+nu[j].n;
			next[0].str="("+nu[i].str+" + "+nu[j].str+")";
			for(k=0;k<n;k++){
				if(k!=i&&k!=j){
					next[t++]=nu[k];
				}
			}
			if(f(next,n-1))return true;
			t=1;
			next[0].n=nu[i].n-nu[j].n;
			next[0].str="("+nu[i].str+" - "+nu[j].str+")";
			for(k=0;k<n;k++){
				if(k!=i&&k!=j){
					next[t++]=nu[k];
				}
			}
			if(f(next,n-1))return true;
			t=1;
			next[0].n=nu[j].n-nu[i].n;
			next[0].str="("+nu[j].str+" - "+nu[i].str+")";
			for(k=0;k<n;k++){
				if(k!=i&&k!=j){
					next[t++]=nu[k];
				}
			}
			if(f(next,n-1))return true;
			t=1;
			next[0].n=nu[i].n*nu[j].n;
			next[0].str="("+nu[i].str+" * "+nu[j].str+")";
			for(k=0;k<n;k++){
				if(k!=i&&k!=j){
					next[t++]=nu[k];
				}
			}
			if(f(next,n-1))return true;
			
		}
	}
	return false;
}

int main() {
	while(inp()){
		if(!f(num,4))cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 968
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[105];
int main()
{
	long long ans=999999999,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int j=a[1];j<=a[n];j++)
	{
		sum=0;
		for(int k=1;k<=n;k++)
		{
			sum+=(a[k]-j)*(a[k]-j);
		}
		if(sum<ans)	ans=sum;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] alphabet = new int[26];
		char a = 'a', ch;
		while (sc.hasNext()) {
			String str = sc.next().toLowerCase();
			for (int i=0; i< str.length(); i++) {
				if (Character.isLetter(ch = str.charAt(i))) {
					alphabet[ch - a]++;
				}
			}
		}
		sc.close();
		for (int i=0; i <= ('z' - 'a'); i++) {
			System.out.println(new StringBuilder().append(a++).append(" : ").append(alphabet[i]).toString());
		}
	}
}

Measured memory_bytes: 19244
s=input()
n=len(s)
for i in range(n-1):
  t=s[i:i+2]
  if t[0]==t[-1]:
    print(i+1,i+2)
    exit(0)
for i in range(n-2):
  t=s[i:i+3]
  if t[0]==t[-1] and t[0]!=t[1]:
    print(i+1,i+3)
    exit(0)
print(-1,-1)


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

const long long MAX_N = 1000000;
vector<long long> primes;

int init(){
    vector<bool> is_primes(MAX_N, true);
    is_primes[0] = is_primes[1] = false;
    
    for (long long i = 2; i < MAX_N; i++){
        if (is_primes[i]){
            for (long long j = i * i; j < MAX_N; j += i){
                is_primes[j] = false;
            }
            primes.push_back(i);
        }
    }
}

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

    init();

    long long a, b;
    cin >> a >> b;

    long long _gcd = __gcd(a, b);
    
    int ans = 1;
    for (auto i: primes){
        bool ok = false;
        while (_gcd % i == 0){
            if (!ok){
                ok = true;
                ans += 1;
            }
            _gcd /= i;
        }
    }

    if (_gcd != 1LL)
        ans += 1;

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1528
3.times do |i|
	if i == 0
		N = gets.to_i
	elsif i == 1
		S = gets.to_s.chomp
	elsif i == 2
		K = gets.to_i
	end
end
i = 0
while i < N
	if S[K-1] == S[i]
	else
		S[i] = '*'
	end
	i += 1
end
puts S

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(data[j]<data[j-1]){
	swap(data[j],data[j-1]);
	cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
  }

Measured memory_bytes: 1164
n = int(input())
d = input().split()
 
# print(n)
# print(d)

cnt = 1
a=[]
b=[]
for i in d:
    if(int(i) != cnt):
        a.append(d.index(i)+1)
        b.append(int(i))
        # print("i,cnt=",i,cnt)
    cnt += 1


if(len(a)==2 or len(a)==0):
    b.sort()
    if(a==b):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>

auto main() -> int {
  int n;
  std::cin >> n;

  int hs[20];
  for (int i = 0; i < n; ++i) {
    std::cin >> hs[i];
  }

  int o = 0;
  int maximum = 0;
  for (int i = 0; i < n; ++i) {
    maximum = std::max(maximum, hs[i]);
    if (maximum <= hs[i]) o++;
  }

  std::cout << o << std::endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(1<<3):
  t=[0] *n
  for j in range(n):
    for k in range(3):
      if i&(1<<k):t[j]+=xyz[j][k]
      else:t[j]-=xyz[j][k]
  t.sort()
  ans=max(ans,sum(t[n-m:]))
print(ans)

Measured memory_bytes: 3316
class Node():
    def __init__(self, key):
        self.key = key
        self.left = self.right = None
        
def insert(key):
    global root

    x = root
    y = None
    while x:x, y = x.left if key < x.key else x.right , x
    if y == None:root = Node(key)
    elif y.key < key:y.right = Node(key)
    else:y.left = Node(key)
        
        
def pre(node):
    if node == None:return
    print('',node.key, end = '');pre(node.left);pre(node.right)
    
def ino(node):
    if node == None:return
    ino(node.left);print('',node.key,end='');ino(node.right)

def find(node, key):
    if node == None:
        print('no');return
    if node.key == key:
        print('yes');return
    elif node.key > key:
        find(node.left, key)
    else:
        find(node.right, key)

def delete(node, key):
    x = node
    while x.key != key and x:
        x, y = node.left if key < x.key else x.right, x
    if x == None:
        return
    else:
        if x.left == None and x.right == None:
            if key < y.key:y.left = None
            else:y.right = None
        elif x.right == None:
            if key < y.key:y.left = x.left
            else:y.right = x.left
        elif x.left == None:
            if key > y.key:y.right = x.right
            else:y.left = x.right
        else:
            a = x.right
            c = 0
            b = 1
            while a:a, b, c = a.left if a.left != None and a.right != None else a.left if a.left != None else None  , a, b
            if c == 1:
                b.left = x.left
                if key < y.key:y.left = b
                else:y.right = b
            else:
                c.left = b.right
                x.key = b.key
                
                
            
        
        
    

n = int(input())
root = None
for j in range(n):
    s, *i = input().split()
    if s[0] == 'i':insert(int(i[0]))
    elif s[0] == 'f':
        find(root, int(i[0]))
    elif s[0] == 'd':
        delete(root, int(i[0]))
    else:
        ino(root);print();pre(root);print()
        
    


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

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	cout << (K % 2 ? -1 : 1) * (A - B) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  S.push_back('#');
  S.push_back('#');
  S.at(A - 1) = 'A';
  S.at(B - 1) = 'B';
  bool a = true, b = true;
  while(a || b){
     if(S.at(A) == '.' && a ){
      S.at(A-1) = '.';
      A++;
      S.at(A-1)= 'A';
      if(A == C){
        a = false;
      }
    }
    else if(S.at(A + 1) == '.' && a){
      S.at(A-1) = '.';
      A += 2;
      S.at(A-1) = 'A';
      if(A == C){
        a = false;
      }
    }
    else if(S.at(B) == '.' && b){
      S.at(B-1) = '.';
      B++;
      S.at(B-1)= 'B';
      if(B == D){
        b = false;
      }
    }
    else if(S.at(B + 1) == '.' && b){
      S.at(B-1) = '.';
      B += 2;
      S.at(B-1) = 'B';
      if(B == D){
        b = false;
      }
    }
    else{
      cout << "No" << endl;
      break;
    }
  }
  if(!a && !b) cout << "Yes" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  long long result = 0;
  map<string, int> countS;
  
  for (int i = 0; i < N; i++) {
  	string str;
    cin >> str;
    map<char, int> count;
    string tmp;
	int size = str.size();
    for (int j = 0; j < size; j++) {
    	count[str[j]] += 1;
    }
    for (auto p : count) {
  	  tmp += p.first;
  	  tmp += to_string(p.second);
    }
    if (countS[tmp] > 0) {
      	result += countS[tmp];
      	countS[tmp] += 1;
    } else {
    	countS[tmp] = 1;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 16716
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int x,y,z;
vector<tuple<ll,ll,ll>> Coin;
vector<ll> c_sum;
ll dp_gold[200000],dp_silver[200000];

void solve(){
    cin >> x >> y >> z;
    c_sum.push_back(0);
    rep(i,x+y+z){
        ll a,b,c;
        cin >> a >> b >> c;
        tuple<ll,ll,ll> C=make_tuple(a,b,c);
        Coin.push_back(C);
        c_sum.push_back(c+c_sum.back());
    }

    sort(Coin.begin(),Coin.end(),[&](tuple<ll,ll,ll> x, tuple<ll,ll,ll> y){return get<0>(x)-get<1>(x) > get<0>(y)-get<1>(y);});
    //cout << "" << endl;
    // rep(i,x+y+z){
    //     cout << get<0>(Coin[i]) << " " << get<1>(Coin[i]) << " " << get<2>(Coin[i]) << endl;
    // }

    priority_queue<ll,vector<ll>,greater<ll>> que_gold,que_silver;
    dp_gold[x]=0;dp_silver[x+z]=0;
    rep(i,x) {
        que_gold.push(get<0>(Coin[i])-get<2>(Coin[i]));
        dp_gold[x]+=get<0>(Coin[i])-get<2>(Coin[i]);
        //cout << get<0>(Coin[i])-get<2>(Coin[i]) << endl;
    }
    //cout << "gold:" << x << " " << dp_gold[x] << endl;
    Rep(i,x,x+z) {
        que_gold.push(get<0>(Coin[i])-get<2>(Coin[i]));
        dp_gold[i+1]=dp_gold[i]+get<0>(Coin[i])-get<2>(Coin[i]);
        ll k=que_gold.top();que_gold.pop();
        //cout << dp_gold[i+1] << " " << k << endl;
        dp_gold[i+1]-=k;
        //cout << "gold:" << i+1 << " " << dp_gold[i+1] << endl;
    }
    Per(i,x+z,x+y+z) {
        que_silver.push(get<1>(Coin[i])-get<2>(Coin[i]));
        dp_silver[x+z]+=get<1>(Coin[i])-get<2>(Coin[i]);
    }
    //cout << "silver:" << x+z << " " << dp_silver[x+z] << endl;
    Per(i,x,x+z) {
        que_silver.push(get<1>(Coin[i])-get<2>(Coin[i]));
        dp_silver[i]=dp_silver[i+1]+get<1>(Coin[i])-get<2>(Coin[i]);
        ll k=que_silver.top();que_silver.pop();
        //cout << dp_silver[i] << " " << k << endl;
        dp_silver[i]-=k;
        //cout << "silver:" << i << " " << dp_silver[i] << endl;
    }

    ll ans=0;

    Rep(i,x,x+z+1){
        ans=max(ans,dp_gold[i]+dp_silver[i]+c_sum[x+y+z]);
        //cout << dp_gold[i]+dp_silver[i]+c_sum[x+y+z] << endl;
    }

    cout << ans << endl;

}

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

Measured memory_bytes: 5928
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	sort(ASC(s));
	sort(DESC(t));

	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
a = []

for i in range(N):
    if v[i] > c[i]:
        a.append(v[i] - c[i])
print(sum(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      long n;
      int a,ans;
      a =0;ans=0;
      cin >> n;
      for(int i=2;i<=sqrt(n);i++){
        while(n%i == 0){
          n/=i;
          a++;
        }
        for(int j=1;j*(j+1)/2<=a;j++){
          ans++;
        }
        a = 0;
      }
      if(n != 1)ans++;
      cout << ans << endl;
    }

Measured memory_bytes: 3588
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int i = 0; i < N; ++i)
    std::cin >> A[i];

  // int sum = 0;
  // for (int i = 0; i < N; ++i)
  //   sum += A[i];

  int max = 0;
  int iMax = -1;
  int max2 = 0;
  for (int i = 0; i < N; ++i)
    if (chmax(max, A[i]))
      iMax = i;

  for (int i = 0; i < N; ++i) {
    if (i == iMax)
      continue;
    chmax(max2, A[i]);
  }

  // std::cout << max << std::endl;
  // std::cout << max2 << std::endl;
  // std::cout << std::endl;

  if (max2 == max)
    for (int i = 0; i < N; ++i)
      std::cout << max << std::endl;
  else
    for (int i = 0; i < N; ++i) {
      if (A[i] == max)
        std::cout << max2 << std::endl;
      else
        std::cout << max << std::endl;
    }

  return 0;
}


Measured memory_bytes: 2432
alst = list(map(int, input().split()))
ans = 1000
for i in range(3):
  for j in range(3):
    for k in range(3):
      if i != j and j != k and i != k:
        ans = min(ans, 0 + abs(alst[j] - alst[i]) + abs(alst[k] - alst[j]))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
P az(int x){
  int a=x%10 ;
  int b=0;
  while(x>=1){
    b=x ;
    x /= 10 ;
  }
  return P(a,b) ;
}
int main() {
  int n;
  cin>>n ;
  map< P,int > freq ;
  for(int i=1 ;i<=n ;i++){
   freq[az(i)]++ ;
  }
    ll ans=0 ;
    for(int i=1 ;i<=n ;++i) {
    P p=az(i) ;
    P q(p.second,p.first) ;
    ans +=freq[q]  ;  
    }
    cout << ans <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){

    while(true){
        int w,h;
        cin >> w >> h;
        if(w == 0) break;
        int sy,sx,gy,gx;
        cin >> sx >> sy >> gx >> gy;
        sx--,sy--,gx--,gy--;
        int n;
        cin >> n;
        vector<vector<int> > color(h,vector<int>(w));
        for(int block=0;block<n;block++){
            int c,d,x,y;
            cin >> c >> d >> x >> y;
            x--;y--;
            // yoko
            if(d == 0){
                for(int i=0;i<2;i++){
                    for(int j=0;j<4;j++){
                        color[y+i][x+j] = c;
                    }
                }
            }else{
                for(int i=0;i<4;i++){
                    for(int j=0;j<2;j++){
                        color[y+i][x+j] = c;
                    }
                }
            }
        }
        // for(int i=0;i<h;i++){
        //     for(int j=0;j<w;j++){
        //         cerr << color[i][j];
        //     }
        //     cerr << endl;
        // }
        int c = color[sy][sx];
        vector<vector<char> > visited(h,vector<char>(w));
        queue<pair<int,int> > Q;
        Q.push(make_pair(sy,sx));
        while(not Q.empty()){
            int y = Q.front().first;
            int x = Q.front().second;
            Q.pop();

            if(y >= h or y < 0 or x >= w or x < 0) continue;
            if(color[y][x] != c) continue;
            if(visited[y][x]) continue;
            visited[y][x] = true;
            for(int i=0;i<4;i++){
                Q.push(make_pair(y+dy[i],x+dx[i]));
            }
        }
        if(visited[gy][gx]){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1272
#include<stdio.h>
#include<float.h>

int main(){
 int n,i=0,j=0;
 int *data,*inv;

 scanf("%d",&n);

 data=(int *)malloc(sizeof(int)*n);
 while(1){
    scanf("%d",&data[i]);
    i++;
    if(n<=i) break;
 }

 inv=(int *)malloc(sizeof(int)*n);
 while(1){
    inv[j]=data[i-1];
    i--;
    j++;
    if(n<=j) break;
 }

 for(i=0;i<n-1;i++)
    printf("%d ",inv[i]);
 printf("%d\n",inv[i]);

return 0;
}

Measured memory_bytes: 596
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc091_a {
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        if (N == 1 || M == 1) {
            if (N == 1 && M == 1) {
                out << 1 << "\n";
            } else if (N == 1) {
                out << M - 2 << "\n";
            } else {
                out << N - 2 << "\n";
            }
        } else {
            long long res = 1LL * (N - 2) * (M - 2);
            out << res << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc091_a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
Ascore = 0
Bscore = 0
A, B = [], []
for i in range(n):
    a, b = map(int, input().split())
    c = a + b
    A.append((a,b,c))
A.sort(key=lambda x:x[2], reverse=True)
Aturn = True
for a in A:
    if Aturn:
        Ascore += a[0]
        Aturn = False
    else:
        Bscore += a[1]
        Aturn = True
print(Ascore-Bscore)


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

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


Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;cin>>n;
  int t = 7%n;
  for(int i=0;i<n+3;i++){
    if(t==0){
      cout<<i+1<<endl;
      return 0;
    }
    t = (t*10+7)%n;
  }
  cout<<-1<<endl;
  return 0;
}


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

int main(){
	char c;
	cin >> c;
	if(c == 'A') cout << 'T';
	if(c == 'T') cout << 'A';
	if(c == 'C') cout << 'G';
	if(c == 'G') cout << 'C';
	cout << endl;
	return 0;	
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		
		char[] arr = new char[str.length()];
		for(int i = 0;i<str.length();i++){
			arr[i] = str.charAt(i);
		}
		
		int count = 0;
		for(int i = 0;i<str.length()-1;i++){
			if(arr[i] != arr[i+1]){
				count++;
			}
		}
		System.out.println(count);
		
	}
	

}

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

typedef long long int ll;



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    //vector<ll> x = vector<ll>(n, 0);
    vector<ll> a = vector<ll>();
    ll inp;
    for(int i=0; i < n; i++) {
        cin >> inp;
        a.push_back(inp);
    }
    ll sol = 0;
    ll x = 0;
    for(int i=n-1; i > -1; i--) {
        if(x < a[i]) {
            sol += a[i];
            if(a[i] > i) {
                cout << -1 << endl;
                return 0;
            }
            x = a[i]-1;

        }
        else if(x == a[i]) {
            x--;
        }
        else if(x > a[i]) {
            cout << -1 << endl;
            return 0;
        }

    }
    cout << sol << endl;
}


Measured memory_bytes: 2548
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		while ((line = br.readLine()) != null) {

			char[] input = line.toCharArray();

			for (int i = input.length; i > 0; i--) {
				System.out.print(input[i - 1]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 16860
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M= scan.nextInt();
		int m = 1000000007;
		HashSet<Integer> map = new HashSet<>();
		for (int i=0;i<M;i++) {
			map.add(scan.nextInt());
		}
		int[] grid = new int[N+1];
		grid[0] = 1;
		for (int i=1;i<=N;i++) {
			if (!map.contains(i)) {
				if (i-1>=0 && !map.contains(i-1)) {
					grid[i] = (grid[i]%m+grid[i-1]%m)%m;
				}
				if (i-2>=0 && !map.contains(i-2)) {
					grid[i] = (grid[i]%m+grid[i-2]%m)%m;
				}
			}
		}
		System.out.println(grid[N]);
	}
}

Measured memory_bytes: 63796
n = gets.strip.chomp.to_i
h = gets.strip.chomp.split.map(&:to_i)

(0..n-2).each do |i|
  if(h[i+1]) > h[i]
    h[i+1] = h[i+1]-1
  elsif h[i+1] < h[i]
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 9604
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
        //freopen("b.inp","r",stdin);
        int n, h, w, ans = 0;
        int a[1001], b[1001];
        cin >> n >> h >> w;
        int smain = h*w;
        for (int i=0; i<n; i++)
        {
                int s;
                cin >> a[i] >> b[i];
                s = a[i] * b[i];
                if (a[i]>=h&&b[i]>=w)
                {
                        ans++;
                }
        }
        cout << ans;
        return 0;
}


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

int main(){
  int N;
  std::cin >> N;
  vt<int> two(3);
  rep(i,N){
    int a;
    std::cin >> a;
    if(a%4 == 0)
      two[2]++;
    else if(a%2 == 0)
      two[1] = 1;
    else
      two[0]++;
  }

  if(two[0] == 0 || two[2] + 1 - two[1] >= two[0])
    std::cout << "Yes" << '\n';
  else
    std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;

	ll mn=1e18;
	for(i=0;i<=2*(x+y);i+=2){
		k=(i/2);
		ll v=max((ll)0,(x-k))*a+max((ll)0,(y-k))*b+i*c;
		if(v<mn){
			mn=v;
			//cout<<v<<" "<<i<<endl;
		}
	}
	cout<<mn;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

ll LCM = 1;
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
    if (a < b) swap(a, b);
    return a / gcd(a, b) * b;
}

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, LCM);
        //最下段
        for (int i = 0; i < sz; ++i) node[i + (n - 1)] = v[i];
        for (int i = n - 2; i >= 0; --i) //0 ~ n-2, n-1 ~ 2n - 1
            node[i] = gcd(node[2 * i + 1], node[2 * i + 2]);
        
    }
    void update(int x, int val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
        //再帰であり、最初r = -1. 最初の区間は[0, n)
        if (r < 0) r = n;
        //関係ない区間ならminになり得ないのを
        if (r <= a || b <= l) return LCM;
        if (a <= l && r <= b) return node[k];
        
        ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
        return gcd(vl, vr);
    }
    void res() {
        rep(i, 2 * n - 1) cout << node[i] << " "; cout << endl;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) {cin >> v[i]; LCM = lcm(LCM, (ll)v[i]);}
    SegmentTree sgt(v);
    ll ans = 0;
    rep(i, n) {
        ans = max(ans, gcd(sgt.get(0, i), sgt.get(i + 1, n)));
    }
    //sgt.res();
    cout << ans << endl;
}
    


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    char s[101];
    rep(i, 101) s[i] = '\0';
    scanf("%s", s);
    int count = 0;
    while (s[count] != '\0') count++;
    int ans = 0;
    for (int i = 0; i < count / 2; ++i) {
        if (s[i] != s[count - 1 - i]) ans++;
    }
    printInt(ans);
    return 0;
}

Measured memory_bytes: 3824
from collections import Counter
N=int(input())
A=[int(i) for i in input().split()]
Q=int(input())
K=Counter(A)
S=sum(A)
for i in range(Q):
    B,C=map(int,input().split())
    if C in K:
        K[C]+=K[B]
    else:
        K[C]=K[B]
    S+=((C-B)*K[B])
    print(S)
    K[B]=0

Measured memory_bytes: 23952
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<long long int,long long int>
#define vi vector<long long int >
#define vvi vector<vector< long long int>>
#define MP make_pair
#define PB push_back 
#define pb pop_back
#define PF push_front
#define pf pop_front
#define MOD 1000000007
#define MT make_tuple

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	if(n==0)
		cout<<1<<endl;
	else	   
		cout<<0<<endl; 
    return 0;
}
			

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k,ans;cin >> a >> b >> k;
    for(int i=(min(a,b));k>0;i--){
      (a%i==0&&b%i==0) ? ans=i,k--:ans+=0;
}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

V<V<ll>> dp(401, V<ll>(410, HINF));
V<ll> a(410),b(410,0);

ll rec(int l,int r){
	if (dp[l][r] != HINF) return dp[l][r];
	if (l + 1 == r) return dp[l][r] = 0;

	ll mini = HINF;
	for(int i = l+1; i < r; ++i){
		mini = min(mini, rec(l, i) + b[i] - b[l]+ rec(i, r) + b[r] - b[i]);
	}

	return dp[l][r] = mini;
}

int main() {
	int N; cin >> N;
	FOR(i,1,N + 1) cin >> a[i];
	FOR(i,1,N + 1) b[i] = b[i - 1] + a[i];
	cout << rec(0, N) << endl;
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#define INF (1 << 30)
using namespace std;

int main() {
    int N, A, count, min_count = INF;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A;
        if (A % 2 != 0) {
            cout << 0 << endl;
            return 0;
        }
        else {
            count = 0;
            while (A % 2 == 0) {
                A /= 2;
                count++;
            }
            min_count = min(min_count, count);
        }
    }
    cout << min_count << endl;
    return 0;
}

Measured memory_bytes: 256