akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>



using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll mod = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> b(n);

	rep(i , n - 1) {
		int t;
		cin >> t;
		t--;
		b[t]++;
	}
	rep(i, n) {
		cout << b[i] << endl;
	}


 	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;

// Problem https://atcoder.jp/contests/diverta2019/tasks/diverta2019_a

int solver(int n,int c){
    int result = n -c +1;
    return result;
}

int main(void){
    int N,K,answer;
    cin >> N >> K ;
    answer = solver(N,K);
    cout << answer << endl;


}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<vector<int>> num(12, vector<int> (10));
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        num[(b - 1) * 3 + f - 1][--r] += v;
    }
    for (int i = 0; i < 12; ++i) {
        for (int j = 0; j < 10; ++j) {
            cout << " " << num[i][j];
        }
        cout << '\n';
        if (i % 3 == 2 && i != 11) {
            cout << "####################" << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    double a,b,p,q,r;
    cin >> a >> b;
    cin >> p >> q >> r;
    printf("%.10f\n", b + (p * b - q * (b - a)) / (q + r));
    return 0;
}


Measured memory_bytes: 3292
#include<iostream>
#include<string>

int main(){

    std::string s, t, u;
    size_t a, b;
    std::cin >> s >> t >> a >> b >> u;

    if(s == u){
        std::cout << a - 1 << ' ' << b << std::endl;
    }else{
        std::cout << a << ' ' << b - 1 << std::endl;
    }

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  if(k%2==0){
    ans += (n/k)*(n/k)*(n/k);
    ans += ((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
  }else{
    ans += (n/k)*(n/k)*(n/k);
  }
  cout << ans << endl;
}



Measured memory_bytes: 384
import sys 
N = list(input())
K = int(input())

L = len(N)
if K>L:
    print(0)
    sys.exit()
#%%
def cmb(l,k):
    if k<0 or l<0:
        return 0
    if k>L:
        return 0
    elif k==0 or l==0:
        return 1
    
    ret = l
    for i in range(k-1):
        ret *= (l-i-1)
    for i in range(k):
        ret //= (1+i)
    return ret


ans = 0
K2 = K
L2 = L
for i in range(L):
    if K2 < 0 or L2 < 0:
        break
    if N[i]=='0':
        L2 -= 1
        continue
    elif N[i]=='1':
        ans += 9**K2 * cmb(L2-1,K2)* int((L2-1)>0)
    else:
        ans += 9**K2 * cmb(L2-1,K2) * int((L2-1)>0)
        t = int(N[i])
        ans += (t-1)* 9**(K2-1) * cmb(L2-1,K2-1)
    K2 -= 1
    L2 -= 1

ttmp = 0
for a in N:
    if a!='0':
        ttmp+=1
if ttmp == K:
    ans += 1
print(int(ans))

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

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

#define i5 100002

int main(){
	string s;
	bool f[3] = {};
	cin >> s;
	rep(i, 3){
		f[s[i] - 'a'] = true;
	}
	cout << (f[0] && f[1] && f[2] ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double distance(double p, int n, int *temp, int *TEMP){
    double ans = 0;
    for (int i = 0; i < n; i++){
        ans += pow(fabs(temp[i] - TEMP[i]), p);
    }
    ans = pow(ans, double(1 / p));
    return ans;
}

double distance_infi(int n, int *temp, int *TEMP){
    double ans = 0;
    for (int i = 0; i < n; i++ ){
        if (ans < fabs(temp[i] - TEMP[i])){
            ans = fabs(temp[i] - TEMP[i]);
        }
    }
    return ans;

}

int main(){
    int n;
    cin >> n;
    int a[n],b[n];
    double ans ;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    cout << setprecision(10) << distance(1, n, a, b) << endl;
    cout << setprecision(10) << distance(2, n, a, b) << endl;
    cout << setprecision(10) << distance(3, n, a, b) << endl;
    cout << setprecision(10) << distance_infi(n, a, b) << endl;


}


Measured memory_bytes: 3420
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,pair<int,int>>
#define F first
#define S second
using namespace std;
#define mod 1000000007

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

    int n; ll d; cin>>n>>d;
    int ans=0;
    while(n--){
        ll x,y; cin>>x>> y;
        ll curr=(ll)x*x+y*y;
        if(curr<=(ll) d*d) ans++;
    }
    cout<< ans <<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!

bool isOdd(ll a,ll b,ll c){
    return a&1 || b&1 || c&1 ;
}
ll _find(ll a,ll b,ll c){
    if(isOdd(a,b,c)){
        return 0;
    }
    ll x=(b+c)/2;
    ll y=(a+c)/2;
    ll z=(a+b)/2;
    vll p={a,b,c};
    vll q={x,y,z};
    sort(all(p));
    sort(all(q));
    return p==q?INT_MAX:1+_find(x,y,z);
}

void solve(){
    
    ll a,b,c;
    cin>>a>>b>>c;
    
    ll ans=_find(a,b,c);
    if(ans==INT_MAX){ans=-1;}
    cout<<ans<<endl;
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.1415926
double a,b,x;
double c;
double ans;
double deg;
int main(){
    scanf("%lf %lf %lf",&a,&b,&x);
    if(x >= a * a *  b / 2) {
    c = a * a;
    ans = (2*b-2*x/c)/a;
    deg = atan(ans)*180.0/PI;
    printf("%.10lf\n",deg);
    }
    else {
        deg = atan(a * b * b / 2 / x )*180.0/PI;
         printf("%.10lf\n",deg);
    }
    return 0;
}


Measured memory_bytes: 256
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N,A,B = imn()

# 繰り返し2乗法
ans = pow(2,N,MOD)-1

MAX = (10**5)*2

# nCrを求める
def cmb(n,r):
    denominator = numerator = 1
    for i in range(1,r+1):
        denominator = (denominator*i)%MOD
        numerator = (numerator * (n-i+1)) % MOD
    return (numerator * pow(denominator, MOD-2, MOD))%MOD

print((ans-cmb(N,A)-cmb(N,B))%MOD)

Measured memory_bytes: 5812
import sys
input = sys.stdin.readline
import numpy as np

MOD = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp = np.zeros(s+1, dtype=np.int64)
dp[0] = 1
for a in A:
  t = dp.copy() * 2
  t[a:] += dp[:-a]
  t %= MOD
  dp = t
ans = dp[s]
print(ans)

Measured memory_bytes: 27300
#include<bits/stdc++.h>
using namespace std;
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int M,K;

int main(){
	cin>>M>>K;
	int a=1;
	REP(i,M){
		a*=2;
	}
	if(a<=K){
		cout<<-1<<endl;
		return 0;
	}
	if(M==0){
		cout<<"0 0"<<endl;
		return 0;
	}
	if(M==1&&K==1){
		cout<<-1<<endl;
		return 0;
	}
	if(M==1&&K==0){
		cout<<"1 0 0 1"<<endl;
		return 0;
	}
	REP(i,a){
		if(i==K){
		}else{
			cout<<i<<" ";
		}
	}
	cout<<K<<" ";
	for(int i=a-1;i>=0;i--){
		if(i==K){
		}else{
			cout<<i<<" ";
		}
	}
	cout<<K<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<ll>> m(n + 1, vector<ll>(2));
  m.at(0) = {0, -INT_MAX};
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    m.at(i + 1).at(0) = max(m.at(i).at(0) + a.at(i), m.at(i).at(1) - a.at(i));
    m.at(i + 1).at(1) = max(m.at(i).at(0) - a.at(i), m.at(i).at(1) + a.at(i));
  }
  cout << m.at(n).at(0) << endl;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

const int N = 200010;

int n;
int m;
char h[N];
int w[N];
int cnt[N][2];
vi v[N];
int was[N];
int q[N];

int main () {
	scanf ("%d%d", &n, &m);
	scanf (" %s", h);
	for (int i = 0; i < n; i++) w[i] = h[i] - 'A';
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf ("%d%d", &a, &b); a--; b--;
		v[a].pb (b);
		v[b].pb (a);
		cnt[a][w[b]]++;
		cnt[b][w[a]]++;
	}
	int l = 0, r = 0;
	for (int i = 0; i < n; i++)
		if (cnt[i][0] == 0 || cnt[i][1] == 0) {
			q[r++] = i;
			was[i] = 1;
		}
	while (l < r) {
		int x = q[l++];
		for (int i = 0; i < sz (v[x]); i++) {
			int y = v[x][i];
			if (!was[y]) {
				cnt[y][w[x]]--;
				if (cnt[y][w[x]] == 0) {
					was[y] = 1;
					q[r++] = y;
				}
			}
		}
	}
	if (r < n) printf ("Yes\n"); else printf ("No\n");
	return 0;
}

Measured memory_bytes: 14208
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($a[$i], $b[$i]) = ints();
    $x[$i] = $a[$i] + $b[$i];
}
array_multisort($x, SORT_DESC, $a, $b);
$ascore = $bscore = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($i % 2 === 0) $ascore += $a[$i];
    else $bscore += $b[$i];
}
echo $ascore - $bscore;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 38708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main
{

	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str=br.readLine())!=null)
		{
			String[] buf=str.split(" ");
			int ans=1+(int)Math.log10((double)(Integer.parseInt(buf[0])+Integer.parseInt(buf[1])));
			System.out.println(ans);
		}


	}

}

