akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 2005;
ll fact[N],inv[N];
void pre()
{
    fact[0] = 1; inv[0] = 1;
    for(ll i=1;i<N;i++)
    {
        fact[i] = (fact[i-1]*i)%M;
        inv[i] = powerm(fact[i],M-2);
    }
}

ll C(ll n,ll r)
{
    ll ans = ((fact[n]*inv[r])%M + M)%M;
    ans = (ans*inv[n-r])%M + M;
    return ans%M;
}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	pre();
	int h,w; cin>>h>>w;
	string s[h];
	forn(i,h) cin>>s[i];
	ll dp[h][w];
	dp[0][0] = 1;
	forn(i,h)
	{
	    forn(j,w)
	    {
	        if(i>0||j>0) dp[i][j] = 0;
	        if(s[i][j]=='#') continue;
	        if(i>0) dp[i][j] += dp[i-1][j];
	        if(j>0) dp[i][j] += dp[i][j-1];
	        dp[i][j] %= M;
	    }
	}
	cout<<dp[h-1][w-1];
	return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>



using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main()
{
	int n, m; cin >> n >> m;
	vector<pair<int, int>> pp(m);
	rep(i, m)
		cin >> pp[i].first >> pp[i].second;
	rep(i, 1000) {
		int keta = 1;
		int ni = i / 10;
		vector<int> d(1, i % 10);
		while (ni) {
			d.push_back(ni % 10);
			ni /= 10;
			keta++;
		}
		if (keta != n) continue;
		reverse(d.begin(), d.end());
		bool ok = true;
		rep(i, m) {
			if (d[0, pp[i].first - 1] != pp[i].second)
				ok = false;
		}
		if (ok) {
			cout << i;
			return 0;
	}
	}
	cout << -1;
}





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

using namespace std;

u_int seed = 3;
u_int xor_shift()
{
    seed ^= seed << 1;
    seed ^= seed >> 3;
    seed ^= seed << 10;
    return seed;
}

chrono::system_clock::time_point start_time;
int elapsed()
{
    auto cur = chrono::system_clock::now();
    return chrono::duration_cast<chrono::milliseconds>(cur - start_time).count();
}

// セグ木を使えば二分探索で一点をlog(n)で更新できる これ嘘で，後ろのスコアも変更する必要があるため
// 前からA*とかビームサーチもできそう
// とりあえず焼きなます
// 最初はCを考慮せずに焼きなます(いや，貪欲でいいだろ)
int score = 0;
int d;
vector<int> T, C;
vector<vector<int>> S, last;

// i日目をj番目に
int calc(int i, int to){
    int res = 0;
    int from = T[i];
    res -= S[i][from];
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        res += C[from] * (j - last[j][from]);
        res -= C[from] * (j - l);
    }

    res += S[i][to];
    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        res += C[to] * (j - last[j][to]);
        res -= C[to] * (j - i);
    }

    return res;
}

void change(int i, int to){
    int from = T[i];
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        last[j][from] = l;
    }

    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        last[j][to] = i;
    }
}



int main(){
    cin >> d;
    start_time = chrono::system_clock::now();
    C.resize(26);
    copy_n(istream_iterator<int>(cin), 26, C.begin());
    S.assign(d, vector<int>(26));
    last.assign(d, vector<int>(26));
    for (auto &s: S)
        copy_n(istream_iterator<int>(cin), 26, s.begin());

    T.assign(d, -1);

    for (int i = 0; i < d; i++){
        int to = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        T[i] = to;
        for (int j = i; j < d; j++){
            last[j][to] = i;
        }
    }

    auto ans = T;
    int max_score = score;
    const double s_temp = 2000, e_temp = 0;
    const constexpr int L = 1e5;
    double delta = (s_temp - e_temp) / L;
    double temp = s_temp;
    const double sup = pow(2, 32) - 1;

    while (elapsed() < 1950){
        auto i = xor_shift() % d;
        auto to = xor_shift() % 26;
        if (T[i] == to)
            continue;
        auto cost = calc(i, to);
        if (cost > 0 or exp(cost / temp) > xor_shift() / sup){
            change(i, to);
            // cerr << "change: " << i << " " << to << " " << cost << endl;
            score += cost;
        }
        if (score > max_score){
            ans = T;
            max_score = score;
        }
        temp -= delta;
    }

    for (const auto &t: ans)
        cout << t + 1 << endl;

}

