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

using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979

signed main(){

	lli n,m;
	cin>>n>>m;

	vector<lli> x(m),y(m),z(m);
	map<lli,vector<lli>> d;

	REP(i,0,m){
		cin>>x[i]>>y[i]>>z[i];
		x[i]--,y[i]--;
		d[x[i]].push_back(y[i]);
		d[y[i]].push_back(x[i]);
	}

	lli data[100100]={0};
	lli cnt=1;
	REP(i,0,n){
		if(data[i]!=0)continue;

		queue<lli> q;
		q.push(i);
		data[i] = cnt;
		while(q.size()){
			lli top = q.front();
			q.pop();
			for(auto e:d[top]){
				if(data[e]!=0)continue;
				data[e] = cnt;
				q.push(e);
			}
		}
		cnt++;
	}
	cout<<cnt-1<<endl;

	return 0;
}

Measured memory_bytes: 15988
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 100010
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define lint long long
#define mod 1000000007
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std; inline int inn() { int x,ch;while((ch=gc)<'0'||ch>'9'); x=ch^'0';while((ch=gc)>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x; } int fac[N],facinv[N],f[N],onc[N],sz[N],p[N],cnt[N]; int cyc_cnt,vis[N],l[N],pre[N],jhs[N],in[N],mi[N],it[N]; inline int fast_pow(int x,int k,int ans=1) { for(;k;k>>=1,x=(lint)x*x%mod) (k&1)?ans=(lint)ans*x%mod:0;return ans; } inline int prelude(int n) { rep(i,fac[0]=1,n) fac[i]=(lint)fac[i-1]*i%mod; facinv[n]=fast_pow(fac[n],mod-2); for(int i=n-1;i>=0;i--) facinv[i]=facinv[i+1]*(i+1ll)%mod; rep(i,mi[0]=1,n) mi[i]=mi[i-1]*2,(mi[i]>=mod?mi[i]-=mod:0); rep(i,f[0]=1,n/2) f[i]=f[i-1]*(2*i-1ll)%mod;return 0; } inline int C(int n,int m) { if(n<0||m<0||n<m) return 0;return (lint)fac[n]*facinv[m]%mod*facinv[n-m]%mod; } int main() { int n=inn();rep(i,1,n) in[p[i]=inn()]++; for(int i=1,x;i<=n;i++) { for(x=i;!vis[x];x=p[x]) vis[x]=i; if(vis[x]^i) continue; for(cyc_cnt++;!onc[x];x=p[x]) onc[x]=cyc_cnt,sz[cyc_cnt]++; } memset(vis,0,sizeof(int)*(n+1)); for(int i=1,x,c;i<=n;i++) if(!in[i]) { for(x=i,c=0;!onc[x];vis[x]=1,x=p[x],c++) if(vis[x]) return !printf("0\n"); if(vis[x]) return !printf("0\n");vis[x]=1,l[x]=c; } rep(i,1,n) if(onc[i]&&l[i]) jhs[onc[i]]=1; rep(i,1,cyc_cnt) if(!jhs[i]) cnt[sz[i]]++; prelude(n);int ans=1; for(int i=1,k,t,s,v;i<=n;i++) if(cnt[i]) { rep(j,it[0]=1,cnt[i]/2) it[j]=(lint)it[j-1]*i%mod; for(k=cnt[i],t=0,s=0;t<=cnt[i]/2;t++) v=(lint)C(k,2*t)*f[t]%mod*it[t]%mod, (((i&1)&&i>1)?v=(lint)v*mi[k-2*t]%mod:0), s+=v,(s>=mod?s-=mod:0); ans=(lint)ans*s%mod; } for(int i=1,x,c;i<=n;i++) if(onc[i]&&l[i]) {  for(x=i,c=1;!l[p[x]];x=p[x],c++);pre[p[x]]=c; } rep(i,1,n) if(onc[i]&&l[i]) { if(l[i]>pre[i]) return !printf("0\n"); else if(l[i]<pre[i]) ans=ans*2,(ans>=mod?ans-=mod:0); } return !printf("%d\n",ans); }


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

int main(){
  int n,ans;
  int a[500000];
  int MOD[3]={0};

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    MOD[a[i]%3]++;
  }
  
  int MIN=min(MOD[1],MOD[2]);
  int MAX=max(MOD[1],MOD[2]);
  
  ans = MIN + min(MAX,MIN+3);
  ans += MOD[0];

  if(MOD[1]==0&&MOD[2]==0)
    cout<<1<<endl;
  else
    cout<<ans<<endl;
  
  return 0;
}

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