Measured memory_bytes: 24264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <complex>
#include <complex>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <cstring>
#include <queue>
#include <set>
#define mp make_pair
#define pb push_back
const int MOD = 1e9 + 7;
const int N = 1e5;
using namespace std;
map<int , int> cnt;

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n , k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i< n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int t = 0;
    set <pair <int, int> > s;
    for (auto p : cnt)
    {
        s.insert(mp(p.second, p.first));
    }
    int ans = 0;
    while (s.size() > k)
    {
        auto x = *s.begin();
        s.erase(s.begin());
        auto y = *s.rbegin();
        s.erase(y);
        y.first += x.first;
        ans += x.first;
        s.insert(y);
    }
    cout << ans << "\n";
  }


Measured memory_bytes: 19840
#include <string>
#include <iostream>

#pragma warning(disable : 4996)

#define mod 100000

using namespace std;

int H, W, dp[2][1 << 19][2][2], bits[10946], maxbits;

string M[20];

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

	for (int i = 0; i < H; i++) cin >> M[i];

	if (M[0][0] == 'J' || M[0][0] == '?') dp[0][0][0][0] += 1;
	if (M[0][0] == 'O' || M[0][0] == '?') dp[0][0][1][0] += 1;
	if (M[0][0] == 'I' || M[0][0] == '?') dp[0][0][1][0] += 1;

	for (int i = 0; i < (1 << (W - 1)); i++)
	{
		bool ok = true;

		for (int j = 0; j < W - 2; j++)
		{
			if ((i & (1 << j)) && (i & (1 << (j + 1))))
			{
				ok = false; break;
			}
		}

		if (ok) bits[maxbits++] = i;
	}

	for (int i = 0; i < H * W - 1; i++)
	{
		for (int j = 0; j < maxbits; j++)
		{
			dp[(i ^ 1) & 1][bits[j]][0][0] = 0;
			dp[(i ^ 1) & 1][bits[j]][0][1] = 0;
			dp[(i ^ 1) & 1][bits[j]][1][0] = 0;
			dp[(i ^ 1) & 1][bits[j]][1][1] = 0;
		}

		char nowc = M[i / W][i % W];
		char nxtc = M[(i + 1) / W][(i + 1) % W];

		for (int j = 0; j < maxbits; j++)
		{
			int nxt = (bits[j] << 1) % (1 << (W - 1));

			int sum0 = (dp[i & 1][bits[j]][0][0] + dp[i & 1][bits[j]][1][0]) % mod;
			int sum1 = (dp[i & 1][bits[j]][0][1] + dp[i & 1][bits[j]][1][1]) % mod;

			if (nxtc == 'J' || nxtc == '?')
			{
				dp[(i ^ 1) & 1][nxt][0][0] += sum0;
				dp[(i ^ 1) & 1][nxt][0][1] += sum1;
			}

			if (nxtc == 'O' || nxtc == '?')
			{
				if ((nowc == 'J' || nowc == '?') && i % W != W - 1)
				{
					dp[(i ^ 1) & 1][nxt + 1][1][0] += dp[i & 1][bits[j]][0][0];
					dp[(i ^ 1) & 1][nxt + 1][1][1] += dp[i & 1][bits[j]][0][1];

					dp[(i ^ 1) & 1][nxt + 1][1][0] %= mod;
					dp[(i ^ 1) & 1][nxt + 1][1][1] %= mod;

					dp[(i ^ 1) & 1][nxt][1][0] += (sum0 - dp[i & 1][bits[j]][0][0] + mod);
					dp[(i ^ 1) & 1][nxt][1][1] += (sum1 - dp[i & 1][bits[j]][0][1] + mod);
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
					dp[(i ^ 1) & 1][nxt][1][1] += sum1;
				}
			}

			if (nxtc == 'I' || nxtc == '?')
			{
				if (bits[j] & (1 << (W - 2)))
				{
					dp[(i ^ 1) & 1][nxt][1][1] += sum0;
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
				}

				dp[(i ^ 1) & 1][nxt][1][1] += sum1;
			}

			dp[(i ^ 1) & 1][nxt][1][0] %= mod;
			dp[(i ^ 1) & 1][nxt][1][1] %= mod;
		}
	}

	int ret = 0;

	for (int i = 0; i < maxbits; i++)
	{
		ret += dp[(H * W - 1) % 2][bits[i]][0][1];
		ret += dp[(H * W - 1) % 2][bits[i]][1][1];

		ret %= mod;
	}

	printf("%d\n", ret);

	return 0;
}