Measured memory_bytes: 4332
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<ll> prime_factorization(ll n){
    vector<ll> v;
    ll num = n;
    for(ll i=2; i*i<=n; i++){
        while(num % i == 0){
            num /= i;
            v.emplace_back(i);
        }
    }

    if(num != 1){
        v.emplace_back(num);
    }

    return v;
}

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

    int n; cin>>n;
    map<int, int> cnt;
    for(int i=2; i<=n; i++){
        auto v = prime_factorization(i);
        for(auto j : v) cnt[j]++;
    }

    for(auto i : cnt) cnt[i.first]++;

    int ans = 0;
    // 1 * 75
    for(auto i : cnt){
        if(75 <= i.second) ans++;
    }

    // 3 * 25
    for(auto i : cnt){
        for(auto j : cnt){
            if(i.first == j.first) continue;
            if(3 <= i.second && 25 <= j.second) ans++;
        }
    }

    // 5 * 15
    for(auto i : cnt){
        for(auto j : cnt){
            if(i.first == j.first) continue;
            if(5 <= i.second && 15 <= j.second) ans++;
        }
    }

    // 3 * 5 * 5
    for(auto i : cnt){
        for(auto j : cnt){
            for(auto k : cnt){
                if(i.first == j.first) continue;
                if(j.first == k.first) continue;
                if(k.first == i.first) continue;
                if(j.first > k.first) continue;
                if(3 <= i.second && 5 <= j.second && 5 <= k.second) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  "use strict";
	const lines = input.split("\n");
  const line1 = lines[0].split(" ");
  let nums = line1.map(s => parseInt(s, 10));
  let k = nums.pop();

  let S = lines[1]
  let c = String(S[k-1]).toLowerCase()
  console.log(S.substring(0,k-1) + c + S.substring(k))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
	int g;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	f = b / d + 1;
	if (b % d == 0)
	{
		f -= 1;
	}
	g = c / e + 1;
	if (c % e == 0)
	{
		g -= 1;
	}
	if (f > g)
	{
		cout << a - f << endl;
	}
	else
	{
		cout << a - g << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second


const int mn = 1 << 16;
bool isp[mn];
vector<int> vp;
void init() {
	fill(isp + 2, isp + mn, true);
	Rep(i, 2, mn) {
		if (!isp[i])continue;
		vp.push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
		}
	}
}
vector<int> factorize(int x) {
	if (x == 0)return vp;
	x = abs(x);
	vector<int> ret;
	rep(i, vp.size()) {
		int d = vp[i];
		if (x%d == 0) {
			ret.push_back(d);
			while (x%d == 0)x /= d;
		}
	}
	if (x > 1)ret.push_back(x);
	return ret;
}
ll gcd(ll a, ll b) {
	a = abs(a), b = abs(b); if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
vector<int> ans;
void solve() {
	init();
	int n; cin >> n;
	vector<ll> a(n + 1); per(i, n + 1)cin >> a[i];

	rep(i, vp.size()) {
		if (vp[i] > n)break;
		int p = vp[i];
		vector<ll> b = a;
		for (int j = n; j >= p; j--) {
			b[j - p + 1] += b[j];
			b[j] = 0;
		}
		bool f = true;
		rep(j, n + 1) {
			if (b[j] % p) {
				f = false; break;
			}
		}
		if (f)ans.push_back(p);
	}

	ll g = 0;
	rep(i, n + 1) {
		g = gcd(g, a[i]);
	}
	vector<int> c = factorize(g);
	rep(i, c.size()) {
		if (c[i] > n)ans.push_back(c[i]);
	}
	sort(ans.begin(), ans.end());
	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 100 + 10;
const int N = 3 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;

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

int dp[N][N];
pii ans[N][N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    int n = s.size(), m = t.size();

    fore(i, 1, n + 1) {
        fore(j, 1, m + 1) {
            if (dp[i - 1][j] > dp[i][j - 1]) {
                dp[i][j] = dp[i - 1][j];
                ans[i][j] = { -1, 0 };
            }
            else {
                dp[i][j] = dp[i][j - 1];
                ans[i][j] = { 0, -1 };
            }
            if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                ans[i][j] = { -1, -1 };
            }
        }
    }

    string sbstr;
    
    int x = n, y = m;

    while (x > 0 && y > 0) {
        auto p = ans[x][y];
        if (p == make_pair(-1, -1)) {
            sbstr += s[x - 1];
        }
        x += p.fr;
        y += p.sc;
    }

    reverse(all(sbstr));

    cout << sbstr << '\n';

}


Measured memory_bytes: 111744
n,k=gets.split.map(&:to_i)
ab=[0]*(10**5+1)
n.times do
  a,b=gets.split.map(&:to_i)
  ab[a]+=b
end
c=0
100000.times do |i|
  c+=ab[i+1]
  if k<=c
    puts i+1
    exit
  end
end


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

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        cout<<(n*(n-1))/2 + (m*(m-1))/2 ;     
    }
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  long long sma = 0;
  long long smb = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sma += a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    smb += b[i];
  }
  if (sma > smb) {
    cout << "No" << '\n';
    return 0;
  }
  long long diff = smb - sma;
  long long mv = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < b[i]) {
      mv += (b[i] - a[i] + 1) / 2;
    }
  }
  cout << (mv <= diff ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3720
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = -1
dif = 100000000.0
for i in range(N):
    if abs(T-H[i]*0.006- A) < dif:
        dif = abs(T-H[i]*0.006-A)
        ans = i+1
print(ans)

Measured memory_bytes: 3060
import math
n, m, r = map(int, input().split())
a = r - n * m
def combination(p, q):
    if q < 0 or p < q:
        return 0
    return math.factorial(p) // math.factorial(q) // math.factorial(p - q)
if a < 0:
    print(0)
else:
    print(int(combination(a + n - 1, a)))


Measured memory_bytes: 5804
#include<iostream>

using namespace std;

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

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

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>

using namespace std;

int main() {

	int n, m, j=0, x, min;
	deque<int> p;

	while(cin >> n >> m) {
		if(n==0&&m==0)
			break;
		int a=m-1;
		min=0;
		p.clear();
		for(int i=0; i<n; i++) {
			cin >> x;
			p.push_back(x);
		}
		sort(p.begin(), p.end(), greater<int>());
		for(int i=0; i<p.size(); i++) {
			(i==a) ? a+=m : min+=p[i];
		}
		cout << min << endl;
	}

	return 0;

}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

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

		long K = in.nextLong();
		long A = in.nextLong();
		long B = in.nextLong();

		if (B <= A + 2 || K < 3 || (1 + K) - 2 < A) {
			System.out.println(1 + K);
			return;
		}

		long diff = B - A;
		long K2 = K - (A - 1);
		long maisu = A + (K2 / 2) * diff + (K2 % 2);

		System.out.println(maisu);
	}
}