int main(){
    bool flg=false;
    string number;
    string a;
    string b;
    cin >> a >> b;

    number = a+b;
    int nm = atoi(number.c_str());

    for(int i=0;i<=1000; i++){
        if(nm == i*i){
            flg = true;
            break;
        }
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 3636
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

/************************************************/

const int N=2e5+5;
ll a[N],pref[N],odd[N],even[N];
ll fun(ll x,ll y,ll p)
{
    ll sum=pref[y-1]-pref[x];
        bool flag=false;
        if(p%2==0)
        {
            ll pp=even[y-1]-even[x];
            if(pp%2==0)
                flag=true;
        }
        else
        {
            ll pp=odd[y-1]-odd[x];
            if(pp%2==1)
                flag=true;
        }
        if(flag)
            return sum;
        else
            return 0LL;
}
void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    cout<<s;
    if(s[n-1]=='s')
        cout<<"es";
    else
        cout<<"s";
}

int main()
{
    fast();
    int t;
    t=1;
    while(t--)
        solve();
   // time();
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
#include <math.h>
#include <stack>
#define pb push_back
// #define pop pop_back
#define ll long long int
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define I long_max
#define pii pair<int, int>
#define pll pair<long, long>
#define vpair vector<pair<int, int>>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fir first
#define sec second
#define d (int)1e9 + 7
#define INF (int)2e9 + 1
#define el "\n"
#define fs fastscan

#define vrep(vec) for (const auto &value : vec)
#define arep(arrat) for (const auto &value : array)
using namespace std;

bool sortinrev(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.first > b.first);
}
void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

//over

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //use auto instead of data types
    // int t;
    // cin >> t;
    // while (t--)
    {
        string s, t;
        cin >> s >> t;
        vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
        for (ll i = 1; i <= s.size(); i++)
        {
            for (ll j = 1; j <= t.size(); j++)
            {
                if (s[i - 1] == t[j - 1])
                {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                else
                {
                    dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
                }
            }
        }
        string final = "";
        for (ll i = s.size(), j = t.size(); i > 0 && j > 0;)
        {
            if (s[i - 1] == t[j - 1])
            {
                final = s[i - 1] + final;
                i--;
                j--;
            }
            else if (dp[i][j - 1] >= dp[i - 1][j])
            {
                j--;
            }
            else
            {
                i--;
            }
        }
        cout << final << endl;
    }
    return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if (a < 6) {
    cout << 0 << endl;
  } else if (a <= 12) {
    cout << b/2 << endl;
  } else {
    cout << b << endl;
  }
}

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

using namespace std;

int abs(int x){
	if(x<0)return -x;
	return x;
}
int main(){
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	int DP[n];
	DP[n-1]=0;
	for(int i=n-2;i>-1;i--){
		DP[i]=1000000000;
		for(int j=1;j<=k;j++){
			if(i+j<n)DP[i]=min(DP[i],DP[i+j]+abs(arr[i]-arr[i+j]));
		}
		//cout<<DP[i]<<endl;
	}
	cout<<DP[0]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e18
int main(){
  ll N,W;
  cin>>N>>W;
  ll w[N],v[N];
  for(int i=0;i<N;i++) cin>>w[i]>>v[i];
  vector<vector<ll>> dp(N+1,vector<ll>(100010,W+1));
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<=100000;j++){
      if(j<v[i]) dp[i+1][j]=dp[i][j];
      else dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
    }
  }
  for(int i=100000;i>=0;i--){
    if(dp[N][i]<W+1){
      cout<<i;
      break;
    }
  }
}

Measured memory_bytes: 80256
#include<iostream>
using namespace std;
int main()
{
    int ret=false;
    string s;
    cin >> s;
    if (s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) {
        ret=true;
    } else if (s[0]==s[2]&&s[1]==s[3]&&s[1]!=s[2]) {
        ret=true;
    } else if (s[0]==s[3]&&s[1]==s[2]&&s[1]!=s[3]) {
        ret=true;
    } else {
        // nothing
    }
    if (ret) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

public class Main {
	//2-100
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		String string = in.next();
		int sum = 0;
		for (int i = 0; i < string.length(); i++) {
			sum+=string.charAt(i)-48;
		}
		if (sum%9==0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 31488
import java.util.*;
 
public class Main { 
	public static int n;
	public static int m;
	public static int x;
	public static int[] kingakus;
	public static int[][] cs;
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		x = sc.nextInt();
		cs = new int[n][m];
		kingakus = new int[n];
		for(int i=0; i<n; i++){
			kingakus[i] = sc.nextInt();
			for(int j=0; j<m; j++){
				cs[i][j] = sc.nextInt();
			}
		}
		bitSearch();
	}

	static void bitSearch() {
		int ans = 200000000;
		for (int i = 0; i < (Math.pow(2, n)); i++) {
			boolean[] hantei = new boolean[n];
			int[] rikaido = new int[m];
			int kingaku = 0;
			for (int j = 0; j < n; j++) {
				if ((1 & i >> j) == 1) {
					hantei[j] = true;
				} else {
					hantei[j] = false;
				}
			}
			for(int j=0; j<n; j++){
				if(hantei[j]){
					kingaku += kingakus[j];
					for(int k=0; k<m; k++){
						rikaido[k] += cs[j][k];
					}
				}
			}
			boolean flag = true;
			for(int j=0; j<m; j++){
				if(rikaido[j] < x){
					flag = false;
					break;
				}
			}
			if(flag) {
				ans = Math.min(ans, kingaku);
			}
		}
		if(ans == 200000000) System.out.println(-1);
		else System.out.println(ans);
	}
}


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

int main(){
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  int m = min(min(A.at(0),A.at(1)),A.at(2));
  int M = max(max(A.at(0),A.at(1)),A.at(2));
  
  cout << M-m << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			System.out.println(String.format("%d %d", Math.min(Math.min(a, b), c), Math.max(Math.max(a, b), c)));
		}
	}
}


