akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

vector<vector<P>> to;

const int MAX_N = 101000;
const ll INF = 1LL << 50;

ll dist[MAX_N];

void Dijkstra(int v){
  //vが始点
  dist[v] = 0;
  priority_queue<P,vector<P>,greater<P>> Q;
  // {距離、ノード}の組みを保持
  Q.push({0,v});

  while(!Q.empty()){
    P p = Q.top();  Q.pop();
    ll load = p.first; int pos = p.second;
    
    for(auto next : to[pos]){ 
      int u = next.first; ll cost = next.second;
      if(dist[u] <= load+cost){ continue;} 
      else{ dist[u] = load+cost;
           
           Q.push({dist[u],u});
          }
    } // for-とじ
  }// whileとじ
  
  return ;
}
    

int main(){ 
  int N,M; scanf("%d %d", &N, &M);
  to.resize(N);
  
  for(int i = 0; i < N; i++){ dist[i] = INF;}
  
  for(int i = 0; i < M; i++){
    int L,R; ll C; scanf("%d %d %lld", &L, &R, &C); L--; R--;
    to[L].push_back({R,C});
  }
  
  for(int i = 0; i < N-1; i++){
    to[i+1].push_back({i,0});
  }
  
  //隣接リストto上で、0からN-1まで動くのにかかる時間を見つける
  
  Dijkstra(0);
  
  ll res = dist[N-1];
  if( res == INF){ res = -1;}
  
  printf("%lld\n", res);
  
  return 0;
}

Measured memory_bytes: 9340
N = int(input())
seq = list(map(int, input().split()))
best = float('inf')
if 1 in seq:
    best = N - 1
else:
    print(-1)
    quit()

cur = 1
todel = 0
for i in range(N):
    if seq[i] == cur:
        cur += 1
    else:
        todel += 1
best = min(best, todel)

print(best)


Measured memory_bytes: 77516
import java.util.Scanner;

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

        int N = Integer.parseInt(scanner.nextLine());
        String[] a = scanner.nextLine().split(" ");
        int[] array = new int[N];

        for (int i = 0; i < N; ++i) {
            array[i] = Integer.parseInt(a[i]);
        }

        long count = 1;
        int work = array[0];
        int start = 0;
        int current = 1;

        while (current < N) {
            if ((work & array[current]) == 0) {
                work ^= array[current];
                ++current;
                count += current - start;
            } else {
                work ^= array[start];
                ++start;
            }
        }

         System.out.println(count);
    }
}

