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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge
{
	int s, t, cost;
	Edge(int s, int t, int cost) :s(s), t(t), cost(cost) {}
	Edge() :Edge(-1, -1, -1) {}
};

int D[2][310][310];

int V, E, L, Q;

void shortest_path(int d[310][310])
{
	rep(k, 0, V)rep(i, 0, V)rep(j, 0, V)chmin(d[i][j], d[i][k] + d[k][j]);
}

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

	cin >> V >> E >> L;

	rep(i, 0, V)rep(j, 0, V)
	{
		if (i != j)
		{
			D[0][i][j] = INF;
			D[1][i][j] = INF;
		}
	}

	int A, B, C;
	rep(i, 0, E)
	{
		cin >> A >> B >> C;
		A--, B--;
		D[0][A][B] = C;
		D[0][B][A] = C;
	}

	shortest_path(D[0]);

	rep(i, 0, V)rep(j, 0, V)
	{
		if (D[0][i][j] <= L)
		{
			D[1][i][j] = 1;
		}
	}

	shortest_path(D[1]);

	cin >> Q;
	int s, t;
	rep(i, 0, Q)
	{
		cin >> s >> t;
		s--, t--;
		if (D[1][s][t] == INF)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << D[1][s][t]-1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)

int main(){
    int X;
    cin >> X;
    int happy = 0;
    happy += 1000*(X/500);
    X -= 500*(X/500);
    happy += 5*(X/5);
    cout << happy << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
//コンパイラオプション？お試し中
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 19;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[4];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), M = getint(), L = getint();
	int C[300][300];
	rep(j, N) rep(i, j) C[i][j] = 1e9 + 1;
	rep(i, M) {
		int a = getint(), b = getint(), c = getint();
		C[--a][--b] = c;
		C[b][a] = c;
	}

	rep(k, N) {
		rep(j, k) {
			rep(i, j) {
				chmin(C[i][j], C[i][k] + C[j][k]);
			}
		}
		for (int j = k + 1; j < N; j++) {
			rep(i, k) {
				chmin(C[i][j], C[i][k] + C[k][j]);
			}
			for (int i = k + 1; i < j; i++) {
				chmin(C[i][j], C[k][i] + C[k][j]);
			}
		}
	}

	rep(j, N) rep(i, j) {
		C[i][j] = (C[i][j] <= L) ? 1 : 1e9;
	}

	rep(k, N) {
		rep(j, k) {
			rep(i, j) {
				chmin(C[i][j], C[i][k] + C[j][k]);
			}
		}
		for (int j = k + 1; j < N; j++) {
			rep(i, k) {
				chmin(C[i][j], C[i][k] + C[k][j]);
			}
			for (int i = k + 1; i < j; i++) {
				chmin(C[i][j], C[k][i] + C[k][j]);
			}
		}
	}

	int Q = getint();
	rep(i, Q) {
		int s = getint(), t = getint();
		if (--s > --t) swap(s, t);
		if (C[s][t] == 1) {
			*di++ = '0';
			*di++ = '\n';
		}
		else if (C[s][t] < 1e9) putint(C[s][t] - 1);
		else {
			*di++ = '-';
			*di++ = '1';
			*di++ = '\n';
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main(){
    int K,N;
    cin >> N >> K;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    int sum=0;
    for(int j=0;j<K;j++){
        sum += vec.at(j);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3628
//https://atcoder.jp/contests/dp/tasks/dp_h

#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
ll modd= 1e9+7;
const int mxN=100005;
vector<string>ar;

ll rfun(int n, int m){
    ll ans=0;
    ll dp[n+1][m+1];
    memset(dp, 0 ,sizeof dp);
    fo(i, n){
        fo(j, m){
            if(i==0 and j==0){dp[i][j]=1;continue;}
            if(ar[i][j]=='#'){dp[i][j]=0;continue;}
            if(i==0){dp[i][j]=dp[i][j-1];continue;}
            if(j==0){dp[i][j]=dp[i-1][j];continue;}
            dp[i][j]=(dp[i][j-1]+ dp[i-1][j])%modd;
        }
    }
    //fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<endl;}
    return dp[n-1][m-1];
}

int main(){
    fast;
    int n,m;
    cin>>n>>m;
    fo(i, n){
        string s;cin>>s;
        ar.push_back(s);
    }
    cout<<rfun(n, m);
}


Measured memory_bytes: 9216
#!/usr/bin/env ruby
require 'prime'

n = gets.chomp.split(" ").map(&:to_i).first

factor = n.prime_division
ans = 0

factor.each do |p, i|
  1.upto(i/2 + 1) do |x|
    break if x * (x + 1) / 2 > i
    ans += 1
  end

end

puts ans


Measured memory_bytes: 14420
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    if(n == m)yn;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>

using namespace std;

#define fi first	
#define se second
#define long long long
typedef pair<int,int> ii;

vector<long> vec;
bool prime(int x)
{
	for(int i = 2; i <= sqrt(x); i++)
	{
		if(x%i == 0)
			return 0;
	}
	return 1;
}
long MAXN = 500;
long A[503][503];
long gcd(long a, long b) {return (b)? gcd(b,a%b) : a;}
long lcm(long a, long b) 
{
	if(a == b && b == 0) return 0;
	else if(a == 0) return b;
	else if(b == 0) return a;
	else return a/gcd(a,b)*b;
}

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	for(int i = 2; i <= 10000; i++)
		if(prime(i))
			vec.push_back(i);

	int n; scanf("%d", &n);

	int idx = 0;
	for(int i = 1; i <= MAXN; i+=2)
	{
		int x = 1, y = i;
		while(y <= MAXN)
			A[x++][y++] = vec[idx];
		idx++;
	}
	for(int i = 3; i <= MAXN; i+=2)
	{
		int x = i, y = 1;
		while(x <= MAXN)
			A[x++][y++] = vec[idx];
		idx++;
	}
	for(int i = 1; i <= MAXN; i+=2)
	{
		int x = 1, y = i;
		while(y >= 1 && x <= MAXN)
			A[x++][y--] *= vec[idx];
		idx++;
	}
	for(int i = MAXN; i >= 2; i-=2)
	{
		int x = i, y = MAXN;
		while(y >= 1 && x <= MAXN)
			A[x++][y--] *= vec[idx];
		idx++;
	}

	long mx = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(A[i][j] == 0) A[i][j] = lcm(lcm(A[i-1][j],A[i][j-1]),lcm(A[i+1][j],A[i][j+1]))+1;
			// mxnax(A[i][j],mx);
			printf("%lld", A[i][j]);
			if(j < n) printf(" ");
		}
		printf("\n");
	}
	// printf("%lld\n", mx);
}











Measured memory_bytes: 5120
#include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

#define ull unsigned long long

ull mcd(ull a,ull b){
	ull r = a%b;
	ull q = b;
	while(r>0){
		ull c = r;
		r = q%r;
		q = c;
	}
	return q;
}

int main(){
	ull n,m;
	while(cin>>n>>m){
		ull w = mcd(max(n,m),min(n,m));
		cout<<w<<" "<<(n*m)/w<<endl;
	}
	return 0;
}	

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

const int kN = 4000 + 5;
const int kMod = 998244353;
int cb[kN][kN], pw[kN];

int main() {
    cb[0][0] = 1;
    for (int i = 1; i < kN; ++i) {
        cb[i][0] = 1;
        for (int j = 1; j < kN; ++j) {
            cb[i][j] = cb[i - 1][j] + cb[i - 1][j - 1];
            if (cb[i][j] >= kMod) cb[i][j] -= kMod;
        }
    }
    pw[0] = 1;
    for (int i = 1; i < kN; ++i) pw[i] = (pw[i - 1] + pw[i - 1]) % kMod;
    int k, n; scanf("%d%d", &k, &n);
    for (int i = 2; i <= k + k; ++i) {
        int x = 0, y = 0, z = 0;
        for (int j = 1; j <= k; ++j) {
            if (i > j && i - j != j && i - j <= k) ++x;
            else if (i - j == j) ++y;
        }
        z = k - x - y;
        int w = x >> 1;
        // printf("i = %d x = %d y = %d z = %d\n", i, x, y, z);
        int ans = 0;
        for (int a = 0; a <= y; ++a) {
            for (int b = 0; b <= w; ++b) {
                if (a + b > n) continue;
                int g = 1LL * cb[y][a] * cb[w][b] % kMod * pw[b] % kMod;
                g = 1LL * g * cb[n - a + z - 1][z + b - 1] % kMod;
                (ans += g) %= kMod;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 62976
if __name__ == "__main__":
    input_data =[]
    for x in range(4):
        input_data.append(input())
    dim = int(input_data[0])
    A = [int(x) for x in input_data[1].split()]
    B = [int(x) for x in input_data[2].split()]
    C = [int(x) for x in input_data[3].split()]

    goukei = 0
    pre = -10
    for x in range(dim):
        goukei += B[A[x]-1]
        if A[x] - pre == 1:
            goukei += C[pre - 1]
        
        pre = A[x]

    print(goukei)

Measured memory_bytes: 3064
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

bool isPrime(long long n){
    if (n <= 2) return false;
    if (n % 2 == 0) return false;

    long double sqrtN = sqrt(n);
    for (long long i = 3; i <= sqrtN; i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}

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

    // 素数判定
    if (isPrime(N)) {
        cout << N - 1 << endl;
        return 0;
    }
    
    vector<long long > products; 
    long long left = 1;
    long long right = 1;
    long long max = sqrt(N);
    for (long long i = 2; i <= max + 1; i++){
        if ( N % i == 0) {
            left = i - 1;
            right = N / i - 1;
            products.push_back(left + right);
        }
    }
    sort(products.begin(), products.end());
    cout << products[0] << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val c = List(3) { readIntList() }

    val b = c[0]
    val a = listOf(0, c[1][0] - b[0], c[2][0] - b[0])
    var ans = true
    for (i in 0..2) {
        for (j in 0..2) {
            if (c[i][j] != a[i] + b[j]) ans = false
        }
    }
    if (ans) {
        println("Yes")
    } else {
        println("No")
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 38872
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    int A[101];
    int Alice = 0, Bob = 0;
    cin >> N;
    for (int i = 0; i < N; i++) 
    {
        cin >> A[i];
    }
    sort(A, A+N, greater<int>());
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            Alice += A[i];
        }
        else
        {
            Bob += A[i];
        }
    }
    cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    long[] a=new long[n];
   double l=0,sum=0;
    for(int i=0;i<n;i++) {
    	a[i]=sc.nextLong();
    	sum+=a[i];
    }
    for(int i=0;i<n;i++) {
    	if(l<sum/2) {
    		l+=a[i];
    	}
    	if(l==sum/2){
    		System.out.println("0");
    		break;
    	}
    	if(l>sum/2){
    		System.out.println((long)Math.min(Math.abs(2*l-sum), Math.abs(2*(l-a[i])-sum)));
    		break;
    	}
    }
  }
}


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


int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i,N) scanf("%d",&H[i]);
    sort(H.begin(),H.end());
    int p = min(N,K);
    ll ans = 0;
    for (int i = 0; i < N-p; i++)
    {
        ans += H[i];
    }
    cout << ans << endl;
}

    


Measured memory_bytes: 1792
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = ReadLine().Split();
      int h = int.Parse(input[0]);
      int w = int.Parse(input[1]);
      List<List<string>> a = new List<List<string>>();
      List<string> slis = new List<string>();
      
      string s = "";
      for (int i=0;i<w+2;i++)
      {
        s+="#";
      }
      
      a.Add(s.ToList().ConvertAll(x=>x.ToString()));
      
      for (int i=0;i<h;i++)
      {
        slis.Clear();
        slis.Add("#");
        slis.AddRange(ReadLine().ToList().ConvertAll(x=>x.ToString()));
        slis.Add("#");
        
        a.Add(string.Join("",slis).ToList().ConvertAll(x=>x.ToString()));
      }
      
      a.Add(s.ToList().ConvertAll(x=>x.ToString()));
      
      foreach (var i in a)
      {
        WriteLine(string.Join("",i));
      }
    }
}