Measured memory_bytes: 26360
#include<stdio.h>
#include<string.h>
#include<math.h>



int main(){
	char s[11];
	long long ans=0,a,p[11];
	int i, j, n;
	scanf("%s", s);
	n = strlen(s);
	for (i = 0; i < n; i++)p[i] = s[i] - '0';
	for (i = 0; i < (1<<(n-1)); i++) {
		a = p[0];
		for (j = 0; j < (n-1); j++) {
			if ((i&(1<<j)) ) {
				a = 10*a+p[j+1];
				//printf("%d\n", a);
			}
			else {
				ans +=a;
				a = p[j + 1];
				
			}
			
		}
		ans += a;
       
	}
	printf("%lld", ans);
	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long int;
const ll MAXV = 1LL << 60;
ll mul(ll A, ll B) {
    if(A == MAXV or B == MAXV) return MAXV;
    ll ret = 0;
    for(; B>0; B>>=1) {
        if(B & 1) ret += A;
        if(ret > MAXV) return MAXV;
        (A += A);
    }
    return ret;
}

ll gcd(ll A, ll B) {
    return B ? gcd(B, A%B) : A;
}

ll lcm(ll A, ll B) {
    if(A == MAXV or B == MAXV) return MAXV;
    return mul(A / gcd(A, B), B);
}

ll N, M, A[25], P[25]; long double dp[1 << 20], ans;
int main() {
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> P[i];
    for(int bit=0; bit<(1<<N); bit++) {
        ll mul = 1;
        for(int i=0; i<N; i++) if(bit >> i & 1) mul = lcm(mul, A[i]);
        dp[bit] = M / mul;
    }
    for(int i=0; i<N; i++) for(int bit=0; bit<(1<<N); bit++) {
         if(bit >> i & 1) dp[bit] -= dp[bit ^ (1 << i)];
    }
    for(int bit=0; bit<(1<<N); bit++) {
        long double prob = 1.0;
        for(int i=0; i<N; i++) prob *= 1.0 * (bit >> i & 1 ? P[i] : 100 - P[i]) / 100.0;
        ans += prob * (M - abs(dp[bit]));
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 19668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b << endl;
}

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

int main(){
  int q;
  cin >> q;
  vector<ll> ans;
  rep(i,q) {
    ll a, b;
    cin >> a >> b;
    if(a == b) {
      ans.push_back((a-1)*2);
    } else {
      ll c = a*b;
      ll l = 0, r = INF;
      while(r - l > 1) {
        ll m = (l + r) / 2;
        if((m+1)/2*(m+1-(m+1)/2) < c) l = m;
        else r = m;
      }
      ans.push_back(l-1);
    }
  }
  for(auto k : ans) cout << k << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
def solve(N,A):
    liss = []
    lis = []
    lis.append(A[0])
    a = A[0]
    for i in range(1,N):
        if len(lis)==1 or prev==0:
            if A[i]>a:
                prev = 1
            elif A[i]<a:
                prev = -1
            else:
                prev = 0
        elif ((A[i]>a)+(A[i]>=a)-1)*prev<0:
            liss.append(lis)
            lis = []
        lis.append(A[i])
        a = A[i]
    liss.append(lis)
    ans = len(liss)
    return ans
print(solve(N,A))

Measured memory_bytes: 14484
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int num;
	char a[1000],b[1000];
	int i,j;
	for(i=0;;i++){
	scanf("%c",&a[i]);
	if(a[i]=='\n'){
	break;
	}
	if(a[i]>='A' && a[i]<='C'){
		b[i]=a[i]+23;
	}
	else{
		b[i]=a[i]-3;
	}
	printf("%c",b[i]);
	}
	cout<<endl;
return 0;
} 

Measured memory_bytes: 3232
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s1[101],s2[101];
int main()
{
    gets(s1);
    gets(s2);
    int n=strlen(s1);
    int m=strlen(s2); 
    sort(s1,s1+n);
    sort(s2,s2+m);
    for(int i=0;i<fmax(n,m);i++)
    {
        if(s1[i]<s2[m-i-1])
        {
            printf("Yes\n");
            return 0;
        }
        if(s1[i]>s2[m-i-1])
            break;
    }
    printf("No\n");
    return 0;
} 

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() int {
	sc.Scan()
	data, _ := strconv.Atoi(sc.Text())
	return data
}

func main() {
	args := []int{nextLine(), nextLine(), nextLine(), nextLine(), nextLine()}

	time := 0
	min := 10

	for _, arg := range args {
		remainder := int(arg % 10)
		if remainder > 0 {
			arg = arg - remainder + 10
			if min > remainder {
				min = remainder
			}
		}
		time += arg
	}

	time -= 10 - min

	fmt.Print(time)
}

Measured memory_bytes: 640
#include<stdio.h>

#define N 100

int main(){
  int i,j,num[N],n,min,tmp,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }

  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(num[j]<num[min]){
	min=j;
      }
    }
    if(min != i){
    tmp=num[i];
    num[i]=num[min];
    num[min]=tmp;
    count++;
    }
  }
  for(i=0;i<n-1;i++){
    printf("%d ",num[i]);
  }
  printf("%d\n",num[n-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
    int a, b, sum;
    int i, nod;

    while (scanf("%d%d", &a, &b) != EOF){
        nod = 1;
        sum = a + b;
        for(i = 10; i <= 1000000; i *= 10){
            if(sum / i == 0)    break;
            else nod++;
        }
        printf("%d\n", nod);
        //fflush(stdout);
        //fflush(stdin);
    }
    
    return (0);
}


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

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 1e12+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}