Measured memory_bytes: 5868
def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [0] * i
            break
        else:
            i *= 2
    return tree

def update(i, x):
    i += len(tree) // 2
    tree[i] = x
    i //= 2
    while True:
        if i == 0:
            break
        tree[i] = tree[2 * i] + tree[2 * i + 1]
        i //= 2
    return

def get_sum(s, t):
    s += len(tree) // 2
    t += len(tree) // 2
    ans = 0
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            ans += tree[s]
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            ans += tree[t]
            t = (t - 1) // 2
    return ans

n, k = map(int, input().split())
s = list(input())
t = []
if s[0] == "0":
    t.append(0)
u = s[0]
c = 0
for i in s:
    if i == u:
        c += 1
    else:
        t.append(c)
        u = i
        c = 1
t.append(c)
if s[n - 1] == "0":
    t.append(0)
lt = len(t)
tree = make_tree(lt)
for i in range(lt):
    update(i, t[i])
k = 2 * k + 1
ans = 0
if lt - k > 0:
    for i in range((lt - k) // 2 + 1):
        ans = max(ans, get_sum(2 * i, 2 * (i + (k - 1) // 2)))
else:
    ans = n
print(ans)

Measured memory_bytes: 6840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <list>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    int N,H,W;
    cin >> N >> H >> W;
    cout << (N-H+1)*(N-W+1) << endl;
}

Measured memory_bytes: 256
S=input()
if len(S)==1:
    print(S)
else:
    bs=[bin(i)[2:].zfill(len(S)-1) for i in range(2**(len(S)-1))]
    operators=[['' if b[i]=='0' else '+' for i in range(len(S)-1)] for b in bs]
    formulas=[''.join([S[j]+operator[j] for j in range(len(S)-1)])+S[-1] for operator in operators]
    print(sum([eval(formula) for formula in formulas]))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = 1000000;
		boolean[] map = new boolean[N + 1];
		for (int i = 1; i <= N; i *= 2) {
			for (int j = 1; i * j <= N; j *= 3) {
				for (int k = 1; i * j * k <= N; k *= 5) {
					int s = i * j * k;
					map[s] = true;
				}
			}
		}
		int c = 0;
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			if (map[i])
				c++;
			num[i] = c;
		}

		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int m = scanner.nextInt();

			System.out.println(num[m] - num[n - 1]);
		}
	}
}

