akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=1000010, Mod=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,a[N],sum;
inline int ksc(int x,int p) { int res=1; for(;p;p>>=1, x=x*x%Mod) if(p&1) res=res*x%Mod; return res; }
signed main()
{
    n=read();
    int inv2=ksc(2,Mod-2);
    for(ri int i=1;i<=n;i++) a[i]=read(), sum=(sum+a[i])%Mod;
    int res=0;
    for(ri int i=1;i<=n;i++) res=res+a[i]%Mod*(sum-a[i]+Mod)%Mod, res%=Mod;
    printf("%lld\n",res*inv2%Mod);
    return 0;
}

Measured memory_bytes: 5320
#include <iostream>
using namespace std;
int main()
{
  int n,i,j,s,a,b;
  while(cin >> n, n){
    a = -1;
    b = 501;
    while(n--){
      s = 0;
      for(i=0;i<5;i++){
	cin >> j;
	s += j;
      }
      if(a < s) a = s;
      if(b > s) b = s;
    }
    cout << a << " " << b << endl;
  }
  return 0;
}

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

int main() {
  int N,M,i,j,k,l;
  int x=0;
  cin >> N >> M;
  vector<vector<char>> A(N,vector<char>(N));
  vector<vector<char>> B(M,vector<char>(M));
  vector<vector<char>> X(M,vector<char>(M));
  for(i=0; i<N; i++){
    for(j=0; j<N; j++) cin >> A.at(i).at(j);
  }
  for(i=0; i<M; i++){
    for(j=0; j<M; j++) cin >> B.at(i).at(j);
  }
  for(i=0; i<N-M+1; i++){
    for(j=0; j<N-M+1; j++){
      for(k=0; k<M; k++){
        for(l=0; l<M; l++) X[k][l] = A[i+k][j+l];
      }
      if(B == X){
        x++;
        break;
      }
    }
  }
  if(x>0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<functional>
#include<queue>
using namespace std;

struct edge
{
	int from, to, cost;
	bool operator>(const edge& other)const {
		return cost > other.cost;
	}
};

using edges = vector <edge>;
using graph = vector<edges>;

void add_edge(graph& g, int from, int to, int cost)
{
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{ to,from,cost });
}

edges prim(graph& g)
{
	const int N = g.size();
	vector<bool>used(N);
	used[0] = true;
	priority_queue<edge, vector<edge>, greater<edge>>p_que;
	for (auto e : g[0])
	{
		p_que.push(e);
	}
	edges mst;
	while (!p_que.empty())
	{
		auto e = p_que.top();
		p_que.pop();
		if (used[e.to])
		{
			continue;
		}
		mst.push_back(e);
		used[e.to] = true;
		for (auto new_e : g[e.to])
		{
			p_que.push(new_e);
		}
	}
	return mst;
	

}

int main()
{
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++)
	{
		int from, to, cost;
		cin >> from >> to >> cost;
		add_edge(g, from, to, cost);
	}
	const auto mst = prim(g);
	int ans = 0;
	for (auto e : mst)
	{
		ans += e.cost;

	}
	cout << ans << endl;

}




Measured memory_bytes: 10132
#include <iostream>
using namespace std;
int main(){
    char s[16];
    cin>>s;
    int cnt=0;
    int i=0;
    while(s[i]!='\0'){
        if(s[i]=='o')
            cnt++;
        i++;
    }
    if((15-i)+cnt>=8)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
string s;
int flag;
int cnt=0;
cin>>s;
vector<string>a;
a={"dream","dreamer","erase","eraser"};
reverse(s.begin(),s.end());
for(int i=0;i<a.size();i++){
    reverse(a.at(i).begin(),a.at(i).end());
}
while(1){
    flag=0;
for(int j=0;j<a.size();j++){
    if(s.substr(cnt,a.at(j).size())==a.at(j)){
        cnt+=a.at(j).size();
        flag++;
    }
}
if(flag==0){
    cout<<"NO"<<endl;
    break;
}
if(cnt>=s.size()){
    cout<<"YES"<<endl;
    break;
}
}

}








Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    int n,i,max=0,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]>a[max])max=i;
    }
    a[max]=a[max]/2;
    for(i=0;i<n;i++)
        sum+=a[i];
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(u,a,b) for(int u=(a);u<(b);u++)
#define rrep(u,a,b) for(int u=(b)-1;u>=(a);u--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

