akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll X;
  std::cin >> X;

  ll num500 = X / 500;
  ll num5   = (X % 500) / 5;

  ll sum = num500 * 1000 + num5 * 5;

  print(sum);
  return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

struct Line {
    ll k, b;

    Line() = default;

    Line(ll K, ll B)
        : k(K)
        , b(B)
    {
    }

    ll at(ll x) {
        return k * x + b;
    }
};

ld inter(const Line& x, const Line& y) {
    return 1.0 * (x.b - y.b) / (y.k - x.k);
}

const int MX = 200 * 1000 + 7;

Line st[MX];
int stp = 0;
int opt = 0;

void add(const Line& l) {
    while (stp >= 2 && inter(st[stp - 2], l) <= inter(st[stp - 2], st[stp - 1])) {
        stp--;
    }
    opt = min(opt, stp - 1);
    opt = max(opt, 0);
    st[stp++] = l;
}

ll gt(ll x) {
    while (opt + 1 < stp && st[opt + 1].at(x) < st[opt].at(x)) {
        opt++;
    }
    return st[opt].at(x);
}

ll h[MX];
ll f[MX];
int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    ll C;
    cin >> n >> C;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    f[0] = 0;
    add(Line(-2ll * h[0], h[0] * h[0]));
    for (int i = 1; i < n; i++) {
        f[i] = gt(h[i]) + h[i] * h[i] + C;
        add(Line(-2ll * h[i], f[i] + h[i] * h[i]));
    }

    cout << f[n - 1] << "\n";
    return 0;
}



Measured memory_bytes: 6528
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int a[3][3];
	int c[3][3] = {};
	rep(i,3)rep(j,3)cin >> a[i][j];
	int n;
	cin >> n;

	rep(i,n){
		int b;
		cin >> b;
		rep(i,3)rep(j,3)if(a[i][j] == b)c[i][j] = 1;
	}

	if(c[0][0]*c[0][1]*c[0][2] == 1 || 
	   c[1][0]*c[1][1]*c[1][2] == 1 || 
	   c[2][0]*c[2][1]*c[2][2] == 1 || 
	   c[0][0]*c[1][0]*c[2][0] == 1 || 
	   c[0][1]*c[1][1]*c[2][1] == 1 || 
	   c[0][2]*c[1][2]*c[2][2] == 1 ||
	   c[0][0]*c[1][1]*c[2][2] == 1 || 
	   c[0][2]*c[1][1]*c[2][0] == 1){
		   cout << "Yes" << endl;
	   }
	else{
		cout << "No" << endl;
	}

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc157.contest.atcoder.jp/tasks/abc157_b

Measured memory_bytes: 3648
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W = (int(i) for i in input().split())
    c = [[int(i) for i in input().split()] for j in range(H)]
    ans = []
    for h in range(H):
        for w in range(W):
            if c[h][w] % 2 == 1:
                if h != H - 1 and w != W - 1:
                    c[h][w] -= 1
                    c[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif w != W - 1:
                    c[h][w] -= 1
                    c[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif h != H - 1:
                    c[h][w] -= 1
                    c[h+1][w] += 1
                    ans.append((h+1, w+1, h+2, w+1))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75100
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#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 <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

int main()
{
	int t;
	cin >> t;
	int h = t / 3600;
	int m = t % 3600;
	int s = m % 60;
	m /= 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H;
    ll ans = 0;
    ll num = 1;
    cin >> H;
    while(H >= 1) {
        ans += num;
        num *= 2;
        H /= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String s = sc.next();
        String t = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(s.charAt(i));
            sb.append(t.charAt(i));
        }
        System.out.println(sb.toString());

        sc.close();
    }
}


Measured memory_bytes: 22612
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		int ans = 0;
		long [] a = new long[100];
		if (n ==1) {
			System.out.println(ans);
			return;
		}
		a = soinsubunakai(n);

		int k = 1;
		long pa = 0;
		int j = 1;
		for (int i=0; a[i]!=0; i++, j++) {
			if (pa != a[i]) {
				k = 1;
				j = 1;
			}
			if (j == k) {
				ans++;
				k++;
				j = 0;
			}
			pa = a[i];
		}
		System.out.println(ans);
	}

	private static long[] soinsubunakai(long num)
	{
		long [] a = new long[100];
		int index = 0;
        boolean endFlag = false;
        long i = 2;
        long x = num;
        for (;i*i <= x;) {
            if (x % i == 0) { // 最小の因数を求める
                //System.out.print(i);
            	a[index] = i;
            	index++;
                if (x == i) {
                	endFlag = true;
                	break;
                }
                //System.out.print(" * "); // xと因数が同値になったら＊の挿入をやめる
                x /= i; // 最小の因数で割った数を代入する
            } else {
                i++;
            }
        }
        if (!endFlag) {
            //System.out.println(x);
        	a[index] = x;
            //System.out.print(i);
        }
		return a;
	}
}