Measured memory_bytes: 26232
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;



// auto mod ll
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
//const ll mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//入力
ll n;
string s;

int main(){
    cin >> n >> s;
    ll n2 = 2*n;
    vector<char>c(n2);
    if(s[0]=='W'||s[n2-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    c[0]='L';
    ll l=0;
    ll r = 0;
    rep(i,n2-1){
        if(s[i]==s[i+1]){
            if(c[i]=='L'){
                c[i+1]='R';
            }
            else{
                c[i+1]='L';
            }
        }
        else{
            c[i+1]=c[i];
        }
    }
    rep(i,n2){
        if(c[i]=='L')l++;
        else r++;
    }
    if(l!=r){
        cout<<0<<endl;
        return 0;
    }
    ll res = 0;
    mint ans = 1;
    for(int i=n2-1;i>=0;i--){
        if(c[i]=='R'){
            res++;
        }
        else{
            ans *= res;
            res--;
        }
    }
    for(int i=n;i>=1;i--){
        ans *= i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
int dp[100000]={0};
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i=0;i<N;i++) cin >> h.at(i);
    dp[0]=0;
    dp[1]=abs(h.at(1)-h.at(0));
    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-1]+abs(h.at(i)-h.at(i-1)), dp[i-2]+abs(h.at(i)-h.at(i-2)));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 4064
def readinput():
    n,a,b = list(map(int,input().split()))
    return n,a,b

def sumdigit(n):
    sum=0
    t = getdigits(n)
    #print(n, t)
    for n in t:
        sum+=n
    return sum

def getdigits(n):
    if (n==10000):
        return (1,0,0,0,0)
    
    d4 = n // 1000
    n -= d4*1000
    d3 = n // 100
    n -= d3*100
    d2 = n // 10
    n -= d2*10
    return (d4,d3,d2,n)

def main(n,a,b):
    sum=0
    for i in range(1,n+1):
        s = sumdigit(i)
        #print(s)
        if (a<=s and s<= b):
            sum += i
    return sum

if __name__ == '__main__':
    n,a,b = readinput()
    sum = main(n,a,b)
    print(sum)

Measured memory_bytes: 3064
import Control.Monad
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    _ <- readInt
    ts <- readInts
    m <- readInt
    px <- replicateM m readInts
    forM_ px $ \[p, x] -> print $ sum $ replace ts (p - 1) x
    where
        readB = fst . fromJust . B.readInt
        readInt = readB <$> B.getLine
        readInts = map readB . B.words <$> B.getLine
        replace xs i v = take i xs ++ [v] ++ drop (i + 1) xs


Measured memory_bytes: 764
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let ab = get!(usize, usize; n);

    if ab.iter().all(|&(a,b)| a == b) {
        println!("0");
        return;
    }

    let total = ab.iter().map(|e| e.0).sum::<usize>();

    let mut mn = std::usize::MAX;
    for &(a,b) in &ab {
        if a > b {
            mn = min!(mn, b);
        }
    }
    println!("{}", total-mn);
}