Measured memory_bytes: 23124
N = int(input())
A = list(map(int, input().split()))
count = 0
check = 0
for i in A:
    if i%2 == 0:
        count += 1
        if i%3 == 0 or i%5 == 0:
            check += 1
if count == check:
	print('APPROVED')
else:
	print('DENIED')

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

public class Main {

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int n = Integer.parseInt(line);
		long tt = 0;
		long aa = 0;
		for (int i=0; i<n; i++) {
			line = br.readLine();
			String[] flds = line.split(" ");
			int t = Integer.parseInt(flds[0]);
			int a = Integer.parseInt(flds[1]);
			if (i == 0) {
				tt = t;
				aa = a;
				continue;
			}
			long tn = tt/t;
			long an = aa/a;
			long nn = Math.max(tn, an);
			while (true) {
				long nt = t*nn;
				long na = a*nn;
				if (nt >= tt && na >= aa) {
					tt = nt;
					aa = na;
					break;
				}
				nn++;
			}
			//System.out.println("tt="+tt+",aa="+aa);
		}
		System.out.println(tt+aa);
		long end = System.currentTimeMillis();
		//System.out.println((end-start) + "ms");
	}

}


Measured memory_bytes: 9808
n = gets.to_i
l = gets.split.map(&:to_i).sort

ans = 0

n.times do |i|
  i.times do |j|
    j.times do |k|
      if l[i] != l[j] && l[j] != l[k] && l[k] + l[j] > l[i]
        ans += 1
      end
    end
  end
end

