akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////

signed main()
{
    fastio;
    int n;
    cin>>n;
    int a[n+2];
    for(int i=0;i<n;++i)
    {
        cin>>a[i+1];
    }
    int l[n+2]={},r[n+2]={};
    int su=0;
    
    int lr[n+2]={},rr[n+2]={};
    su=0;
    for(int i=n;i>=1;--i)
    {
        su+=a[i];
        if(a[i]%2==0)
        {
            if(a[i]==0)
                lr[i]=min(su,2+lr[i+1]);
            else
                lr[i]=min(su,lr[i+1]);
        }
        else
        {
            lr[i]=min(su,1+lr[i+1]);
        }
    }
    su=0;
    for(int i=1;i<=n;++i)
    {
        if(a[i]%2==0)
        {
            if(a[i]==0)
                rr[i]=min(su,2+rr[i-1]);
            else
                rr[i]=min(su,rr[i-1]);
        }
        else
        {
            rr[i]=min(su+1,1+rr[i-1]);
        }
        su+=a[i];
    }
    for(int i=n;i>=1;--i)
    {
        if(a[i]%2==0)
        {
            l[i]=min(1+min(l[i+1],lr[i+1]),su);
        }
        else
        {
            l[i]=min(l[i+1],lr[i+1]);
        }
        su+=a[i];
    }
    su=0;
    for(int i=1;i<=n;++i)
    {
        if(a[i]%2==0)
        {
            r[i]=min(su,1+min(rr[i-1],r[i-1]));
        }
        else
        {
            r[i]=min(rr[i-1],r[i-1]);
        }
        su+=a[i];
    }
    int ans=inf;
    for(int i=0;i<=n;++i)
    {
        ans=min(ans,lr[i+1]+r[i]);
        ans=min(ans,rr[i]+l[i+1]);
        ans=min(ans,rr[i]+lr[i+1]);
    }
    su=0;
    for(int i=1;i<=n;++i)
    {
        ans=min(ans,su+l[i]);
        ans=min(ans,su+lr[i]);
        su+=a[i];
    }
    su=0;
    for(int i=n;i>=1;--i)
    {
        ans=min(ans,su+r[i]);
        ans=min(ans,su+rr[i]);
        su+=a[i];
    }
    cout<<ans;
}

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

#define endl '\n'
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back
#define MAXN 200005

int main(){ios_base::sync_with_stdio(false);

    ll a, b, n;
    
    cin >> a >> b >> n;
    
    n = min(n, b-1);
    ll ans = ((a*n)/b) - (a*(n/b));

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    switch (n % 10) {
        case (0):
        case (1):
        case (6):
        case (8):
            cout<<"pon"<<endl;
            break;
        case (2):
        case (4):
        case (5):
        case (7):
        case (9):
            cout<<"hon"<<endl;
            break;
        default:
            cout<<"bon"<<endl;
            break;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
    string S;
    getline(cin, S);

    stack<int> st;
    for (int i = 0; i < S.size(); i++){
        int elem = S[i] - '0';
        if (st.empty() || st.top() == elem)
            st.push(elem);
        else
            st.pop();
    }

    cout << S.size() - st.size() << endl; 

    return 0;
}

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

const int maxn = 2e5+5;
int n, a[2*maxn], b[2*maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    priority_queue<pair<int,int>> q;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) q.push({b[i],i});
    }
    ll cnt = 0;
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        int i = p.second;

        int s = b[(i-1+n)%n] + b[(i+1+n)%n];
        if (b[i] <= s) continue;
        int k = (b[i]-a[i])/s;
        cnt += k;
        b[i] -= k*s;

        if (b[i] > a[i] && k > 0) q.push({b[i],i});
    }
    bool poss = true;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) poss = false;
    }
    if (poss) {
        cout << cnt << '\n';
    }
    else {
        cout << -1 << '\n';
    }
}



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

int n;
long long int k;
long long int sum;
int cnt[40];

long long int dfs(int i, int f){
	if(i<0){
		return 0;
	}
	long long int m = 1LL << i;
	if(f){
		return dfs(i-1, 1) + m*max(n-cnt[i],cnt[i]);
	}else{
		if(k >> i & 1){
			return max(dfs(i-1, 1) + m*cnt[i], dfs(i-1, 0) + m*(n-cnt[i]));
		}else{
			return dfs(i-1, 0)+m*cnt[i];
		}
	}
}