Measured memory_bytes: 8572
#include <iostream>
#include <string>
using namespace std;

int toI(char c) {
	return c - '0';
}

int main() {
	string s;
	
	cin >> s;
	int m = toI(s[5]) * 10 + toI(s[6]);
	if (m <= 4) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Mehul Mathur randi hai
// Murali big ghey
// RisHiH is slave
// Anamaya is Sexy
// Arihanth is gay

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

ll ncr(ll n, ll r) 
{ 
    long long p = 1, k = 1; 
  
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            long long m = __gcd(p, k); 
  
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        }  
    }
    else
        p = 1; 
  
    return p; 
} 

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

    ll ans =0;

    if(m>1)
    {
        ans = ncr(m,2);
    }

    if(n>1)
    {
        ans = ans + ncr(n,2);
    }

    cout<<ans<<endl;
}


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

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    if(a==b&&b==c&&a==c) cout<<"1"<<endl;
    else if(a==b||b==c||a==c) cout<<"2"<<endl;
    else cout<<"3"<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappop, heappush
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def solve():
  n,m = (int(i) for i in input().split())
  route = Graph()
  tmp = [[0]*n for _ in range(n)]
  
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    route.add_edge(a-1,b-1,c)
    route.add_edge(b-1,a-1,c)
    tmp[a-1][b-1] = 1

  
  for i in range(n):
    #iを始点としてjに着く経路
    ds = Dijkstra(route,i)
    for j in range(n):
      if not i== j:
        query = ds.shortest_path(j)
        for k in range(len(query)-1):
            tmp[query[k]][query[k+1]] = 0
  ans = 0
  for i in range(n):
    ans += sum(tmp[i])
  print(ans)
        