Measured memory_bytes: 28720
#include<stdio.h>
int view(int *,int);// 1 hairetu 2 nagasa
int swap(int *,int*);

int main(){
  int t,i,j,n,a[100],cn=0,*min;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n-1;i++){
    min=&a[i];
    for(j=i+1;j<n;j++){
      if(*min>a[j]){
	min=&a[j];
      }
    }
    if(min !=&a[i]){
    swap(&a[i],min);
    cn++;
    }
  }
  view(a,n);
  printf("%d\n",cn);
return 0;  
  
return 0;
}
int view(int *a,int n){
  int i;
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i==n-1)printf("\n");
    else printf(" ");
  }

}
int swap(int *a,int *b){
  int t;
        t = *a;
	*a = *b;
	*b = t;
}



Measured memory_bytes: 2104
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
   static long i,j,k,l;
   long n;
   long cnt = 0;
   long f,g;
   char mark;
   int num;
   static char card[14] = {};
   char chars[5] = "SHCD";
   int nums[4] = {1,2,4,8};

   cin >> n;
   for(i = 0; i < n; i++) {
      cin >> mark >> num;
      switch(mark) {
      case 'S' : card[num] += 1;break;
      case 'H' : card[num] += 2;break;
      case 'C' : card[num] += 4;break;
      case 'D' : card[num] += 8;break;
      }
   }
   for (i = 0; i < 4; i++) {
      for (j = 1; j < 14; j++) {
         if( ( (card[j]/nums[i]) % 2) == 0)
            cout << chars[i] <<' '<< j << endl;
      }
   }
   return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 500010