int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int m = 1000, M = -1000, tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        chmax(M,tmp);
        chmin(m,tmp);
        a[i] = tmp;
    }
    int res = 1e9;
    for (int x = m; x <= M; x++) {
        tmp = 0;
        for (int i = 0; i < N; i++) {
            tmp += (a[i] - x) * (a[i] - x);
        }
        chmin(res,tmp);
    }
    cout << res << endl;

}


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

int main(void)
{
    int x, y;

    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;

        if (x <= y)
            cout << x << " " << y << endl;
        else
            cout << y << " " << x << endl;
    }
}



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

int digit(int x){
	if(x == 0){
		return 0;
	}
	else{
		return digit(x / 10) + 1;
	}
}

int main(){
	int N, i, ans = 0;
	scanf("%d", &N);
	for(i = 1; i <= N; i++){
		ans += digit(i) % 2;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9,maxn=2e5+5;
int n,a[maxn],oa=0,o=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n+1;i++)oa+=abs(o-a[i]),o=a[i];
	for(int i=1;i<=n;i++){int del=abs(a[i-1]-a[i+1]),del2=abs(a[i-1]-a[i])+abs(a[i]-a[i+1]);printf("%d\n",oa+del-del2);}

	return 0;
}


Measured memory_bytes: 1664
N = int(input())
B = list(map(int,input().split()))

A = [None] * N
A[0] = B[0]
for i in range(N-1):
  if i+1 < len(B):
    A[i+1] = min(B[i], B[i+1])
  else:
    A[i+1] = B[i]

print(sum(A))

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main() {
    int x;
    cin >> x;
    if(x==0){
        cout << 1<<endl;
    }
    else{
        cout << 0<<endl;
    }
}

Measured memory_bytes: 3632
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 100000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 


const ll sz = 300009;

ll row[sz], col[sz];

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

	ll t, i, x, j, y, m,	z = 0, k, n;
	cin >> n >> m >> t;
	set<pll> st;

	set<ll> x_co, y_co;

	rep(i, 0, t, 1) {
		cin >> x >> y;
		x--, y--;
		row[x]++;
		col[y]++;
		st.insert({x, y});
		x_co.insert(x);
		y_co.insert(y);
	}

	ll y_max = 0, x_max = 0;

	std::vector<ll> x_alt, y_alt;

	for (auto &x : x_co) {
		if (row[x] > row[x_max]) {
			x_max = x;
		}
	}

	for (auto &x : x_co) {
		if (row[x] == row[x_max]) {
			x_alt.push_back(x);
		}
	}

	// ll mx_size = hell / y_co.size();
	// while (x_alt.size() > mx_size)	x_alt.pop_back();

	for (auto &y : y_co) {
		if (col[y] > col[y_max]) {
			y_max = y;
		}

		// for (auto x_max : x_alt) {
		// 	t = row[x_max] + col[y] - (st.count({x_max, y}) > 0);
		// 	z = max(z, t);
		// }
	}
	for (auto &y : y_co) {
		if (col[y] == col[y_max]) {
			y_alt.push_back(y);
		}
	}

	// while (y_alt.size() > 100)	y_alt.pop_back();

	for (auto &x_max : x_alt) {
		for (auto &y_max : y_alt) {
			t = row[x_max] + col[y_max] - (st.count({x_max, y_max}) > 0);
			z = max(z, t);
			if (st.count({x_max, y_max}) == 0)	{
				return cout << z, 0;
			}
		}
	}

	cout << (z);
	// debug(x_co);
	// debug(y_co);
	// debug(st);
	debug(z, x_max, y_max);
}



Measured memory_bytes: 63152
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int A[105];