solve()

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main() {
	int H,W;
	cin >> H >> W;
	vector<string> a(H);
	for(int i=0;i<H;i++){
		cin >> a[i];
	}
 
	vector<bool> row(H,false);
	vector<bool> col(W,false);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(a[i][j]=='#'){
				row[i]=true;
				col[j]=true;
			}
		}
	}
 
	for(int i=0;i<H;i++){
		if(row[i]){
			for(int j=0;j<W;j++){
				if(col[j]){
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace abc116a
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            Console.ReadKey(true);
#endif
        }
        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            double c = (double)a / (double)b;
            WriteLine($"{c}");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define limit 1e18
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long input;
  vector<long long >arr;
  int flag = 0;
  for(int i=0;i<n;++i)
  {
    cin>>input;
    arr.push_back(input);
    if(input == 0)flag = 1;
  }
  if(flag)cout<<0;
  else
  {
     long long ans = 1;
    long long present_limit = 1e18;
    for(int i=0;i<n;++i)
    {
       ans *= arr[i];
       present_limit = (long long int )limit / ans;
      if(i+1 < n and arr[i+1] > present_limit)
      {
        cout<<-1;
        return 0;
      }
    }
    cout<<ans;
  }
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7+7;
map<int,int> sum;
int n;
ll ans;
int a[maxn],vis[maxn];
bool cmp(int x,int y) {return x>y;}
int main()
{
//    freopen("powers.in","r",stdin);
//	freopen("powers.out","w",stdout);
//	ios::sync_with_stdio(false);
//	cin>>n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
//		cin>>a[i];
		scanf("%d",&a[i]);
		sum[a[i]]++;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(sum[a[i]]==0) continue;
//		vis[i]=1;
		int k=1;
		for(int j=1;j<=30;j++) 
		{
			if(k>a[i]) break ; 
			k*=2;
		} 
		int x=k-a[i];
		if(x==a[i])
		{
			if(sum[x]>1)
			{
				sum[x]-=2;
				ans++;
			}
		}
		else
		if(sum[x]>0 && sum[a[i]]>0)
		{
//			cout<<sum[a[i]]<<endl;
			sum[a[i]]--;
			sum[x]--;
			ans++;
		}
//			int x=a[i]-j;
////			cout<<x<<endl;
//			for(int k=1;k<=n;k++)
//			if(a[k]==x && vis[k]!=1)
//			{
////				cout<<i<<' '<<k<<endl;
//				vis[i]=1;
//				vis[k]=1;
//				ans++;
//				break ;
//			}
//			int lb=lower_bound(a+1,a+n+1,a[i]-j)-a;
//			while(a[lb]==a[i]-j && vis[lb]==1) lb--;
//			if(a[lb]==a[i]-j)
//			{
//				vis[i]=1;
//				vis[lb]=1;
//				ans++;
//			}
	}
	cout<<ans;
	return 0;
}
 

Measured memory_bytes: 20992
fun main(args: Array<String>) {
    val (N, C) = listOfInt()
    val D = Array(C) { listOfInt().toIntArray() }
    val t = Array(3) { IntArray(C) }
    repeat(N) { i ->
        listOfInt().forEachIndexed { j, x ->
            t[(i + j) % 3][x - 1] += 1
        }
    }
    var ans = Int.MAX_VALUE
    for (i in 0 until C) {
        for (j in 0 until C) {
            if (i == j) continue
            for (k in 0 until C) {
                if (i == k || j == k) continue
                var x = 0
                x += (0 until C).sumBy { D[it][i] * t[0][it] }
                x += (0 until C).sumBy { D[it][j] * t[1][it] }
                x += (0 until C).sumBy { D[it][k] * t[2][it] }
                ans = Math.min(x, ans)
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

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

typedef long long ll;
 
int main(){
  int n, k;
  cin >> n >> k;
  int a[n]={}, cnt=0;
  for(int i=0; i<n; i++){
    int b;
    cin >> b;
    b--;
    if(a[b]==0) cnt+=1;
    a[b]++;
  }
  priority_queue<int,  vector<int>, greater<int>> que;
  for(int i=0; i<n; i++){
    if(a[i]!=0) que.push(a[i]);
  }
  int ans = 0;
  while(cnt>k){
    ans += que.top();
    que.pop();
    cnt--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int[] machi = new int [N+1];
        int[] kougeki = new int [N];
        
        for (int index=0; index<N+1; index++){
            machi[index]=sc.nextInt();
        }
        for (int index=0; index<N; index++){
            kougeki[index]=sc.nextInt();
        }
        
        Long count = 0l;
        
        for (int index=0; index<N+1; index++){
            if (index==0&&machi[index]>kougeki[index]){
                machi[index]=machi[index]-kougeki[index];
                count+=kougeki[index];
                kougeki[index]=0;
            } else if (index==0&&machi[index]<=kougeki[index]){
                count+=machi[index];
                kougeki[index]=kougeki[index]-machi[index];
                machi[index]=0;
            } else if (machi[index]<=kougeki[index-1]){
                count+=machi[index];
                machi[index]=0;
                kougeki[index-1]=0;
            } else {
                count+=kougeki[index-1];
                machi[index]-=kougeki[index-1];
                kougeki[index-1]=0;
                if (index<N){
                    if (machi[index]>kougeki[index]){
                        machi[index]-=kougeki[index];
                        count+=kougeki[index];
                        kougeki[index]=0;
                    } else {
                        count+=machi[index];
                        kougeki[index]=kougeki[index]-machi[index];
                        machi[index]=0;
                    }
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 79284
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
max_num = 0
for i in range(N):
    if A[i] == m:
        max_num += 1
        if max_num >1:
            print(m)
        else:
            print(max(A[:i]+A[i+1:]))
    else:
        print(m)

Measured memory_bytes: 15580
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cmath>
#include <numeric>

using ll = long long;
using std::cout;
using std::cin;
using std::endl;

const ll max = 100005;
typedef enum{ UNDEF=0, PRIME, NONP} Prime;

bool is_prime(ll num){
    static Prime prime_table[max] = {NONP,NONP,PRIME,PRIME};
    if(prime_table[num]!=UNDEF){
        return (prime_table[num]==PRIME);
    }
    ll eratos_max = (ll)(std::sqrt(num))+1;
    for(int i=2; i<=eratos_max; i++){
        if(num%i==0){
            prime_table[num] = NONP;
            return false;
        }
    }
    prime_table[num] = PRIME;
    return true;
    
}

int main(){
    ll n,q;
    cin >> n >> q;
    std::string s;
    cin >> s;
    std::vector<ll> l(q),r(q);
    for(int i=0; i<q; i++){
        cin >> l[i] >> r[i];
    }

    std::vector<ll> a(s.size());
    a[s.size()-1] = 0;
    for(int i=0; i<s.size()-1; i++){    // ACACTACG
        if(s[i]=='A' && s[i+1]=='C'){ // 10100100
            a[i] = 1;
        }else{
            a[i] = 0;
        }
    }
    std::vector<ll> sum(s.size()+1);
    sum[0] = 0;
    for(int i=0; i<s.size(); i++){   // 011222333 
        sum[i+1] = sum[i] + a[i];
    }
    for(int i=0; i<q; i++){
        cout << sum[r[i]-1] - sum[l[i]-1] << endl;
    }
    // 12345678
    // ACACTACG
    // 10100100
    // 011222333
    // 3,7
    //   ACTAC
    //   12223
    
    return 0;
}

Measured memory_bytes: 4224
import sys
import bisect

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    count = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if L[i] == L[j]:
                continue
            a = bisect.bisect_right(L[j+1:],L[j])
            b = bisect.bisect_left(L[j+1:],L[i]+L[j])
            count +=b-a


    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73616
#include <stdio.h>

#define MAX 100003

int p[MAX],l[MAX],r[MAX],d[MAX];

void depth(int x,int dep){
  d[x]=dep;
  if(r[x]!= -10)depth(r[x],dep);
  if(l[x]!= -10)depth(l[x],dep+1);
}

int main(){
  int i,j,n,m,v,t,ll,root;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    p[i]=-1;
    l[i]=-10;
    r[i]=-10;
  }

  for(i=0;i<n;i++){
    scanf("%d",&v);
    scanf("%d",&m);
    for(j=0;j<m;j++){
      scanf("%d",&t);
      if(j==0)l[v]=t;
      else r[ll]=t;
      ll=t;
      p[t]=v;
    }
  }

  for(i=0;i<n;i++){
    if(p[i]==-1){
      root=i;
      break;
    }
  }

  depth(root,0);
  
  for(i=0;i<n;i++){
    printf("node %d: parent = ",i);
    printf("%d, depth = %d, ",p[i],d[i]);
    if(p[i]==-1)printf("root, [");
    else if(l[i]==-10)printf("leaf, [");
    else printf("internal node, [");
    t=l[i];
    for(j=0;t != -10;t=r[t]){
      if(j!=0){
	printf(", ");
      }
      j=1;
      printf("%d",t);
    }
    printf("]\n");
  }

  return 0;
}



Measured memory_bytes: 6392
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

int N;


int main()
{
	int A, B, C, X, Y;
	ll ans = INF;
	cin >> A >> B >> C >> X >> Y;

	REP(i,100001){
		ll cost = A * max(0,X - i) + B * max(0,Y - i) + C * 2 * i;
		if(cost<ans){
			ans = cost;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
alpha_cnt = [100 for _ in range(26)]

for _ in range(int(input())):
    cnt_sub = [0 for _ in range(26)]
    for ss in input():
        pos = ord(ss) - ord("a")
        cnt_sub[pos] += 1
    for i in range(26):
        alpha_cnt[i] = min(alpha_cnt[i], cnt_sub[i])

ans = ""
for i in range(26):
    num = ord("a") + i
    ans += chr(num) * alpha_cnt[i]
print(ans)
    

Measured memory_bytes: 65552
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
  int n, l;
  cin>>n>>l;
  vector<string> s(n); rep(i, n) cin>>s[i]; sort(all(s));
  string res;
  rep(i, n) res += s[i]; cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

nyan :: Int -> Int -> [Int] -> Bool
nyan _ _ [] = True
nyan a b (x:xs)
    | a < x && b < x = nyan x b xs || nyan a x xs
    | a < x          = nyan x b xs
    | b < x          = nyan a x xs
    | otherwise      = False

solve :: [Int] -> IO ()
solve = putStrLn . (\ x -> if x then "YES" else "NO") . nyan 0 0

main :: IO ()
main = readLn
    >>= (\ n -> replicateM n getLine)
    >>= mapM_ solve . map (map read) . map words

Measured memory_bytes: 4088
#include <stdio.h>
int main(){
	int a,b,c;
	int j=0;
	scanf("%d %d %d",&a,&b,&c);
	for (int i=a;i<=b;i++){
		if (i%c==0){
			
			j++;
		}
	}
	printf("%d",j);
	
	return 0;
}

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

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

	
	int n;
	cin >> n;
	vll t(n);
	rep(i,n)cin >> t[i];
	int m;
	cin >> m;
	vll p(m),x(m);
	rep(i,m)cin >> p[i] >> x[i];

	int s = 0;
	rep(i,n)s += t[i];

	rep(i,m){
		cout << s + x[i] - t[p[i]-1] << endl;
	}



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

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

Measured memory_bytes: 3612
import sys
import itertools
from decimal import Decimal, ROUND_CEILING
array = [ int(input()) for I in range(5) ]
for I in array:
    if not ( 1 <= I <= 123 ):
        sys.exit()

min = (123 * 5) + (10 * 5)
for J in list(itertools.permutations(array)):
    time = 0
    for K in J[0:-1]:
        time += K
        time = Decimal(time).quantize(Decimal('1E1'), rounding=ROUND_CEILING)
    time += J[-1]
    if min > time: min = time
print(min)

Measured memory_bytes: 9984
k=input()
if int(k)%2==0:
    print(-1)
else:
    s=7
    count=1
    flag=0
    while 1:
        if s%int(k)==0:
            print(count)
            break
        if count>int(k):
            print(-1)
            break
        s=(s%int(k))*10+7
        count+=1
    

Measured memory_bytes: 9152
#include <iostream>
using namespace std;

int getSumOfDigit(int n) {
    return (n > 0 ? (n % 10) + getSumOfDigit(n / 10) : 0);
}

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

    cout << (n % getSumOfDigit(n) == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    queue<string> que;
    que.push("a");
    int cnt = 1;
    set<string> ans;
    while(1){
        string fa = que.front();
        // if(fa.size() == n) ans.insert(fa);
        // que.pop():
        if(que.front().size() >= n) break;
        char maxc = 'a';
        rep(i,fa.size()){
            chmax(maxc,fa[i]);
        }
        rep(i,int(maxc - 'a' + 2)){
            que.push(fa + char('a' + i));
        }
        que.pop();
        cnt++;
    }
    // for(auto u : ans){
    //     cout << u << endl;
    // }
    while(!que.empty()){
        cout << que.front() << endl;
        que.pop();
    }
    return 0;
}

Measured memory_bytes: 7216
from fractions import gcd
 
a,b=map(int,input().split())

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

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

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

    return arr
x=gcd(a,b)
if x!=1:
    print(len(factorization(x))+1)
else:
    print(1)

Measured memory_bytes: 5084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,y;
  while(cin>>n&&n){
    vector<int> w(n),h(n);
    w[0]=h[0]=0;
    for(int i=1;i<n;++i){
      cin>>x>>y;
      switch(y){
      case 0:
	w[i]=w[x]-1;
	h[i]=h[x];
	break;
      case 1:
	w[i]=w[x];
	h[i]=h[x]-1;
	break;
      case 2:
	w[i]=w[x]+1;
	h[i]=h[x];
	break;
      case 3:
	w[i]=w[x];
	h[i]=h[x]+1;
      }
    }
    sort(w.begin(),w.end());
    sort(h.begin(),h.end());
    int maxw=w[n-1];
    int minw=w[0];
    int maxh=h[n-1];
    int minh=h[0];
    cout<<maxw-minw+1<<" "<<maxh-minh+1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092