using namespace std;

long long depth[MAX],L[MAX],R[MAX],N,noSaveDp[MAX],saveDp[MAX],leaf[MAX];

int main(){
  scanf("%d",&N);
  depth[0] = leaf[N-1] = 1;
  rep(i,N-1){
    scanf("%d %d",&L[i],&R[i]);
    depth[--L[i]] = depth[--R[i]] = depth[i] + 1;
  }

  for(int i = N-2;i>=0;i--){
    leaf[i] = leaf[L[i]] + leaf[R[i]];
    saveDp[i] = noSaveDp[i] = noSaveDp[L[i]] + noSaveDp[R[i]] + leaf[L[i]] + leaf[R[i]];
    saveDp[i] = min(saveDp[i],
		    min(noSaveDp[L[i]]+leaf[L[i]]+1+saveDp[R[i]],
			noSaveDp[R[i]]+leaf[R[i]]+1+saveDp[L[i]]));
    saveDp[i] = min(saveDp[i],
		    saveDp[L[i]]+1+depth[i]-1+1+saveDp[R[i]]);
  }
  /*
  rep(i,N)cout << "depth[" << i <<"] = " << depth[i] << endl;
  rep(i,N)cout << "leaf[" << i << "] = " << leaf[i] << endl;
  rep(i,N)cout << "noSaveDp[" << i << "] = " << noSaveDp[i] << endl;
  rep(i,N)cout << "saveDp[" << i << "] = " << saveDp[i] << endl;
  */
  printf("%d\n",saveDp[0]);
  return 0;
}