int main() {
	cin >> n >> k;
	for(int i=0;i<n;i++){
		long long int a; cin >> a;
		sum += a;
		for(int j=0;j<40;j++){
			cnt[j] += a >> j & 1;
		}
	}
	cout << dfs(39, 0) << endl;
	return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n);
    vec<P> b(n);
    REP(i, n) {
        cin >> a[i];
        b[i] = {-a[i], i};
    }
    b.push_back({0, INF});
    sort(all(b));
    ll con = 0;
    ll mi = INF;
    ll pre = 0;
    vec<ll> ans(n, 0);
    REP(i, n + 1) {
        auto [aa, j] = b[i];
        ll now = -aa;
        if(pre) {
            ans[mi] += (pre - now) * con;
        }
        pre = now;
        con++;
        chmin(mi, j);
    }
    for(auto i : ans) {
        cout << i << en;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 7128
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();    
        int n = r.i();
        int[] a = r.ii();
        int[] b = new int[n];
        int i = 0;
        int j;
        while((j = n-1-2*i) >= 0){
            b[i] = a[j];
            i++;
        }
        int k = 2*i-n;
        while(i < n){
            b[i] = a[k];
            i++;
            k+=2;
        }           
        StringBuffer sb = new StringBuffer();
        for(int x : b)
            sb.append(x+" ");
        println(String.valueOf(sb));
    }

    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 72580
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 105;
char s[maxn], t[maxn];

int main()
{
    int n;
    int i, j;
    int num;
    while(scanf("%d", &n)==1&&n)
    {
        scanf("%s", s);
        scanf("%s", t);
        if(strcmp(s, t)==0)
            printf("%d\n", n);
        else
        {
            int len1 = strlen(s);
            int len2 = strlen(t);
            i = 0;
            num = 0;
    //        for(int i = 0; i < len1;)
    //        {
                for(j = 0; j < len2&& i< len1;)
                {
                    if(t[j]==s[i])
                    {
                        num++;
                        i++;
                        j++;
    //                    break;
                    }
                    else
                    {
                        i++;
                    }
                }
    //        }
            printf("%d\n", 2*n-num);
        }
    }
    return 0;
}


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

int main(void) {
    int n, i;
    string s;
    cin >> n;

    map<string, int> Smp;
    vector<vector<string>> Svec(n+1);
    
    for (i = 0; i < n; i++) {
        cin >> s;
        Smp[s]++;
    }

    for (auto j = Smp.begin(); j != Smp.end(); ++j) {
        Svec[j->second].push_back(j->first);
    }
    int mx = 0;
    for (i = 1; i <= n; i++) {
        if (!Svec[i].empty()) mx = max(mx, i);
    }

    sort(Svec[mx].begin(), Svec[mx].end());
    for (auto next: Svec[mx]) cout << next << endl;
    return 0;
}

Measured memory_bytes: 31604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int A[N];
    int sum=0;
    rep(i,N){
        cin >> A[i];
    }
    int x=A[0];
    rep(i,N){
        x=x*A[i]/__gcd(x,A[i]);
    }
    rep(i,N){
        sum+=x/A[i];
    }

    cout << fixed << setprecision(14);
    cout << (double)x/sum <<endl;
    



}


Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:09:02:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

ll C(ll n,ll k)
{
    if(n<k)
        return 0;
    ll num=1,den=1,p=n,q=k,i;
    fn(i,k)
    {
        num=num*p;
        p--;
        den=den*q;
        q--;
    }
    return num/den;
}

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,k,i,ans;
    string s;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s>>k;
        n=s.length();
        ans=0;
        fs(i,1,n)
        {
            ans+=(9*C(i-1,k-1))*(ll)(pow(9,k-1)+.5);
        }

        //cout<<ans<<endl;
        fs(i,1,n+1)
        {
            if(s[i-1]-'0'>=1)
            {
                ans+=(max(0,(s[i-1]-'0')-1)*C(n-i,k-1))*(ll)(pow(9,k-1)+.5);
                if(i>1)
                {
                    ans+=C(n-i,k)*(ll)(pow(9,k)+.5);
                }
                k--;
            }
            if(k==0)
            {ans+=1;break;}
        }
        cout<<ans<<"\n";
    }
    return 0;
}





























Measured memory_bytes: 256
def resolve():

    N=int(input())
    s = str(input())


    l=['%03d'%(p) for p in range(0,10**3)]
    ans=[]
    for i in l:
        if i[0] in s:
            s0=s.index(i[0])
            if i[1] in s[s0+1:]:
                s1=s[s0+1:].index(i[1])
                if i[2] in s[s0+1:][s1+1:]:
                    ans.append(i)



    print(len(set(ans)))