Measured memory_bytes: 27156
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int gcd(int x, int y){
		if(y == 0)return x;
		else return gcd(y, x % y);
}

int main(int argc, char const* argv[])
{
	int n, k;
	cin >> n >> k;
	int tmp = 0;
	bool flag = false;
	for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			if(i == 0)tmp = a;
			else tmp = gcd(tmp, a);
			if(a >= k)flag = true;
	}
	if(flag && k % tmp == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define fi first 
#define se second
#define endl '\n'

pii arr[105]; //fi = wi; se = vi;
ll dp[105][100005];

int main(){
	
	ios_base::sync_with_stdio(0);
	int n, w; cin >>n >>w;
	
	for(int i = 1; i<=n; i++) cin >>arr[i].fi >>arr[i].se;
	
	for(int i = 1; i<=n; i++){
		for(int j = 1; j<=w; j++){
			if(j - arr[i].fi >= 0){
				dp[i][j] = max(dp[i-1][j], dp[i-1][j - arr[i].fi] + arr[i].se);
			}
			else dp[i][j] = dp[i-1][j];
		}
		/*
		for(int j = 1; j <= w; j++) cout <<dp[i][j] <<endl;
		cout <<endl;*/
	}

	cout <<dp[n][w] <<endl;
	return 0;
}	

Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>//cout << fixed << setprecision() <<
#include <set>
#include <map>
using ll = long long;
using namespace std;

int main(void){
    double pi= 3.141592653589793;
    double a,b,h,m,t;
    double k1,k2,k,kakudo;
    cin>>a>>b>>h>>m;
    k1=h*30.0+0.5*m;
    k2=m*6.0;
    k=abs(k1-k2);
    if(k>=180)kakudo=360.0-k;
    else kakudo=k;
    
    k1=kakudo*pi/180;
    
    t=pow(a,2)+pow(b,2)-2*a*b*cos(k1);
    cout<< fixed << setprecision(10)<<sqrt(t);
}


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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	ll n, m;
	cin >> n >> m;
	ll sum = 0;
	rep(i, m) {
		ll a;
		cin >> a;
		sum += a;
	}
	if (sum > n) {
		cout << -1 << endl;
	} else {
		cout << n - sum << endl;
	}
	return 0;
}



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

using namespace std;

int main() {
    int N, K, current_min;
    cin >> N >> K;

    int heights[N];
    int dp[N] = { 0 };
    
    for (int i = 0; i < N; i++)
    {
        cin >> heights[i];
    }
    
    dp[1] = abs(heights[1] - heights[0]);
    for (int i = 2; i < N; i++)
    {
        current_min = abs(heights[i] - heights[i - 1]) + dp[i - 1];

        for (int j = 2; j <= K && i - j >= 0; j++)
        {
            current_min = min(current_min, abs(heights[i] - heights[i - j]) + dp[i - j]);
        }
    
        dp[i] = current_min;
    }

    cout << dp[N - 1];
}


Measured memory_bytes: 1024
// Problem : C - Fennec vs Monster
// Contest : AtCoder Beginner Contest 153
// URL : https://atcoder.jp/contests/abc153/tasks/abc153_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n,k;
        cin >> n >> k;
        long long int arr[n];
        for(int i=0;i<n;i++)
        {
                cin >> arr[i];
        }
        sort(arr,arr+n);
        long long int ans=0;
        for(int i=0;i<n-k;i++)
        {
                ans+=arr[i];
        }
        cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
MOD = 10**9 + 7