puts ans


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf 1000000007
int dp[100001], height[100001];
int main()
{
    //freopen("input.txt", "r", stdin);
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++)scanf("%d", &height[i]);
    for(int i = 0; i < n; i++)dp[i] = inf;
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 1; j <= k; j++){if(i+j < n)dp[i+j] = min(dp[i+j], abs(height[i+j]-height[i]) + dp[i]);}
    }
    printf("%d", dp[n-1]);
    //printf("\nTime: %lf", ((double)(clock() - z) / CLOCKS_PER_SEC)*1e-6);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	// long long?
	int N, K;
	cin >> N >> K;

	vector<int> vPosi;
	vector<int> vNega;
	for (int i = 0; i != N; ++i) {
		int tmp = 0;
		cin >> tmp;
		if (tmp >= 0) {
			vPosi.push_back(tmp);
		}
		else {
			vNega.push_back(tmp);
		}
	}

	reverse(vNega.begin(), vNega.end());
	rep(i, vNega.size()) vNega[i] = vNega[i] * (-1);

	if (!vNega.empty() && !vPosi.empty()) {
		int mintime = inf;
		int upper = min((int)vPosi.size(), K - 1);
		int lower = max(K - (int)vNega.size() - 1, 0);
		for (int i = lower; i != upper; ++i) {
			int smaller = min(2 * vPosi[i] + vNega[K - i - 2], vPosi[i] + 2 * vNega[K - i - 2]);
			mintime = min(mintime, smaller);
		}

		cout << mintime << endl;
	}
	else if (vNega.empty()) {
		cout << vPosi[K-1] << endl;
	}
	else if (vPosi.empty()) {
		cout << vNega[K-1] << endl;
	}

	return 0;

}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,sum=0,d;
  int p[1100];
  while(1){
    sum = 0;
    cin >> n >> m;
    if(n==0 && m==0) break;
    for(int i=0; i<n; i++) {
      cin >> p[i];
      sum += p[i];
    }
    sort(p,p+n);
    reverse(p,p+n);
    /*for(int i=1; i<=n/m; i++) p[i*m-1]=0;
    for(int i=0; i<n; i++) sum += p[i];*/
    for(int i=1; i<=n/m; i++){
      d = m*i-1;
      sum -= p[d];
    }
    cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,w,i,j;
    scanf("%lld %lld",&n,&w);
    long long int ar[n+6][5]={0},dp[n+6][100009]={0};
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=100000;j++)
    	{
    		dp[i][j]=9999999999;
    	}
    }
    
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=2;j++)
        {
            scanf("%lld",&ar[i][j]);
        }
    }
    dp[1][ar[1][2]]=ar[1][1];
    for(i=2;i<=n;i++)
    {
        dp[i][ar[i][2]]=ar[i][1];
        for(j=1;j<=100000;j++)
        {
            if(dp[i-1][j]!=0)
            {
                if(ar[i][2]==j)
                {
                    dp[i][j]=min(ar[i][1],dp[i-1][j]);
                    if(j+ar[i][2]<=100000)
                    {
                        dp[i][j+ar[i][2]]=min(dp[i-1][j]+ar[i][1],dp[i][j+ar[i][2]]);
                    }
                }
                else
                {
                    dp[i][j]=min(dp[i-1][j],dp[i][j]);
                    if(j+ar[i][2]<=100000)
                    {
                        dp[i][j+ar[i][2]]=min(dp[i-1][j]+ar[i][1],dp[i][j+ar[i][2]]);
                    }
                }
            }
        }
    }
    long long int max1=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=100000;j++)
        {
            if(dp[i][j]!=9999999999 && dp[i][j]<=w)
            {
                max1=max(max1,j);
            }
           //printf("%lld ",dp[j][i]);
        }
        //printf("\n");
    }
    printf("%lld\n",max1);
}