Measured memory_bytes: 54032
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	LL n,d;
	cin>>n>>d;
	LL tmp;
	d=d*d;
	LL ans =0;
	rep(i,n){
		LL x,y;
		cin>>x>>y;
		tmp = x*x+y*y;
		if(tmp<=d)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
string s,t;
int dp[3001][3001];
int main(){
  cin >> s >> t;
  memset(dp,0,sizeof(dp));
  for(int i=0;i<s.size();i++){
    for(int j=0;j<t.size();j++){
      if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
      else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    }
  }
  int a=s.size(),b=t.size();
  string res="";
  while(a>0&&b>0){
    if(dp[a-1][b]==dp[a][b]) a--;
    else if(dp[a][b-1]==dp[a][b]) b--;
    else {
      a--;b--;
      res=s[a]+res;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 35456
import math

k, q = map(int, input().split())
_d = list(map(int, input().split()))
for _ in range(q):
    n, x, m = map(int, input().split())
    d = map(lambda xx: xx % m, _d)
    ans = 0
    s = 0
    for i, di in enumerate(d):
        if di == 0:
            ans += math.ceil((n - i - 1) / k)
        else:
            s += di * math.ceil((n - i - 1) / k)
    ans += (s + x) // m - x // m
    print(n - 1 - ans)


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

int calc(int n, int a, int s) {
  if(s<0) return 0;
  if(n==0) {
    if(s==0) return 1;
    else return 0;
  }
  int cnt = 0;
  for(int i=a; i<10; i++) {
    cnt += calc(n-1, i+1, s-i);
  }
  return cnt;
}

int main() {
  int n, s;
  while(cin >> n >> s && (n || s)) {
    cout << calc(n,0,s) << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include<stdio.h>
int i;
char r[7][4]={"AAA","AA","A","B","C","D","E"};
float s,t,h[7]={35.50,37.50,40,43,50,55,70},m[7]={71,77,83,89,105,116,148};
int main()
{
	for(;~scanf("%f%f",&s,&t);)
	{
		for(i=0;i<7;i++)
			if(s-h[i]<0&&t-m[i]<0)
			{
				puts(r[i]);
				break;
			}
		if(i==7)
			puts("NA");
	}
	return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int k[31];
  int a[30][30];
  for(int i = 0; i < n; i++){
    cin >> k[i];
    for(int j = 0; j < k[i]; j++){
      cin >> a[i][j];
    }
  }
  int b[31]{0};
  for(int i = 0; i < n; i++){
    for(int j = 0; j < k[i]; j++){
      b[a[i][j]]++;
    }
  }
  int ans = 0;
  for(int i = 0; i <= m; i++){
    if(b[i] == n){
      ans++;
    }
  }
  cout << ans << endl;
}

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

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        try {
            String word = br.readLine();
            int count = 0;
            String line = "";
            
            while(true){
                line = br.readLine();
                if("END_OF_TEXT".equals(line)){
                    break;
                }
                String[] arr = line.split("\\s");
                for(int i=0; i<arr.length; i++){
                    if(arr[i].toLowerCase().equals(word)){
                        count++;
                    }
                }
            }
            
            System.out.println(String.valueOf(count));
            
            
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
 
int main() {
 
    int n;
    cin >> n;
    int n100 = n % 100;
    if (n / 100 == 7 || n100 / 10 == 7 || n % 10 == 7) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
 
    return 0;
 
}

Measured memory_bytes: 3636
n = int(input())
L = [list(map(int, input().split())) for _ in range(n)]
L.sort(key=lambda x:x[1])
time = 0
for i in range(n):
    time += L[i][0]
    if time > L[i][1]:
        print('No')
        break
else:
    print('Yes')


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

struct toup {
	char operator()(char c) { return toupper(c); }
};

int main() {
	string str;
	getline(cin, str);
	transform(str.begin(), str.end(), str.begin(), toup());
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    if(a1+a2+a3>=22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)

const int INF = 1 << 30;
int cnt = 0;

using namespace std;

void Merge(int x[],int left, int mid, int right){
    //define range
    int n1 = mid - left;
    int n2 = right - mid;

    //working array
    int l[n1+10],r[n2+10];

    //init
    rep(i,n1) l[i] = x[left + i]; 
    rep(i,n2) r[i] = x[mid + i];

    //番兵
    l[n1] = r[n2] = INF;

    int il = 0;
    int ir = 0;
    

    for(int i = left; i < right ; i++){
        if(l[il] <= r[ir]){
            x[i] = l[il];
            il++;
        }else{
            x[i] = r[ir];
            ir++;
        }
        cnt++;
    }
}

void MergeSort(int x[],int left,int right){
    if(left+1 < right){
        int mid = (left + right)/2;

        MergeSort(x,left,mid);
        MergeSort(x,mid,right);
        Merge(x,left,mid,right);
    }
}

int main(){
    int n; cin >> n;
    int t[n];
    rep(i,n) cin >> t[i];

    
    MergeSort(t,0,n);
    
    rep(i,n) cout << t[i] << (i == n-1 ? '\n':' ');
    cout << cnt << endl;
    
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  vector<ll> a(3);
  cin >> a[0] >> a[1]>>a[2];
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  sort(ALL(a));
  if(a[0]%2==a[1]%2&&a[1]%2==a[2]%2){
    cout<<a[2]-(a[0]+a[1])/2<<endl;
  }
  else{
    if(a[0]%2==a[1]%2){
      a[0]++;a[1]++;
    }
    else if(a[0]%2==a[2]%2){
      a[0]++;a[2]++;
    }
    else{
      a[1]++;a[2]++;
    }
    cout<<a[2]-(a[0]+a[1])/2+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  
  vector <int> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];
  
  vector <int> dp(N);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; ++i) {
    int mini = INT_MAX;
    for (int k = 1; k <= K && i - k >= 0; ++k) {
      mini = min(mini, 
                 dp[i - k] + abs(h[i] - h[i - k]));
    }
    dp[i] = mini;
  }
  cout << *dp.rbegin() << endl;
  return 0;
}

Measured memory_bytes: 3644
from collections import deque

def main():
    S = input()
    Q = int(input())
    q = deque(S)
    cnt = 0
    for _ in range(Q):
        query = list(input().split())
        if query[0] == '1':
            cnt += 1
        else:
            if query[1] == '1':
                if cnt % 2 == 0:
                    q.appendleft(query[2])
                else:
                    q.append(query[2])
            else:
                if cnt % 2 == 1:
                    q.appendleft(query[2])
                else:
                    q.append(query[2])

    if cnt % 2 == 0:
        print(*q, sep ="")
    else:
        q.reverse()
        print(*q, sep ="")







if __name__ == "__main__":
    main()

Measured memory_bytes: 81456
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n);

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

	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 4032
N = int(input())
A = [0] * N
B = list(map(int, input().split()))

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

print(sum(A))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x,y;
    cin >> x >> y;
    int ans = 0;
    while(x <= y) {
        ans++;
        x *= 2;
    }
    cout << ans << endl;
}


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

int main(){
  string N;cin>>N;
  int t = 0;
  rep(i,N.size()){
    t += (N[i]-'0');
    t %= 9;
  }
  if(t==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3756
from functools import reduce
import fractions


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def problem():
    N = int(input())
    A = list(map(int, input().split()))

    print(algorithm(N, A))


def algorithm(N, A):
    if N == 0:
        return 0
    if N == 1:
        return A[0]
    if N == 2:
        return max(A[0],A[1])

    L_i = 0
    R_i = [0] * N
    R_i[N - 1] = A[N - 1]
    R_i[N-2] = fractions.gcd(A[N-1], A[N-2])
    
    for i in range(3,N):
        R_i[N - i] = fractions.gcd(R_i[N - i + 1], A[N - i])

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = gcd_list(A[:N-1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD

problem()

Measured memory_bytes: 16120
import sys

n = int(input())
s = [int(input()) for i in range(n)]
s.sort()

ans = sum(s)

for i in s:
	if(ans%10==0):
		if(i%10!=0):
			print(ans-i)
			sys.exit()
	else:
		print(ans)
		sys.exit()

print(0)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e20;

signed main(){
    int N;cin>>N;
    int even=0;
    REP(i,N){
        int a;cin>>a;
        if(a%2==0)even++;
    }
    int ans=pow(3,N)-pow(2,even);
    cout<<ans<<endl;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int n;  cin >> n;
    
    ll H[n];
    rep(i,n)    cin >> H[i];

    if(n==1){
        cout << 0 << endl;
        return 0;
    }

    int ans(0),sum(0);
    for(int i=1;i<n;i++){
        if(H[i]<=H[i-1]){
            sum++;
        }else{
            ans = max(ans,sum);
            sum = 0;
        }
    }

    ans = max(ans,sum);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(si,h)rep(sj,w) {
    if (s[si][sj] == '#') continue;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x) {
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(P(i,j)); // .emplace(i,j)
    };
    update(si,sj,0);
    while (!q.empty()) {
      int i = q.front().first;
      int j = q.front().second; q.pop();
      rep(dir,4) {
        int ni = i+di[dir], nj = j+dj[dir];
        if (ni<0||ni>=h||nj<0||nj>=w) continue;
        if (s[ni][nj] == '#') continue;
        update(ni, nj, dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w) {
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
t = [int(input()) for _ in range(N)]

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

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

from functools import reduce

r = reduce(lcm, t)

print(r)

Measured memory_bytes: 3700
let N =
    stdin.ReadLine()
    |> int
let A =
    stdin.ReadLine().Split()
    |> Array.map int

let dists =
    A
    |> Array.indexed
    |> Array.groupBy (fun (_,v) -> v)
    |> Array.map (fun (k,vs) -> (k,vs.Length))
let distMap =
    dists
    |> Map.ofArray
let sum =
    dists
    |> Array.fold (fun state (_,v) -> state+int64(v)*int64(v)) 0L

A
|> Array.iter (fun v ->
    let l = int64(distMap.[v])
    let ans = (sum - l*l + (l-1L)*(l-1L) + 1L - int64(N))/2L
    stdout.WriteLine ans)

Measured memory_bytes: 106748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    int len = s.size();
    int k = 1;
    rep(i,len-1){
        k *= 2;
    }
    ll ans = 0;
    rep(i,k){
        int x = i;
        ll tmp = s[0]-'0';
        rep(j,len-1){
            int r = x % 2;
            x /= 2;
            if(r == 0){
                tmp *= 10;
                tmp += (s[j + 1]-'0');
            }else{
                ans += tmp;
                tmp = s[j + 1]-'0';
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[6];
    rep(i,4){
        cin >> A[i];
    }
    // sort(A,A+3);
    cout << (A[0]<A[1] ? A[0]*A[2] :A[1]*A[2]+(A[0]-A[1])*A[3] ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
 
using namespace std;
 
typedef pair<int, int> P;
typedef long long lli;
 
P factor();
P term();
P exp();
 
bool f;
lli pos;
string data;
 
P factor(){
  if(f) return P(0, 0);
  P res;
  if(data[pos] == '('){
    pos++;
    res = exp();
    pos++;
  }else{
    bool comp = false;
    lli i;
    for(i=pos;i<data.size();i++){
      if(data[i] == 'i'){
        comp = true;
        break;
      }
      if(data[i] == '+' || data[i] == '-' || data[i] == '*' || data[i] == ')') break;
    }
    if(comp){
      res.first = 0;
      res.second = 1;
      i++;
    }else{
      res.first = atoi(data.substr(pos, i-pos).c_str());
      res.second = 0;
    }
    pos = i;
  }
  if(res.first < -10000 || 10000 < res.first) f = true;
  if(res.second < -10000 || 10000 < res.second) f = true;
  return res;
}
 
P term(){
  if(f) return P(0, 0);
  P res = factor();
  while(data[pos] == '*'){
    char op = data[pos++];
    if(op == '*'){
      P tmp = factor();
      lli a = res.first * tmp.first - res.second * tmp.second;
      lli b = res.first * tmp.second + res.second * tmp.first;
      res.first = a;
      res.second = b;
    }
    if(res.first < -10000 || 10000 < res.first) f = true;
    if(res.second < -10000 || 10000 < res.second) f = true;
    if(f) return res;
  }
  return res;
}
 
P exp(){
  if(f) return P(0, 0);
  P res = term();
  while(data[pos] == '+' || data[pos] == '-'){
    char op = data[pos++];
    if(op == '+'){
      P tmp = term();
      res.first += tmp.first;
      res.second += tmp.second;
    }
    if(op == '-'){
      P tmp = term();
      res.first -= tmp.first;
      res.second -= tmp.second;
    }
    if(res.first < -10000 || 10000 < res.first) f = true;
    if(res.second < -10000 || 10000 < res.second) f = true;
    if(f) return res;
  }
  return res;
}
 
main(){
  while(cin >> data){
    pos = 0;
    f = false;
    P ans = exp();
    if(f) cout << "overflow" << endl;
    else{
      if(ans.first == 0 && ans.second == 0) cout << 0 << endl;
      else{
        if(ans.first != 0) cout << ans.first;
        if(ans.second == 0) cout << endl;
        else if(ans.second > 0 && ans.first != 0) cout << "+" << ans.second << "i" << endl;
        else cout << ans.second << "i" << endl;
      }
    }
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    string s;
    int i;
    int hug = 0;
    int mid;

    cin >> s;

    if (s.size() % 2 == 0)
    {
        mid = s.size() / 2;

        rep(i, 0, s.size() / 2)
        {
            if (s[mid + i] != s[mid - i - 1])
            {
                hug++;
            }
        }
    }
    else
    {
        mid = s.size() / 2;

        rep(i, 0, s.size() / 2 + 1)
        {
            if (s[mid + i] != s[mid - i])
            {
                hug++;
            }
        }
    }

    cout << hug << endl;
}

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

using namespace std;
int yaku(int);

int main()
{
  int a,c=0;
  cin>>a;
  for(int i=1;i<=a;i+=2) c+=yaku(i); 
  cout<<c<<endl;
}

int yaku(int a)
{
  int c=0;
  for(int i=1;i<=a;i+=2){
    if(a%i==0) c++;
  }
  if(c==8) return 1;
  else return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#include<deque>
#include<set>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
vector<vector<int> > road;
int main(){
    int N;
    cin >> N;
    road.resize(N);
    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    vector<int> line(N);
    vector<int> ans(N, -1);
    REP(i, N){
        cin >> line[i];
    }
    sort(ALL(line));
    int place = 0;
    REP(i, N){
        if(road[place].size() > road[i].size()){
            place = i;
        }
    }
    priority_queue<PII, vector<PII>, greater<PII> > que;
    que.push(PII(road[place].size(), place));
    while(!que.empty()){
        PII top = que.top();
        que.pop();
        ans[top.second] = line.back();
        line.pop_back();
        REP(i, road[top.second].size()){
            if(ans[road[top.second][i]] != -1)continue;
            que.push(PII(road[road[top.second][i]].size(), road[top.second][i]));
        }
    }
    LL sum = 0;
    REP(i, N){
        REP(j, road[i].size()){
            sum += min(ans[i], ans[road[i][j]]);
        }
    }
    cout << sum/2 << endl;
    REP(i, N){
        cout << ans[i] << (i+1==N?"\n":" ");
    }
    return 0;
}


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

using namespace std;

int n;

void solve(){
    int i,j,k;
    string str;
    cin >> n;
    vector<int> a(n),b(n),v(n);
    for(i = 0;i < n;i++) cin >> a[i];
    for(i = 0;i < n;i++) cin >> b[i];
    long long ans = -1;
    for(i = 0;i < (1<<n);i++){
        int sa = 0,sb = 0;
        for(j = 0;j < n;j++){
            if(i&(1<<j)){
                v[j] = a[j];
                sa++;
            }
            else{
                v[j] = b[j];
                sb++;
            }
        }
        if(sb%2) continue;
        sort(v.begin(),v.end());
        vector<int> used(n,-1);
        int ma = 0;
        for(j = 0;j < n;j++){
            int f = 0;
            if(i&(1<<j)){
                for(k = j%2;k < n;k+=2){
                    if(v[k] == a[j] && used[k] == -1){
                        used[k] = j;
                        f = 1;
                        break;
                    }
                }
            }
            else{
                for(k = (j+1)%2;k < n;k+=2){
                    if(v[k] == b[j] && used[k] == -1){
                        used[k] = j;
                        f = 1;
                        break;
                    }
                }
            }
            if(f == 0){
                ma = -1;
                break;
            }
        }
        if(ma == -1) continue;
        for(j = 0;j < n;j++){
            for(k = j+1;k < n;k++){
                if(used[j] > used[k]) ma++;
            }
        }
        if(ans == -1 || ma < ans){
            ans = ma;
        }
    }
    cout << ans << endl;
}

int main(){
    solve();
}


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


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

    vector<int> vec(300);
    rep(i,n){
        int a =0;
        cin >> a;
        vec.at(a)++;

    }
    int ans = 200;

    

    for(int i =x ;i>=0; i--){
        if(vec.at(i) == 0 ){
            ans = i;
            break;
        }
    }
    for(int i = x ; i < 210; i++){
        if(vec.at(i)==0 && ans == 200 ){
            ans = i;
            break;
        }
        else if( vec.at(i) == 0 && ans != 200 && x-ans > i-x){
            ans = i;
            break;
        }

    }
        


 cout << ans << endl;
}




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


class UnionFind {
public:
    // parent node index if not root index
    // minus size of the tree if root index
    std::vector<int> data;

    UnionFind( int n ) {
        data.resize( n, -1 );
    }

    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }

    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }
};


void solve() {
    ll N, K, L;
    cin >> N >> K >> L;
    UnionFind uw(N), ut(N);
    int a,b;
    for ( int i = 0; i < K; i++ ) {
        cin >> a >> b;
        a--, b--;
        uw.unite(a, b);
    }
    for ( int i = 0; i < L; i++ ) {
        cin >> a >> b;
        a--, b--;
        ut.unite(a, b);
    }
    map<pair<int,int>, int> num;
    for ( int i = 0; i < N; i++ ) {
        num[make_pair(uw.find(i), ut.find(i))]++;
    }
    for ( int i = 0; i < N; i++ ) {
        cout << num[make_pair(uw.find(i), ut.find(i))] << " ";
    }
    cout << "\n";
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 13568
N = int(input())
edge = [[0] for _ in range(N)]
for i in range(N):
    A = list(map(int, input().split()))
    for i,a in enumerate(A):
        A[i] -= 1
    edge[A[0]] = sorted(A[2:])
ans = [[0,0] for _ in range(N)]
import sys
sys.setrecursionlimit(10**8)

def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now

visited = [False]*N

now = 0
for i in range(N):
    if visited[i]==False:
        visited[i]=True
        now += 1
        ans[i][0] = now
        now = dfs(i,now)
for i in range(N):
    ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1])
print(*ans,sep='\n')


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll n;cin>>n;
    vector<ll> sum(100000,0);
    ll idx;
    for(ll i=1;i<=10000;i++){
        sum[i] = sum[i-1]+i;
        if(sum[i]>=n){
            idx=i;
            break;
        }
    }
    for(int i=1;i<=idx;i++){
        if(i==sum[idx]-n) continue;
        cout<<i<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	VI l(n,0), r(n,0);
	REP(i,n){
		if(i-a[i]>=0)
			l[i-a[i]]++;
		if(i+a[i]<n)
			r[i+a[i]]++;
	}
	ll ans=0;
	REP(i,n)
		ans+=l[i]*r[i];
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  double A, B, P, Q, R;
  cin >> A >> B >> P >> Q >> R;

  auto check = [&](double v) {
    double X = (v - A) * Q;
    double Y = B * P - R * (v - B);
    return X < Y;
  };
  double low = B, high = 1e9;
  for(int i = 0; i < 100; i++) {
    double mid = (low + high) / 2;
    if(check(mid)) low = mid;
    else high = mid;
  }
  cout << low << endl;
}


Measured memory_bytes: 3284
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


X,Y = map(int,input().split())
a = 2*Y-X
b = 2*X-Y
if (a//3)*3!=a or (b//3)*3!=b or a<0 or b<0:
    ans = 0
else:
    A,B = a//3,b//3
    mod = 10**9+7
    N = A+B
    g1 = [1, 1] 
    g2 = [1, 1] 
    inverse = [0, 1] 

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    ans = cmb(A+B,A,mod)
print(ans)

Measured memory_bytes: 82240
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int q;
    cin >> q;
    vector<int> A;
    rep(i, q){
        int que1, que2;
        cin >> que1;
        if(que1 == 0){
            cin >> que2;
           A.push_back(que2);
        }
        if(que1 == 1){
            cin >> que2;
            cout << A[que2] << endl;
        }
        if(que1 == 2){
            A.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;
using VP = vector<P>;
using VVI = vector<VI>;

int b[50][50];
int h, w;

bool wh(int i, int j) {
    if (i >= 0 && i < h && j >= 0 && j < w) {
        if (b[i][j] == 0) {
            return true;
        } else {
            return false;
        }
    }
    return true;
}

bool one(int i, int j) {
    if (b[i][j] == 0) return false;
    return wh(i,j-1) && wh(i,j+1) && wh(i-1,j) && wh(i+1,j);
}

int main() {
    cin >> h >> w;
    
    REP(i,h) {
        REP(j,w) {
            char c;
            cin >> c;
            if (c == '#') {
                b[i][j] = 1;
            }
        }
    }
    
    
    REP(i,50) {
        REP(j,50) {
            if (b[i][j]) {
                if (one(i,j)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int x;
	cin>>x;
	cout<<(x/500)*1000+((x%500)/5)*5<<ln;
}

signed main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3588
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int kazu = int.Parse(ReadLine());
        long ans = 1;
        for(int i=1;i<=kazu;i++){
            ans*=i;
            if(ans>1000000007){
                ans%=1000000007;
            }
        }
        WriteLine(ans);
    }
}


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

int main() {
    long long int a, b, n, ans = 0;
    cin >> a >> b >> n;
    if(a == 1 || b == 1) { 
        ans = 0;
    } else {
        if(n >= b) {
            ans = a*(b-1)/b;
        } else {
            ans = a*n/b;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct monster
{
	long long x,h;
}a[500005];
bool cmp(monster a,monster b)
{
	return a.x<b.x;
}
int main()
{
	long long n,d,hurt,ans=0,l=0,r=0,now=0;
	scanf("%lld%lld%lld",&n,&d,&hurt);
	for(long long i=0;i<n;i++) scanf("%lld%lld",&a[i].x,&a[i].h);
	sort(a,a+n,cmp);
	while(r<n)
	{
		ans+=(a[r].h+hurt-1)/hurt;
		now+=(a[r].h+hurt-1)/hurt;
		r++;
		while(a[r].x>2*d+a[l].x&&l<r)
		{
			now-=(a[l].h+hurt-1)/hurt;
			l++;
		}
		a[r].h-=now*hurt;
		if(a[r].h<0) a[r].h=0;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4352
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//ll z[1000001]={0};

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll a,b;
    cin>>a>>b;
    ll l=(a*b)/gcd(a,b);
    cout<<l<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi A(N);
	REP(i, N)cin >> A[i];
	so(A);
	int pre[2] = { A[0], A[0] };
	ll ans = 0;
	ll ans1 = 0;
	int left = 1;
	int right = N - 1;
	REP(k, 2) {
		while (left <= right) {
			int cnt = 0;
			while (cnt < 2 && left <= right) {
				ans1 += abs(pre[cnt] - A[right]);
				pre[cnt] = A[right];
				right--;
				cnt++;
			}
			cnt = 0;
			while (cnt < 2 && left <= right) {
				ans1 += abs(pre[cnt] - A[left]);
				pre[cnt] = A[left];
				left++;
				cnt++;
			}
			if (left > right)break;
		}
		if (k == 1)break;
		pre[0] = A[N - 1];
		pre[1] = A[N - 1];
		ans = ans1;
		ans1 = 0;
		left = 1;
		right = N - 1;
		rev(A);
	}

	cout << max(ans, ans1) << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 888
import sys


def isRectangle(s1, s2, d):
    if s1*s1 + s2*s2 == d*d:
        return True
    else:
        return False

def isLozenge(s1, s2):
    if s1 == s2:
        return True
    else:
        return False

rcnt = 0
lcnt = 0
L = sys.stdin.readlines()
for dataset in L:
    side1, side2, diagonal = map(int, dataset.split(','))
    if isRectangle(side1, side2, diagonal):
        rcnt += 1
    if isLozenge(side1, side2):
        lcnt += 1
print(rcnt)
print(lcnt)

Measured memory_bytes: 7624
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define UMLL unordered_map<ll,ll>
#define UMII unordered_map<int,int>
#define VI vector<int>
#define VL vector<ll>
#define S second
#define F first
#define PB push_back


int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    
    string s,t;
    cin>>s>>t;
    ll n=s.size(),m=t.size(),i;
    VL v[26];
    for(i=0;i<n;i++) {
        v[s[i]-'a'].PB(i);
    }
    ll cnt=0,last=-1;
    if(v[t[0]-'a'].size()==0) {
        cout << "-1";
        return 0;
    } else {
        last=v[t[0]-'a'][0];
    }
    bool flag=true;

    for(i=1;i<m;i++)
    {
        ll pos=t[i]-'a';
        if(v[pos].size()==0) {
            flag=false;
            break;
        }
        ll ind=lower_bound(v[pos].begin(),v[pos].end(),last+1)-v[pos].begin();
        if(ind==v[pos].size()) {
            cnt++;
            last=v[pos][0];
        } else {
            last=v[pos][ind];
        }
    }
    if(flag==false) {
        cout << "-1";
        return 0;
    } else {
        cout << n*cnt+last+1;
    }


    
    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include "string"

using namespace std;
int N,W,w[100],v[100];
bool point[301][301],link[301][301];
string S;
int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

int main(){
	cin >>S;
	if(S.size()>=4){
	if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	}
	else{
		cout<<"No"<<endl;
	}

	
	return 0;
}


Measured memory_bytes: 256
PROGRAM takoFes
      IMPLICIT NONE
      INTEGER :: N
      INTEGER,ALLOCATABLE :: d(:)
      INTEGER(8) :: ans
      
      INTEGER :: a,piyo
      READ*,N
      ALLOCATE( d(N) )
      read*,d(:)
      
      ans = 0
      DO a = 1,N-1
        piyo = sum(d(a+1:N))
        ans = ans + d(a)*piyo
      END DO
      
      print*,ans
      
      
      END PROGRAM

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
	if(n<m){
		for(int i=1;i<=m;i++){
			cout<<n;
		}
	}else{
		for(int i=1;i<=n;i++){
			cout<<m;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<functional>
#include<cstring>

using namespace std;

#define MOD 1000000007

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

	int n;
	long long dp[2001] = { 0, };

	scanf("%d", &n);

	if (n < 3)
	{
		printf("0\n");

		return 0;
	}

	dp[0] = 1;

	for (int i = 3; i <= n; i++)
	{
		for (int j = 0; j <= i - 3; j++)
		{
			dp[i] = (dp[i] + dp[j]) % MOD;
		}
	}

	printf("%lld\n", dp[n]);

	return 0;
}

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

int main() {
  char s;
  cin >> s;
  if (s=='a' || s=='i' || s=='u' || s=='e' || s=='o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3624
import java.util.*;

import javax.swing.plaf.synth.SynthSplitPaneUI;

import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long X = sc.nextLong();
		long Y = sc.nextLong();
		//boolean boo = false;
		if(A+B>C*2) {
			long min = Math.min(X, Y);
			long sum =C*2*min;
			if(min == X) {
				long div = Y-X;
				if(C*2*div<B*div) {
					sum+=C*2*div;
				}else {
					sum+=B*div;
				}
			}else if(min == Y) {
				long div = X-Y;
				if(C*2*div<A*div) {
					sum+=C*2*div;
				}else {
					sum+=A*div;
				}
			}
			System.out.println(sum);
		}else {
			System.out.println(A*X+B*Y);
		}
		
		//System.out.println();
		sc.close();
	}

}


Measured memory_bytes: 23380