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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector< pair<int,int> > edge;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    edge.emplace_back(u, v);
  }

  vector<long long> res(m);
  long long ans = (long long) n * (n - 1) / 2;

  vector<int> pa(n), num(n, 1);
  iota(pa.begin(), pa.end(), 0);

  function<int(int)> find = [&](int i) {
    if (i == pa[i]) return i;
    return pa[i] = find(pa[i]);
  };
  auto unite = [&](int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) return;
    ans += (long long) num[i] * (num[i] - 1) / 2;
    ans += (long long) num[j] * (num[j] - 1) / 2;
    pa[j] = i;
    num[i] += num[j];
    ans -= (long long) num[i] * (num[i] - 1) / 2;
  };

  for (int i = m - 1; i >= 0; i--) {
    res[i] = ans;
    int u, v;
    tie(u, v) = edge[i];
    unite(u, v);
  }

  for (int i = 0; i < m; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 3700
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  string ss;
  cin >> ss;
  bool n,e,w,s;
  n = e = w = s = false;
  rep(i,0,ss.size()) {
    if(ss[i] == 'N') n = true;
    if(ss[i] == 'S') s = true;
    if(ss[i] == 'E') e = true;
    if(ss[i] == 'W') w = true;
  }
  if((n ^ s) || (e ^ w)) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}

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

using namespace std;

void solve()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << char(s1[0] + 'A' - 'a') << char(s2[0] + 'A' - 'a') << char(s3[0] + 'A' - 'a') << endl;
}

int main()
{
	solve();
	return(0);
}

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

string str;

int main( void ) {
    
    cin >> str;
    
    for( int i = 0; i < 4; i ++ )
        cout << str[i];
    cout << " ";
    for( int i = 4; i < 12; i ++ )
        cout << str[i];
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = rr()
x = 0
for i in n:
    x += int(i)
n = int(n)
if n % x == 0:
    print('Yes')
else:
    print('No')













Measured memory_bytes: 26744
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll n, a[5];
    cin >> n;
    REP(i, 5) cin >> a[i];
    ll mn = INF, mn_i;
    REP(i, 5){
        if(mn > a[i]){
            mn = a[i];
            mn_i = i;
        }
    }
    cout << mn_i + ((n % a[mn_i] == 0)? n / a[mn_i] : n / a[mn_i] + 1) + 4 - mn_i << endl;
}

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