D = [[0]*(K+1) for i in range(N+1)]
D[0][0] = 1
for n in range(1, N+1):
    D0 = D[n-1]
    for k in range(1, K+1):
        D[n][k] = (D0[k-1] + k * D0[k]) % MOD
print(sum(D[N]) % MOD)



Measured memory_bytes: 29344
import math

X, N = map(int, input().split())



def main(X, N):
  if N == 0:
    print(X)
    return
     
  p = list(map(int, input().strip().split()))
  if not X in p:
    print(X)
    return
    
  for i in range(math.ceil((N-1)/2)+1):
    a = X-i-1
    b = X+i+1
    if not a in p:
      print(X-i-1)
      return
    if not b in p:
      print(X+i+1)
      return
   
  
main(X, N)

Measured memory_bytes: 9204
n = int(input())
xy = []
lili = []
for i in range(n):
    x,y = map(int,input().split())
    xy.append([x,y])
for a in xy:
    for b in xy:
        aa = a[0]-b[0]
        bb = a[1]-b[1]
        if not (aa == 0 and bb == 0):
            lili.append([aa,bb])

kyoutuu = 0
for y in lili:
    if lili.count(y) > kyoutuu:
        kyoutuu = lili.count(y)

print(n-kyoutuu)

Measured memory_bytes: 3316
n,k=map(int,input().split())
s=input()
if s[k-1]=='A':
  s=s[:k-1]+'a'+s[k:]
elif s[k-1]=='B':
  s=s[:k-1]+'b'+s[k:]
else:
  s=s[:k-1]+'c'+s[k:]
print(s)

Measured memory_bytes: 3060
# Coloring Dominoes
N = int(input())
s1 = input()
s2 = input()

if (s1[0]==s2[0]):
    c = 3
else:
    c = 6


for i in range(N-1):
    if (s1[i]==s2[i]):
        c*=2
    else:
        if (s1[i]!=s1[i+1]):
            if (s1[i+1]!=s2[i+1]):
                c*=3
print(c%1000000007)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int N = sc.nextInt();
		int Q = sc.nextInt();

		// 文字列の入力
		String s = sc.next();
		String[] S = s.split("");
		int[] splitL = new int[N+1];
		int cnt = 0;

		for(int i=2;i<=N;i++){
			if(S[i-2].equals("A")&&S[i-1].equals("C"))cnt++;
			splitL[i]=cnt;
		}

		for(int i=0;i<Q;i++){
			int lq = sc.nextInt();
			int rq = sc.nextInt();

			// 出力
			System.out.println(splitL[rq]-splitL[lq]);
		}
	}
}