Measured memory_bytes: 24624
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct BIT { //1-indexed
private:
    int n,n2;
    vector<ll> bit;

public:
    BIT(vector<ll> v){
        n = v.size();
        rep(i,0,n) bit.push_back(v[i]);
        n2 = 1;
        while(n2 * 2 <= n) n2 *= 2;
    }

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

    void add(ll i, ll x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
    ll lower_bound(ll w) {
        if (w <= 0) return 0;
        ll x = 0;
        for (ll k = n2; k > 0; k /= 2) {
            if (x + k <= n && bit[x + k] < w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }

};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[200010], y[200010];
    rep(i,0,N) cin >> x[i] >> y[i];
    vector<ll> X, Y;
    rep(i,0,N){
        X.push_back(x[i]);
        Y.push_back(y[i]);
    }
    X.push_back(-INF);
    X.push_back(INF);
    Y.push_back(-INF);
    Y.push_back(INF);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    rep(i,0,N){
        x[i] = lower_bound(X.begin(), X.end(), x[i]) - X.begin();
        y[i] = lower_bound(Y.begin(), Y.end(), y[i]) - Y.begin();
    }
    vector<lpair> lp;
    rep(i,0,N) lp.push_back(make_pair(x[i], y[i]));
    sort(lp.begin(), lp.end());
    rep(i,0,N){
        x[i] = lp[i].first;
        y[i] = lp[i].second;
    }

    vector<ll> v(N+1, 0);
    BIT Lb(v), Rb(v);
    rep(i,0,N) Rb.add(y[i], 1);
    ll pow_mod[200010] = {};
    pow_mod[0] = 1;
    rep(i,0,N+1) pow_mod[i+1] = pow_mod[i] * 2 % MOD;
    ll ans = 0;
    rep(i,0,N){
        Rb.add(y[i], -1);
        rep(bit,0,16){
            ll RT = Rb.sum(N) - Rb.sum(y[i]);
            ll RD = Rb.sum(y[i]);
            ll LT = Lb.sum(N) - Lb.sum(y[i]);
            ll LD = Lb.sum(y[i]);
            ll b0 = ((bit>>0) & 1);
            ll b1 = ((bit>>1) & 1);
            ll b2 = ((bit>>2) & 1);
            ll b3 = ((bit>>3) & 1);
            RT = b0 ? pow_mod[RT] - 1 : 1;
            RD = b1 ? pow_mod[RD] - 1 : 1;
            LT = b2 ? pow_mod[LT] - 1 : 1;
            LD = b3 ? pow_mod[LD] - 1 : 1;
            
            ll v = RT * RD % MOD * LT % MOD * LD % MOD;
            if((b0 && b3) || (b1 && b2)) (v *= 2) %= MOD;
            (ans += v) %= MOD;
        }
        Lb.add(y[i], 1);
    }
    print(ans);
}

Measured memory_bytes: 21216
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int n, k; std::cin >> n >> k;
	int r, s, p; std::cin >> r >> s >> p;
	std::string str; std::cin >> str;
	std::vector<bool> won(n, false);
	long long int sum = 0;
	for (auto i = 0; i < k; ++i) {
		switch (str[i]) {
		case 'r': sum += p; break;
		case 's': sum += r; break;
		case 'p': sum += s; break;
		default: throw 0;
		}
		won[i] = true;
		for (auto j = i + k; j < n; j += k) {
			if (str[j] != str[j - k] || !won[j - k]) {
				switch (str[j]) {
				case 'r': sum += p; break;
				case 's': sum += r; break;
				case 'p': sum += s; break;
				default: throw 0;
				}
				won[j] = true;
			}
		}
	}
	std::cout << sum << std::endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

class UnionFind{
private:
    vec<int> p,s;
    int cnt;
public:
    UnionFind(){}
    UnionFind(int N):cnt(N),s(N,1),p(N){
        iota(p.begin(),p.end(),0);
    }
    int find(int x){
        if(p[x]==x) return x;
        else return p[x] = find(p[x]);
    }
    void unite(int x,int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(s[x]>s[y]) swap(x,y);
        p[x] = y;
        s[y] += s[x];
        cnt--;
    }
    bool is_same_set(int x,int y) {return find(x)==find(y);}
    int size(int x) {return s[find(x)];}
    int compnents_number(){return cnt;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    for(int i=0;i<N;i++) ans = max(ans,uf.size(i));
    cout << ans << "\n";
}

Measured memory_bytes: 4776
#include<stdio.h>
int main()
{
		long long n,a,b;
		scanf("%lld%lld%lld",&n,&a,&b);
		if(b<a)
		puts("0");
		else if(n!=1)
		printf("%lld\n",(n-1)*b+a-((n-1)*a+b)+1);
		else if(a==b)
		puts("1");
		else
		puts("0");
		return 0;
}


Measured memory_bytes: 128
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""

d=defaultdict(int)
s=list(ip())
for i in s:
    d[i]+=1
f=0
for i in set(s):
    if(d[i]%2):
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38384
/*
#include<iostream>
#include<queue>
#include<utility>
using namespace std;
int bfs();
const int INF = 100000000;
typedef pair<int, int> P;
int N, M;
int sx, sy;
int gx, gy;
int d[100][101];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
	cin >> N >> M;
	int res = bfs();
	printf("%d\n", res);
	return 0;
}
int bfs() {
	queue<P> que;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			d[i][j] = INF;
		}
	}

}
*/
#include<iostream>
using namespace std;
	long  W, H, N;
	long long huX = 1, huY = 1,ans=0;
	long  kaX, kaY;
	void kita();
	void higashi();
	void minami();
	void nishi();
	void naname();
int main() {
	cin >> W >> H >> N;
	for (int i = 0; i < N; i++) {
		cin >> kaX >> kaY;
		if (i!=0) {
			if (huX == kaX && huY < kaY) {
				kita();
			}
			else if (huY == kaY && huX < kaX) {
				higashi();
			}
			else if (huY == kaY && huX > kaX) {
				nishi();
			}
			else if (huX == kaX && huY > kaY) {
				minami();
			}
			else  {
				naname();
			}
		}
		if (i == 0) {
			huX = kaX;
			huY = kaY;
		}
		
	}
		cout << ans << endl;
	}
	void kita() {
		ans += kaY - huY;
		huY = kaY;
		huX = kaX;
		return;
	}
	void higashi() {
		ans += kaX - huX;
		huX = kaX;
		huY = kaY;
		return;
	}
	void minami() {
		ans += huY - kaY;
		huY = kaY;
		huX = kaX;
		return;
	}
	void nishi() {
		ans += huX - kaX;
		huY = kaY;
		huX = kaX;
		return;
	}
	void naname() {
		int saX, saY;
		saX = kaX - huX;
		saY = kaY - huY;
		if (saX == saY ) {
			if (saX > 0) {
				ans += saX;
			}
			else {
				ans += saX*-1;
			}
			huX = kaX;
			huY = kaY;
		}
		else if (saX == saY*-1 || saX*-1 == saY) {
			if (saY > 0) {
				ans += saY * 2;
			}
			else {
				ans += saX * 2;
			}
			huX = kaX;
			huY = kaY;
		}
		else if (saX < saY && saX > 0 && saY > 0) {//hokuhokutou nannansei
		
			ans += saY;
			huX = kaX;
			huY = kaY;
		}
		else if (saX > saY && saX > 0 && saY > 0) {//touhokutou
			ans += saX;
			huX = kaX;
			huY = kaY;
		}
		else if (saX>saY && saX>0 && saY<0) {//tounantou 
			ans += kaX - huX + huY - kaY;
			huX = kaX;
			huY = kaY;
		}
		else if (saX < saY && saX < 0 && saY < 0) {//seinansei
			
			ans += huX-kaX;
			huX = kaX;
			huY = kaY;
		}
		else if (saX > saY && saX < 0 && saY < 0) {
			ans += huY - kaY;
			huX = kaX;
			huY = kaY;
		}
		else if (saX < saY && saX < 0 && saY> 0) {//seihokusei hokuhokusei
			ans += huX - kaX + kaY-huY;
			huX = kaX;
			huY = kaY;
		}
		else if (saX>saY && saX>0 && saY>0) {//nannnantou
			ans += kaX - huX + huY - kaY;
			huX = kaX;
			huY = kaY;
		}
		return;
	}

Measured memory_bytes: 3100
#include<stdio.h>
int main()
{
  int l,r,d;
   scanf("%d %d %d",&l,&r,&d);
  int count=0;   
for(int i=l;i<=r;i++)
  {
      if(i%d==0) count++;
  }
  printf("%d\n",count);
 return 0;
}

Measured memory_bytes: 1732
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))

# print(N, K, A)

ma = 0
d = A[0]
found = False
for a in A:
    ma = max(ma, a)
    d = gcd(d, a)
    if a == K:
        found = True
if found:
    print('POSSIBLE')
    exit()

if ma < K:
    print('IMPOSSIBLE')
    exit()
if K % d == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 88684
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn f(x: usize) -> usize {
   if x <= 2 {
      return 0;
   }
   1 + f((x - 1) >> 1)
}

fn main() {
   let x: usize;
   input!(x);
   let mut ok = 0;
   let mut ng = usize::max_value() / 10;
   while ng - ok > 1 {
      let mid = (ok + ng) / 2;
      if f(mid) <= x {
         ok = mid;
      } else {
         ng = mid;
      }
   }
   println!("{}", ok);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    if(n>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}





Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int n,a[105],m,s;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)
		if(s%(4*m)==0&&a[i]<s/(4*m))
		{
			cout<<"No";
			return 0;
		}
		else if(s%(4*m)!=0&&a[i]<=s/(4*m))
		{
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
tenboudai=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    tenboudai[a-1].append(b-1)
    tenboudai[b-1].append(a-1)
count=0
for i in range(n):
    flag=0
    for j in tenboudai[i]:
        if h[i]<=h[j]:
            flag=1
    if flag==0:
        count+=1
print(count)

Measured memory_bytes: 92860
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

class union_find {
  private:
    vector<int> par, rank;
  public:
    explicit union_find(int n) : par(n), rank(n) {
      for (int i = 0; i < n; i++)
        par[i] = i;
    }
    int root_of(int x) {
      auto& p = par[x];
      if (p == x) return x;
      return p = root_of(p);
    }
    void unite(int x, int y) {
      x = root_of(x);
      y = root_of(y);
      if (x == y) return;
      if (rank[x] < rank[y])
        par[x] = y;
      else {
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
      }
    }
    bool connected(int x, int y) {
      return root_of(x) == root_of(y);
    }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<int> xs(n), ys(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xs[i] = ys[i] = i;
  }
  sort(begin(xs), end(xs),
      [&](int u, int v) { return x[u] < x[v]; });
  sort(begin(ys), end(ys),
      [&](int u, int v) { return y[u] < y[v]; });
  vector<tuple<int, int, int>> es;
  for (int i = 0; i < n - 1; i++) {
    int j = i+1;
    es.emplace_back(x[xs[j]] - x[xs[i]], xs[i], xs[j]);
    es.emplace_back(y[ys[j]] - y[ys[i]], ys[i], ys[j]);
  }
  sort(begin(es), end(es));
  union_find uf(n);
  auto it = begin(es);
  long long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    int cost, u, v;
    do {
      tie(cost, u, v) = *it++;
    } while (uf.connected(u, v));
    sum += cost;
    uf.unite(u, v);
  }
  cout << sum << endl;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> ans(N,0);
    vector<int> city(2);
    for (int i=0; i<M; i++){
        cin >> city[0] >> city[1];
            for(int j=0; j < N; j++){
                int num = count(city.begin(), city.end(), j+1);
                ans[j] += num;
            }
    }
    for (int i=0; i<N; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
// typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 100000

ll N,M,ans=0;
ll X[3][1001];

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,N){
        cin>>X[0][i]>>X[1][i]>>X[2][i];
    }
    REP(Bit,8){
        ll A[1001];
        REP(i,1000)A[i]=0;
        ll a=0;
        REP(i,3){
            REP(j,N){
                if(Bit&1<<i)A[j]+=X[i][j];
                else A[j]-=X[i][j];
            }
        }
        std::sort(A,A+N);
        REP(i,M)a+=A[N-i-1];
        ans=std::max(a,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

vector<vector<int>> A;
vector<vector<int>> G;
vector<vector<int>> D;
int N;
void WF(vector<vector<int>> &D){
    REP(i, N) D[i][i] = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            for(int k=0; k<N; k++){
                D[i][j] = D[j][i] =  min(D[i][j], D[i][k]+D[j][k]);
            }
        }
    }
}
signed main(){
    cin>>N;
    A.resize(N, vector<int>(N));
    G.resize(N, vector<int>(N));
    D.resize(N, vector<int>(N, MOD));
    REP(i, N){
        REP(j, N){
            cin>>G[i][j];
            A[i][j] = G[i][j];
        }
    }
    ll res = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            bool hasR = true;
            for(int k=0; k<N; k++){
                if(k==i or k==j) continue;
                if(G[i][j]>=G[i][k]+G[j][k]){
                    hasR = false;
                    break;
                }
            }
            if(hasR){
                D[i][j] = D[j][i] = G[i][j];
                res += G[i][j];
            }
        }
    }
    WF(G);
    REP(i, N){
        REP(j, N){
            if(A[i][j]>G[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private class Altitude {
        private int x;
        private int y;
        private int h;

        public Altitude() {
            this.x = 0;
            this.y = 0;
            this.h = 0;
        }

        public int getX() {
            return this.x;
        }

        public void setX(int x) {
            this.x = x;
        }

        public int getY() {
            return this.y;
        }

        public void setY(int y) {
            this.y = y;
        }

        public int getH() {
            return this.h;
        }

        public void setH(int h) {
            this.h = h;
        }
    }

    private Scanner stdin;
    private PrintWriter stdout;

    public void execute() {
        this.stdin = new Scanner(new BufferedInputStream(System.in));
        this.stdout = new PrintWriter(new BufferedOutputStream(System.out));

        while (this.stdin.hasNext()) {
            int n = stdin.nextInt();
            Altitude[] a = new Altitude[100];
            for (int i = 0; i < n; ++i) {
                a[i] = new Altitude();
                a[i].setX(this.stdin.nextInt());
                a[i].setY(this.stdin.nextInt());
                a[i].setH(this.stdin.nextInt());
            }
            Altitude foo = new Altitude();
            for (int x = 0; x <= 100; ++x) {
                boolean done = false;
                for (int y = 0; y <= 100; ++y) {
                    foo.setX(x);
                    foo.setY(y);
                    foo.setH(0);
                    for (int i = 0; i < n; ++i) {
                        if (a[i].getH() > 0) {
                            foo.setH(a[i].getH() + Math.abs(foo.getX() - a[i].getX()) + Math.abs(foo.getY() - a[i].getY()));
                            break;
                        }
                    }
                    if (foo.getH() > 0) {
                        done = true;
                        for (int i = 0; i < n; ++i) {
                            if (Math.max(foo.getH() - Math.abs(foo.getX() - a[i].getX()) - Math.abs(foo.getY() - a[i].getY()), 0) != a[i].getH()) {
                                done = false;
                                break;
                            }
                        }
                    }
                    if (done)
                        break;
                }
                if (done)
                    break;
            }
            this.stdout.printf("%d %d %d\n", foo.getX(), foo.getY(), foo.getH());
        }

        this.stdin.close();
        this.stdout.close();
    }

    public static void main(String[] args) throws Exception {
        Main instance = new Main();
        instance.execute();
    }

}

Measured memory_bytes: 23508
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
  print(a*x+b*y)
elif x>=y:
  print(min(y*2*c+(x-y)*a,x*2*c))
else:
  print(min(x*2*c+(y-x)*b,y*2*c))

Measured memory_bytes: 3064
#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 pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}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)...);}

pair<ll,ll> gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	ll sum=0;
	while(ll r=(a%b)){
		a = b;
		b = r;
		sum++;
	}
	return make_pair(b,sum+1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		ll A=in(),B=in();
		if(!A && !B) break;

		auto res = gcd(A,B);
		out(res.first,res.second);
	}
	return 0;
}



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

int main() {
    int N, X, Y; 
    cin>> N >> X >> Y;
    vector<vector<int>> G(N+1, vector<int>(0));
    REP(i, 1, N){
        G[i].push_back(i+1);
        G[i+1].push_back(i); 
    }
    G[X].push_back(Y); G[Y].push_back(X);
    queue<int> que;
    vector<int> Ans(N+1, 0);
    REP(i, 1, N+1){
        vector<int> Used(N+1, -1);
        que.push(i);
        Used[i] = 0;
        while(!que.empty()){
            int current = que.front(); que.pop();
            for(auto next: G[current]){
                if(Used[next] != -1) continue;
                Used[next] = Used[current] + 1; 
                que.push(next);
            }
        }
        REP(j, 1, N+1){
            Ans[Used[j]]++;
        }
    }
    REP(i, 1, N){
        cout << Ans[i]/2 << endl;
    }
}

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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 5 * 1e3 + 5;
typedef pair<int, int> pii;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}

int main() {

    int n;
    cin>>n;
    vector<int> a(n);
    For(i,0,n) cin>>a[i];

    vector<vector<ll>> dp(n,vector<ll>(n));

    for(int l=n-1;l>=0;l--){
        for(int r=l;r<n;r++){
            if(l == r) dp[l][r] = a[l];
            else dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
        }
    }

    cout<<dp[0][n-1]<<endl;

    return 0;

}

Measured memory_bytes: 70656
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

#define MAXN 100000
LL a[MAXN+10][3];
int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>a[i][0];
	}
	for(int j=1; j<=2; ++j) {
		a[0][j-1]=a[n][j-1];
		for(int i=1; i<=n; ++i) {
			a[i][j]=a[i][j-1]-a[i-1][j-1];
		}
	}
	queue<int> q;
	LL sum=0;
	for(int i=1; i<=n; ++i) {
		sum+=a[i][0];
	}
	if (sum%(LL(n)*(n+1)/2)!=0) {
		puts("NO");
		return 0;
	}
	LL x=sum/(LL(n)*(n+1)/2);
	sum=0;
	for(int i=1; i<=n; ++i) {
		LL t=x-a[i][0]+a[i-1][0];
		if (t%n!=0 || t<0) {
			puts("NO");
			return 0;
		}
		sum+=t/n;
	}
	if (sum!=x) {
		puts("NO");
		return 0;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define m 1000000007
typedef long long ll;
int h,w;
char g[1001][1001];
ll dp[1001][1001];
/*
bool val(int x, int y)
{
  if(x>=0 && x<h && y>=0 && y<0)
     return true;
    return false;
}
 */
ll fun(int x,int y)
{
  if(x==h-1 && y==w-1)
    return 1;
    else if(x==h-1 && y>w-1)
       return 0;
       else if(y==w-1 && x>h-1)
         return 0;
          else if(g[x][y]=='#')
            return 0;
         if(dp[x][y]!=-1)
           return dp[x][y];
           
           ll ans=fun(x,y+1)+fun(x+1,y);
           
       
     dp[x][y]=ans%m;
     
     return ans%m;

}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin>>h;
	if(h==0)
	   return 0;
	   cin>>w;
	   if( w==0)
	  return 0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		 {
		   cin>>g[i][j];
		   dp[i][j]=-1;
		   
		   }

      ll ans=fun(0,0)%m;
      cout<<ans<<endl;

return  0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#if __has_include("debug.h")
#include "debug.h"
#endif
using namespace std;

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

#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rep_(i, a, b) for (ll i = a; i > b; --i)
#define endl '\n'

const ll maxn = 1e5 + 5;

// -------------- Arithmetic --------------
const ll mod = 1e9 + 7;

ll power(ll x, ll y, ll m) {
	ll ans = 1;
	x = x % mod;
	if (x == 0) return 0;
	while (y > 0) {
		if (y & 1) ans = (ans * x) % m;
		y = y >> 1;
		x = (x * x) % m;
	}
	return ans;
}

ll mod_inv(ll a) {return power(a, mod - 2, mod);}

ll add(ll a, ll b) {return (((a + b) % mod) + mod) % mod;}
ll sub(ll a, ll b) {return (((a - b) % mod) + mod) % mod;}
ll mul(ll a, ll b) {return (((a * b) % mod) + mod) % mod;}
ll div(ll a, ll b) {return mul(a, mod_inv(b));}

// -------------- Code --------------

ll n, m, num_comps;
ll a[maxn];
vi g[maxn];
string s;
// char c;

void dfs(ll u, ll comp) {
	a[u] = comp;
	for (ll v: g[u]) {
		if (!a[v]) dfs(v, comp);
	}
}

void solve() {
	cin >> n >> m;
	memset(a, 0, sizeof(a));
	num_comps = 0;
	rep(i, 0, m) {
		ll u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	rep(i, 1, n + 1) {
		if (!a[i]) {
			dfs(i, ++num_comps);
		}
	}
	cout << (num_comps - 1) << endl;
}

void aux() {
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);
	aux();
	ll _ = 1;
	// cin >> _;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 11504
#include<stdio.h>
int main() {
	int count[4][3][10] = { 0 };
	int n, b, f, r, v, i, j, k;
	scanf("%d", &n);
	for (i = 0;i < n;i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
			count[b-1][f-1][r-1] += v;
	}
	for (i = 0;i <= 3;i++) {
		for (j = 0;j <= 2;j++) {
			for (k = 0;k <= 9;k++) {
					printf(" %d", count[i][j][k]);			
			}
			printf("\n");
		}
		if (i == 3) {
			break;
		}
		printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
vector<string>vs;
void solve(string x){
	if(vs.empty()){
		vs.push_back(x);
		return;
	}
	for(int i=0;i<vs.size();i++)if(vs[i]==x)return;
	vs.push_back(x);
	sort(vs.begin(),vs.end());
	if(vs.size()>k)vs.pop_back();
}
int main(){
	cin>>s>>k;
	for(int i=0;i<s.size();i++){
		string st;
		for(int j=i;j<s.size()&&j<i+k;j++){
			st+=s[j];
			solve(st);
		}
	}
	cout<<vs[k-1];
	return 0;
}


Measured memory_bytes: 256