struct HopcroftKarp {
	int n;
	vector<vector<int>> g;
	vector<int> match, dist;
	vector<bool> used, alive;
	HopcroftKarp(int n) : n(n), g(n), match(n), dist(n), used(n), alive(n, true) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		fill(match.begin(), match.end(), -1);
		while (true) {
			buildAlternatingLevelGraph();
			fill(used.begin(), used.end(), false);
			int flow = 0;
			for (int u = 0; u < n; u++)
				if (match[u] == -1 && augment(u))
					flow++;
			if (flow == 0)break;
			cnt += flow;
		}
		return cnt;
	}
	void buildAlternatingLevelGraph() {
		fill(dist.begin(), dist.end(), -1);
		queue<int> q;
		for (int u = 0; u < n; u++)
			if (match[u] == -1) {
				q.emplace(u);
				dist[u] = 0;
			}
		while (q.size()) {
			int u = q.front(); q.pop();
			for (int v : g[u]) {
				int w = match[v];
				if (w != -1 && dist[w] == -1) {
					dist[w] = dist[u] + 1;
					q.emplace(w);
				}
			}
		}
	};
	bool augment(int u) {
		used[u] = true;
		for (int v : g[u]) {
			if (!alive[v])continue;
			int w = match[v];
			if (w == -1 || (!used[w] && dist[w] == dist[u] + 1 && augment(w))) {
				match[u] = v;
				match[v] = u;
				used[v] = true;
				return true;
			}
		}
		return false;
	}
};

template<class T, class ...Tail>
void tiedSort(vector<T> &a, vector<Tail>&... tail) {
	int n = a.size();
	using S = tuple<T, Tail...>;
	vector<S> s(n);
	for (int i = 0; i < n; i++)
		s[i] = make_tuple(a[i], tail[i]...);
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)
		tie(a[i], tail[i]...) = s[i];
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		vector<vector<int>> g(N, vector<int>(N, INF));
		rep(i, 0, M) {
			int u, v, d; cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		rep(i, 0, N)
			g[i][i] = 0;
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N) {
			if (g[i][k] != INF&&g[k][j] != INF)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}

		vector<int> p(L), t(L); rep(i, 0, L) {
			cin >> p[i] >> t[i];
		}
		tiedSort(t, p);
		HopcroftKarp hk(L + L);
		int source = hk.n - 2, sink = source + 1;
		rep(i, 0, L) {
			rep(j, i + 1, L) {
				if (g[p[i]][p[j]] <= t[j] - t[i]) {
					hk.addEdge(i, L + j);
				}
			}
		}
		auto ans = L - hk.maximumMatching();
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    int h,w;
    while(true){
        cin >> h >>w;
        if(h==0&&w==0)
        break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1,0,1,0 }; const int dy[] = { 0,1,0,-1 };

int main() {
	int n;
	cin >> n;
	int mi = 1001;
	int ma = -1;
	REP(i, n) {
		int a;
		cin>>a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << ma - mi << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c, i, j, temp;
  scanf("%d %d %d", &a, &b, &c);
  int int_arr[3] = {a,b,c};

  for (i = 0; i < 3; i++) {
    for (j = 3 - 1; j > i; j--) {
      if(int_arr[j] < int_arr[j-1]) {
        temp = int_arr[j];
        int_arr[j] = int_arr[j - 1];
        int_arr[j - 1] = temp;
      }
    }
  }
  printf("%d %d %d\n", int_arr[0], int_arr[1], int_arr[2]);
	return 0;
}


Measured memory_bytes: 2112
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		n = sc.nextInt();
		int [][]v = new int[n][3];
		for(int i = 0; i < n; i++) {
			v[i][0] = sc.nextInt();
			v[i][1] = sc.nextInt();
			v[i][2] = sc.nextInt();
		}
		int [][]dp = new int[n][3];
		int i;
		dp[0][0] = v[0][0];
	    dp[0][1] = v[0][1];
	    dp[0][2] = v[0][2];
	    for(i = 1; i < n; i++){
	        dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2]) + v[i][0];
	        dp[i][1] = Math.max(dp[i-1][0], dp[i-1][2]) + v[i][1];
	        dp[i][2] = Math.max(dp[i-1][0], dp[i-1][1]) + v[i][2];
	    }
	    System.out.println(Math.max(Math.max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]));
	}

}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

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

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

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), T = input();
    auto P = make_vector(N, make_pair(0, 0));
    cin >> P;
    
    whole(sort, P);
    
    auto dp = make_vector(T + 1, 0);
    range(i, 0, N) {
        i32 a = P[i].first;
        i32 b = P[i].second;
        rrange(t, 0, T) {
            chmax(dp[min(t + a, T)], dp[t] + b);
        }
    }
    
    cout << dp[T] << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,x,y,ans,fa[200001];