Measured memory_bytes: 83072
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n, l;
	cin >> n >> l;
	
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += l + i - 1;
	}
	if (l >= 0) {
		sum -= l;
	} else if (l + n > 0) {
		// 何もしない
	} else {
		sum -= l + n - 1;
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n;
    char p, dummy;
    int input;
    int arr[4][13];
    int i, j;
    
    // array initialization
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            arr[i][j] = 0;
        }
    }
    
    // array input
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%c", &dummy);
        scanf("%c %d", &p, &input);
        switch(p){
            case 'S':
                arr[0][input - 1] = 1;
                break;
            case 'H':
                arr[1][input - 1] = 1;
                break;
            case 'C':
                arr[2][input - 1] = 1;
                break;
            case 'D':
                arr[3][input - 1] = 1;
                break;
        }
    }
    
    // output
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(arr[i][j] == 0){
                switch(i){
                    case 0:
                        printf("S %d\n", j + 1);
                        break;
                    case 1:
                        printf("H %d\n", j + 1);
                        break;
                    case 2:
                        printf("C %d\n", j + 1);
                        break;
                    case 3:
                        printf("D %d\n", j + 1);
                        break;
                }
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2032
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n;
	public void run(){
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		solve(a, b, c, k);
	}
	public void solve(int a, int b, int c, int k){
		int ans = a + b + c;
		int t = a;
		if(t < b) t = b;
		if(t < c) t = c;
		
		ans = ans - t;
		
		for (int i = 0; i < k; i++){
			t = t * 2;
		}
		
		ans = ans + t;
		
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 20820
def koubai(a,b):
    if b==0:
        return a
    return(koubai(b,a%b))
def kouyaku(a,b):
    return a*b//koubai(a,b)

N=int(input())
if N==1:
    print(int(input()))
    exit()
ans=1
for i in range(N):
    ans=kouyaku(ans,int(input()))
print(int(ans))


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

int dsum(int n){
	int ret=0;
	while(n>0){
		ret+=n%10;
		n/=10;
	}
	return ret;
}

int main(){

	int n;cin>>n;
	int inf=1e9;
	int ret=inf;
	for(int i=1;i<n;i++){
		int x=dsum(i);
		int y=dsum(n-i);
		ret=min(ret,x+y);
	}
	cout<<ret<<endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq
import functools
INF = float("inf")

# 無向グラフを仮定する。


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = [[] for _ in range(N)]

    def add_edge(self, s, t, w=1):
        self.E[s].append((t, w))
        self.E[t].append((s, w))


def Warshall_Floyd(g: Graph):
    N = g.N
    dist = [[INF]*N for _ in range(N)]
    for from_, toweights in enumerate(g.E):
        for to_, w in toweights:
            dist[from_][to_] = w

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist


def solve(N: int,
          M: int,
          L: int,
          A: "List[int]",
          B: "List[int]",
          C: "List[int]",
          Q: int,
          s: "List[int]",
          t: "List[int]"):
    g = Graph(N)
    for i in range(M):
        g.add_edge(A[i]-1, B[i]-1, C[i])
    dist = Warshall_Floyd(g)

    g = Graph(N)
    for i in range(N):
        for j in range(i+1, N):
            if dist[i][j] <= L:
                g.add_edge(i, j, 1)
    dist = Warshall_Floyd(g)

    for i in range(Q):
        ans = dist[s[i]-1][t[i]-1]-1
        if ans == INF:
            print(-1)
        else:
            print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    s = [int()] * (Q)  # type: "List[int]"
    t = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
    solve(N, M, L, A, B, C, Q, s, t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125148
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> d(N);
  REP(i, N) cin >> d[i];

  int ans = 0;
  REP(i, N) REP(j, N) if(i != j){
    ans += d[i]*d[j];
  }

  cout << ans/2 << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long ans = 0;
		for(long i=1; i<=n; i++) {
			if(i%3==0||i%5==0) continue;
			ans += i;
		}
		System.out.println(ans);
		sc.close();
	}


}


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

#define rep(i, n) for(int i = 0; i < n; i++)
vector<int> node[200000];
int cost[200000];

int op(int id, int parent=-1){
    for(auto &p : node[id]){
        if(p == parent)
            continue;
        cost[p] += cost[id];
        op(p, id);
    }
}
    

int main(void){
    int n, q;
    cin >> n >> q;

    int a, b;
    rep(i, n - 1){
        cin >> a >> b;
        a--;
        b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    int p, x;
    rep(i, q){
        cin >> p >> x;
        p--;
        cost[p] += x;
    }

    op(0);

    rep(i, n)
        cout << cost[i] << endl;
}



Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n;
  cin >> n;
  vi a1(n), a2(n), sum1(n), sum2(n);
  for (int i = 0; i < n; i++) {
    cin >> a1[i];
    if (i == 0) sum1[0] = a1[0];
    else sum1[i] = sum1[i - 1] + a1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a2[i];
    if (i == 0) sum2[0] = a2[0];
    else sum2[i] = sum2[i - 1] + a2[i];
  }
  ll maxsum = 0;
  for (int i = 0; i < n; i++) {
    ll sum = 0;
    sum += sum1[i];
    if (i == 0) sum += sum2[n - 1];
    else sum += sum2[n - 1] - sum2[i - 1];
    maxsum = max(maxsum, sum);
  }
  cout << maxsum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
	for (int i = 0; i < N; i++) {
  	cin >> vec.at(i);
	}
  
  int a = 0;
  
  for (int i = 0; i < N; i++) {
	if (vec.at(i) - 1 != i) {
      a++;
    }
 
  }
 
  if (a == 0||a == 2) {
    cout << "YES" << endl;
  }
  
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
S = list(input())

f_cd1, f_cd2, f_cd3 = False, False, False
cd3_ng = True
c_cnt, c_idx = 0, -1

if S[0] == 'A' :
    f_cd1 = True
    for i in range(2, len(S) - 1) :
        if S[i] == 'C' :
            c_cnt += 1
            c_idx = i
            
    if c_cnt == 1 :
        f_cd2 = True
        
        for i in range(len(S)) : 
            if (i != 0 and i != c_idx) and S[i] not in list('abcdefghijklmnopqrstuvwxyz') :
                cd3_ng = False
                break
                
        if cd3_ng == True :
            f_cd3 = True
            
if f_cd1 == f_cd2 == f_cd3 == True :
    print("AC")
else :
    print("WA")

Measured memory_bytes: 3064
#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>
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORD(i,a,b) for(int i=(a);i>(b);i--)
typedef long long ll;
const ll mod =1e9 +7;

int main(){
   string s,t;
   cin>>s>>t;
   int mn=0;
   int n=t.size();
   int ns=s.size();
   int mx=0;
   for(int i=0;i<=ns-n;++i){
       string str=s.substr(i,n);
        int sz=0;
       for(int j=0;j<n;++j){
           if(str[j]==t[j]) sz++;
       }
       mx=max(mx,sz);

   }
   cout<<n-mx<<endl;
    return 0;
}

Measured memory_bytes: 3628
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n), b(n);
    for (int i=0; i<n; i++) cin >> a[i] >> b[i];
    vll ord(n); iota(ALL(ord), 0LL);
    sort(ALL(ord), [&](ll i, ll j) {
        if (b[i]-a[i]>=0 || b[j]-a[j]>=0) return b[i]-a[i] > b[j]-a[j];
        else return b[i] > b[j];
    });
    if (b[ord[0]] - a[ord[0]] == 0) cout << 0 << '\n';
    else {
        ll ans = 0, tmp = 0;
        for (int i=0; i<n; i++) {
            if (b[ord[i]] - a[ord[i]] > 0) {
                ans += a[ord[i]];
            } else if (b[ord[i]] - a[ord[i]] == 0) {
                ans += a[ord[i]];
            } else if (b[ord[i]] - a[ord[i]] < 0) {
                if (i == n-1) {
                    ans += a[ord[i]] - b[ord[i]];
                } else {
                    ans += a[ord[i]];
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 768
fn main() {
    let (d,t,s)={
        let mut s=String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut it=s.split_whitespace().map(|i| i.parse::<i32>().unwrap());
        (it.next().unwrap(),it.next().unwrap(),it.next().unwrap())
    };

    println!("{}",if d>s*t {"No"}else{"Yes"});
}


Measured memory_bytes: 2076
#include<stdio.h>
char a[103][103];
int main()
{
    int h,w;
    int i,j;
    scanf("%d%d",&h,&w);
    for(i=1;i<=h;i++)
    {
         scanf("%s",a[i]);
    }
    for(i=0;i<=w+1;i++)
        printf("#");
    printf("\n");
    for(i=1;i<=h;i++)
    {
        printf("#");
        for(j=0;j<w;j++)
        {
            printf("%c",a[i][j]);
        }
        printf("#\n");
    }
    for(i=0;i<=w+1;i++)
        printf("#");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N;
	string S;
	cin >> S;
	N = S.length();
	int ans = 0;
	rep(i, N / 2) {
		if (S[i] != S[N - i - 1])
			ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
# 056a

# a=H, b=H TCD君は正直者
# a=H, b=D TCD君は嘘つき
# a=D, b=H TCD君は嘘つき
# a=D, b=D TCD君は正直者

a, b = map(str, input().split())

if a == 'H' and b == 'H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
else:
    print('H')


Measured memory_bytes: 8928
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<LL> a(n);
		vector<LL> b(n);
		REP(i,n) cin >> a[i] >> b[i];
		LL ans = 0;
		RREP(i,n){
			ans += (b[i]-(a[i]+ans)%b[i])%b[i];
			DEBUG(ans);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
 
ans = 0
n = inp()
a = [inp() for _ in range(n)]
d = defaultdict(int)
 
for key in a:
    d[key] += 1
for i in d:
    if d[i] % 2:
        ans += 1 
print(ans)

Measured memory_bytes: 17480
program main
	implicit none
    character::a,b
    read(*,*) a,b
    if(a=='H' .and. b=='H')then
    	write(*,*)'H'
    else if(a=='H' .and. b=='D')then
    	write(*,*)'D'
    else if(a=='D' .and. b=='H')then
    	write(*,*)'D'
    else
    	write(*,*)'H'
    end if
    stop
end program main

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

using namespace std;
typedef long long ll;

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

  int a, p, c; cin >> a >> p;
  
  cout << ( (a * 3 + p) >> 1 ) << endl;;

  //vector<int> as;

  // for (int i = 0; i < n; i++) {
  //    int t; cin >> t;
  // }



  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b, c) << " " << max(0, b + c - a) << endl;

	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

int main() {
    int N, c = 0;
    string S;
    cin >> N >> S;

    for(int i = 0; i < N - 2; i++) {
        if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') c++;
    }

    cout << c << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
#define PI		3.14159265358979323846

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cout.precision(10);
    cout << fixed;

    ld x;
    cin >> x;
    db(x*PI*2.0)

    return 0;
}


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

int main(){
    ll q,h,s,d;
    ll n;
    cin >> q >> h >> s >> d >> n;
    ll ans = 0;
    ans += (n/2)*(min({8*q,4*h,2*s,d}));
    n -= (n/2)*2;
    ans += (n/1)*(min({4*q,2*h,s}));
    cout << ans << endl;
}


Measured memory_bytes: 256
class Num:
    a=0
    b=0
    origin=0

def partition(A, p, r):
    x=A[r].b
    i=p-1
    for j in range(p,r):
        if A[j].b <= x:
            i += 1
            A[i].b,A[j].b = A[j].b,A[i].b
            A[i].a,A[j].a = A[j].a,A[i].a
            A[i].origin,A[j].origin = A[j].origin,A[i].origin
    A[i+1].b,A[r].b = A[r].b,A[i+1].b
    A[i+1].a,A[r].a = A[r].a,A[i+1].a
    A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin
    return i+1
def quick_sort(A , p, r):
    if p < r:
        q = partition(A,p,r)
        quick_sort(A, p, q-1)
        quick_sort(A, q+1, r)
def isStable(A):
    flag=True
    n=len(A)
    for i in range(n-1):
        if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:
            flag = False
    return flag

if __name__ == "__main__":
    
    n=int(input())
    A=[]
    for i in range(n):
        num =Num()
        a=input().split()
        num.a = a[0]
        num.b = int(a[1])
        num.origin=i
        A.append(num)
    quick_sort(A,0,n-1)
    if isStable(A):
        print("Stable")
    else:
        print("Not stable")
    for i in A:
        print(i.a,end=" ")
        print(i.b)
            
    


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

using namespace std;

int main(int, char**) {
	int n;
	string s;
	int q;
	cin >> n >> s >> q;
	vector<set<int>> alp;
	alp.assign(26, set<int>());

	for (int i=0; i<n; i++) {
		char c = s.at(i);
		alp[s.at(i) - 'a'].insert(i + 1);
	}


	for (int i=0; i<q; i++) {
		int qu;
		scanf("%d", &qu);
		if (qu==1) {
			int l;
			char c;
			scanf("%d %c", &l, &c);
			char b = s.at(l - 1);
			alp[b - 'a'].erase(l);
			s.at(l - 1) = c;
			alp[c - 'a'].insert(l);
		} else {
			int l, r;
			scanf("%d %d", &l, &r);
			int cnt = 0;
			for (int i=0; i<26; i++) {
				if (alp[i].empty()) continue;
				auto itr = alp[i].lower_bound(l);
				if (itr != alp[i].end() && *itr <= r) cnt++;
			}
			cout << cnt << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24196
A = list(map(int,input().split()))
s = sum(A)
ans = 1000
for i in range(3):
    for j in range(3):
        if i == j:
            continue
        b = abs(A[i]-A[j])+abs(A[j]-(s-(A[i]+A[j])))
        ans = min(ans,b)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

#define N 500000

int H,tmp=0,A[N];

void maxHeapify(int i){
int l,r,largest;
l = 2*i;
r = 2*i+1;
  
if (l <= H && A[l] > A[i]) largest = l;
 else largest = i;

if(r <= H && A[r] > A[largest]) largest = r;
  
  
if(largest != i){
tmp = A[i];
A[i] = A[largest];
A[largest] = tmp;
maxHeapify(largest);
}
}

void buildMaxHeap(void){
int i;
for(i=H/2; i>0; i--){
maxHeapify(i);
}
}


int main(){
int i;
scanf("%d", &H);
for(i=1; i<=H; i++){
scanf("%d", &A[i]);
}
buildMaxHeap();
for(i=1; i<=H; i++){
printf(" %d", A[i]);
}
printf("\n");
 
return 0;
}



Measured memory_bytes: 3692
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
ll dp[N][3];
std::vector<ll> a[N];
void dfs(ll node,ll par)
{
  dp[node][1]=1;
  dp[node][0]=1;
  for(auto i:a[node])
  if(i!=par)
  {
    dfs(i,node);
    dp[node][1]=(dp[node][1]*dp[i][0])%hell;
    dp[node][0]=(dp[node][0]*(dp[i][1]+dp[i][0])%hell)%hell;
  }
}
void solve()
{
   ll n;
   cin>>n;
   for(int i=1;i<n;i++)
   {
      ll x,y;
      cin>>x>>y;
      a[x].pb(y);
      a[y].pb(x);
   }
   dfs(1,0);
   cout<<(dp[1][0]+dp[1][1])%hell;
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, i, result;
  int p = 0, w = 0, g = 0, y = 0;
  string arare;
  cin >> n;

  for(i = 0; i < n; i++) {
    cin >> arare;
    
    if (arare == "P") {
      p = 1;
    }
    if (arare == "W") {
      w = 1;
    }
    if (arare == "G") {
      g = 1;
    }
    if (arare == "Y") {
      y = 1;
    }
  }
  
  result = p + w + g + y;
  
  if (result == 3) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int T = 0, U = S.size();
  for (int i = 0; i < U / 2; i++) {
    if (S.at(i) != S.at(U - 1 - i)) {T++;}
  }
  cout << T << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<long long>A(N);
  vector<long long>B(N + 1, 0);
  for (int i = 0; i < N; i ++) {
    cin >> A[i];
    B[A[i]] ++;
  }
  long long ans = 0;
  for (int i = 1; i <= N; i ++) {
    ans += B[i] * (B[i] - 1) / 2;
  }
  for (int i = 0; i < N; i ++) {
    cout << ans - B[A[i]] + 1 << endl;
  }
}



Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[101], ans[101];
	int ln;
	int i, j, k;;
	while (scanf("%s", str) != EOF) {
		ln = strlen(str);
		for (i = 0, j = 0; i < ln; i++) {
			if (str[i] == '@') {
				for (k = str[i+1] - '0'; k > 0; k--) {
					ans[j++] = str[i+2];
				}
				i += 2;
			}
			else {
				ans[j++] = str[i];
			}
		}
		ans[j] = '\0';
		printf("%s\n", ans);
	}
	return 0;
}

Measured memory_bytes: 524
from functools import reduce
import fractions
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
n = int(input())

inp_list = list(map(int,(input().split())))

lcm = lcm_list(inp_list)

ans = 0

for i in inp_list:
    ans += lcm // i


print(ans % (10**9+7))



Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=222;
const uli mod=998244353;
uli pwr[mx];
int x[mx],y[mx];
int gcd(int a,int b){ 
  if(b==0)return a;
  return gcd(b,a%b);
}
bool inside(int k,int i,int j){
  if(k==i || k==j)return false;
  int a=x[k]-x[i],b=y[k]-y[i];
  int g=gcd(abs(a),abs(b));
  a/=g,b/=g;
  int c=x[j]-x[k],d=y[j]-y[k];
  g=gcd(abs(c),abs(d));
  c/=g,d/=g;
  return a==c && b==d;
}
int main(){
  pwr[0]=1;
  for(int i=1;i<mx;i++)pwr[i]=pwr[i-1]*2ll%mod;
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d %d",x+i,y+i);
  uli ans=pwr[n];
  for(int i=0;i<n;i++){ 
    for(int j=i+1;j<n;j++){
      int cnt=0;
      for(int k=0;k<n;k++)
        if(inside(k,i,j))
          cnt++;
      ans=(ans-pwr[cnt]+mod)%mod;
    }
  }
  ans=(ans-n-1+mod)%mod;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
s1 = input()
s2 = input()

if(s1[0] == s2[2]):
    if(s1[1] == s2[1]):
        if(s1[2] == s2[0]):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3060
import java.util.Scanner;

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

        for (s = input.next(); !s.equals("0"); s = input.next()){
            int sum = 0;
            for (char c : s.toCharArray()){
                sum += c - '0';
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 17268