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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) {
					if (a[i] + a[j] > a[k]) cnt++;
				}
			}
		}
	}
	cout << cnt << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int ans = 0;
  cin >> n;

  int mh = 0;
  for (int i = 0; i < n; ++i)  {
    int h;
    cin >> h;
    if (mh <= h) {
      ans++;
    }
    mh = max(mh, h);
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
"""
半分全列挙
"""
from bisect import bisect
N,W = map(int,input().split())
items = []
for i in range(N):
    v,w = map(int,input().split())
    items.append((v,w))
A = [(0,0)]
for i in range(N//2):
    v,w = items[i]
    A += [(v+x,w+y) for x,y in A]
A.sort(key = lambda x: (x[1],-x[0]))
underV = -1
tmpA = []
for v,w in A:
    if underV < v and w <= W:
        tmpA.append((v,w))
        underV = v
A = tmpA

B = [(0,0)]
for i in range(N//2,N):
    v,w = items[i]
    B += [(v+x,w+y) for x,y in B]
B.sort(key = lambda x: (x[1],-x[0]))
underV = -1
tmpB = []
for v,w in B:
    if underV < v and w <= W:
        tmpB.append((v,w))
        underV = v
B = tmpB

ans = 0
BV,BW = zip(*B)
for v,w in A:
    idx = bisect(BW,W-w)-1
    ans = max(ans,BV[idx]+v)

print(ans)





Measured memory_bytes: 286508
import sys
from math import ceil


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = int(input())
    T = [int(input()) for _ in range(5)]
    min_t = min(T)
    num = ceil(n / min_t)
    print(5 + num - 1)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
    int n;
    int p[50];
    int i,j;

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

    int ts;

    for(i=0;i<n;i++){
        if(p[i]!=i+1){
            ts++;
        }
    }

    if(ts<=2){
        puts("YES");
    }else{
        puts("NO");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,q,a;
int s[100005];
int main(){
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++)
		s[i]=k;
	for(int i=1;i<=q;i++){
		cin>>a;
		s[a]++;
	}
	for(int i=1;i<=n;i++){
		if(s[i]<=q) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
 
int main()
{
  int num,dig,n;
  int sum = 0;
  std::cin >> num;
  n = num;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  // sum は各桁の和
  if(n%sum==0){
  	std::cout << "Yes" << endl;
  }
  else {
    std::cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N >> L >> R;
	M = N / (L + R);
	K = M * L;
	K += min(N % (L + R), L);
	cout << K << endl;
}

Measured memory_bytes: 256
// AGC040A.cpp
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const int MAX_N = 5e5 + 200;

ll n, acc, ans, seq[MAX_N];
char str[MAX_N];

int main()
{
    scanf("%s", str + 1);
    n = strlen(str + 1);
    seq[1] = 0;
    for (int i = 1; i <= n; i++)
    {
        acc = (str[i] == '<') ? acc + 1 : 0;
        seq[i + 1] = acc;
    }
    acc = 0;
    for (int i = n; i >= 1; i--)
    {
        acc = (str[i] == '>') ? acc + 1 : 0;
        seq[i] = max(seq[i], acc);
    }
    for (int i = 1; i <= n + 1; i++)
        ans += seq[i];
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 4608
import numpy as np

N, D = list(map(int, input().split()))
X = [[int(i) for i in input().split()] for i in range(N)] 
X = np.array(X)

ans = 0
for i in range(N):
    for j in range(N):
        if(i > j):
            dist = np.linalg.norm(X[i]-X[j])
            if dist.is_integer():
                ans += 1
print(ans)

Measured memory_bytes: 14436
#!/usr/bin/env python3

def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


# ????????????b???????????????a??????????????´????????£?°???±???????????????????????????
def project(a, b):
    return a * inner_product(a, b) / (abs(a) ** 2)


# p0??¨p1????????¶??´???????????????p2???????§°?§??????????
def reflect(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    v = project(a, b)
    u = v - b
    p3 = p2 + 2 * u
    return p3


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        t = reflect(p0, p1, p2)
        print("{:.10f} {:.10f}".format(t.real, t.imag))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7812
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll Q;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;
    cin >> K;
    cin >> Q;

    rep(qi,Q){
        cin >> ltmp;
        A.push_back(ltmp);
    }

    vll point;
    rep(ni,N+10){
        point.push_back(0);
    }

    rep(qi,Q){
        ll geti = A[qi];
        point[geti]++;
    }

    for( ll ni = 1 ; ni <=N ; ni++ ){
        //cout << point[ni] << " ";
        if(K+point[ni]>Q){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }

    }

}

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

using namespace std;

bool issquare(vector<string> m, vector<char> &c, int k){
	if(k >= c.size()){
		return true;
	}
	int n = (int)c.size();
	int h = (int)m.size();
	int w = (int)m[0].size();
	int r = 0, l = w, u = h, d = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(m[i][j] == c[k]){
				r = max(r, j);
				l = min(l, j);
				u = min(u, i);
				d = max(d, i);
			}
		}
	}
	//printf("(%d, %d), (%d, %d)\n",r,l,u,d);
	bool flag = true;
	for(int i = u; i <= d; i++){
		for(int j = l; j <= r; j++){
			if(m[i][j] != '?' && m[i][j] != c[k]){
				flag = false;
				i = j = (int)1e9;
			}
		}
	}
	if(!flag)return false;
	for(int i = u; i <= d; i++){
		for(int j = l; j <= r; j++){
			if(m[i][j] == c[k]){
				m[i][j] = '?';
			}
		}
	}
	return issquare(m, c, k+1);
}




int main(){
	int nn; cin >> nn;
	for(int z = 0; z < nn; z++){
		int h,w; cin >> h >> w;
		vector<string> m(h);
		vector<char> c;
		for(int i = 0; i < h; i++){
			cin >> m[i];
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(m[i][j] == '.')continue;
				bool flag1 = true;
				for(int k = 0; k < c.size(); k++){
					if(m[i][j] == c[k]){
						flag1 = false;
						break;
					}
				}
				if(flag1)c.push_back(m[i][j]);
			}
		}
		sort(c.begin(), c.end());/*
		for(int i = 0; i < c.size(); i++){
			cout << c[i] << " ";
		}
		cout << endl;*/
		bool flag = false;
		do{
			if(issquare(m, c, 0)){
				flag = true;
				break;
			}
		}while(next_permutation(c.begin(), c.end()));
		if(flag){
			cout << "SAFE" << endl;
		}
		else{
			cout << "SUSPICIOUS" << endl;
		}
	}
	return 0;
}





Measured memory_bytes: 3140
#include <stdio.h>
#include <string.h>
char moji[200];
int kaisu[100];
 
int main(void)
{
    while(1){
        int n,i,j=0;
        scanf("%s",moji);
        if(moji[0]=='-') break;
        scanf(" %d",&n);
        for(i=0;i<n;i++){
            scanf("%d",&kaisu[i]);
        }
        for(i=0;i<n;i++){
            strncat(moji,moji,kaisu[i]);
            fun(i);
        }
        printf("%s\n",moji);
    }
    return 0;
}
 
int fun(int i){
    int j=0;
    while(moji[j]!='\0'){
        moji[j]=moji[j+kaisu[i]];
        j++;
    }
     
    return 0;
}

Measured memory_bytes: 592
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

map <string,int> my_map;
int n,map_si,m;
int f[3000];
char ch[100];
int id[3000];
struct AA
{
	int p,w,t;
	bool f;
}a[1010];
bool cmp(AA a,AA b)
{
	if (a.w==b.w) return a.t<b.t;
	return a.w<b.w;
}
int main()
{
	scanf("%d",&n);
	while (n!=0)
	{
		my_map.clear();
		map_si=0;
		for (int i=0;i<n;i++)
		{	
			scanf("%s",ch);
			if (my_map[ch]==0) my_map[ch]=++map_si;
			a[i].p=map_si;
			id[map_si]=i;
			scanf("%d%d",&a[i].w,&a[i].t);
			a[i].t=a[i].t/100*60+a[i].t%100;
			a[i].t-=240;
			a[i].f=false;
		}
		scanf("%d",&m);
		for (int i=0;i<m;i++)
		{
			scanf("%s",ch);
			a[id[my_map[ch]]].f=true;
		}
		sort(a,a+n,cmp);
		int now=0,p=0;
		int ans=0;
		bool fail=false;
		while (now<7)
		{
			int q=0,pre=-100;
			f[0]=0;
			while (a[p].w==now)
			{
				while (q<a[p].t)
				{
					q++;
					f[q]=f[q-1];
				}
				if (a[p].f)
				{
					if (a[p].t-30<pre)
					{
						fail=true;
						break;
					}
					pre=a[p].t;
					if (q<30) f[q]=1;
					else f[q]=f[q-30]+1;
				}
				else
				{
					if (a[p].t-30>=pre) 
					{
						if (q<30) f[q]=1;
						else f[q]=max(f[q],f[q-30]+1);
					}
				}
				p++;
			}
			if (fail) break;
			else ans+=f[q];
			now++;
		}
		if (fail) printf("-1\n");
		else printf("%d\n",ans);
		scanf("%d",&n);
	}
}

Measured memory_bytes: 1356
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        System.out.printf("%d %d %d\n", Z,X,Y);
    }
}


Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX (50100)
int main(){
  vector<bool> isP(MAX,true);
  isP[0] = isP[1] = false;
  for(int i=2; i*i<MAX; i++){
    if(isP[i]){
      for(int j=i+i; j<MAX; j+=i){
	isP[j] = false;
      }
    }
  }
  int n;
  while(cin>>n){
    for(int i = n-1; ; i--){
      if(isP[i]){
	cout << i;
	break;
      }
    }
    cout << " ";
    for(int i = n+1; ; i++){
      if(isP[i]){
	cout << i;
	break;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }
    set<int> S;
    rep(i, 0, N) {
        S.insert(A[i]);
    }
    if (S.size() == N) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string n;
    cin >> n;
    ll sum=0;
    rep(i,n.size()){
        sum+=n.at(i)+0-'0';
    }
    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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


using namespace std;
int a[3];

struct node{
    int s = 0;
    int a[3];
    node(int x = 0, int y = 0, int z = 0, int s = 0) {
        a[0] = x;
        a[1] = y;
        a[2] = z;
        this -> s = s;
    }
};

void BFS(){
    node t(a[0], a[1], a[2], 0);
    queue<node> Q;
    Q.push(t);
    while(!Q.empty()){

    }
}
int main(){
    cin >> a[0] >> a[1] >> a[2];/*
    BFS();*/
    int cnt = 0;
    while(a[0] != a[1]|| a[1] != a[2] || a[0] != a[2]){
        sort(a, a + 3);
        if(a[0] < a[2] && a[1] < a[2]){
            a[0] ++;
            a[1] ++;
        }else if(a[1] == a[2]){
            a[0] += 2;
        }

        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    int x;
    cin >> x;
    for(int i = 2; ; ++i) {
    	if((x * i) % 360 == 0) {cout << i; exit(0);}
    }
    return 0;
}

Measured memory_bytes: 3608
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;

const int N = 1e5 + 5;

vector<pair<int, int>> g[N];
int c[N];
int used[N];

void dfs(int v) {
    used[v] = 1;
    for (auto p : g[v]) {
        if (!used[p.first]) {
            c[p.first] = c[v] ^ p.second;
            dfs(p.first);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].emplace_back(v, w & 1);
        g[v].emplace_back(u, w & 1);
    }
    dfs(1);
    for (int i = 1; i <= n; i++) {
        cout << c[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 7936
#include <iostream>
#define rep(i,n) for(long i=0; i<(n); i++)
using namespace std;

int main(){
  long n,q,num[100010],sum=0;
  rep(i,100010){num[i]=0;}
  cin >> n;
  long long a[n];
  rep(i,n){
    cin >> a[i];
    num[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  long long b[q],c[q];
  rep(i,q){
    cin >> b[i] >> c[i];
  }
  
  rep(i,q){
    num[c[i]] += num[b[i]];
    sum = sum + ((c[i]-b[i]) * num[b[i]]);
    num[b[i]] = 0;
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

void dfs(int v, mat &chi, int n, mat &g){
    g[n].push_back(v);
    for(int c: chi[v]) dfs(c, chi, n + 1, g);
}

void dfs2(int v, mat &chi, bools &used, int n){
    used[v] = true;
    if(n == 0) return;
    for(int c: chi[v]) if(!used[c]) dfs2(c, chi, used, n - 1);
}

signed main(){

    int N, K; cin >> N >> K;
    vec a(N); readi(a);
    int ans = 0;
    if(a[0] != 0){
        a[0] = 0;
        ans++;
    }

    if(K >= N - 1){
        cout << ans << endl;
        return 0;
    }

    mat chi(N), g(N);
    FOR(i, 1, N) chi[a[i]].push_back(i);
    dfs(0, chi, 0, g);

    bools used(N, false);
    IFOR(i, K + 1, N){
        for(int v: g[i]){
            if(used[v]) continue;
            ans++;
            int p = v;
            REP(j, K - 1) p = a[p];
            dfs2(p, chi, used, K - 1);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 18176
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define ff first
#define ss second
#define pb push_back
#define fff(i,n) for(int i=0;i<n;i++)
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int n;
    cin >> n;
    fff(i,n) {
        int x;
        cin >> x;
        if(x%2==0) {
            if(x%3==0 or x%5==0) {
                continue;
            }
            else {
                cout << "DENIED" ;
                return 0;
            }
        }
    }
    cout << "APPROVED" ;
    
    
    return 0;
    
}

Measured memory_bytes: 8832
#include<stdio.h>
#include<string.h>
int main(){
char a[200100];
long long int i,j=0,k;
gets(a);
k=strlen(a);
for(i=0;i<=k-1;i++){
    j+=a[i]-'0';}
if(j%9==0){
    printf("Yes\n");
}
else
    printf("No\n");
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S;
  cin >> K >> S;
  int count = 0;
  for(int i=0; i<K+1; i++){
    for(int j=0; j<K+1; j++){
      int z = S - i - j;
        if(0 <= z && z <= K){
          count++;
        
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<cpp_int> A(N);
  vector<cpp_int> B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }
  
  cpp_int cnt{};
  for (int i = N - 1; i >= 0; --i) {
    auto a = cnt + A[i];
    auto b = B[i];
    
    b = (a + b - 1) / b * b;
    auto c = b - a;
    cnt += c;
  }
  cout << cnt << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
void dfs(vector< vector< int > > &G, vector< int > &done, int x) {
	done[x] = 1;
	for (auto j : G[x]) {
		if (done[j])
			continue;
		dfs(G, done, j);
	}
}
signed main() {
	cin >> N >> M;
	vector< vector< int > > G(N);
	rep(i, M) {
		int x, y, z;
		cin >> x >> y >> z;
		--x;
		--y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int ans = 0;
	vector< int > done(N, 0);
	rep(i, N) if (!done[i]) {
		dfs(G, done, i);
		++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#define S str[ima]
using namespace std;
string str;
int ima;

int formula(int P,int Q,int R) {
  int res;
  while(S=='0' || S=='1' || S=='2' || S=='P'||S=='Q'||S=='R'||S=='-'||S=='('){
    if(S=='0' || S=='1' || S=='2' || S=='P'||S=='Q'||S=='R'){
      res = S-'0';
      if(S=='P') res = P;
      if(S=='Q') res = Q;
      if(S=='R') res = R;
      ima++;
    }
    else if(S=='-') {
      ima++;
      res = formula(P,Q,R);
      if(res == 0) res = 2;
      else if(res == 2) res = 0;
    }
    else if(S=='(') {
      ima++;
      res = formula(P,Q,R);
      if(S=='*')ima++, res = min(formula(P,Q,R),res);
      if(S=='+')ima++, res = max(formula(P,Q,R),res);
      ima++;
    }
  }
  return res;
}

int main() {

  while(1) {
    cin >> str;
    if(str==".") break;
    int ans = 0;
    for(int i=0;i<3;i++)
      for(int j=0;j<3;j++)
	for(int k=0;k<3;k++){
	  ima = 0;
	  if(formula(i,j,k) == 2) ans++;
	}
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
"""
item: ２次元配列 item[i] = [weight, value]
bounds: size of knapsack
"""
def knapsack(item, bounds):
    n = len(item)
    dp_table = [[0] * (bounds+1) for i in range(n)]
    for w in range(1,bounds+1):
        if item[0][0] > w:
            continue
        dp_table[0][w] = item[0][1]

    for i in range(1,n):
        for w in range(W+1):
            if item[i][0] > w:
                dp_table[i][w] = dp_table[i-1][w]
            else:
                dp_table[i][w] = max(dp_table[i-1][w], dp_table[i-1][w-item[i][0]] + item[i][1])
    return dp_table[n-1][bounds]


N, W = map(int, input().strip().split())
item = []
for i in range(N):
    value, weight = map(int, input().strip().split())
    item.append([weight, value])

print(knapsack(item, W))


Measured memory_bytes: 25160
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main() {

    int N,M;
    cin>>N;
    vector<string> s(N);
    map<string, int> S,T;
    FOR(i,0,N){
        string u;
        cin>>u;
        s[i]=u;
        S[u]++;
    }
    cin>>M;
    FOR(i,0,M){
        string t;
        cin>>t;
        T[t]++;
    }
    int  ans=0;
    FOR(i,0,N){
        ans=max(ans,S[s[i]]-T[s[i]]);
    }
    cout <<ans <<"\n";
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
x = [0]*N
u = [0]*N
for i in range(N):
    x[i], u[i]= map(str, input().split())
    
x_int = [float(j) for j in x]
u_replace = [1 if k =="JPY" else 380000.0 for k in u]

x_arr = np.array(x_int)
u_arr = np.array(u_replace).reshape(N, 1)

ans = np.dot(x_arr, u_arr)
print(ans[0])

Measured memory_bytes: 12448
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	std::string S;
	in >> N >> K >> S;
	S[K - 1] = std::tolower(S[K - 1]);
	out << S << std::endl;
}


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

#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n;cin>>n;
    int x[n];
    double avr;
    REP(i,n){cin>>x[i];avr+=x[i];}
    avr/=n;
    int tmp=avr;
    if(avr-tmp>0.5)tmp++;
    int ans=0;
    REP(i,n){
        ans+=(tmp-x[i])*(tmp-x[i]);
    }cout<<ans<<endl;
}

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

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

int main() {
	int N;


	while(cin >> N, N) {

	vi taro, hanako;

	int tmp;
	REP(i, N) {
		cin >> tmp;
		taro.push_back(tmp);
	}

	sort(ALL(taro));

	int pos = 0;
	FOR(i, 1, 2*N) {
		if(taro[pos] == i) {
			pos++;
		} else {
			hanako.push_back(i);
		}
		if(pos == N) {
			pos--;
		}
	}

	int tpos = N-1, hpos = N, ba = taro[0];
	taro[0] = 0;

	while(true) {
ha:
		REP(i, N) {
			if(hanako[i] > ba) {
				ba = hanako[i];
				hanako[i] = 0;
				if(--hpos == 0) {
					goto score;
				}
				goto ta;
			}
		}
		ba = 0;
ta:
		REP(i, N) {
			if(taro[i] > ba) {
				ba = taro[i];
				taro[i] = 0;
				if(--tpos == 0) {
					goto score;
				}
				goto ha;
			}
		}
		ba = 0;
	}

score:
	cout << hpos << endl;
	cout << tpos << endl;

	}

	return 0;
}

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


Measured memory_bytes: 128
#include<stdio.h>

int ruijou(int);
int main() {

int n,length[1000][3],i;

scanf("%d",&n);

for(i=0;i<n;i++){
scanf("%d%d%d",&length[i][0],&length[i][1],&length[i][2]);
if(ruijou(length[i][0])==ruijou(length[i][1])+ruijou(length[i][2])||/*
*/ ruijou(length[i][1])==ruijou(length[i][0])+ruijou(length[i][2])||/*
*/ ruijou(length[i][2])==ruijou(length[i][0])+ruijou(length[i][1]))
printf("YES\n");
else printf("NO\n");
}

return 0;
}

int ruijou(int i){
return i*i;
}

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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
    std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#else
#define db(...)
#endif

int n, k;

vector<int> CT;
int fn(int i, int k)
{
    int x = 0, two = 1;
    while (i * two < k)
    {
        x++;
        two *= 2;
    }
    return x;
}

void solve()
{
    cin >> n >> k;
    CT.resize(25);
    for (int i = 1; i <= n; ++i)
        CT[fn(i, k)]++;
    ld prob = 0, p = 1;
    for (int i = 0; i < 25; ++i)
    {
        prob += p * CT[i];
        // db(p,CT[i]);
        p = p/2;
    }
    cout << fixed << setprecision(15) << prob/n << '\n';
}

int main()
{
    ControlIO();
    int t = 1;
#ifdef multitest
    cin >> t;
#endif
    TimerStart();
    while (t--)
        solve();
    TimerStop();
    return 0;
}

void ControlIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef Online
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
    TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
    TimeEnd = chrono::steady_clock::now();
    auto ElapsedTime = TimeEnd - TimeStart;
    cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
ll LongestWordLength(string str) 
{      
    ll n = str.length(); 
    ll res = 0, curr_len = 0, i; 
    for (ll i = 0; i < n; i++) {  
        if (str[i] != ' ') 
            curr_len++; 
        else { 
            res = max(res, curr_len); 
            curr_len = 0; 
        } 
    } 
    return max(res, curr_len); 
} 
int main()
{
	string s;
	cin>>s;
	REP(i,0,s.size()-1)
		if(s[i]!='A' && s[i]!='T' && s[i]!='G' && s[i]!='C')
			s[i]=' ';
	cout<<LongestWordLength(s);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

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

  long double result = 0;
  for(int i=0;i<N;i++){
    long double x;
    string u;
    cin >> x;
    cin >> u;
    if(u == "JPY"){
      result += x;
    }else{
      result += x*380000;
    }
  }

  cout << result << "\n";
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> edge[n];
  int grid[n] = {};
  for(int i = 0; i < n-1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int black = -1, white = 1;
  int sn = 1, fe = 1;
  grid[0] = black;
  grid[n-1] = white;
  queue<int> que;
  que.push(0); que.push(n-1);
  while(!que.empty()){
    int cur = que.front(); que.pop();
    for(int i = 0; i < edge[cur].size(); i++){
      if(grid[edge[cur][i]] == 0){
        grid[edge[cur][i]] = grid[cur];
        if(grid[edge[cur][i]] == black) fe++;
        if(grid[edge[cur][i]] == white) sn++;
        que.push(edge[cur][i]);
      }
    }
  }
  if(sn < fe) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 6144
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	ll A,B,C,X,Y;
	ll sum=0;
	cin>>A>>B>>C>>X>>Y;
	ll mini=INFLL;
	for(int i=0;i<=200000;i++){
		int a=0,b=0;
		ll sum=0;
		sum=i*C;
		a+=i/2,b+=i/2;
		//cout<<mini<<" "<<sum<<" "<<i<<endl;
		sum+=A*max(0LL,(X-a))+B*max(Y-b,0LL);
		mini=min(sum,mini);
	}
	cout<<mini<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define int long long int
using namespace std;

int v[100000+1];

void solve() {
  int N;
  cin >> N;

  int sum = 0;
  while (N--) {
    int a; cin >> a;
    v[a]++;
    sum += a;
  }

  int Q; cin >> Q;
  while (Q--) {
    int b, c; cin >> b >> c;
    int num = v[b];

    v[b] = 0;
    v[c] += num;
    sum = sum - num*b + num*c;

    cout << sum << endl;
  }
}

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


Measured memory_bytes: 3908
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int d, x, y;
  cin >> d >> x;
  string a[x];
  int p[x];
  rep (i, x) {
    cin >> a[i] >> p[i];
    if (a[i] != "D") {
      --i;
      --x;
    }
  }
  cin >> y;
  string b[y];
  int q[y];
  rep (i, y) {
    cin >> b[i] >> q[i];
    if (b[i] != "DD") {
      --i;
      --y;
    }
  }
  int res = 0;
  rep (bit, 1 << (x + y)) {
    int cnt = 0, r = 0;
    rep (i, x) if ((bit >> i) & 1) {
      ++cnt;
      r += p[i];
    }
    rep (i, y) if ((bit >> (x + i)) & 1) {
      cnt += 2;
      r += q[i];
    }
    if (cnt <= d) res = max(res, r);
  }
  cout << res << endl;
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
ll max(ll x, ll y){return x<y?y:x;}
int main(void){
	int n,i,j;
	ll k,ans=0,A,c[40]={0},K[40];
	scanf("%d %lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&A);
		for(j=0;j<40;j++){
			c[j] += A%2;
			A = A>>1;
		}
	}
	k++;
	for(i=0;i<40;i++){
		K[i] = k%2;
		k >>= 1;
	}
	
	for(i=0;i<40;i++){
		if(K[i]){
			ll ans2 = c[i]<<i;
			for(j=39;j>i;j--){
				ll x;
				if(K[j])x=n-c[j];
				else x=c[j];
				ans2 += x<<j;
			}
			for(j=0;j<i;j++){
				ll x;
				if(c[j]>n/2)x=c[j];
				else x=n-c[j];
				ans2 += x<<j;
			}
			ans = max(ans,ans2);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
// B. 

#include <sstream>
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	set<string> m;
	bool ans = true;
	char prev = 0;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if ((prev && prev != s[0]) || m.find(s) != m.end()) {
			ans = false;
		}
		prev = s.back();
		m.insert(s);
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

void solve(long long X) {
  for (lli i = 0; i * i * i * i * i <= 1e9 * X; i++) {
    lli A3 = i * i * i * i * i;
    for (lli j = 0; j * j * j * j * j <= abs(A3 - X); j++) {
      lli B3 = j * j * j * j * j;
      if (A3 - B3 == X) {
        cout << i << " " << j << endl;
        return;
      }
      if (A3 + B3 == X) {
        cout << i << " " << -j << endl;
        return;
      }
    }
    A3 = -(i * i * i * i * i);
    for (lli j = 0; j * j * j * j * j <= abs(A3 - X); j++) {
      lli B3 = j * j * j * j * j;
      if (A3 - B3 == X) {
        cout << -i << " " << j << endl;
        return;
      }
      if (A3 + B3 == X) {
        cout << -i << " " << -j << endl;
        return;
      }
    }
  }
}
signed main() {
  long long X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3764
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int[] n = new int[6];
		for (int i = 0; i < 6; i++) {
			n[i] = in.nextInt();
		}
		Dice d = new Dice(n);

		String input = in.next();
		for (char c : input.toCharArray()) {
			if (c == 'N') {
				d.moveN();
			} else if (c == 'S') {
				d.moveS();
			} else if (c == 'E') {
				d.moveE();
			} else if (c == 'W') {
				d.moveW();
			}
		}
		out.println(d.getTop());
	}

	private static class Dice {
		private int[] no;
		Dice(int[] no) {
			if (no.length != 6) throw new RuntimeException();
			this.no = no;
		}
		private void moveX(boolean rev) {
			int temp = no[0];
			if (rev) {
				no[0] = no[4];
				no[4] = no[5];
				no[5] = no[1];
				no[1] = temp;
			} else {
				no[0] = no[1];
				no[1] = no[5];
				no[5] = no[4];
				no[4] = temp;
			}
		}
		void moveN(){moveX(false);}
		void moveS(){moveX(true);}

		private void moveY(boolean rev) {
			int temp = no[0];
			if (rev) {
				no[0] = no[3];
				no[3] = no[5];
				no[5] = no[2];
				no[2] = temp;
			} else {
				no[0] = no[2];
				no[2] = no[5];
				no[5] = no[3];
				no[3] = temp;
			}
		}
		void moveW(){moveY(false);}
		void moveE(){moveY(true);}

		int getTop(){return no[0];};
	}
}

Measured memory_bytes: 17356
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;

typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;cin>>a>>b;

    int n=(-1+(int)sqrt(1+8*a))/2 +1;

    for(int i=n;i<=999;i++)
    {
        int j=i+1;
        int val1=(i*(i+1))/2;
        int val2=(j*(j+1))/2;

        if(val1-a==val2-b)
        {
            cout<<val1-a;
            break;
        }

    }

    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

void solve () {
	int n;
	cin >> n;
	vi vect(n+1,0);
	for (int i = 1;i <= n;++i) {
		for (int j = i;j <= n;j += i) {
			vect[j]++;
		}
	}
	ll ans = 0;
	for (int i = 1;i <= n;++i) {
		ans += (ll)i*vect[i];
	}
	cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 42272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s1=0;
  cin>>n;
  vector<int> a(n),s(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  s[0]=0;
  for(int i=0;i<n;i++){
    s1+=a[i];
    s[i+1]=s[i]+a[i];
  }
  int m=1000;
  for(int i=1;i<=n;i++){
    int a=abs(s1-2*s[i]);
     m=min(a,m);
  }
     cout<<m<<endl;
}
    
    
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int inf = 1 << 28;
int n, m;
int d[102][102];

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      d[i][j] = inf;
    }
  }
  for (int i = 0; i < n; ++i) {
    int r, k, t;
    cin >> r >> k;
    r--;
    for (int j = 0; j < k; ++j) {
      cin >> t;
      t--;
      d[r][t] = 1;
    }
  }
  
  for (int i = 0; i < n; ++i) d[i][i] = 0;
  
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  cin >> m;
  for (int i = 0; i < m; ++i) {
    int s, de, v;
    cin >> s >> de >> v;
    s--; de--;
    //printf("(%d,%d) ", s, de);
    if (d[s][de]+1 <= v) {
      cout << d[s][de]+1 << endl;
    } else {
      //cout << d[s][de] << endl;
      cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0