map<int,int> num;
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
signed main()
{
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	while(m--)
	{
		scanf("%lld %lld",&x,&y);
		if(find(x)!=find(y))
			fa[find(x)]=find(y);
	}
	for(int i=1;i<=n;i++)
	{
		num[find(i)]++;
		ans=max(ans,num[find(i)]);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 17716
/*
 * atcoder/abc124_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX = 100100;
string S;
int N;

int dp[MAX][2] = {0};

void dump() {
  loop(i,0,2) {
    loop(n,0,N+1) {
      cout << dp[n][i] << " ";
    }
    cout << endl;
  }
}

void solve() {
  cin >> S;
  N = S.size();
  loop(n,0,N+1) loop(i,0,2) dp[n][i] = 500000;

  for (int n=0; n<N; n++) {
    int d = S[n] - '0';
    if (n==0) {
      dp[0][0] = d==1;
      dp[0][1] = d==0;
      continue;
    }
    for (int i=0; i<2; i++) {
      chmin(dp[n][i], dp[n-1][!i] + (d!=i));
    }
  }
  cout << min(dp[N-1][0], dp[N-1][1]) << endl;
  // dump();
}


int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int main(){
	int N;
	cin>>N;
	ll ans=0;
	ll mn=0;
	rep(i,N){
		ll x;
		cin>>x;
		ll p=mn+1;
		ll t=(x-1)/p;
		ans+=t;
//		cout<<"  p="<<p<<" t="<<t<<endl;
		if(i==0) mn=1;
		else if(x==mn+1) mn++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int h1, m1, h2, m2, K;
    scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &K);
    printf("%d\n", 60*(h2-h1) + (m2-m1) - K);
}

Measured memory_bytes: 3812
#include <iostream>
#include <cstdint>
#include <cstdio>
using namespace std;

int main() {
	int q;
	uint32_t x;
	uint32_t i;
	double d;
	
	cin >> q;
	while(q--) {
		scanf("%08x", &x);
		
		i = (x << 1) >> 8;
		d = (x << 25) >> 25;
		
		for (int j = 0; j < 7; j++) d /= 2;
		
		if (x & (1 << 31)) putchar('-');
		if (d == 0.0) printf("%u.0\n", i);
		else {
			printf("%u.", i);
			while (d - (int)d > 0) {
				d *= 10;
				printf("%d", (int)d);
				d -= (int)d;
			}
			putchar('\n');
		}
	}
	
	return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

  rep(i, m){
    cin >> a[i];
  }

  vector<ll> dp(n + 1);

  dp[0] = 1;
  int itr = 0;
  if(m > 0 && a[0] == 1){
    dp[1] = 0;
    itr++;
  } else {
    dp[1] = 1;
  }


  for(int i = 2; i <= n; ++i){
    if(itr < m && i == a[itr]){
      dp[i] = 0;
      itr++;
    } else {
      dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
    }
  }

  cout << dp[n] << endl;


}

Measured memory_bytes: 1792
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int num[8];
int main()
{
	memset(num,0,sizeof(num));
	int n=0,a,b;
	rep(i,3){
		cin>>a>>b;num[a]++;num[b]++;
	}
	rep(i,5){
		n+=num[i]%2;
	}
	if(n>2) cout<<"NO"<<endl;else cout<<"YES"<<endl;
}


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

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

using ll = long long;

int main() {
  ll N, Z, W;
  std::vector<ll> a;

  cin >> N >> Z >> W;
  a.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  ll ans = llabs(a[N - 1] - W);
  if (N >= 2) ans = std::max(ans, llabs(a[N - 2] - a[N - 1]));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s1,s2,a[10]={"0","","2","3","4","5","6","7","8","9"};
		cin>>s1>>s2;
		int l1=s1.size(),l2=s2.size(),n1=0,n2=0,kei=1;
		for(int j=0;j<l1;j++){
			if(s1[j]=='2') kei=2;
			else if(s1[j]=='3') kei=3;
			else if(s1[j]=='4') kei=4;
			else if(s1[j]=='5') kei=5;
			else if(s1[j]=='6') kei=6;
			else if(s1[j]=='7') kei=7;
			else if(s1[j]=='8') kei=8;
			else if(s1[j]=='9') kei=9;
			else if(s1[j]=='m'){
				n1=n1+kei*1000;
				kei=1;
			}
			else if(s1[j]=='c'){
				n1=n1+kei*100;
				kei=1;
			}
			else if(s1[j]=='x'){
				n1=n1+kei*10;
				kei=1;
			}
			else if(s1[j]=='i'){
				n1=n1+kei;
				kei=1;
			}
		}
		for(int j=0;j<l2;j++){
			if(s2[j]=='2') kei=2;
			else if(s2[j]=='3') kei=3;
			else if(s2[j]=='4') kei=4;
			else if(s2[j]=='5') kei=5;
			else if(s2[j]=='6') kei=6;
			else if(s2[j]=='7') kei=7;
			else if(s2[j]=='8') kei=8;
			else if(s2[j]=='9') kei=9;
			else if(s2[j]=='m'){
				n2=n2+kei*1000;
				kei=1;
			}
			else if(s2[j]=='c'){
				n2=n2+kei*100;
				kei=1;
			}
			else if(s2[j]=='x'){
				n2=n2+kei*10;
				kei=1;
			}
			else if(s2[j]=='i'){
				n2=n2+kei;
				kei=1;
			}
		}
		int t=n1+n2;
		int m[4]={t/1000,(t/100)%10,(t/10)%10,t%10};
		string s[4]={"m","c","x","i"};
		for(int j=0;j<4;j++){
			if(m[j]!=0){
				cout<<a[m[j]]<<s[j];
			}
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 1208
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,a,b = li()
x = li()

ans = 0
for i in range(n-1):
    if a*(x[i+1]-x[i]) > b:
        ans += b
        
    else:
        ans += a*(x[i+1]-x[i])
        
print(ans)

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll l = 1, r;
    rep(i, n) {
        cin >> a[i];
        r = max(a[i], r);
    }
    while (l != r) {
        ll mid = (r - l)/2 + l;
        ll s = 0;
        rep(i, n) {
            s += (a[i]-1)/mid;
        } 
        if (s <= k) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define hell 1000000007
#define MAX 1000000000
#define max_int 1000000
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define pi 3.1415926536
#define r0 return 0
#define rep(i,a,b) for(ll i = a;i<b;i++)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  	int k;
  cin>>k;
  cout<<a[k-1];
  
    

}
 

Measured memory_bytes: 256
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  X[i]=[X[i][0]+X[i][1],X[i][0]-X[i][1]]
print(max([max([X[i][j] for i in range(N)])-min([X[i][j] for i in range(N)]) for j in range(2)]))

Measured memory_bytes: 170232
N=int(input())
ans=[0]*10001
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n=x*x+y*y+z*z+x*y+y*z+z*x
            if n<=10000:
                ans[n]+=1
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 74024
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;

template<class T>
T normalize_mod(T a,T m){
	return (m+a%m)%m;
}

int main(){
	ll n,m;
	cin>>n>>m;
	vector<ll> s,t;
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		s.push_back(temp);
	}
	for(ll i2=0;i2<m;i2++){
		ll temp;
		cin>>temp;
		t.push_back(temp);
	}
	ll **d = new ll*[n+1];
	for(ll i1=0;i1<n+1;i1++){
		d[i1]=new ll[m+1];
	}
	for(ll i1=0;i1<n+1;i1++){
		d[i1][0]=1;
	}
	for(ll i1=0;i1<m+1;i1++){
		d[0][i1]=1;
	}

	for(ll i1=1;i1<n+1;i1++){
		for(ll i2=1;i2<m+1;i2++){
			if(s[i1-1]==t[i2-1]){
				d[i1][i2]=normalize_mod<ll>(d[i1-1][i2]+d[i1][i2-1],1000000007);
			}else{
				d[i1][i2]=normalize_mod<ll>(d[i1-1][i2]+d[i1][i2-1]-d[i1-1][i2-1],1000000007);
			}
		}
	}
	cout<<d[n][m]<<endl;
}


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

int main(){
  int w, n;
  vector<int> que;
  cin >> w >> n;
  for(int i = 1;i <= w;i++) que.push_back(i);
  for(int i = 0;i < n;i++){
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(que[a-1], que[b-1]);
  }

for(int i = 0;i < w;i++){
  cout << que[i] << "\n";
}
  return 0;
}



Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] num = line.split(" ");
        int a = Integer.parseInt(num[0]);
        int b = Integer.parseInt(num[1]);
        int c = Integer.parseInt(num[2]);
        int result = Math.min(a + b, Math.min(b + c, c + a));
        System.out.println(result);
    }
}

Measured memory_bytes: 21204
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
s = sum(A)
d = 1 / (4 *  M) * s

A.sort(reverse = True)
count = 0
for i in range(N):
    if A[i] >= d:
        count += 1
    else:
        break
if count >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5716
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

int n, mod;
vector<int> et[100000];
int dp1[100000];	//dp1[u] = 頂点0を根としたとき、部分木uを塗る方法であってuが黒いものは何通り？
int dp2[100000];	//dp2[v] = 頂点vを根としたとき、vを黒くする塗り方は何通り？

int dfs1(int p, int v) {
	int i, ret = 1;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		ret *= dfs1(v, nv) + 1;
		ret %= mod;
	}
	return dp1[v] = ret;
}

//pDp … pを根としたとき、pを黒く塗りvを白く塗る方法は何通り？
int leafId[100000];
void dfs2(int p, int v, int pDp) {
	if (et[v].size() == 0) return;
	//cout << p << " " << v << " " << pDp << endl;
	int i;
	vector<int> ra(et[v].size() + 1);
	vector<int> rb(et[v].size() + 1);
	
	int cor = 0;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		leafId[nv] = cor;
		cor++;
	}
	
	ra[0] = 1;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		ra[leafId[nv] + 1] = ra[leafId[nv]] * (dp1[nv] + 1);
		ra[leafId[nv] + 1] %= mod;
	}
	
	rb[cor] = 1;
	rrep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		rb[leafId[nv]] = rb[leafId[nv] + 1] * (dp1[nv] + 1);
		rb[leafId[nv]] %= mod;
	}
	
	//cout << "p = " << p << ", v = " << v << ", pDp = " << pDp << endl;
	//rep(i, cor + 1) cout << "ra[" << i << "] = " << ra[i] << endl;
	//rep(i, cor + 1) cout << "rb[" << i << "] = " << rb[i] << endl;
	
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		int res = ra[leafId[nv]] * rb[leafId[nv] + 1] % mod * (pDp + 1) % mod;
		dp2[nv] = (res + 1) * dp1[nv] % mod;
		//cout << "dp2[" << nv << "] = " << dp2[nv] << endl;
		dfs2(v, nv, res);
	}
}

signed main() {
	int i;
	
	cin >> n >> mod;
	rep(i, n - 1) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		et[x].push_back(y);
		et[y].push_back(x);
	}
	
	dfs1(-1, 0);
	dp2[0] = dp1[0];
	dfs2(-1, 0, 0);
	
	rep(i, n) cout << dp2[i] << endl;
	return 0;
}

Measured memory_bytes: 19584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.function.LongSupplier;

public class Main{ // 

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

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

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

	static LongSupplier now = new LongSupplier() {
		private long t = System.currentTimeMillis();

		@Override
		public long getAsLong() {
			long a = t;
			t = System.currentTimeMillis();
			long ans = t - a;
			return ans;
		}
	};

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static int tr(Object... objects) {
		System.out.println("tr:" + Arrays.deepToString(objects));
		return 0;
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int x = cin.nextInt();
		int t = cin.nextInt();

		now.getAsLong();

		long ans = Math.max(x - t, 0);
		cout.println(ans);

		assert 0 == tr("elapsed", now.getAsLong());
	}

}


Measured memory_bytes: 22740
#include<iostream>
#include<cmath>
using namespace std;
bool field[210];
signed main(){
	int x,n;
	cin>>x>>n;
	for(int i=0;i<n;i++){int a; cin>>a; field[a]=1;
	}
	if(n==0||field[x]==0){cout<<x<<endl; return 0;
	}
	for(int i=1;;i++){
		if(field[x-i]==0){cout<<x-i<<endl; return 0;
		}
		if(field[x+i]==0){cout<<x+i<<endl; return 0;
		}
	}
	
} 

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

using namespace std;
int main(){
  int w,h,x,y,r,k,t;
  cin>>w>>h>>x>>y>>r;
 
  if (x-r>=0 && x+r<=w && y-r>=0 && y+r<=h){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n; cin>>n;
vv<ll> hero(n), house(n+1);
for(int i=0;i<=n;++i) cin>>house[i];
for(int i=0;i<n;++i) cin>>hero[i];

ll ans=0;
for(int i=0;i<n;++i){
	if(i && hero[i-1]){
		ll q=min(house[i], hero[i-1]);
		ans+=q;
		house[i]-=q;
	}
	ll q=min(house[i], hero[i]);
	ans+=q;
	hero[i]-=q;
}
ans+=min(hero[n-1],house[n]);
cout<<ans<<el;

return 0;
}


Measured memory_bytes: 1792
import Data.List (sort)

main = do
    [m, n, x] <- map read . words <$> getLine
    ys <- map read . words <$> getLine
    print $ solve x ys
	
solve :: Int -> [Int] -> Int
solve x ys = min lcost rcost
    where
        ys' = sort ys
        lcost = llen
        rcost = rlen
        llen = length $ takeWhile (<x) ys'
        rlen = len - llen
        len = length ys'


Measured memory_bytes: 892
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if n == 1:
    print(0)
    exit()
factors = factorization(n)
ans = 0
for f, num in factors:
    i = 1
    while num >= i:
        num -= i
        i += 1
        ans += 1
print(ans)

Measured memory_bytes: 9488
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int t=scan.nextInt();
		Set<String> set=new HashSet<String>();
		while((t--)!=0){
			String s=scan.next();
			String ch=scan.next();
			if(s.equals("insert")){
				set.add(ch);
			}else{
				if(set.contains(ch))
					System.out.println("yes");
				else
					System.out.println("no");
			}
			
			
			
		}
	}


}

Measured memory_bytes: 268888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

      int a, b, numOfPalindromic = 0;
          int[] digit = new int[5];
          Scanner sc = new Scanner(System.in);

          a = sc.nextInt(); b = sc.nextInt();

          for(; a<=b; a++){
          	for(int i=0; i<digit.length; i++)
          		digit[i] = (a/(int)Math.pow(10, i)) % 10; // digit[0] = １の位, digit[1] = 10の位 ・・・

          	if (digit[0] == digit[4] &&  digit[1] == digit[3])
          			numOfPalindromic++;
          }

          System.out.println(numOfPalindromic);

    }
}

Measured memory_bytes: 21972
// https://atcoder.jp/contests/abc074/tasks/abc074_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, k;
  vector<int> x;

  cin >> n >> k;

  REP(i, n)
  {
    int xi;
    cin >> xi;
    x.push_back(xi);
  }

  int sum = 0;
  REP(i, n)
  {
    sum += 2 * min(x[i], k - x[i]);
  }

  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
    int N; cin >> N;
    vector<string> s(N); for (int i = 0; i < N; ++ i) cin >> s[i];
    int M; cin >> M;
    vector<string> t(M); for (int i = 0; i < M; ++ i) cin >> t[i];
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    int ret = 0;
    map<string, int> ss;
    for (int i = 0; i < N; i++) {
        ss[s[i]]++;
    }
    for (int i = 0; i < M; i++) {
        ss[t[i]]--;
    }
    for (int i = 0; i < N; i++) {
        ret = max(ret, ss[s[i]]);
    }
    cout << ret << endl;
}

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

using namespace std;

int main(){
	int x;
	scanf("%d", &x);

	int y;
	y = x / 100;
	x %= 100;

	if(x == 0 || x > 12){
		if(y != 0 && y <= 12) printf("MMYY\n");
		else printf("NA\n");
	} else {
		if(y != 0 && y <= 12) printf("AMBIGUOUS");
		else printf("YYMM\n");
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin >> k;
	string s;
	cin >> s; 
	if(k >= s.length()) cout << s << endl;
	else{ 
		for(int i = 0; i < k; i++)
			cout << s[i];
		cout <<"..." << endl;
	}
} 

Measured memory_bytes: 3624
H,W = list(map(int,input().split()))
grid = [[i for i in input()] for i in range(H)]
cntH = [[0 for i in range(W)] for i in range(H)]
cntW = [[0 for i in range(W)] for i in range(H)]

for h in range(H):
  cnt = 0
  for w in range(W):
    if grid[h][w] == "#":
      cnt = 0
    else:
      cnt += 1
      cntW[h][w] = cnt

for h in range(H-1,-1,-1):
  cnt = 0
  for w in range(W-1,-1,-1):
    if grid[h][w] == "#":
      cnt = 0
    elif cnt == 0:
      cnt = cntW[h][w]
    else:
      cntW[h][w] = cnt

for w in range(W):
  cnt = 0
  for h in range(H):
    if grid[h][w] == "#":
      cnt = 0
    else:
      cnt += 1
      cntH[h][w] = cnt

for w in range(W-1,-1,-1):
  cnt = 0
  for h in range(H-1,-1,-1):
    if grid[h][w] == "#":
      cnt = 0
    elif cnt == 0:
      cnt = cntH[h][w]
    else:
      cntH[h][w] = cnt

ans = 0
for h in range(H):
  for w in range(W):
    ans = max(ans,cntW[h][w]+cntH[h][w])

print(ans-1)

Measured memory_bytes: 250376
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int n = min(x, y);

    int cost = 0;

    if(a+b > 2*c){
        // c is cheaper
        cost += n * (2*c);
    }else{
        cost += n * (a+b);
    }

    if(x > y){
        int rest = x - y;

        int cost0 = rest * a;
        int cost1 = rest * (2*c); 
        
        cost += min(cost0, cost1);
    }
    else if(x < y){
        int rest = y - x;

        int cost0 = rest * b;
        int cost1 = rest * (2*c);

        cost += min(cost0, cost1);
    }

    p(cost);
    
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

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

	int n, l;
	cin >> n >> l;

	int ans = 0;
	int mi = INF;
	int idx = -1;
	for(int i = 0; i < n; i++) {
		ans += i + l;
		if (mi > abs(i + l)) {
			mi = abs(i + l);
			idx = i;
		}
	}

	out(ans - (idx + l));

	return 0;
}

Measured memory_bytes: 256
n=int(input())
l={}
mx=0
for i in range(n):
    s=input()
    if s not in l:
        l[s]=1
    else:l[s]+=1
    mx=max(mx,l[s])
ans=[]
for j in l:
    #print("jの中身",j,"l[j]の中身",l[j])
    if l[j]==mx:
        ans.append(j)
        #print(ans)
#print(ans)
ans.sort()
for k in ans:print(k)

Measured memory_bytes: 32152
#include<stdio.h>
int main(){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b>c+d) puts("Left");
	else if(a+b<c+d) puts("Right");
	else puts("Balanced");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long x, y, d;
int n, ans=0;
int main() {
   cin >> n >> d;
   while (n--) {
       cin >> x >> y;
       if (x*x+y*y<=d*d) ans++;
   }
   
   cout << ans;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end())
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define PI 3.14159265358979
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
using namespace std;

int main(){	
	int n,a,b;
	int u = 0;
	cin >> n >> a >> b;
	rep(i, 1, n+1) {
		int x = i;
		int ans = 0;
		while (x > 0) {
			ans += x % 10;
			x /= 10;
		}
		if (a <= ans&&ans <= b) {
			u += i;
		}
	}
	cout << u << endl;
	
	return 0;
}



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

char a[4];

int b[26];
int main()
{
    cin >> a;
    for (int i = 0; i < 4; ++i)
        b[a[i] - 'A']++;
    for (int i = 0; i < 26; ++i)
    {
        if (b[i] == 0 || b[i] == 2)
            continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};



//20:10
//20:13
//
int main(){
    cout << fixed << setprecision(16) << endl;
    ll W, H, X, Y;
    cin >> W >> H >> X >> Y;
    double ans =W*H;
    ans = (double)ans/ 2;
    if (X + X == W && Y + Y == H)
    {
        cout << ans << " " << 1 << endl;
    }
    else{
        cout << ans << " " << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>

using namespace std;

int main(void){
	
	int C[3];
	
	while(scanf("%d %d %d" ,&C[0], &C[1], &C[2]) != EOF){
		int card[16]={0};
		int my;
		int out = 0;
		
		for(int i = 0; i < 3; i++)card[C[i]] = 1;
		
		my = C[0] + C[1];
		
		for(int i = 1; i < 11; i++){
			if(card[i] == 0 && my + i > 20){
				out++;
			}
		}
		
//		printf("%dÂ:%lf\n", out, 1-out/7.0);
		
		if(my <= 10){
			puts("YES");
		}else if(out == 0){
			puts("YES");
		}else{
			printf("%s\n", 1-out/7.0>=0.5?"YES":"NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
 
#define WHITE 0
#define BLACK 1
 
int **matrix;
int *d;
int *parent;
int *color;
 
void dijkstra(int);
 
int main()
{
  int n,i,j,k,u,v;
  scanf("%d",&n);
 
  color =  malloc(n * sizeof(int ));
  d =  malloc(n * sizeof(int ));
  parent = malloc(n * sizeof(int));
 
  matrix = malloc(n * sizeof(int *));
  for(i=0;i<n;i++)
    matrix[i] = malloc(n * sizeof(int));
  
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      matrix[i][j] = -1;
  
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d",&v);
	  scanf("%d",&matrix[u][v]);
	}
    }
  
  dijkstra(n);
  
  for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
  
  free(d);
  free(color);
  free(parent);
  for(i=0;i<n;i++) free(matrix[i]);
  free(matrix);
 
  return 0;
   
}
 
 
void dijkstra(int n)
{
  int mincost;
  int i,j,u;
  
  for(i=0;i<n;i++)
    {
      d[i] = INT_MAX;
      parent[i] = -1;
      color[i] = WHITE;
    }
  
  d[0] = 0;
  
  while(1)
    {
      mincost = INT_MAX;
      
      for(i=0;i<n;i++)
	{
	  if(color[i] != BLACK && d[i] < mincost)
	    {
	      mincost = d[i];
	      u = i;
	    }
	}
      
      if(mincost == INT_MAX) break;
      
      color[u] = BLACK;
      
      for(i=0;i<n;i++)
	{
	  if(color[i] != BLACK && matrix[u][i] != -1 && matrix[u][i] + d[u] < d[i])
	    {
	      d[i] = matrix[u][i] + d[u];
	      parent[i] = u;
	    }
	}
    }
}

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

int main() {
    int a, b;
    cin >> a >> b;

    if (a >= b) {
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
        cout << endl;
    }
    else {
        for (int i = 0; i < b; i++)
        {
            cout << a;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0]+list(map(int,input().split()))
b = [0]*(n+1)
for i in range(n,0,-1):
    b_sum = sum([b[i*j] for j in range(1,n//i+1)])
    b_sum %= 2
    if a[i] == 1 and b_sum == 0:
        b[i] = 1
    if a[i] == 0 and b_sum == 1:
        b[i] = 1
print(sum(b))
for i in range(1,n+1):
    if b[i]==1:
        print(i)

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N + 1), B(N);
	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	ll res = 0;
	for (int i = 0; i < N; i++) {
		ll c = min(B[i], A[i]);
		res += c;
		A[i] -= c;
		B[i] -= c;
		c = min(B[i], A[i + 1]);
		res += c;
		A[i + 1] -= c;
		B[i] -= c;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024