resolve()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


int main(){

  set<ll> se;
  map<ll,ll> ma;
  FOR(i,0,100000){
    ll k = i*i*i*i*i;
    if(k > 10000000000000LL){
      break;
    }
    ma[k] = i;
    ma[-k] = -i;
    se.insert(k);
    se.insert(-k);
  }
  ll x;
  cin >> x;

  for(auto b:se){
    if(se.count(x+b)){
      cout << ma[x+b] << " " << ma[b] << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 3688
//program luogu.AT2554 Choose Integers
#include <iostream>
#include <cstdio>
using namespace std;

int a,b,c;

int main() {
	scanf("%d %d %d",&a,&b,&c);
	for(int i = 1; i <= b; ++i) {
		if( i * a % b == c ) {
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())
n =len(s)

dp = [[[0] * 2 for _ in range(4)] for _ in range(105)]

dp[0][0][0]=1
for i in range(n):
    for j in range(4):
        for k in range(2):
            nd = int(s[i])- 0

            for d in range(10):
                ni = i+1; nj = j; nk = k

                if d != 0 :nj+=1
                if nj > K:continue
                if k==0:
                    if d > nd:continue
                    if d < nd:nk =1

                dp[ni][nj][nk] += dp[i][j][k]

ans=dp[n][K][0] + dp[n][K][1]
print(ans)

Measured memory_bytes: 3064
# ABC045 D
h, w, n = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
n.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  a -= 1
  b -= 1
  (a-2).upto(a) do |i|
    (b-2).upto(b) do |j|
      if i >= 0 && i + 2 < h && j >= 0 && j + 2 < w
        x = [i, j]
        hash[x] += 1
      end
    end
  end
end
ans = Array.new(10, 0)
s = 0
hash.each do |k, v|
  ans[v] += 1
  s += 1
end

ans[0] = (h - 2) * (w - 2) - s
ans.each{|x| puts x}

Measured memory_bytes: 104700
import sys
import math

n = int(input())
if n%2 == 1:
    print(0)
    sys.exit()
if n == 0:
    print(0)
    sys.exit()

p = n / 2

x = int(math.log(p, 5))
#print(x)

count = 0
""" for i in range(1,x+1):
    count += int(p/(5**i))
    #print(i,p,p/(5**1))
print(count) """
i = 1
while i * 10 <= n:
    #print(i)
    count += n // (i*10)
    #print('aaa',n // i*10)
    i *= 5
print(count)

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

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

int main(){
  int X,N, pin;
  vector<int> p;
  vector<int> plen;

  cin >> X >> N;

  if(N == 0){
    cout << X << endl;
    return 0;
  }


  for(int i=0;i < N; i++){
    cin >> pin;
    p.push_back(pin);
    plen.push_back(abs(X - pin));
  }

  auto plenMaxMin = minmax_element(plen.begin(), plen.end());
  int plenMax = (int)*plenMaxMin.second;
  
  for(int anslen=0; anslen <= plenMax; anslen++){
    if(!vector_finder(p, X - anslen)){
      cout << X - anslen << endl;
      return 0;
    }
    else if(!vector_finder(p, X + anslen)){
      cout << X + anslen << endl;
      return 0;
    }
  }
  cout << X - plenMax - 1 << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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 MAX_BITS = 63;
const ll INF = LONG_LONG_MAX / 2;

vector<ll> as;
vector<ll> ones; // {0, ones at the MSB, ..., ones at the LSB}

vector<ll> dp1, dp2;

void calc_ones() {
    ones.push_back(0);
    for (int i = MAX_BITS - 1; i >= 0; i--) {
        int cnt = 0;
        for (auto &a : as) {
            if (a & (1LL << i)) cnt++;
        }
        ones.push_back(cnt);
    }
}

void solve(const ll N, const ll K) {
    for (int i = 1; i <= MAX_BITS; i++) {
        ll d_of_k = (K & (1LL << (MAX_BITS - i)));
        // printf("i: %d, d_of_k: %lld\n", i, d_of_k);

        // dp1
        if (d_of_k) {
            if (ones[i] * 2 > N) {
                chmax(dp2[i], dp1[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
            } else if (ones[i] * 2 < N) {
                chmax(dp1[i], dp1[i - 1] + (N - ones[i]) * (1LL << (MAX_BITS - i)));
            } else {
                chmax(dp2[i], dp1[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
                chmax(dp1[i], dp1[i - 1] + (N - ones[i]) * (1LL << (MAX_BITS - i)));
            }
        } else {
            chmax(dp1[i], dp1[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
        }

        // dp2
        if (dp2[i - 1] >= 0) {
            if (ones[i] * 2 >= N) {
                chmax(dp2[i], dp2[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
            } else {
                chmax(dp2[i], dp2[i - 1] + (N - ones[i]) * (1LL << (MAX_BITS - i)));
            }
        }
    }
}

int main(void) {
    ll N, K;
    cin >> N >> K;

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

    calc_ones();
    // cout << "ones: ";
    // for (auto &one : ones) {
    //     cout << one << " ";
    // }
    // cout << endl;

    dp1.resize(MAX_BITS + 1, 0);
    dp2.resize(MAX_BITS + 1, -INF);
    dp1[0] = 0;

    solve(N, K);

    // printf("dp1: \n");
    // for (auto &x : dp1) {
    //     cout << x << " ";
    // }
    // cout << endl;
    // printf("dp2: \n");
    // for (auto &x : dp2) {
    //     cout << x << " ";
    // }
    // cout << endl;

    cout << max(dp1[MAX_BITS], dp2[MAX_BITS]) << endl;

    return 0;
}


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

int main(){
  ll N;
  cin >> N;
  
  ll ans = 1;
  for (int i = 0; i < N; i++){
    ans *= 10;
    ans %= 1000000007;
  }
  
  ll yobun = 1, yobun2 = 1;
  for (int i = 0; i < N; i++){
    yobun *= 9;
    yobun %= 1000000007;
    yobun2 *= 8;
    yobun2 %= 1000000007;
  }
  yobun *= 2;
  yobun %= 1000000007;
  
  ans -= yobun - yobun2;
  if (ans < 0){
    ans += 1000000007;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <vector>
#include <array>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}


int main(void) {

	int i, j, k, tmp, n, ans = 0, prev = 0;
	vector<int> vec;
	vector<array<int, 2>> ABC;

	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", &tmp);
		vec.push_back(tmp - 1);
	}
	rep(i, n) {
		scanf("%d", &tmp);
		array<int, 2> t;
		t.at(0) = tmp;
		ABC.push_back(t);
	}
	
	rep(i, n - 1) {
		scanf("%d", &tmp);
		ABC.at(i).at(1) = tmp;
	}

	rep(i, n - 1) {
		ans += ABC.at(vec.at(i)).at(0);
		if (vec.at(i) + 1 == vec.at(i + 1)) {
			ans += ABC.at(vec.at(i)).at(1);
		}

	}
	ans += ABC.at(vec.at(n - 1)).at(0);

	printf("%d", ans);


	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<long long> c(m), d(m);
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    vector<long long> dis(m);
    for (int j = 0; j < m; j++) {
      dis[j] = llabs(a[i] - c[j]) + llabs(b[i] - d[j]);
    }
    cout << (int)distance(dis.begin(), min_element(dis.begin(), dis.end())) + 1
         << '\n';
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll ans=1e9;
	int n;
	cin>>n;
	
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}

	for(int i=1;i<=100;i++){
		ll sum=0;
		for(auto x:arr){
			sum+=pow(x-i,2);
		}
		ans=min(sum,ans);
	}
	
	cout<<ans<<"\n";

}


Measured memory_bytes: 256
n = int(input())
ans = n

for i in range(n + 1):
    count = 0
    
    s = i
    while s > 0:
        count += s % 6
        s = s // 6
        
    t = n - i
    while t > 0:
        count += t % 9
        t = t // 9
        
    if ans > count:
        ans = count
        
print(ans)

Measured memory_bytes: 3060
try:
    N = int(input())
    if N>0 or N<=100:
        S = input()
        A = S.split()
        A = list(map(int, A)) 
 
        sum1 = 1/A[0]
 
        for i in range(0,N-1):
         sum1 = sum1 + 1/A[i+1]
 
        result = 1/sum1
        print(result)

except:
        print("Error")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iomanip>
#define pb push_back 
#define lli long long int
#define block 700
#include<iostream>
#include<cmath>
using namespace std;

int main(void)
{
  	int n;
  	double m;
	   cin>>n>>m;
  	double ar[n+1];
  	int sum =0;
  	for(int i=0;i<n;i++)
  	{
  		cin>>ar[i];
  		sum += ar[i];
	}
	int c = 0;
	double v= (double)(1/(m*4));
	//cout<<v<<endl;
	for(int i=0;i<n;i++)
	{
		double f1=(double)(ar[i]/sum);
		if(f1 >= v)
		{
			c++;
			//cout<<"m is:"<<m<<endl;
		}
	}
	if(c>=m)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 MRINF = 5000000000000000;

int main() {


    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;


    ll ans1 = A * X + B * Y;
    ll ans2 = C * 2 * max(X, Y);
    ll ans3 = C * 2 * min(X, Y);
    if(X < Y) ans3 += (Y-X) * B;
    else if(X>Y) ans3 += (X-Y) * A;


    cout << min(ans1, min(ans2, ans3)) << endl;

    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int N, M;

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

    int ans = pow(2, M) * (1900 * M + (N - M) * 100);
    cout << ans << endl;
}

Measured memory_bytes: 256
def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if(i!=j):
                    d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
def main():

    n,m=map(int, input().split())
    edge = [[] for _ in range(n)]
    d = [[float("inf")]*n for i in range(n)]
    d_1 = [[float("inf")]*n for i in range(n)]
    e_lis = [0]*m
    for i in range(m):
        a,b,c=map(int, input().split())
        d[a-1][b-1]=d[b-1][a-1]=d_1[a-1][b-1]=d_1[b-1][a-1]=c
    res = warshall_floyd(d,n)
    cnt=0
    for i in range(n):
        for j in range(n):
            if(res[i][j]!=d_1[i][j] and d_1[i][j]<10000):
                cnt+=1
    print(cnt//2)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (auto &x : h) {
		cin >> x;
	}
	sort(h.begin(), h.end());

	int ans = h.back() - h.front();
	for (int i = 0; i + K <= N; ++i) {
		ans = min(ans, h[i + K - 1] - h[i]);
	}

	cout << ans << endl;
}


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

//階乗
ll factorial(ll num){ll sum = 1; for(ll i=1;i<=num;i++) sum*=i; return sum;}
//素数判定
bool isPrime(ll num){if(num<2){return false;}else if(num==2){return true;}else if(num%2==0){return false;} double sqrtNum=sqrt(num);for(int i=3;i<=sqrtNum;i+=2){if(num%i==0)return false;}return true;}

int main(){
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  
  if(a >= b){
    if(a-v*t <= b-w*t) cout << "YES" << endl;
    else cout << "NO" << endl;
  }else if(a < b){
    if(a+v*t >= b+w*t) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    int a;
    vector<int>b;
    while(n--)
    {
        cin>>a;
        a*=-1;
        int it=upper_bound(b.begin(),b.end(),a)-b.begin();
        if(it==b.size())
            b.push_back(a);
        else
            b[it]=a;

    }
    cout<<b.size()<<endl;
    return 0;
}

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

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

    int sum = 0, input;
    rep(i, M){
        cin >> input;
        sum += input;
    }

    if(N - sum >= 0){
        cout << N - sum << endl;
    }
    else{
        cout << (-1) << endl;
    }

}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
const int N_MAX = 100000;

vector<vector<int>> g;
vector<vector<int>> block;
int group[N_MAX];
int num_of_groups;
int size_of_group[N_MAX];

void dfs(int s, int k) {
	stack<int> st;
	st.push(s);
	group[s] = k;
	size_of_group[k]++;
	while (!st.empty()) {
		int v = st.top(); st.pop();
		for (int i : g[v]) {
			if (group[i] != -1) continue;
			st.push(i);
			group[i] = k;
			size_of_group[k]++;
		}
	}
	return;
}

void connected_component_decomposition() {
	const int V = g.size();
	num_of_groups = 0;
	fill(group, group+V, -1);
	for (int i = 0; i < V; i++) {
		if (group[i] == -1) {
			dfs(i, num_of_groups);
			num_of_groups++;
		}
	}
	return;
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	g.assign(n, vector<int>());
	block.assign(n, vector<int>());
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	connected_component_decomposition();
	for (int i = 0; i < n; i++) {
		int ans = size_of_group[group[i]];
		ans--;
		ans -= g[i].size();
		for (int j : block[i]) {
			if (group[i] == group[j]) ans--;
		}
		cout << ans;
		if (i < n-1) cout << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 12664
/**
 * B - Good Distance
 * https://atcoder.jp/contests/abc133/tasks/abc133_b
 **/
#include<iostream>
#include<cmath>
#include<limits>

using namespace std;

const int MAX_N = 10;
const int MAX_D = 10;

int N, D;
int X[MAX_N+1][MAX_D+1];

bool is_integer(double x) {
    return floor(x)==x;
}

void solve() {
    int ans = 0;
    for (int i = 1; i < N; i++) {
        for (int j = i+1; j < N+1; j++) {
            double p_sum = 0;
            for (int k = 1; k < D+1; k++) {
                p_sum += pow(X[i][k] - X[j][k], 2);
            }
            double f_p_sum = sqrt(p_sum);
            if(is_integer(f_p_sum)) {
                ans += 1;
            }

        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N >> D;
    for (int i = 1; i < N+1; i++) {
        for (int j = 1; j < D+1; j++) {
            cin >> X[i][j];
        }
    }
    solve();
}

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

int main(){
    int w;
    cin>>w;
    int i=0;
    int *a;
    a=(int*)malloc(sizeof(int)*114514);
    while(w>0){
        a[i++]=(w%3);
        w=w/3;
    }
    //cout<<i<<endl;
    //cout<<a[0]<<a[1]<<a[2]<<endl;
    for(int j=0;j<i;j++){
        if(a[j]>=2){
            a[j]-=3;
            a[j+1]++;
        }
    }
    //cout<<a[0]<<a[1]<<a[2]<<a[3]<<endl;
    while(a[i])i++;
    for(i=i-1;i>=0;i--){
        if(a[i]==1)cout<<'+';
        if(a[i]==0)cout<<'0';
        if(a[i]==-1)cout<<'-';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; string s; cin >> N >> s;
	int r=0;
	rep(i,N) if(s[i] == 'R') r++;
	int d = 0;
	rep(i,N) if((s[i]=='R') ^ (i<r)) d++;
	cout << d/2 << endl;
}


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

int main(){
    string str;
    cin>>str;
    bool res = true;
    int n = str.length();
    for(int i=0; i<n; i++){
        if(res){
            if(i%2 != 0){
                if(str[i] == 'L'||str[i] == 'U'||str[i] == 'D'){
                    res = true;
                }
                else{
                    res = false;
                }
            }
            if(i%2 == 0){
                if(str[i] == 'R'||str[i] == 'U'||str[i] == 'D'){
                    res = true;
                }
                else{
                    res = false;
                }
            }
        }
        else{
            break;
        }
    }
    if(res){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }



return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s[]={ "","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts" };
main(){
  int n,m,a[18];
  while(cin>>m>>n,m){
    memset(a,0,sizeof(a));
    a[0]=1;
    for(int i=0;i<n;i++)
      for(int j=17;j>=0;j--){
        a[j]*=m;
        a[j+1]+=a[j]/10000;
        a[j]=a[j]%10000;
      }
    for(int i=17;i>=0;i--)if(a[i])cout<<a[i]<<s[i];
    cout<<endl;
  }
}

Measured memory_bytes: 3196
mod = 2019
l, r = map(int, input().split())
e = []
for i in range(l, min(r, l + mod * 2) + 1):
    e.append(i % mod)
e.sort()

ans = mod
for i in range(len(e)):
    for j in range(i + 1, len(e)):
        ans = min(ans, e[i] * e[j] % mod)
        if ans == 0:
            break
    else:
        continue
    break
print(ans)


Measured memory_bytes: 3316
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K, S = map(int, input().split())

if S == 10 ** 9:
    for i in range(N):
        if i < N - K:
            print(S - 1)
        else:
            print(S)
    exit()

for i in range(N):
    if i < K:
        print(S)
    else:
        print(S + 1)


Measured memory_bytes: 9632
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

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



signed main(){

    int N; cin >> N;
    vector<char> c(2 * N);
    vec a(2 * N);
    REP(i, 2 * N){
        cin >> c[i] >> a[i];
        a[i]--;
    }

    mat inv(2, vec(N));
    REP(i, 2 * N){
        if(c[i] == 'W') inv[0][a[i]] = i;
        else inv[1][a[i]] = i;
    }

    mat B(N + 1, vec(2 * N + 1, 0)), W(N + 1, vec(2 * N + 1, 0));
    REP(i, N) FOR(j, inv[0][i] + 1, 2 * N + 1) W[i + 1][j] = 1;
    REP(j, 2 * N + 1) FOR(i, 1, N + 1) W[i][j] += W[i - 1][j];
    REP(i, N) FOR(j, inv[1][i] + 1, 2 * N + 1) B[i + 1][j] = 1;
    REP(j, 2 * N + 1) FOR(i, 1, N + 1) B[i][j] += B[i - 1][j];

    mat dp(2 * N + 1, vec(N + 1, INF));
    dp[0][0] = 0;
    FOR(i, 1, 2 * N + 1){
        REP(j, min(i, N) + 1){
            int v1 = INF, v2 = INF;
            int nW = i - j, nB = j;
            if(nW > N) continue;
            //W置いた
            if(nW >= 1) v1 = dp[i - 1][j] + nW - 1 + nB - W[nW - 1][inv[0][nW - 1]] - B[nB][inv[0][nW - 1]];
            //B置いた
            if(nB >= 1) v2 = dp[i - 1][j - 1] + nB - 1 + nW - B[nB - 1][inv[1][nB - 1]] - W[nW][inv[1][nB - 1]];

            dp[i][j] = min(v1, v2);
        }
    }
    cout << dp[2 * N][N] << endl;
    
    return 0;
}

Measured memory_bytes: 188288
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define mp make_pair
int main()
{
	std::ios::sync_with_stdio(false);
	int n,a[200005];
	ll ans=1e18;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	int mid=n/2;
	for(int i=-1;i<=1;i++)
	{
		ll sum=0;
		for(int j=1;j<=n;j++)
			sum+=abs(a[j]-a[mid+i]);
			ans=min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
// agc044_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

ll N, A, B, C, D;
map<ll, ll> memo;

ll dfs(ll n){

    if (memo.find(n) != memo.end()){
        return memo[n];
    }

    ll tmp = 1e18;
    if (n < tmp / D) tmp = n * D;

    ll a = n - n % 2;
    tmp = min(tmp, D * (n % 2) + A + dfs(a/2));
    if (n % 2) tmp = min(tmp, D * (2 - (n % 2)) + A + dfs(a/2+1));

    ll b = n - n % 3;
    tmp = min(tmp, D * (n % 3) + B + dfs(b/3));
    if (n % 3) tmp = min(tmp, D * (3 - (n % 3)) + B + dfs(b/3+1));

    ll c = n - n % 5;
    tmp = min(tmp, D * (n % 5) + C + dfs(c/5));
    if (n % 5) tmp = min(tmp, D * (5 - (n % 5)) + C + dfs(c/5+1));

    return memo[n] = tmp;
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int T;
    cin >> T;
    REP(_, T){
        cin >> N >> A >> B >> C >> D;
        memo.clear();
        memo[1] = D;
        memo[0] = 0;
        ll ans = dfs(N);
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 4332
#include <iostream>
using namespace std;
int main(){
	int N,A,B;
	int *P;
	int ct=0;
	cin>>N;
	cin>>A>>B;
	P=new int[N];
	for(int a=0;a<N;a++){
		cin>>P[a];
	}
	for(int a=0;a<N;a++){
		if(P[a]<=A){
			for(int b=0;b<N;b++){
				if(P[b]<=B&&P[b]>A){
					for(int c=0;c<N;c++){
						if(P[c]>B&&P[c]!=21){
							ct++;
							P[a]=21;
							P[b]=21;
							P[c]=21;
							b=N;
							c=N;
						}
					}
			
				}
			}
		}


	}

	cout<<ct<<endl;

}

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

public class Main {
  static int MOD = 1000000007;
  static double EPS = 1e-9;

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    int N = Integer.parseInt(in.readLine());

    System.out.println(N * (N + 1) / 2);

    in.close();
  }
}

Measured memory_bytes: 21204
/**
 *    author:   K.R.Surrya  
 *    created:  03/05/2020 17:38:21
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}
vector<set<int>> graph(100010);
vector<int> viz(100010);
vector<int> mark(100010,1);
vector<int> H(100010);

void dfs(int src,int par=-1) { 
    viz[src]=1;

    for(auto v:graph[src]) {
        if(!viz[v]) {
            dfs(v,src);
            if(H[v]>=H[src]) mark[src]=0;
        } else {
            if(H[v]>=H[src])  mark[src]=0;
        }
    }
}
void solve() { 
    int N,M;
    cin >> N >> M;
    // H.resize(N+1);
    for(int i=1;i<=N;++i) { 
        cin >> H[i];
    }
    set<int> visited;
    while(M--) { 
        int x,y;
        cin >> x >> y;
        graph[x].insert(y);
        graph[y].insert(x);
        visited.insert(x);
        visited.insert(y);
    }
    int ret=0;
    ret+=-1*visited.size()+N;
    for(auto it=visited.begin();it!=visited.end();++it) {
        int src=*it;
             if(!viz[src]) {
                 dfs(src);
               }
    }
    for(auto check:visited) { 
        ret+=mark[check];
    }
    cout << ret << '\n';
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

     //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


Measured memory_bytes: 24216
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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(){
	int n,m,x;
	cin >> n >> m >> x;
	vector<bool> a(n+1,false);
	REP(i,m){
		int in;
		cin >> in;
		a[in] = true; 
	}
	
	int ans,cost=0;
	for(int i=x+1; i<=n; ++i){
		if(a[i]) cost++;
	}
	ans = cost;
	cost=0;
	for(int i=x-1; i>=0; --i){
		if(a[i]) cost++;
	}
	chmin(ans,cost);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const long long INF = (1ull<<63) - 1;

long long extgcd(long long a, long long b, long long &x, long long &y) {
	x = 1; y = 0;
	long long u = 0, v = 1;
	while (b != 0) {
		long long r = a % b, q = a / b;
		a = b; b = r;
		long long nu = x - q*u, nv = y - q*v;
		x = u; y = v;
		u = nu; v = nv;
	}
	return a;
}

pair<long long, long long> crt(const vector<long long> &r, const vector<long long> &m) {
	long long x = 0, l = 1;
	for (int i = 0; i < r.size(); i++) {
		long long m0 = l, m1 = m[i];
		long long r0 = x, r1 = r[i] % m1;
		if (r1 < 0) r1 += m1;
		if (m0 < m1) {
			swap(m0, m1);
			swap(r0, r1);
		}
		long long k0, k1;
		const long long g = extgcd(m0, m1, k0, k1);
		if ((r1 - r0) % g != 0) return {0, -1};
		const long long m1_g = m1 / g;
		x = (r1 - r0) / g % m1_g * (k0 % m1_g) % m1_g * m0 + r0;
		l = m0 * m1_g;
		if (x < 0) x += l;
	}
	return {x, l};
}

vector<pair<long long, int>> prime_factorization(long long n) {
	vector<pair<long long, int>> v;
	for (long long i = 2; i * i <= n; ++i) {
		int e = 0;
		while (n % i == 0) {
			++e;
			n /= i;
		}
		if (e != 0) v.emplace_back(i, e);
	}
	if (n != 1) v.emplace_back(n, 1);
	return v;
}

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

int main() {
	long long n;
	cin >> n;
	auto v = prime_factorization(2*n);
	vector<long long> r(v.size()), m(v.size());
	for (int i = 0; i < m.size(); i++) {
		m[i] = pow(v[i].first, v[i].second);
	}
	long long ans = INF;
	for (int bits = 0; bits < (1<<r.size()); bits++) {
		bitset<32> t(bits);
		for (int i = 0; i < r.size(); i++) {
			r[i] = t[i] ? 0 : m[i]-1;
		}
		long long now = crt(r, m).first;
		if (now == 0) now = 2*n;
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 1987654321
#define IINF 87654321987654321
#define MOD 1000000007

const int MAXN = 2e5 + 50;
ll n, k;
ll a[MAXN];

void readInput() {
	scanf("%lld%lld", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
}

inline ll C2(ll n) {
	return n * (n-1) / 2;
}

ll s[MAXN], cnt[MAXN];
int main() {
	readInput();
	s[0] = 0;
	for(int i = 1; i <= n; i++)
		s[i] = s[i-1] + a[i];
	for(int i = 0; i <= n; i++)
		s[i] = (s[i] - i + k) % k;

	if(k > n) {
		ll ans = 0;
		map<ll, ll> M;
		for(int i = 0; i <= n; i++)
			M[s[i]]++;
		for(auto e : M)
			ans += C2(e.second);
		printf("%lld\n", ans);
	} else {
		ll ans = 0;
		for(int i = 0; i <= n; i++) {
			ans += cnt[s[i]];
			if(i-k+1 >= 0)
				cnt[s[i-k+1]]--;
			cnt[s[i]]++;
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		System.out.println(calc(N,0));
	}

	public static int calc(int n,int ans) {

		if(n < 6) return ans + n;

//		int a = (int)Math.pow(6,Math.floor(Math.log(n)/Math.log(6)));
//		int b = (int)Math.pow(9,Math.floor(Math.log(n)/Math.log(9)));
		int a=1,b=1;
		while(a*6<=n) a*=6;
		while(b*9<=n) b*=9;

		return Math.min(calc(n-a,ans+1),calc(n-b,ans+1));
	}

}

Measured memory_bytes: 21972