Measured memory_bytes: 75684
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int H,W ;
  cin >> H >> W ;
  vector<string> a(H) ;
  cinf(H,a) ;
  
  vector<bool> row(H,false) ;
  vector<bool> col(W,false) ;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(a[i][j] == '#'){
        row[i] = true ;
        col[j] = true ;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(row[i]){
      for(int j=0;j<W;j++){
        if(col[j])
          cout<<a[i][j] ;
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d" @@ fun n ->
  Array.init (int_of_float (ceil @@ sqrt @@ float_of_int n)) (fun a ->
    if n mod (a + 1) = 0 then max (a + 1) (n / (a + 1))
    else max_int)
  |> Array.fold_left min max_int
  |> (fun a -> Printf.printf "%d\n" @@ succ @@ int_of_float @@ log (float_of_int a) /. log 10.)


Measured memory_bytes: 2944
import sys

#+++++
		
def main():
	b , c = map(int, input().split())
	if b <= 9 and c <= 9:
		return b*c
	print(-1)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k,ans=0;
	cin>>n>>k;
	while(n){
		++ans;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

char a[101][101];
int n,m;
int kilk[30];

int main()
{
          cin>>n>>m;
          for(int i=0;i<n;i++)
                    for(int j=0;j<m;j++)
                    {
                              cin>>a[i][j];
                              kilk[a[i][j]-'a']++;
                    }
          int res=0;
          for(int i=0;i<30;i++)
                    res+=kilk[i]/4;
          if(res<n/2*(m/2) && n/2*(m/2)!=0)
          {
                    cout<<"No";
                    return 0;
          }
          res=n/2*(m/2);
          while(res)
          {
                    for(int i=0;i<30;i++)
                              if(kilk[i]>=4)
                              {
                                        kilk[i]-=4;
                                        res--;
                                        break;
                              }
          }
          int res2=0;
          for(int i=0;i<30;i++)
                    res2+=kilk[i]/2;
          if(n%2==0 && m%2==0 && res2==0)
          {
                    cout<<"Yes";
                    return 0;
          }
          if(n%2==1 && m%2==1)
          {
                    if(res2==(n+m-2)/2)
                              cout<<"Yes";
                    else
                              cout<<"No";
                    return 0;
          }
          if(n%2==1)
          {
                    if(res2==m/2)
                              cout<<"Yes";
                    else
                              cout<<"No";
                    return 0;
          }
          if(m%2==1)
          {
                    if(res2==n/2)
                              cout<<"Yes";
                    else
                              cout<<"No";
                    return 0;
          }
          cout<<"No";


}


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

int main()
{
    string s1, s2, s3, s4, s;
    s1 = "dream";
    s2 = "dreamer";
    s3 = "erase";
    s4 = "eraser";
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    reverse(s3.begin(), s3.end());
    reverse(s4.begin(), s4.end());

    cin >> s;

    string tmp;
    string lst;
    for (int i = (int)s.size() - 1; i >= 0; i--) {
        tmp.push_back(s[i]);
        if (tmp == s1) lst += s1, tmp.clear();
        else if (tmp == s2) lst += s2, tmp.clear();
        else if (tmp == s3) lst += s3, tmp.clear();
        else if (tmp == s4) lst += s4, tmp.clear();
    }

    reverse(lst.begin(), lst.end());
    if (lst == s) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll solve(ll n, ll m) {
	ll mx = m / n;
	vector<ll> v;
	for (ll i = 1; i * i <= m; i++) {
		if (m % i != 0) continue;
		if (i <= mx) v.push_back(i);
		if (m / i <= mx) v.push_back(m / i);
	}
	sort(ALL(v));
	return v[v.size() - 1];
}

int main() {
	ll n, m;
	cin >> n >> m;
	cout << solve(n, m) << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class BIT {
  vector<int> dat;
public:
  BIT (int n) {
    dat.resize(n+1, 0);
  }
  void add(int i, int n) {
    while (i < dat.size()) {
      dat[i] += n;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += dat[i];
      i -= i & -i;
    }
    return res;
  }
  void clear() {
    for (int i = 1; i < dat.size(); i++)
      dat[i] = 0;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] -= k;
  vector<ll> sum(n+1);
  rep(i, n) sum[i+1] = sum[i]+a[i];
  map<ll, int> mp;
  rep(i, n+1) mp[sum[i]];
  int idx = 1;
  for (auto& e : mp) {
    e.second = idx;
    idx++;
  }
  rep(i, n+1) sum[i] = mp[sum[i]];
  BIT bit(n+1);
  ll ans = 0;
  rep(i, n+1) {
    ans += bit.sum(sum[i]);
    bit.add(sum[i], 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19504
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1LL << 60;

ll dp[100010][3];  // i日目、A~Cを選んだ時の最大値

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

  int k[100010][3];  // プラン
  for (int i = 0; i < n; i++) cin >> k[i][0] >> k[i][1] >> k[i][2];

  for (int i = 0; i < 3; i++) dp[0][i] = k[0][i];

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      if (j == 0) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + k[i][0];
      }
      if (j == 1) {
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + k[i][1];
      }
      if (j == 2) {
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + k[i][2];
      }
    }
  }
  cout << *max_element(dp[n - 1], dp[n]) << endl;
}


Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)


int main() {
  int n;
  cin >> n;
  vector<int> n1, n2;
  rep(i, n){
      int num; cin >> num;
      if(i % 2 == 0) n1.push_back(num);
      else n2.push_back(num);
  }
  if(n % 2 == 0){
      reverse(all(n2));
      rep(i, n2.size()) cout << n2[i] << " ";
      rep(i, n1.size()){
          cout << n1[i];
          cout << " ";
          }
  } else{
      reverse(all(n1));
      rep(i, n1.size()) cout << n1[i] << " ";
      rep(i, n2.size()){
        cout << n2[i];
        cout << " ";
      }
  } cout << ln;
}

Measured memory_bytes: 3188
package main

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

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	var jpy, btc float64
	for i := 0; i < n; i++ {
		var a float64
		var b string
		fmt.Scan(&a, &b)
		if b == "JPY" {
			jpy += a
		} else {
			btc += a * 380000
		}
	}
	fmt.Println(jpy + btc) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int a,b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b});
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int W = sc.nextInt();
			
			long[] ws = new long[N];
			int[] vs = new int[N];
			
			for(int i = 0; i < N; i++) {
				ws[i] = sc.nextLong();
				vs[i] = sc.nextInt();
			}
			
			final int MAX_V = N * 1000;
			long[] DP = new long[MAX_V + 1];
			Arrays.fill(DP, Integer.MAX_VALUE);
			DP[0] = 0;
			
			for(int item = 0; item < N; item++) {
				for(int curr = MAX_V - vs[item]; curr >= 0; curr--) {					
					DP[curr + vs[item]] = Math.min(DP[curr + vs[item]], DP[curr] + ws[item]);
				}
			}
			
			long answer = 0;
			for(int i = 0; i <= MAX_V; i++) {
				if(DP[i] <= W) { answer = i; }
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 24020
#include <stdio.h>

int main(void){
  int a, b, c, d, count, n;
  while(scanf("%d", &n) != EOF){
    count = 0;
    for(a = 0; a < 10; a ++){
      for(b = 0; b < 10; b ++){
	for(c = 0; c < 10; c ++){
	  for(d = 0; d < 10; d ++){
	    if(a + b + c + d == n)
	      count ++;
	  }
	}
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

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



int main(){
    int a, b;
    cin >> a >> b;
    if(a + b == 0){
        cout << 0 << '\n';
    }else if(a + b < 0){
        cout << -1 << '\n';
    }else{
        cout << 1 << '\n';
    }
    return 0;
}


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

const int MOD=1e9+7;
int dp[100005][13];

int main() {
  string s;
  cin>>s;
  int n=s.size();
  dp[0][0]=1;

  for(int i=0;i<n;i++){
    for(int j=0;j<13;j++){
      if(s[i]=='?'){
        for(int k=0;k<10;k++){
          (dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD;
        }
      }
      else{
        int k=s[i]-'0';
        (dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD;
      }
    }
  }

  cout<<dp[n][5];
  return 0;
}


Measured memory_bytes: 5504
W,H,n=map(int,input().split())
l=[[0 for i in range(W)] for j in range(H)] 
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1: #x<xi
    for i in range(H):
      for j in range(x):
        l[i][j]=1
  elif a==2: #x>xi
    for i in range(H):
      for j in range(x,W):
        l[i][j]=1
  elif a==3: #y<yi
    for i in range(y):
      for j in range(W):
        l[i][j]=1
  else: #y>yi
    for i in range(y,H):
      for j in range(W):
        l[i][j]=1
print(W*H-sum([sum(i) for i in l]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200000
#define LL long long int

struct Line {
    LL m, b;
    Line(LL _m, LL _b) {
        m = _m;
        b = _b;
    }
};

int N, pointer;
LL C, h[MAXN + 3], dp[MAXN + 3];
vector<Line> lines;

/*
line 1 and line 2 cross at x = (b2 - b1)/(m1 - m2)
*/
bool useless(Line line1, Line line2, Line line3) {
    return (line3.b - line2.b) * (line1.m - line2.m) < (line2.b - line1.b) * (line2.m - line3.m);
}

void insert(Line line) {
    while (lines.size() > 1 && useless(lines[lines.size() - 2], lines[lines.size() - 1], line))
        lines.pop_back();

    lines.push_back(line);
}

LL query(LL x) {
    while (pointer < lines.size() - 1 && (lines[pointer + 1].b - lines[pointer].b) < x * (lines[pointer].m - lines[pointer + 1].m))
        pointer++;

    return lines[pointer].m * x + lines[pointer].b;
}

int main() {
    cin >> N >> C;
    for (int i = 1; i <= N; i++)
        cin >> h[i];

    /*
    dp[j] = min(dp[i] + (hj - hi)^2 + C)
    dp[j] = min(dp[i] + hj^2 + hi^2 - 2*hj*hi + C)
    dp[j] = hj^2 + C + min(-2*hj*hi + dp[i] + hi^2)

    m is -2*hi
    b is dp[i] + hi^2
    */
    pointer = 0;
    dp[1] = 0;
    insert(Line(-2 * h[1], dp[1] + h[1]*h[1]));
    for (int j = 2; j <= N; j++) {
        LL queryResult = query(h[j]);
        dp[j] = h[j] * h[j] + C + queryResult;

        insert(Line(-2 * h[j], dp[j] + h[j] * h[j]));
    }

    cout << dp[N] << endl;
}


Measured memory_bytes: 9072
N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse = True)

alice = 0
bob = 0
count = 0

for i in range(0, len(a)):
	if count % 2 == 0:
		alice += a.pop(0)
	elif count % 2 == 1:
		bob += a.pop(0)
	count += 1

print(alice - bob)

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

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

  rep(i, s.size()) {
    int tmp=(int)(s[i]-'A')+n;
    if (tmp>=26) tmp-=26;
    cout<<(char)(tmp+'A');
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

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

  return os;
}

using ll = long long;

int main() {
  int N;

  cin >> N;

  std::vector<ll> a(N), sum(N + 1, 0LL);

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

  std::map<ll, ll> mp;

  for (int i = 0; i < N + 1; ++i) {
    mp[sum[i]]++;
  }

  ll ans = 0;

  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    ans += (itr->second * (itr->second - 1)) / 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;
//#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}



int main() {
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, M, A[100000]; cin >> N >> M;
  prique<int> que;
  int S = 0;
  REP(i, N){
    cin >> A[i]; S += A[i];
    int tmp = A[i];
    while(tmp != 0){
      A[i] /= 2;
      que.push(tmp - A[i]);
      tmp = A[i];
    }
  }
  REP(i, M){
    if(!que.empty()){
      S -= que.top(); que.pop();
    }
  }
  cout << max((int)0, S) << endl;
}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<int> tri;
vector<int> b;
vector<int> a;
int ansa[1000005];
int ansb[1000005];

int main()
{
	tri.push_back(0);
	a.push_back(0);
	FOR(i, 1, 10000) tri.push_back(tri[i - 1] + i);
	FOR(i, 1, 10000)
	{
		a.push_back(a[i - 1] + tri[i]);
		if (a.back() & 1) b.push_back(a.back());
		if (a.back() > 1000001) break;
	}
	fill(ALL(ansa), INF);
	fill(ALL(ansb), INF);
	ansa[0] = ansb[0] = 0;
	REP(j, 1000001)
	{
		REP(i, a.size())
		{
			int t = j + a[i];
			if (t > 1000001) break;
			ansa[t] = min(ansa[t],ansa[j] + 1);
		}
	}
	REP(j, 1000001)
	{
		REP(i, b.size())
		{
			int t = j + b[i];
			if (t > 1000001) break;
			ansb[t] = min(ansb[t],ansb[j] + 1);
		}
	}


	int n;
	while (cin >> n, n)
	{
		cout << ansa[n] << " " << ansb[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 9132
using System;

namespace ABC081
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(A_PlacingMarbles.CountSquare(s));
        }
    }
  
  public class A_PlacingMarbles
    {
        public static int CountSquare(string s)
        {
            var cnt = 0;
            if (s[0] == '1') cnt++;
            if (s[1] == '1') cnt++;
            if (s[2] == '1') cnt++;

            return cnt;
        }
    }
}

Measured memory_bytes: 25816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int x=in(),a=in(),b=in();
	print((x-a)%b);
	return 0;
}

Measured memory_bytes: 128
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	int n,r;
	cin>>n>>r;	
	int ans = 0;
	if(n >= 10){
		ans = r;
	}
	else{
		ans = r + 100*(10-n);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def pricing(A, B, C, tmp):
    A_price = tmp * A
    B_price = tmp * B
    AnB_price = A_price + B_price
    AB_price = tmp * 2 * C
    price = AnB_price if AnB_price < AB_price else AB_price
    return price


A, B, C, X, Y = map(int, input().split())
ans = 0
tmp = min(X, Y)
price = pricing(A, B, C, tmp)

if X > Y:
    tmp = max(X, Y) - tmp
    price += pricing(A, 0, C, tmp)
else:
    tmp = max(X, Y) - tmp
    price += pricing(0, B, C, tmp)

print(price)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
    ll n, m;

    cin >> n >> m;

    cout << min(n, m / 2) + (m - min(n, m / 2) * 2) / 4 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct node{
	int nxt, to;
};
node g[maxn];
int head[maxn];
void add(int i , int u , int v){
	g[i].nxt = head[u];
	g[i].to = v;
	head[u] = i;
}
bool vis[maxn];
int a[maxn] , ans = 0;
void bfs(int x , int Max){
	queue<int>q;
	q.push(x);
	vis[x] = 1;
	int to , now;
	bool ok = 1;
	while(!q.empty()){
		now = q.front() , q.pop();
		for(int i = head[now];i != 0;i = g[i].nxt){
			to = g[i].to;
			if(!vis[to]){
				q.push(to);
				vis[to] = 1;
				if(a[to] > Max)Max = a[to];
				else if(a[to] == Max)ok = 0;
			}
		}
	}
	if(ok)ans++;
}
int main(){
	int n , m , u , v;cin >> n >> m;
	fo(i,1,n)cin >> a[i];
	fo(i,1,m){
		cin >> u >> v;
		add(i,u,v);
		add(i+m,v,u);
	}
	bool ok;
	fo(i,1,n){
		ok = 1;
		for(int j = head[i];j != 0;j = g[j].nxt){
			if(a[i] <= a[g[j].to])ok = 0;
		}
		if(ok)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5956
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n;
    scanf("%d",&n);
    int i, j, t[n+1], x[n+1], y[n+1], disp, tm;
    t[0] = 0;  x[0] = 0;  y[0] = 0;
    for(i=1; i<=n; i++) scanf("%d %d %d",&t[i],&x[i],&y[i]);
    for(i=0,j=1; j<=n; i++,j++){
        disp = abs(x[j]-x[i]) + abs(y[j]-y[i]);
        if(disp > (tm = t[j] - t[i]) || ((tm-disp) % 2) != 0){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<int> a(n);
	vector<vector<int>> graph(n, vector<int>());
	vector<P> pa(n);
	rep(i, n) {
		cin >> a[i];
		pa.pb(P(a[i], i));
	}
	sort(all(pa));
	rep(_, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	vector<int> ans(n, -1);
	for (P p : pa) {
		bool flag = false;
		int num = p.first; int v = p.second;
		for (int i : graph[v]) {
			if (a[i] < a[v] && ans[i] == 0) flag = true;
		}
		if (flag) ans[v] = 1;
		else ans[v] = 0;
	}
	rep(i, n) if (ans[i]) cout << i + 1 << ' ';
	cout << '\n';
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

template<class T>
void VPout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i].first<<" "<<V[i].second<<'\n';
    }
    cout<<"end\n"<<endl;
}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));


ll dp[110][5][3];

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

    string N;
    int K;
    cin>>N>>K;
    dp[0][0][0]=1;
    for(int i=0;i<(int)N.size();i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<3;k++){
                if(dp[i][j][k]==0) continue;
                if(k==2){
                    dp[i+1][j+1][2]+=dp[i][j][2]*9;
                    dp[i+1][j][2]+=dp[i][j][2];       
                }else if(k==1){
                    int x=(int)( N[i]-'0' );
                    if(x==0){
                        dp[i+1][j][1]+=dp[i][j][k];
                    }else{
                        dp[i+1][j][2]+=dp[i][j][k];
                        dp[i+1][j+1][2]+=dp[i][j][k]*(x-1);
                        dp[i+1][j+1][1]+=dp[i][j][k];
                    }
                }else{
                    dp[i+1][j][k]+=dp[i][j][k];
                    if(i==0){
                        int x=(int)( N[i]-'0' );
                        dp[i+1][j+1][2]+=dp[i][j][k]*(x-1);
                        dp[i+1][j+1][1]+=dp[i][j][k];
                    }else{
                        dp[i+1][j+1][2]+=dp[i][j][k]*9;
                    }
                }
            }
        }
    }
    cout<<dp[(int)N.size()][K][1]+dp[(int)N.size()][K][2]<<endl;
}

Measured memory_bytes: 256