int main(){
    int n;
    int ans=0;
    cin>>n;
    vector<int>p(n);
    vector<int>q(n);

    for(int a=0;a<n;a++){
        cin>>p.at(a);
    }

    for(int b=0;b<n-2;b++){
        if(p.at(b)<=p.at(b+1) &&p.at(b+1)<=p.at(b+2)){
        ans++;
    }else if(p.at(b)>=p.at(b+1) &&p.at(b+1)>=p.at(b+2)){
        ans++;
    }
    }

    cout<<ans<<endl;
    return 0;
}



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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    int tmp;

    for (int n = 1; n <= N; n += 2) {
        tmp = 0;
        for (int i = 1; i <= sqrt(n); ++i) {
            if (n%i == 0) {
                if (n/i == i) tmp++;
                else tmp += 2;
            }
        }
        if (tmp == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(int argc,char* argv[]){
  int mode[100];
  int num;
  int i;
  int max = 0;
  
  for(i = 0;i < 100;i++){
    mode[i] = 0;
  }
  
  while(scanf("%d",&num) != EOF){
    mode[num-1]++;
  }
  
  for(i = 0;i < 100;i++){
    if(mode[i] > max){
      max = mode[i];
    }
  }
  
  for(i = 0;i < 100;i++){
    if(mode[i] == max){
      printf("%d\n",i+1);
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<li> as(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
    }

    sort(as.begin(), as.end());

    li left = -1, right = n;
    while (right - left > 1) {
        li idx = (left + right) / 2;
        li init_a = as[idx];
        li best_a = init_a + m;

        vector<li> bins;
        li uppers = 0;
        for (int i = 0; i < n; ++i) {
            if (i == idx) {
                continue;
            }
            li sz = best_a - as[i];
            if (sz < 0) {
                uppers += 1;
            } else {
                bins.push_back(sz);
            }
        }

        while (uppers < p - 1 && !bins.empty()) {
            uppers++;
            bins.pop_back();
        }

        bool ok;
        if (uppers >= p) {
            ok = false;
        } else {
            li votes = max(v - 1 - uppers, 0LL);
            li judges = m;
            li costs = votes * judges;
//            cout << idx << " " << bins.size() << " " << votes << " " << judges << endl;

            for (int i = 0; i < bins.size(); ++i) {
                costs -= min(bins[i], judges);
            }

//            cout << costs << endl;
            ok = costs <= 0;
        }

        if (ok) {
            right = idx;
        } else {
            left = idx;
        }
    }

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

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

int main(){
  int N;
  cin >> N;
  for(int i=0;i<=N;i++){
    int res = i*1.08;
    if(res == N){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())

robots = []

# ロボットを設定する
for _ in range(N):
    x, l = map(int, input().split())
    robots.append([x-l, x+l])
    
# 手の届く最大値でソートする
robots = sorted(robots, key=lambda x: x[1])

# Maxが小さいもの優先で選択する
pos = robots[0][1]
cnt = 1
for i in range(1, len(robots)):
    robo = robots[i]
    if robo[0] >= pos:
        pos = robo[1]
        cnt += 1

print(cnt)

Measured memory_bytes: 22104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int n, k;
    cin >> n >> k;
    
    double ans = 0;
    
    for(int i=1; i<=n; i++){
        int now = i;
        double bun = 1.0;
        while(now < k){
            now *= 2;
            bun /= 2.0;
        }
        
        ans += bun;
    }
    
    ans = ans * (1.0 / n);
    
    printf("%.12f\n", ans);

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoderPractice0704
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            long[] X = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            long Xmin = X.ToList().Min();
            long Xmax = X.ToList().Max();


            long minsouwa = 0;
            //体力の総和を出す
            for (var p = Xmin; p <= Xmax; p++)
            {
                long souwa = 0;
                for (var i = 0; i < N; i++)
                {
                    souwa += (X[i] - p) * (X[i] - p);
                }
                if (p == Xmin)
                {
                    minsouwa = souwa;
                    continue;
                }
                if (minsouwa >= souwa)
                {
                    minsouwa = souwa;
                }
            }
            Console.WriteLine(minsouwa);
        }
    }
}

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
string b;
int main(){
	ios::sync_with_stdio(false);
	cin>>b;
	sort(b.begin(),b.end());
	if(b[0]==b[1]&&b[2]==b[3]&&b[1]!=b[2])cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import sys

l = [int(i) for i in sys.stdin]

done = [False] * (l[0] + 1)

i = 1

ans = 0

while True:
    if done[i] == False:
        done[i] = True
        ans += 1
        if l[i] == 2:
            break
        i = l[i]
    else:
        ans = -1
        break

print(ans)


Measured memory_bytes: 7840
while true
  xs,ys=gets.split
  x=xs.to_i
  y=ys.to_i
  break if x == 0 && y == 0
  results = []
  prices = gets.split(' ').map(&:to_i)
  (0..x-1).each do |i|
    (0..i-1).each do |j|
      sum = prices[i] + prices[j]
      results.push(sum) if sum <= y
    end
  end
  puts results.empty? ? 'NONE' : results.max
end


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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


long int gcd(long int a, long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

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

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


int main(void){
  long int a,b,c,k;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&k);
  if(k%2==0){
    printf("%ld\n",a-b);
  }else{
    printf("%ld\n",b-a);
  }
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	int x, n;

	cin >> n;

	x = (int)ceil(n / 1.08);
	if ((int)(floor(x * 1.08) == n))
		cout << x << endl;
	else
		cout << ":(" << endl;
		

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

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

        int ans = 0;
        for(int i=0; i<n; ++i){
            if(a[i] * n <= sum)
                ++ ans;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

bool isBeki(int n){
  if(n==1){
    return true;
  }
  int so[1000]={};

  while(n!=1){
    for(int i = 2; i < n+1; i++){
      if(n % i == 0){
        so[i]++;
        n /= i;
        break;
      }
    }
  }

  int su=0, m=99999;
  for(int i = 0; i < 1000; i++){
    if(so[i] != 0)
      m = min(m,so[i]);
  }

  for(int i = 0; i < 1000; i++){
    if(so[i] % m != 0){
      return false;
    }
  }
  return m >= 2;
}

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

  for(int i = X; i >= 1; i--){
    if(isBeki(i)){
      cout << i << endl;
      return;
    }
  }
}

int main(){
  solve();
  return 0;
}

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

int main() {
  long long MOD = 1000000007;
  long long N, K; cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  long long a = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      if (A.at(i) > A.at(j)) a++;
    }
  }
  long long d = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A.at(i) > A.at(j)) d++;
    }
  }
  long long ans = ((K * a) % MOD + (((K * (K-1) / 2) % MOD) * d) % MOD) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
"""
aabbaa

aa b ba a
a ab b aa
"""
s = list(input())

n = len(s)
hst = []
sk = ""

for i in range(n):
    sk += s[i]
    if i == 0:
        hst.append(sk)
        sk = ""
    elif hst[-1] != sk:
        hst.append(sk)
        sk = ""

print(len(hst))

Measured memory_bytes: 9636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff     first
#define  ss     second
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; 
#define  D2p(x)	cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << "\n";
#define  ps(x,y) fixed<<setprecision(y)<<x

int main() {
    IOS;
    long double l; cin >> l;
    long double x = (l / 3); 
    cout << ps(x*x*x,12);
}

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

typedef unsigned long long ll;

int main(int, char**)
{
	ll a, b;
	cin >> a >> b;
	if ((a+b)%2 > 0)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << ((a + b)/2) << endl;
	return 0;
}

Measured memory_bytes: 256
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int l,r,d;
	cin >> l >> r >> d;
	cout << r/d-(l-1)/d << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];
ll nu_b[200005];

ll n, m, k;

ll bin(int st, int en, ll val)
{
	if (en - st <= 1)
		return st;

	int mi = (st + en) / 2;
	ll look = nu_b[mi];

	if (look == val)
		return mi;
	else if (look < val)
		return bin(mi, en, val);
	else
		return bin(st, mi, val);
}

int main()
{
	cio;
	cin >> n >> m >> k;

	for (ll i = 1; i <= n; i++)
		cin >> arr[i];
	for (ll i = 1; i <= m; i++)
	{
		ll inp;
		cin >> inp;
		nu_b[i] = nu_b[i - 1] + inp;
	}

	ll ma = 0;
	ll nu_a = 0;
	for (ll i = 0; i <= n; i++)
	{
		nu_a += arr[i];

		if (nu_a > k)
			break;

		ma = max(ma, i + bin(0, m + 1, k - nu_a));
	}

	cout << ma;
}

Measured memory_bytes: 6300
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

map<ll, int> mp;
void factorize(ll n) {
    for (ll i = 2; i*i <= n; ++i) {
        if (n%i) continue;
        while (n%i == 0) {
            n /= i;
            mp[i]++;
        }
    }
    if (n != 1) mp[n]++;
}

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

    rep(i, n) factorize(i+1);

    map<int, int> src;
    for(auto x : mp) {
        if (x.se >= 74) src[75]++;
        if (x.se >= 24) src[25]++;
        if (x.se >= 14) src[15]++;
        if (x.se >= 4) src[5]++;
        if (x.se >= 2) src[3]++;
    }

    int ans = 0;
    ans += src[75];
    ans += src[25] * max(src[3]-1, 0);
    ans += src[15] * max(src[5]-1, 0);
    ans += src[5] * max(src[5]-1, 0) / 2 * max(src[3]-2, 0);    

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
const int maxn=1000000; 
bool arr[maxn+1]={false}; 
vector<int> produce_prim_number() 
{ 
        vector<int> prim; 
        prim.push_back(2); 
        int i,j; 
        for(i=3;i*i<=maxn;i+=2) 
        { 
                if(!arr[i]) 
                { 
                        prim.push_back(i); 
                        for(j=i*i;j<=maxn;j+=i) 
                                arr[j]=true; 
                } 
        } 
        while(i<maxn) 
        { 
                if(!arr[i]) 
                        prim.push_back(i); 
                i+=2; 
        } 
        return prim; 
} 
//计算n!中素数因子p的指数  
int cal(int x,int p) 
{ 
        int ans=0; 
        long long rec=p; 
        while(x>=rec) 
        { 
                ans+=x/rec; 
                rec*=p; 
        } 
        return ans; 
} 
//计算n的k次方对m取模，二分法  
int pow(long long n,int k,int M) 
{ 
        long long ans=1; 
        while(k) 
        { 
                if(k&1) 
                { 
                        ans=(ans*n)%M; 
                } 
                n=(n*n)%M; 
                k>>=1; 
        } 
        return ans; 
} 
//计算C（n，m）  
int combination(int n,int m) 
{ 
        const int M=1e9+7; 
        vector<int> prim=produce_prim_number(); 
        long long ans=1; 
        int num; 
        for(int i=0;i<prim.size()&&prim[i]<=n;++i) 
        { 
            num=cal(n,prim[i])-cal(m,prim[i])-cal(n-m,prim[i]); 
            ans=(ans*pow(prim[i],num,M))%M; 
        } 
		return ans; 
}
int main(){
	int x,y;
	cin>>x>>y;
	if((x+y)%3==0){
		int Y=(y+y-x)/3,tot=(x+y)/3;
		int X=tot-Y;
		if(X<0||Y<0){
			cout<<0<<endl;
			return 0;
		}
		cout<<combination(tot,Y)<<endl;
	}
	else{
		cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 1916
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//typedef
//------------------------------------------
template<class T> using v=vector<T>;
using VI = v<int>;
using VVI = v<v<int>>;
using VS = v<string>;
using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
using VLL = v<LL>;
using VVLL = v<VLL>;

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

//update
//------------------------------------------
template<class T>inline T updmax(T& target, T val) { return target = max(target, val); }
template<class T>inline T updmin(T& target, T val) { return target = min(target, val); }

const int N = 1005;
LL a[N];
LL s[N];
bool b[N];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%lld", &a[i]);
	LL ma = a[0];
	int ma_idx = 0;
	REP(i, n) {
		if (ma < a[i]) {
			ma = a[i];
			ma_idx = i;
		}
	}
	if (ma <= 0) {
		printf("%lld\n", ma);
		printf("%d\n", n - 1);
		for (int i = n - 1; i > ma_idx; i--)printf("%d\n", i + 1);
		REP(i, ma_idx)printf("%d\n", 1);
		return 0;
	}
	REP(i, n)s[i + 2] = s[i] + max(a[i], 0LL);
	printf("%lld\n", max(s[n], s[n+1]));
	VI ret;
	int k = (s[n + 1] > s[n]) ? (n - 1) : (n-2);
	for (int i = k; i >= 0; i-=2)b[i] = (a[i] > 0);
	while (!b[n-1]) ret.PB(--n);
	for (int i = n-1; i >= 2; i -= 2) {
		if (b[i - 2])ret.PB(i - 1);
		else ret.PB(i - 2);
	}
	if (!b[0])ret.PB(0);
	printf("%d\n", ret.size());
	for (auto v : ret)printf("%d\n", v+1);
	return 0;
}

Measured memory_bytes: 256
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

###########

n=i()
a=ii()
cost=0
ave=int(round(float(sum(a))/float(n)))
for i in range(n):
    cost+=(a[i]-ave)**2
print int(cost)


Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){

	string s;
	cin >> s;

	for(int i=0;i<4;i++) cout << s[i] ;
	cout << " ";
	for(int i=4;i<12;i++) cout << s[i] ;

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef int LL;
const LL mod=998244353,maxn=3e2+9;
LL n;
LL f[maxn][maxn][maxn],g[maxn][maxn][maxn],is[maxn][maxn][maxn];
char s[maxn];
LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; }
LL mul(LL x,LL y){ return 1ll*x*y%mod; }
void chkmax(LL &x,LL y){ x=std::max(x,y); }
void chkmin(LL &x,LL y){ x=std::min(x,y); }
int main(){
	scanf(" %s",s+1);
	//f[n][0][0]=1;
	n=strlen(s+1);
	f[n][0][0]=1;
	for(LL i=n;i>=1;--i){
		for(LL j=0;j<=n;++j){
			for(LL k=0;k<=n;++k){
				f[i-1][j][k]=add(f[i-1][j][k],f[i][j][k]);
				if(s[i]=='0'){
					f[i][j][k+1]=add(f[i][j][k+1],f[i][j][k]);
				}else{
					f[i][j+1][k]=add(f[i][j+1][k],f[i][j][k]);
				}
				//if(i==3 && !j && !k) printf("%d,%d\n",f[n][0][0],f[i][j][k]);
			}
		}
	}
	memset(g,-1,sizeof(g));
	g[0][0][0]=0;
	for(LL i=0;i<=n;++i){
		for(LL j=0;j<=i;++j){
			for(LL k=0;k<=i;++k){
				LL tmp(g[i][j][k]);
				if(tmp==-1) continue;
				if(i+1<=n && tmp){
					if(s[i+1]=='0') chkmax(g[i+1][j+1][k],tmp-1);
					if(s[i+1]=='1') chkmax(g[i+1][j][k+1],tmp-1);
				}
				if(i+2<=n){
					if(s[i+1]=='0' || s[i+2]=='0') chkmax(g[i+2][j+1][k],tmp);
					if(s[i+1]=='1' || s[i+2]=='1') chkmax(g[i+2][j][k+1],tmp);
					chkmax(g[i+2][j][k],tmp+1);
				}
			}
		}
	}
	LL ret(0);
	for(LL i=0;i<=n;++i){
		for(LL j=i;j>=0;--j){
			for(LL k=i;k>=0;--k){
				is[i][j][k]=(g[i][j][k]!=-1);
				if(i) is[i][j][k]|=is[i-1][j][k];
				is[i][j][k]|=is[i][j+1][k];
				is[i][j][k]|=is[i][j][k+1];
			}
		}
	}
	for(LL i=0;i<=n;++i){
		for(LL j=0;j<=i;++j){
			for(LL k=0;k<=i;++k){
				if(n-i+j+k && is[i][j][k]){
					ret=add(ret,f[i][j][k]);
					//printf("%d,%d,%d\n",i,j,k);
				}
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}

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

int main() {
	int r, D, x;
	cin >> r >> D >> x;

	int FirstNum = r * x - D;

	cout << FirstNum << endl;

	for (int i = 1; i < 10; i++) {
		cout << r * FirstNum - D << endl;
		FirstNum = r * FirstNum - D;
	}

}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(int a,int b)
{
	return a>b;
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int r;cin>>r;
	int ans=r*r;
	cout<<ans<<endl;
	return 0;
}
 















 
 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 - y2 + y1 << ' ' <<  y2 + x2 - x1 << ' '<<  x1 - y2 + y1 << ' ' <<  y1 + x2 - x1;
	return 0;
}

Measured memory_bytes: 3564
from statistics import mean, median,variance,stdev
from collections import  Counter
n =int(input())
D = sorted(list(map(int,input().split())))
med = int(median(D))
middle = D[n//2+1 if n%2==1 else n//2 ]
if med >=middle:
	print(0)
else:
	print(D[(n//2+1 if n%2==1 else n//2)]-D[(n//2+1 if n%2==1 else n//2)-1])


Measured memory_bytes: 16036
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
vector<long long> divisor(long long n){//nの約数列挙
    vector<long long> res;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}
int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    long long sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    vector<long long> d = divisor(sum);
    sort(d.begin(), d.end());
    int size = d.size();
    for(int i = size - 1; i >= 0; i--){
        long long cnt = 0;
        vector<P> low(N);
        for(int j = 0; j < N; j++){
            long long temp = A[j] / d[i] * d[i];
            low[j] = P(A[j] - temp, temp + d[i] - A[j]);
        }
        sort(low.begin(), low.end());
        vector<P> sum(N + 1);
        sum[0] = P(0, 0);
        for(int j = 1; j < N + 1; j++){
            long long l = sum[j - 1].first + low[j - 1].first;
            long long r = sum[j - 1].second + low[j - 1].second;
            sum[j] = P(l, r);
        }
        for(int j = 0; j < N + 1; j++){
            if(sum[j].first == sum[N].second - sum[j].second && sum[j].first <= K){
                cout << d[i] << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a==1&&b==0&&c==0)||(a==0&&b==1&&c==0)||(a==0&&b==0&&c==0)){
    printf("Close\n");
  }else{
    printf("Open\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

using namespace std;

template <class T> int find_index(T x, const std::vector<T> &v) {
    auto it = std::find(v.begin(), v.end(), x);
    if (it != v.end()) { return (int)std::distance(v.begin(), it); }
    return -1;
}

template <class T> void print(T x) {
    std::cout << x << std::endl;
}
// 4近傍（右, 下, 左, 上）
const vector<int> dy = { 0, -1, 0, 1 };
const vector<int> dx = { 1, 0, -1, 0 };




int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> a(N);
    FOR(i, 0, N) {
        cin >> a[i];
    }

    int max_a_idx = find_index(MAX(a), a);

    bool positive = true;
    FOR(i, 0, N) {
        if (a[i] + a[max_a_idx] < 0) {
            positive = false;
        }
    }

    if (positive) {
        print(2 * N - 1);
        FOR(i, 0, N) {
            cout << max_a_idx + 1 << " " << i + 1 << endl;
        }
        FOR(i, 0, N - 1) {
            cout << i + 1 << " " << i + 1 + 1 << endl;
        }
        return 0;
    }
    else {
        int min_a_idx = find_index(MIN(a), a);
        print(2 * N - 1);
        FOR(i, 0, N) {
            cout << min_a_idx + 1 << " " << i + 1 << endl;
        }
        for (int i = N - 1; i > 0; --i) {
            cout << i + 1 << " " << i - 1 + 1 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;


bool is_connected[150][150];
int min_distance[150];

void init() {
    int i, j;

    rep(i, 150) {
        min_distance[i] = 150;
    }
    min_distance[0] = 0;
    min_distance[1] = 0;
    rep(i, 150) rep(j, 150) is_connected[i][j] = false;
}

void solveDepth(int src_id, int cur_depth) {
    int dst_id;
    rep(dst_id, 150) {
        if (is_connected[src_id][dst_id]) {
            if (cur_depth + 1 < min_distance[dst_id]) {
                min_distance[dst_id] = cur_depth + 1;
                solveDepth(dst_id, cur_depth + 1);
            }
        }
    }
}

int main() {
    int n, i, j, u, v, k;
    cin >> n;

    init();

    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v;
            is_connected[u][v] = true;
        }
    }

    solveDepth(1, 0);

    rep(i, n) {
        cout << i + 1 << " ";
        if (min_distance[i + 1] == 150) {
            cout << -1 << endl;
        } else {
            cout << min_distance[i + 1] << endl;
        }
        
    }

    return 0;
}


Measured memory_bytes: 3112
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

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

    /*
    int array[n];
    rep(i,n){
        array[i] = i+1;
    }
    */

    int p[n],q[n];
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    /*
    rep(i,n){
        if(p[i] > q[i]){
            rep(j,n){
                swap(p[j],q[j]);
            }
            break;
        }
    }
    */

    int a = 0, b = 0;
    while(next_permutation(p,p+n)){
        a++;
    }

    while(next_permutation(q,q+n)){
        b++;
    }

    int ans = abs(b-a);

    dunk(ans);
    return 0;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, m; cin >> n >> m;
	vl a(m);
	for (int i = 0; i < m; i++) cin >> a[i];
	sort(a.begin(), a.end());
	vl data(m - 1);
	if (n >= m) cout << 0 << endl;
	else {
		for (int i = 0; i < m - 1; i++) {
			data[i] = a[i + 1] - a[i];
		}
		sort(data.begin(), data.end());
		ll ans = 0;
		for (int i = 0; i + n < m; i++) {
			ans += data[i];
		}
		cout << ans << endl;
	}
}

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

using namespace std;

const int maxn = 1e6+10;
typedef long long LL;
LL q, h, s, d;
LL cos1, cos2;

int main() {
    LL n;
    scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
    cin >> n;
    cos1 = cos2 = 1e18;
    cos1 = min(cos1, q*4);
    cos1 = min(cos1, 2*q+h);
    cos1 = min(cos1, 2*h);
    cos1 = min(cos1, s);
    cos2 = min(d, cos1*2);
    cout<<min(cos1*n, n/2*cos2+n%2*cos1);
    return 0;
}

/*
5 5
5 6  8 9 10
1 5 7 1 2
2 5 2 1 3
2 3 3 3 3
3 3 3 3 3
3 3 3 3 3
*/


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<cmath>

using namespace std;

struct Info{string name,goods; double price;};
struct Item{
  int mincos, maxcos, total, num;
  Item():mincos(1001),maxcos(0),total(0),num(0){}
};
struct Dealer{int pay, receive;};

typedef vector<Info>::iterator ITE;

vector<Info> buy,sell;
map<string,Item> item;
map<string,Dealer> dealer;
int n;

void init(){
  buy.clear();
  sell.clear();
  item.clear();
  dealer.clear();
}


void updateItemInfo(const string&  name, int price){
  item[name].mincos = min(item[name].mincos,price);
  item[name].maxcos = max(item[name].maxcos,price);
  item[name].total += price;
  item[name].num++;
}

// person name, goods name, goods price
void sellOrder(const string& name, const string& goods, const double& price){
  item[goods];
  dealer[name];

  int pos = -1;
  
  for(int i = 0; i < (int)buy.size(); i++){
    if(name == buy[i].name) continue;
    if(goods != buy[i].goods) continue;
    if(price > buy[i].price) continue;

    if(pos == -1 || buy[pos].price < buy[i].price) pos = i;
  }

  if(pos == -1) sell.push_back((Info){name,goods,price});
  else{
    double ave = (price+buy[pos].price)/2.0;
    dealer[name].receive += (int)ave;
    dealer[buy[pos].name].pay += (int)ave;
    updateItemInfo(goods, (int)ave);
    buy.erase((ITE)&buy[pos]);
  }
}

void buyOrder(const string& name, const string& goods, const double& price){
  item[goods];
  dealer[name];

  int pos = -1;
  
  for(int i = 0; i < (int)sell.size(); i++){
    if(name == sell[i].name) continue;
    if(goods != sell[i].goods) continue;
    if(price < sell[i].price) continue;

    if(pos == -1 || sell[pos].price > sell[i].price) pos = i;
  }

  if(pos == -1) buy.push_back((Info){name,goods,price});
  else{
    double ave = (price+sell[pos].price)/2.0;
    dealer[name].pay += (int)ave;
    dealer[sell[pos].name].receive += (int)ave;
    updateItemInfo(goods, (int)ave);
    sell.erase((ITE)&sell[pos]);
  }
}

void solve(){
  for(int i = 0; i < n; i++){
    string name, state, goods;
    int price;
    cin >> name >> state >> goods >> price;
    if(state == "SELL") sellOrder(name, goods, price);
    else buyOrder(name,goods,price);
  }
}

void print(){
  map<string,Item>::iterator iteI = item.begin();

  while(iteI != item.end()){
    Item it = iteI->second;
    if(it.num != 0)
      cout <<iteI->first<<" "<<it.mincos<<" "<< it.total/it.num <<" "<<it.maxcos<<endl;
    iteI++;
  }

  cout << "--" << endl;

  map<string,Dealer>::iterator iteD = dealer.begin();

  while(iteD != dealer.end()){
    Dealer d = iteD->second;
    cout<<iteD->first<<" "<<d.pay<<" "<<d.receive<<endl;
    iteD++;
  }

  cout << "----------" << endl;
}

int main(){

 
  while(cin >> n && n){
    init();
    solve();
    print();
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string x;
    cin >> x;
    
    int stack = 0;
    int p=0;
    for (int i=0; i<x.size(); i++){
        if(x[i] == 'S'){
            stack++;
        }else if(stack > 0){
            stack--;
            p++;
        }
    }
    cout << x.size() - p * 2 << endl;
}


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

        int N = sc.nextInt();
        int M = sc.nextInt();
        sc.close();

        long[] kaijou = new long[Math.max(N, M)];
        kaijou[0] = 1;
        for(int i = 1; i < kaijou.length; i++){
            kaijou[i] = kaijou[i-1]*(i+1) % mod;
        }

        if(Math.abs(N-M) >= 2)
            System.out.println(0);
        else if(Math.abs(N-M) == 1){
            System.out.println(kaijou[M-1]*kaijou[N-1]%mod);
        } else{
            System.out.println(kaijou[M-1]*kaijou[N-1]*2%mod);
        }
    }
    
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct UnionFind{
    vector<int> par;
    vector<int> dep;
    
    UnionFind(int siz){
        par.assign(siz,0);
        dep.assign(siz,0);
        for(int i=0;i<siz;i++){
            par[i]=i;
        }
    };

    int find(int x){
        if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y){
            return;
        }
        if(dep[x]<dep[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(dep[x]==dep[y]){
                dep[x]++;
            }
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
};
int main(){
    int n,m;cin>>n>>m;
    int p[100010];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    UnionFind uf(n+1);
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        uf.unite(x,y);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(uf.same(i+1,p[i])){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
def is_prime(n):
    if n == 1:
        return False
    elif n == 2 or n == 3:
        return True
    elif n % 2 == 0:
        return False
    else:
        for i in range(3, int(n ** 0.5) + 1, 2):
            if n % i == 0:
                return False
                
        return True
        
n = int(input())
count = 0

for _ in range(n):
    m = int(input())
    if is_prime(m):
        count += 1

print(count)

Measured memory_bytes: 7684
#include <bits/stdc++.h>
#define ll long long
#define pi (acos(-1))
using namespace std;
/*todos
 * prime num gen
 * for macro
 * */
int main()
{   
    int x;
    cin >> x;
    if (x >= 30)
    {   
        cout << "Yes" <<endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
N, K = [int(x) for x in input().split()]
S = [s for s in input()]

t = S.pop(K-1)
if t == "A":
  S.insert(K-1, "a")
elif t == "B":
  S.insert(K-1, "b")
else:
  S.insert(K-1, "c")
S = "".join(S)
print(S)

Measured memory_bytes: 2940