int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);
	}

	int ans = 0;
	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){

			ans = max(ans,abs(A[i]-A[k]));
		}
	}

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

	return 0;
}


Measured memory_bytes: 3788
num = list(map(int,input().split())) #標準入力
if num[0] + num[1] * 5 + num[2] * 10 + num[3] * 50 + num[4] * 100 + num[5] * 500 >= 1000:print("1") #合計が１０００円以上なら"1"を出力する
else:print("0") #1000以下なら"0"を出力する


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 3e4 + 1;

int N;

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

  cin >> N;

  if (N == 3) {
    cout << "2 5 63" << endl;
    return 0;
  } else if (N == 4) {
    cout << "2 5 20 63" << endl;
    return 0;
  } else if (N == 5) {
    cout << "2 5 20 30 63" << endl;
    return 0;
  }

  int sm = 0;
  int cnt = 0;
  vector< int > lis;
  bool ok = false;
  FOR(i, 2, MAX_N) {
    switch(i % 6) {
    case 0:
    case 2:
      // 2N
    case 3:
      // 3N
    case 4:
      // 2N

      lis.emplace_back(i);
      sm += i;
      cnt++;
      if (cnt == N) {
	ok = true;
	/*
	REP(i, lis.size()) {
	  cout << lis[i];
	  if (i < lis.size() - 1) {
	    cout << " ";
	  } else {
	    cout << endl;
	  }
	}
	*/
  
	// debug(sm);
	switch(sm % 6) {
	case 2:
	  REP(j, lis.size()) {
	    if (lis[j] == 8) {
	      lis.erase(lis.begin() + j);
	      break;
	    }
	  }
	  FOR(j, i + 1, MAX_N) {
	    if (j % 6 == 0) {
	      lis.emplace_back(j);
	      break;
	    }
	  }
	
	break;

	case 3:
	  REP(j, lis.size()) {
	    if (lis[j] == 9) {
	      lis.erase(lis.begin() + j);
	      break;
	    }
	  }
	  FOR(j, i + 1, MAX_N) {
	    if (j % 6 == 0) {
	      lis.emplace_back(j);
	      break;
	    }
	  }
	  break;
	  
	case 5:
	  REP(j, lis.size()) {
	    if (lis[j] == 9) {
	      lis.erase(lis.begin() + j);
	      break;
	    }
	  }
	  FOR(j, i + 1, MAX_N) {
	    if (j % 6 == 4) {
	      lis.emplace_back(j);
	      break;
	    }
	  }
	}
      }
      break;

    default:
      break;
    }
    if (ok) break;
  }

  REP(i, lis.size()) {
    cout << lis[i];
    if (i < lis.size() - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 640
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

X, N = MAP()
p = LIST()

ans = -1
min_num = float("INF")
for i in range(-1, 102):
    if i in p:
        continue
    
    if min_num > abs(X-i):
        min_num = abs(X-i)
        ans = i


print(ans)



Measured memory_bytes: 61752
using System;

class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        string b = Console.ReadLine();
        
        if((int.Parse(a) - b.Replace("R","").Length) > (int.Parse(a) - b.Replace("B","").Length))
        {
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}



Measured memory_bytes: 13140
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto A=vecin<ll>(N);
	vector<ll> S(N+1,0);
	//sort(ALL(A));
	REP(i,N){
		S[i+1] = S[i]+A[i];
	}
	ll minS = 1LL<<60;
	REP(i,N){
		minS = min(minS,abs((S[N]-S[i])-S[i]));
	}

	out(minS);
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
long long n,k;
long long ans=1;
int main(){
    scanf("%lld%lld",&n,&k);
    if(k%2){
    	ans=(n/k)*(n/k)*(n/k);
	}
	else ans=((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k)+(n/k)*(n/k)*(n/k);
	printf("%lld",ans);
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int x=a+b;
    if(x>23) cout << x-24 << endl;
    else cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <cmath>
#include <cstdlib>

using namespace std;

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

  vector<int> x(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  x[N] = X;

  sort(x.begin(), x.end());

  int D = 1000000000;
  vector<int> diff(N);
  for (int i = 0; i < N; i++) {
//     cout << x[i] << endl;
//     diff[i] = abs(X - x[i]);
    diff[i] = x[i+1] - x[i];
    D = min(diff[i], D);
  }
//   cout << D << endl;

//   for (int i = 0; i < N; i++) {
// //     if (abs(X - x[i]) % D != 0) {
//     if ((x[i+1] - x[i]) % D != 0) {
//       D = 1;
//     }
//   }

  while (true) {
    for (int i = 0; i < N; i++) {
      if (diff[i] % D != 0) {
	D -= 1;
	break;
      }
      if (i == N - 1) {
	cout << D << endl;
	return 0;
      }
    }
  }

//   cout << D << endl;

//   while (true) {
//     for (int i = 0; i < N; i++) {
//       if (diff[i] % D != 0) {
// 	if (D == 2) {
// 	  D = 1;
// 	} else if (D % 2 == 0) {
// 	  D %= 2;
// 	} else {
	  
// 	}
// 	cout << D << endl;
//       }
//     }
//   }

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Read();
		char[] s = input[0].ToCharArray();
		input = Read();
		char[] t = input[0].ToCharArray();

		int max = 0;
		for(int i = 0; i <= s.Length - t.Length; i++)
		{
			int buf = 0;
			for(int j = 0; j < t.Length; j++)
			{
				if(s[i+j] == t[j]) buf++;
			}
			max = max < buf ? buf : max;
		}
		Write(t.Length - max);
	}

	static string[] Read()
	{
		return Console.ReadLine().Split(' ');
	}

	static void Write(object o)
	{
		Console.WriteLine(o.ToString());
	}
}



Measured memory_bytes: 25852
#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(){
  string s,t;
  int flag=0;
  stack <int> p;
  cin >>s;
  cin >>t;
  rep(i,s.length()){
    rep(j,t.length()){
      if(j+i>=s.length())break;
      if(s[j+i]==t[j])flag++;
      else if(s[j+i]=='?')flag++;
    }
    if(flag==t.length())p.push(i);
    flag=0;
  }
  if(!p.empty()){
    for(int i = p.top(),j=0;j<t.length();i++,j++){
      s[i]=t[j];
    }
  }
  else {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(i,s.length())if(s[i]=='?')s[i]='a';
  cout << s << endl;
  return 0;
}


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

int main() {
  ll x;
  cin >> x;
  vector<ll> p{0, 1};
  for (ll i = 2; p[p.size() - 1] - p[p.size() - 2] < x; i++) {
    p.push_back(i * i * i * i * i);
  }

  bool r = false;
  ll a, b;
  for (int i = 0; i < p.size(); i++) {
    for (int j = 0; j < p.size(); j++) {
      for (auto s : {-1, 1}) {
        if (p[i] - s * p[j] == x) {
          a = i;
          b = s * j;
        }
      }
    }
  }
  cout << a << ' ' << b << endl;
}


Measured memory_bytes: 3632
// Pratiyush Mishra(pratiush7)
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define repab(i,a,b) for(ll i=a;i<=b;i++)
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define popf pop_front
#define p() cout<<'\n'
#define p0(x) cout<<x<<" "
#define p1(x) cout<<x<<'\n'
#define p2(x,y) cout<<x<<" "<<y<<'\n'
#define p3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define pr1(x) cout<<fixed<<setprecision(15)<<x<<'\n'
#define mod 1000000007
#define mod1 998244353
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define get(n) ll n;cin>>n
#define getvec(v,n) vector<ll> v(n);for(ll i=0;i<n;i++) cin>>v[i];
#define getstr(s) string s;cin>>s
#define all(x) x.begin(),x.end()
#define countBits(x) __builtin_popcount (x)
using namespace std;

ll bfs(ll h,ll w,vector<vector<char>> &v,ll x,ll y){
  vector<vector<bool>> vis(h,vector<bool>(w,false));
  queue<pair<ll,pair<ll,ll>>> q;
  q.push({0,{x,y}});
  ll ans=0;
  ll xa[4]={0,-1,1,0};
  ll ya[4]={-1,0,0,1};
  while(!q.empty()){
    ll curr_x=q.front().second.first;ll curr_y=q.front().second.second;ll dist=q.front().first;
    q.pop();
    vis[curr_x][curr_y]=true;
    rep(i,4){
      x=curr_x+xa[i];
      y=curr_y+ya[i];
      if(x<h&&x>=0&&y<w&&y>=0&&v[x][y]=='.'&&!vis[x][y]){
        vis[x][y]=true;
        ans=max(dist+1,ans);
        q.push({dist+1,{x,y}});
      }
    }
  }
  return ans;
}

int main(){
  fio;
  get(h);get(w);
  vector<vector<char>> v(h,vector<char>(w));
  rep(i,h)
    rep(j,w)
      cin>>v[i][j];
  ll ans=0;
  rep(i,h)
    rep(j,w){
      if(v[i][j]=='.')
        ans=max(bfs(h,w,v,i,j),ans);
    }
  p1(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    string s;
    cin >> n >> s;
    cout << (n < 3200 ? "red" : s);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

struct mypt {
        int x;
        int y;
};

bool on_line(mypt a, mypt b, mypt t) {
        return (t.x-a.x)*(t.y-b.y) - (t.y-a.y)*(t.x-b.x) == 0;
}

pair<ll,ll> egcd(ll a, ll b) {
        ll s0=1,s1=0,s2=a;
        ll t0=0,t1=1,t2=b;
        while (t2 != 0) {
                ll q=s2/t2;
                ll r0=t0,r1=t1,r2=t2;
                t0=s0-q*t0,t1=s1-q*t1,t2=s2-q*t2;
                s0=r0,s1=r1,s2=r2;
        }

        return pair<ll,ll>(s0,s1);
}

ll mod_inv(ll x, ll m) {
        x %= m;
        pair<ll,ll> p = egcd(x,m);
        return (p.first%m+m)%m;
}

const int MAXN=2e2+2+2;
const ll MOD=998244353;
int N;
mypt p[MAXN];

ll twos[MAXN];
ll tot_weight[MAXN];
ll line_weight[MAXN];

int main() {
        cin >> N;
        for (int i=0; i<N; ++i)
                cin >> p[i].x >> p[i].y;

        twos[0] = 1;
        for (int i=1; i<MAXN; i++)
                twos[i] = (2*twos[i-1])%MOD;

        tot_weight[0] = 0;
        tot_weight[1] = 0;
        for (int i=2; i<MAXN; ++i)
                tot_weight[i] = (twos[i]+MOD-i-1)%MOD;


        for (int i=0; i<MAXN; ++i)
                line_weight[i] = (mod_inv(i*(i-1)/2,MOD)*tot_weight[i])%MOD;


        ll subs = tot_weight[N];
        for (int a=0; a<N; ++a) {
                for (int b=a+1; b<N; ++b) {
                        int line_ct=0;
                        for (int c=0; c<N; ++c) {
                                if (on_line(p[a],p[b],p[c])) {
                                        line_ct++;
                                }
                        }

                        subs = (subs + MOD - line_weight[line_ct])%MOD;
                }
        }

        cout << subs << "\n";
}

Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 1e6+7 , INF = 0x3f3f3f3f , MOD = 1e9+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

bool vis[15];

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out.txt","w",stdout);
#endif
    int n,fr = 0,x;
    while(~scanf("%d",&n)){
        fr = 0;
        for(int i = 0 ; i < 15 ; i++)   vis[i] = 0;
        for(int i = 0 ; i < n ; i++)
        {
            scanf("%d",&x);
            if( x >= 3200 )
            {
                fr++;
                continue;
            }
            vis[(int)(x/400)] = 1;
        }
        int ans = 0;
        for(int i = 0 ; i < 8 ; i++)
        {
            if( vis[i] )    ans++;
        }
        printf("%d %d\n",ans == 0 ? 1 : ans,ans+fr);
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int main () {
    int a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    int ans;

    ans = 60 * c + d - (60 * a + b) - k;

    cout << ans  << endl;
}

Measured memory_bytes: 3580
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let a: usize = sc.read();
    let b: usize = sc.read();
    let c: usize = sc.read();
    let x: usize = sc.read();
    let y: usize = sc.read();

    let mut ans = usize::max_value();
    for i in 0..=x {
        let mut j = 0;
        let mut k = (x - i) * 2;
        if y <= k / 2 {
        } else if b > 2 * c {
            k += (y - k / 2) * 2;
        } else {
            j = (y - k / 2);
        }
        ans = cmp::min(ans, a * i + b * j + c * k);
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_vec_1_indexed(&mut self, n: usize) -> Vec<usize> {
        (0..n).map(|_| self.read::<usize>() - 1).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2240
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e6 + 5, mod = 998244353;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, k, ans, fac[N], inv[N];
int ksm(int x, int y) {
	int res = 1;
	for( ; y; x = x * x % mod, y >>= 1) {
		if(y & 1) res = res * x % mod;
	}
	return res;
}
void init(int n) {
	fac[0] = 1;
	for(int i = 1; i <= n; ++ i) fac[i] = fac[i - 1] * i % mod;
	inv[n] = ksm(fac[n], mod - 2);
	for(int i = n - 1; ~i; -- i) inv[i] = inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {
	if(n < m || n < 0 || m < 0) return 0;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
signed main() {
	n = read(); k = read(); init(1e6);
	if(k < n) return puts("0"), 0;
	for(int R = 0, B; R <= k; ++ R) {
		B = k - R;
		if(R < B) continue;
		if(R == B) B --;
		(ans += C(R + B, R) - C(R + B, 2 * R - n + 1)) %= mod;
	}
	printf("%lld\n", (ans % mod + mod) % mod);
	return 0;
}


Measured memory_bytes: 15872
#pow(a,b,mod)
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> for i,j, in product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) for i,j,k in product(z,z,z)))


Measured memory_bytes: 68568
import java.util.Scanner;

public class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] t = new int[N + 1];
        int[] v = new int[N + 1];
        for (int i = 0; i < N; i++) {
            t[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
        }
        for (int i = N - 1; i >= 0; i--) {
            v[i] = Math.min(v[i], v[i + 1] + t[i]);
        }
        double x = 0;
        double vc = 0;
        for (int i = 0; i < N; i++) {
            double vn = v[i + 1];
            if (v[i] < vn) {
                vn = v[i];
            }
            if (vc + t[i] < vn) {
                double vmax = vc + t[i];
                x += vmax * t[i];
                x -= (vmax - vc) * (vmax - vc) / 2;
                vc = vc + t[i];
            } else {
                double vmax = Math.min(v[i], (vc + vn + t[i]) / 2);
                x += vmax * t[i];
                x -= ((vmax - vc) * (vmax - vc) + (vmax - vn) * (vmax - vn)) / 2;
                vc = vn;
            }
        }
        System.out.println(x);
    }
}


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

int main(){
  int n,m;cin>>n>>m;
  vector<int> ax(n,0),ay(n,0),cx(m,0),cy(m,0);
  REP(i,n) cin>>ax.at(i)>>ay.at(i);
  REP(i,m) cin>>cx.at(i)>>cy.at(i);

  REP(i,n){
    int num=0,dist=1e9;
    REP(j,m){
      if(dist>abs(ax.at(i)-cx.at(j))+abs(ay.at(i)-cy.at(j))){
        dist=abs(ax.at(i)-cx.at(j))+abs(ay.at(i)-cy.at(j));
        num=j+1;
      }
    }
    cout<<num<<endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
namespace flow{
    const int V = 205;
    const int E = 4e4 + 4;
    const long long inf = 1e12 + 12;
    vector < int > v[V];
    int a[E];
    int b[E];
    long long c[E];
    int cur;
    int s , t;
    void init(){
    	for(int i = 0 ; i < V ; ++i){
    		v[i].clear();
    	}
        cur = 0;
    }
    void addedge(int x , int y , long long z){
        a[cur] = x;
        b[cur] = y;
        c[cur] = z;
        v[x].emplace_back(cur);
        ++cur;
        a[cur] = y;
        b[cur] = x;
        c[cur] = 0;
        v[y].emplace_back(cur);
        ++cur;
    }
    int dist[V];
    int que[V];
    int qs , qe;
    bool bfs(){
        qs = 0;
        qe = 0;
        for(int i = 0 ; i < V ; ++i){
            dist[i] = V;
        }
        que[qe++] = s;
        dist[s] = 0;
        while(qs < qe){
            int node = que[qs++];
            for(int edge : v[node]){
                if(c[edge]){
                    int next = b[edge];
                    if(dist[next] > dist[node] + 1){
                        dist[next] = dist[node] + 1;
                        que[qe++] = next;
                    }
                }
            }
        }
        return dist[t] < V;
    }
    long long res;
    int visited[V];
    int timer;
    long long dfs(int node , long long val){
        if(node == t){
            return val;
        }
        if(visited[node] == timer){
            return 0;
        }
        visited[node] = timer;
        long long tot = 0;
        for(int edge : v[node]){
            if(c[edge]){
                int next = b[edge];
                if(dist[next] == dist[node] + 1){
                    long long tmp = dfs(next , min(val - tot , c[edge]));
                    tmp = min(tmp , val - tot);
                    if(tmp){
                        c[edge] -= tmp;
                        c[edge ^ 1] += tmp;
                        tot += tmp;
                    }
                    if(tot == val){
                        break;
                    }
                }
            }
        }
        return tot;
    }
    void getflow(){
        res = 0;
        while(bfs()){
            ++timer;
            res += dfs(s , inf);
        }
    }
}
const int N = 105;
int n;
int arr[N];
long long sum;
long long res;
int main(){
	scanf("%d" , &n);
	sum = 0;
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
		sum += arr[i];
		arr[i] *= -1;
	}
	flow :: init();
	flow :: s = 0;
	flow :: t = n + 1;
	res = 0;
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i] > 0){
			flow :: addedge(0 , i , arr[i]);
			res += arr[i];
		}
		else{
			flow :: addedge(i , n + 1 , -arr[i]);
		}
	}
	for(int i = 1 ; i <= n ; ++i){
		for(int j = i + i ; j <= n ; j += i){
			flow :: addedge(i , j , flow :: inf);
		}
	}
	flow :: getflow();
	res -= flow :: res;
	sum += res;
	printf("%lld\n" , sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n,k;cin>>n>>k;
    ll m=sqrt(n);
    vector<vector<ll> >dp(k+1,vector<ll>(2*m+1));
    vector<ll>a(2*m+1);
    ll sum=0;
    REP(i,1,m+1){
        a[i]=1;
        sum+=a[i];
        //cout<<i<<' '<<a[i]<<endl;
    }
    REP(i,m+1,2*m+1){
        a[i]=n/(2*m+1-i)-sum;
        sum+=a[i];
        //cout<<2*m+1-i<<' '<<a[i]<<endl;
    }
    rep(i,2*m+1){
        dp[0][i]=1;
    }
    rep(i,k){
        if(i){
            for(int j=2*m-1;j>0;j--){
                dp[i][j]=(dp[i][j]+dp[i][j+1])%inf;
            }
        }
        REP(j,1,2*m+1){
            dp[i+1][2*m+1-j]=(dp[i+1][2*m+1-j]+dp[i][j]*a[j]%inf)%inf;
        }
    }
    ll ans=0;
    REP(i,1,2*m+1){
        ans=(ans+dp[k-1][i]*a[i]%inf)%inf;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 50832