akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long h,n;
    long long ans = 0;
    cin >> h;
    n = 1;
    while (h > 0) {
        ans += n;
        h = h / 2;
        n = n * 2;
    }
    cout << ans << "\n";
    return 0;
}


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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(double, A, B);

    const auto MAX = 1e6;
    reps(i, 1, MAX) {
        if (intmax_t(i * 0.08) == A && intmax_t(i * 0.1) == B) {
            return output(i), 0;
        }
    }

    output(-1);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
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; } 
using ll=long long;
 int main(){
  ll x,a=100,ans=0;
 cin>>x;
   while(a<x){
   a+=a/100;
     ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3624
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n,a;
	cin>>n>>a;
	cout<<((n*a)&1?"Odd":"Even");
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int i = 1;
        int count = 0;
        while(true){
            if(i >= b) break;
            i = i-1 + a;
            count++;
        }

        System.out.println(count);
    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}



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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

const int N = 2e5 + 3;
int n, a[N];
int cntPos(int i, ll val) {
	int lo = i + 1, hi = n - 1, ret = i;
  	while (lo <= hi) {
    	int mid = (lo + hi) / 2;
      	if ((ll) a[i] * a[mid] <= val) {
			ret = mid;
          	lo = mid + 1;
        } else{
        	hi = mid - 1;
        }
    }
	return ret - i;
}
int cntNeg(int i, ll val) {
	int lo = i + 1, hi = n - 1, ret = n;
  	while (lo <= hi) {
    	int mid = (lo + hi) / 2;
      	if ((ll) a[i] * a[mid] <= val) {
			ret = mid;
        	hi = mid - 1;
        } else{
          	lo = mid + 1;
        }
    }
	return n - ret;
}
int main() {
	ll k;
  	cin >> n >> k;
  	for (int i = 0; i < n; ++i)
      	cin >> a[i];
  	sort(a, a + n);
	ll lo = -1e18, hi = 1e18, res = -1;
	while (lo <= hi) {
		ll mid = (lo + hi) / 2, counter = 0;
		for (int i = 0; i < n; ++i) {
          	if (a[i] > 0)
              counter += cntPos(i, mid);
          	else
            	counter += cntNeg(i, mid);
        }
		if (counter < k) {
			lo = mid + 1;
		} else {
			res = mid;
			hi = mid - 1;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
from sys import stdin


def fin(f):
    return f(input())


def gin(f, number=1):
    for _ in range(number):
        yield list(map(f, stdin.readline().split()))


def lin(f):
    return next(gin(f))


n = fin(int)

ans = 0
D = lin(int)
for i, d in enumerate(D):
    for e in D[i+1:]:
        ans += d*e

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int main(){
          int a[3];
          REP(i,3) cin >> a[i];
          sort(a,a+3);

          int count=0;
          for(;;){
                    if(a[0]==a[1] and a[1]==a[2]){
                              cout << count << endl;
                              return 0;
                    }
                    else if(a[2]-a[0]>=2){
                              a[0]+=2;
                              count++;
                    }
                    else if(a[2]-a[1]>=2){
                              a[1]+=2;
                              count++;
                    }
                    else if(a[2]-a[1]==1 and a[2]-a[0]==1){
                              a[0]+=1;
                              a[1]+=1;
                              count++;
                    }
                    else if(a[2]==a[1] and a[1]-a[0]==1){
                              a[1]+=1;
                              a[2]+=1;
                              a[0]+=2;
                              count+=2;
                    }
                    sort(a,a+3);
          }
          return 0;
}


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

#define db(x) cerr << #x ": " << (x) << '\n';

#define int long long

using namespace std;

typedef long long ll;

const int oo = 1e18;

const int MAXN = 5e5 + 100;

int N, K, C;

int G[MAXN];
int rG[MAXN];

char S[MAXN];

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

    cin >> N >> K >> C;

    for(int i = 1 ; i <= N ; i++)
    {
        cin >> S[i];
    }

    for(int i = N ; i >= 1 ; i--)
    {
        rG[i] = rG[i+1];
        if(S[i] == 'o')
        {
            rG[i] = rG[i+C+1]+1;
        }
    }

    if(rG[1] > K)
    {
        return 0;
    }

    int last = 0;

    vector<int> res;

    for(int i = 1 ; i <= N ; i++)
    {
        G[i] = G[i-1];
        if(S[i] == 'o' && i > last)
        {
            if(G[i-1]+rG[i+1] != K)res.push_back(i);
            G[i]++;
            last = i+C;
        }
    }

    for(auto x : res)cout << x << '\n';

    return 0;
}


Measured memory_bytes: 9072
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c)
{
    stack<int> S;
    S.push(r);
    color[r] = c;
    while( !S.empty())
    {
        int u = S.top();
        S.pop();
        for (int i = 0; i < G[u].size(); i++)
        {
            int v = G[u][i];
            if (color[v] == NIL)
            {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor()
{
    int id = 1;
    for (int i = 0; i < n; i++) color[i] = NIL;
    for (int u = 0; u < n; u++)
    {
        if (color[u] == NIL) dfs(u, id++);
    }
}

int main()
{
    int s, t, m, q;

    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for (int i = 0; i < q; i++)
    {
        cin >> s >> t;
        if (color[s] == color[t])
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8932
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string a,b,c;
	cin>>a>>b>>c;
	int ans=0;
	set<int>fuck;
	for(int i=0;i<n;++i)
	{
		fuck.clear();
		fuck.insert(a[i]);
		fuck.insert(b[i]);
		fuck.insert(c[i]);
		ans+=fuck.size()-1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

lli solve(lli n)
{
    if(n==0)
        return 0;
    return 1+2*solve(n/2);
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    cout<<solve(n)<<endl;

}   aryanc403();
    return 0;
}


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

int main(int argc,char* argv[]){
	string s;
	int n;
	cin >> n >> s;
	char a;
	for(int i=0;i<s.size();++i){
		a = s[i] + n;
		if( a > 'Z' ) { a = a - ('Z' - 'A') - 1; s[i] = a; }
		else s[i] = a;
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
	int i,c=1;
	string s; cin>>s;
	for(i=1;i<3;i++)
	{
		if(s[i-1]=='R')
		{
			if(s[i-1]==s[i])
			c++;
		}
	}
	if(s=="SSS")
	cout<<0<<endl;
	else
	{
		cout<<c<<endl;
		
	}

}


Measured memory_bytes: 3596
#include <iostream>
#include <set>

using namespace std;

typedef pair<long, long> P;

long a[100000];
long idx[100000];
long l1[100000], l2[100000], r1[100000], r2[100000];

int main(){
    long N;
    cin >> N;
    for(long i = 0; i < N; i++){
        cin >> a[i];
        a[i]--;
        idx[a[i]] = i;
    }
    set<long> sl;
    sl.insert(-1);
    sl.insert(-2);
    for(long i = N-1; i >= 0; i--){
        sl.insert(idx[i]);
        auto ptr = sl.find(idx[i]);
        ptr--;
        l1[i] = max((long)(-1), *ptr);
        ptr--;
        l2[i] = max((long)(-1), *ptr);
       // cout << l1[i] << ' ' << l2[i] << endl;
    }
    set<long> sr;
    sr.insert(N);
    sr.insert(N+1);
    for(long i = N-1; i >= 0; i--){
        sr.insert(idx[i]);
        auto ptr = sr.find(idx[i]);
        ptr++;
        r1[i] = min(N, *ptr);
        ptr++;
        r2[i] = min(N, *ptr);
        //cout << r1[i] << ' ' << r2[i] << endl;
    }
    long ans = 0;
    for(long i = 0; i < N; i++){
        ans += (i+1)*(r1[i]-idx[i])*(l1[i]-l2[i]);
        ans += (i+1)*(r2[i]-r1[i])*(idx[i]-l1[i]);
        //cout << l1[i] << ' ' << l2[i] << endl;
        //cout << r1[i] << ' ' << r2[i] << endl;
        //cout << (r1[i]-idx[i]) << ' ' << (l1[i]-l2[i]) << endl;;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  
  cout << x2 + y1 - y2 << " " 
    << y2 - x1 + x2 << " " 
    << x1 + y1 - y2 << " " 
    << y1 - x1 + x2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;

int main() {
 int N;
 cin>>N;
 vector<int64_t>A(N);
 for(int i=0;i<N;i++){
     cin>>A[i];
 }
 int64_t ans=0;
 for(int i=0;i<60;i++){
   int64_t cnt1=0,cnt0=0;
   for(int j=0;j<N;j++){if(A[j]>>i&1){cnt1++;} }
   cnt0=N-cnt1;
   int64_t t=cnt1*cnt0%1000000007;
   for(int j=0;j<i;j++){
    t=t*2%1000000007;
   }
   ans+=t;
   ans%=1000000007;
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int i,x,y,z;

	for(i=1;1;i++){
		scanf("%d%d",&x,&y);
		if(x==0&&y==0) break;

		if(x>y){
			z=x;
			x=y;
			y=z;
		}

		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
 
int main(void){
	int A, B, C;
	if (scanf("%d %d %d", &A, &B, &C) == 1);
	if (A >= 1 && B >= 1 && C >= 1 && A <= 10000 && B <= 10000 && C <= 10000){
		if (A + B<A + C){
			if (A + B<B + C)
				printf("%d", A + B);
			else
				printf("%d", B + C);
		}
		else{
			if (A + C<B + C)
				printf("%d", A + C);
			else
				printf("%d", B + C);
		}
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
tmp = input()
my_str = input()

start = 0
end = 1
max_len = 0

while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        if end - start > max_len:
            max_len = end - start
        end += 1
    else:
        start += 1

print(max_len)


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

#define W 5
#define DELETE -1

int main(void){
  while(true){
    int H;
    cin >> H;
    if(H == 0){ break; }

    // ?????¢???????????????
    vector<vector<int> > puyo(H, vector<int>(W));
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++)
        cin >> puyo[i][j];

    // ???????¶????????????§??°?????????
    int flag, ans = 0;
    do{
      // ?????????????????°????????£?????????
      flag = false;

      // ??????????????°???????????????
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          if(puyo[i][j] == DELETE){ continue;}
          
          // ??????[i][j]?????????????????¨??????
          // ??????????????§????????????????±???????
          int seg;
          for(seg = 1; (j + seg < W) && (puyo[i][j] == puyo[i][j + seg]); seg++);

          // ??£?¶??????????3??\????????£???????¶????
          if(seg >= 3){
            for(int k = 0; k < seg; k++){
              // ?¶??????´??????????????°????????????????????????????????????
              flag = true;
              ans += puyo[i][j + k];
              puyo[i][j + k] = DELETE;
            }
          }
        }
      }

      // DELETE ????????£????????????????????????????????????
      // (???????????????????????????)
      for(int k = 0; k < H; k++){
        for(int i = 1; i < H; i++){
          for(int j = 0; j < W; j++){
            if(puyo[i][j] == DELETE){
              int tmp = puyo[i][j];
              puyo[i][j] = puyo[i - 1][j];
              puyo[i - 1][j] = tmp;
            }
          }
        }
      }
      
    }while(flag);

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

Measured memory_bytes: 3136
//Author - Sanket Mundra
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back 
    #define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define fin cin
    #define PI 3.14159265358979323846
    #define M 1000000007;
     
    int main()
    {
        
        fastIO;
        ll t,i,j,k,l,r,n,m,ans,sum,mx,mn,cnt; cin>>t>>n;
        while(n--)
        {
        	cin>>i;
        	t-=i;
        }
        if(t>=0) cout<<t<<"\n";
        else cout<<-1<<"\n";
        return 0;
    }

Measured memory_bytes: 3620
# coding: utf-8
N, K = list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = 0
for k in range(K, N+2):
    tmp1 = k * (k - 1) // 2
    tmp2 = (2 * N - k + 1) * k // 2
    sum += (tmp2-tmp1+1)%mod
print(sum%mod)

Measured memory_bytes: 9188
/*
 * @Author: your name
 * @Date: 2019-11-27 19:32:44
 * @LastEditTime: 2019-11-27 19:39:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \code\AT2685.cpp
 */
#include <bits/stdc++.h>
using namespace std;
string a,b,c;
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
cin>>a;
int len=a.length();
b=a[0];
c=a[len-1];
cout<<b<<len-2<<c;
getchar();getchar();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Data=pair<long,int>;

int main(){
  int i,j,h,N,K,L,R,ans=0,cnt=0,kcnt;
  long val;
  scanf("%d",&N);
  scanf("%d",&K);
  vector<long> v(100),lv(100,0),rv(100,0);
  vector<Data> order(100,Data(0,0));
  for(i=1;i<=N;i++){
    scanf("%ld",&v[i]);
    lv[i]=lv[i-1]+v[i];
    if(v[i]<0)order[cnt++]=Data(v[i],i);
  }
  sort(order.begin(),order.end());
  for(i=N;i>0;i--){
    rv[i]=rv[i+1]+v[i];
  }
  L=min(N,K);
  for(i=0;i<=L;i++){
    R=min(K-i,N-i);
    for(j=0;j<=R;j++){
      val=lv[i]+rv[N-j+1];
      kcnt=K-i-j;
      for(h=0;h<cnt;h++){
        if(kcnt==0)break;
        if(order[h].second<=i || order[h].second>N-j+1){
          val-=order[h].first;
          kcnt--;
        }
      }
      if(ans<val)ans=val;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int h,w;
    cin >> h >> w;
    string a[h];
    bool bh[h],bw[w];
    rep(i, h)cin >> a[i];
    rep(i, h)bh[i] = false;
    rep(i, w)bw[i] = false;
    rep(i, h){
        rep(j, w){
            if (a[i][j] == '#') {
                bh[i] = true;
            }
        }
    }
    
    rep(i, w){
        rep(j, h){
            if (a[j][i] == '#') {
                bw[i] = true;
            }
        }
    }
    
    rep(i, h){
        rep(j, w){
            if (bh[i] && bw[j]) {
                cout << a[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 16;
const ll oo = 1ll<<50;
ll memo[(1<<maxn)];
ll costo[1<<maxn];
int A[maxn][maxn],N;
int idx[1000000],cnt1;
ll fin;

ll dp(int mask){
	if(mask == fin)return 0;
	ll &res = memo[mask];
	if(res != -oo)return res;
	int cnt11 = 0;
	forn(i,0,N)if(!(mask&(1<<i))){
		idx[cnt1++] = i;
		cnt11++;
	}
	res = -oo;
	forn(i,1,(1<<(cnt11))){
		int newMask = mask;
		int mascaraAgarrados = 0;
		forn(j,0,cnt11){
			if(i&(1<<j)){
				newMask |= (1<<idx[cnt1-cnt11+j]);
				mascaraAgarrados |= (1<<idx[cnt1-cnt11+j]);
			}
		}
		ll tmp = costo[mascaraAgarrados];
		res = max(res,tmp+dp(newMask));		
	}
	cnt1 -= cnt11;
	return res;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,(1<<maxn))memo[i] = -oo;
	cin >> N;
	forn(i,0,N)forn(j,0,N)cin >> A[i][j];
	forn(i,0,1<<N){
		vi agarrados;
		forn(j,0,N){
			if(i&(1<<j)){
				agarrados.pb(j);
			}		
		}
		forn(j,0,(int)agarrados.size()){
			forn(k,j+1,(int)agarrados.size()){
				int a1 = agarrados[j];
				int a2 = agarrados[k];
				costo[i] += A[a1][a2];
			}
		}
	}
	fin = (1<<N)-1;
	ll res = dp(0);
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3200
H,W = map(int,input().split())
from collections import deque
S = [list(input()) for i in range(H)]

def bfs(sx, sy):
    ans = 10**9
    dire = ((0, -1), (-1, 0), (1, 0), (0, 1))
    dist = [[-1]*W for _ in range(H)] # 未訪問は-1,訪問済みは距離
    dist[sx][sy] = 1
    que = deque([(sx, sy)]) # (sx, sy)からスタート
    while que:
        x, y = que.popleft()
        d = dist[x][y]
        for dx, dy in dire:
            nx,ny = x+dx,y+dy
            if nx==H-1 and ny==W-1 and S[nx][ny] == '.':
                ans = min(d+1,ans)
            # 内部で、通行可能('.')で、未訪問なら距離を更新し、dequeに入れる
            if 0<=nx<H and 0<=ny<W and S[nx][ny] == '.' and dist[nx][ny] == -1:
                dist[nx][ny] = d+1
                que.append((nx, ny))
    return ans # これは(sx,sy)からの最長距離
black = 0
ans = bfs(0,0)
if ans == 10**9:
    print(-1)
else:
    for i in range(H):
        black += S[i].count('#')

    print(H*W-ans-black)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll n,k,q;
   cin>>n>>k>>q;
   ll t = q;
   int count[n+1];
   memset(count,0,sizeof(count));
   while(t--)
   {
       ll x;
       cin>>x;
       count[x]++;
   }
  
   for( int i=1;i<=n;i++)
   {
      if(count[i]-q+k<=0) 
      {
         cout<<"No"<<endl;
      }
      else
      { 
        cout<<"Yes"<<endl;
      }
   }
  
  
}

  

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

int main(){
  while(true){
  int n,m,a;
  cin>>n>>m>>a;
  if(n==0&&m==0&a==0) break;

  vector<vector<P> > v(1010);
  int h,p,q;
  for(int i=0;i<m;i++){
    cin>>h>>p>>q;
    v[h].push_back(P(p,q));
  }
  for(int i=1000;i>=1;i--){
    int k=v[i].size();
    for(int j=0;j<k;j++){
      if(v[i][j].first==a){
        a=v[i][j].second;
        break;
      }
      else if(v[i][j].second==a){
        a=v[i][j].first;
        break;
      }
    }
  }
  cout<<a<<endl;
}
  return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    getchar();
    while (n--)
    {
        string ara="",ara2="",res="";
        getline(cin,ara);
        getline(cin,ara2);

        if (ara.length()>ara2.length())
            swap(ara,ara2);

        int l1,l2;
        l1=ara.length();
        l2=ara2.length();

        reverse(ara.begin(),ara.end());
        reverse(ara2.begin(),ara2.end());

        int i,sum,carry=0;
        for (i=0;i<l1;i++)
        {
            sum=((ara[i]-'0')+(ara2[i]-'0')+carry);
            res.push_back((sum%10)+'0');
            carry=sum/10;
        }
        for (i=l1;i<l2;i++)
        {
            sum=(ara2[i]-'0')+carry;
            res.push_back((sum%10)+'0');
            carry=sum/10;
        }
        if (carry!=0)
            res.push_back(carry+'0');
        reverse (res.begin(),res.end());
        if (res.length()<=80)
            cout<<res;
        else
            cout<<"overflow";
        cout<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;
typedef tuple<ll,ll,ll> tl;
typedef tuple<ll,ll,ll,ll> ql;

#define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
#define ROF(i, a, b) for(ll i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll n, k;
    cin >> n >> k;
    ll sum=0;
    FOR(i,1,k){
        ll x;
        cin >> x;
        sum+=x;
    }
    n-=sum;
    if (n<0) cout << "-1";
    else cout << n;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  if(s.back()=='s') {
    s += "es";
  } else {
    s += "s";
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  string s; cin >> s;
  ll q; cin >> q;

  deque<char> deq;
  for (int i = 0; i < s.size(); i++)
    deq.push_back(s[i]);
  
  bool rev = false;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;

    if (t == 1) {
      rev = !rev;
    } else {
      int f; cin >> f;
      char c; cin >> c;

      if ((f == 1 && !rev) || (f == 2 && rev)) {
        deq.push_front(c);
      } else {
        deq.push_back(c);
      }
    }

    // outl(string(deq.begin(), deq.end()))
  }

  s = string(deq.begin(), deq.end());

  // outl(s)

  if (rev) reverse(s);

  outl(s)
}


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

int main() {
	int n,m;
	cin>>n>>m;
	if(n>m){
	for(int i=0;i<n;i++)
	cout<<m;
	cout<<endl;}
	else{
	    for(int i=0;i<m;i++)
	cout<<n;
	cout<<endl;}
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
data = list(map(int, input().split()))
l = 0
r = k - 1
ans = float("inf")
while True:
    if r == n:
        break
    ans = min(ans, abs(data[l]) + abs(data[l] - data[r]), abs(data[r]) + abs(data[r] - data[l]))
    l += 1
    r += 1
print(ans)


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

int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
    }
    sort(a ,a+m);
    int temp = lower_bound(a,a+m,x) - a ;
    int temp2 = m - temp;
    cout<<min( temp , temp2);
}

Measured memory_bytes: 3460
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ps = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int ret = 0;
            for (int i = 0; i < ps.Length -2; i++)
            {
                if (ps[i] < ps[i + 1] && ps[i + 1] < ps[i + 2] ||
                    ps[i] > ps[i + 1] && ps[i + 1] > ps[i + 2])
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

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

int aaa(int n)
{
    return n / 1000;
}

int main()
{
    int n;
    cin >> n;
    int b = aaa(n);
    if(n % 1000 == 0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << (b * 1000 + 1000) - n << endl;
        return 0; 
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;

int main() {
	int n;cin >> n;
	vector<int> kisu(100002), gusu(100002);
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (i % 2 == 0) {
			kisu[x]++;
		}
		else {
			gusu[x]++;
		}
	}

	auto a = max_element(kisu.begin(), kisu.end());
	int a0 = *a;
	auto b = max_element(gusu.begin(), gusu.end());
	int b0 = *b;
	if (a - kisu.begin() == b - gusu.begin()) {
		(*a) = 0;
		(*b) = 0;
		int a1 = *max_element(kisu.begin(), kisu.end());
		int b1 = *max_element(gusu.begin(), gusu.end());
		cout << n - max(a0 + b1, b0 + a1);
	}
	else {
		cout << n - a0 - b0;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<pair<int,int>> A;
	vector<int> cnt0(H), cnt1(W);
	int m0 = 0, m1 = 0;
	for (int i = 0; i < M; ++ i) {
		int h, w;
		cin >> h >> w;
		-- h, -- w;
		A.push_back({h,w});
		m0 = max(m0, ++cnt0[h]);
		m1 = max(m1, ++cnt1[w]);
	}
	map<pair<int,int>,int> cnt2;
	for (auto p : A) {
		++ cnt2[{cnt0[p.first],cnt1[p.second]}];
	}
	ll c0 = 0, c1 = 0;
	for (int i = 0; i < H; ++ i) {
		if (cnt0[i] == m0) ++ c0;
	}
	for (int i = 0; i < W; ++ i) {
		if (cnt1[i] == m1) ++ c1;
	}
	int r = m0+m1;
	if (cnt2[{m0,m1}] == c0*c1) -- r;
	cout << r << endl;
}


Measured memory_bytes: 9800
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl color;  // color[i] : 0は白、1は黒、-1は未訪問

bool dfs(ll v, ll now = 0) {
    color[v] = now;
    for(auto u : G[v]) { 
        if(color[u] != -1) {
            if(color[u] == now) {
                return false;
            }
            continue;
        }
        if(!dfs(u, 1-now)) {
            return false;
        }
    }
    return true;
}

// 頂点sと頂点tの間に長さkの奇数長パスが存在すると必ずsとtの間に辺が張られることを示す。
// i番目に通る頂点をv_iとする。
// k = 1 の場合すでに辺がある。
// k >= 3 の場合v_(k-3)とv_kの間に辺を張ることができ、
// 長さk-2奇数長のs-tパスを得ることができる。
// これを繰り返して長さ3になったとき辺を張ることができる。
// よって、ある２頂点間に奇数長パスがあれば辺を張れることが示された。

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

    G.resize(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    color.assign(n, -1);
    bool nibuGraph = true;
    rep(v, n) {
        if(color[v] != -1) {
            continue;
        }
        if(!dfs(v)) {
            nibuGraph = false;
        }
    }
    
    // 二部グラフの場合
    // 異なる頂点集合間の２頂点を結ぶパスは奇数長なのですべて辺を張ることができる。
    // 逆に、同じ頂点集合間の２頂点を結ぶパスは偶数長なので辺を張ることはできない。
    if(nibuGraph) {
        ll cntW = 0, cntB = 0;
        rep(v, n) {
            if(color[v] == 0) {
                cntW++;
            }
            else if(color[v] == 1) {
                cntB++;
            }
        }
        out(cntW*cntB - m);
        re0;
    }
    
    // 二部グラフでない場合
    // 「二部グラフ」 ⇔ 「奇数長サイクルが存在しない」 より
    // 「二部グラフでない」 ⇒ 「奇数長サイクルが存在」
    // あるs-tパスが偶数長だったとしても奇サイクルを用いて奇数長パスにできる
    // よって操作を続けると最終的に完全グラフにできる
    out(n*(n-1)/2 - m);
    re0;
}

Measured memory_bytes: 7424
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,min:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  al:string = 'abcdefghijklmnopqrstuvwxyz';
  tf,tfl,tfr:Boolean;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(a);
    count:=0;
    max  :=0;
    min  :=100;

    if a<1200 then
      Writeln('ABC')
    else if a<2800 then
      Writeln('ARC')
    else
      Writeln('AGC');

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys, math, fractions, itertools, heapq


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    hq = []
    ans, j = 0, 0
    X = sorted(zip(A, B), key=lambda x: x[0])
    for i in range(1,M+1):
        while (j<N) and (X[j][0] <=i):
            heapq.heappush(hq,-X[j][1])
            j+=1
        if hq:
            ans-=heapq.heappop(hq)
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23868
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define int long long
#define ll unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define elif else if
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }


//mint,UnionFind,modnCr,modpow,soinsubunkai
//yakusurekkyo
    ll T,N,A,B,C,D;
    map<ll,ll> m;
    ll dfs(ll n){
        if(n==0)return 0;
        if(n==1)return D;
        if(m[n]!=0)return m[n];
        ll res=D*n;
        chmin(res,D*(n%5)+C+dfs(n/5));
        if(n%5!=0)chmin(res,D*(5-n%5)+C+dfs(n/5+1));
        chmin(res,D*(n%3)+B+dfs(n/3));
        if(n%3!=0)chmin(res,D*(3-n%3)+B+dfs(n/3+1));
        chmin(res,D*(n%2)+A+dfs(n/2));
        if(n%2!=0)chmin(res,D*(2-n%2)+A+dfs(n/2+1));
        return m[n]=res;
    }
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cin>>T;
        rep(i,T){
            cin>>N>>A>>B>>C>>D;
            cout<<dfs(N)<<endl;
            m.clear();
        }
    }


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

int main() {
  int x, y;
  scanf("%d%d", &x, &y);
  int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  printf("%s", (group[x] == group[y]) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long l = sc.nextLong();

		long[][] d1 = new long[n][n];
		long[][] d2 = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(d1[i], Long.MAX_VALUE);
			Arrays.fill(d2[i], Long.MAX_VALUE);
		}

		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			long c = sc.nextLong();
			d1[a][b] = c;
			d1[b][a] = c;
		}

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (d1[i][k] == Long.MAX_VALUE || d1[k][j] == Long.MAX_VALUE) continue;

					d1[i][j] = Math.min(d1[i][j], d1[i][k] + d1[k][j]);
					if (d1[i][j] <= l) d2[i][j] = 1;
				}
			}
		}

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (d2[i][k] == Long.MAX_VALUE || d2[k][j] == Long.MAX_VALUE) continue;
					d2[i][j] = Math.min(d2[i][j], d2[i][k] + d2[k][j]);
				}
			}
		}

		int q = sc.nextInt();

		for (int i = 0; i < q; i++) {
			int s = sc.nextInt() - 1;
			int t = sc.nextInt() - 1;
			if (d2[s][t] == Long.MAX_VALUE) System.out.println(-1);
			else System.out.println(d2[s][t] - 1);
		}
	}
}


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

using namespace std;

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

  char hina_arares[n];
  for(int i = 0; (int)sizeof(hina_arares) > i; ++i){
    scanf("%s", &hina_arares[i]);
  }

  vector<char> hina_vector;
  hina_vector.assign(hina_arares, hina_arares + n);

  sort(hina_vector.begin(), hina_vector.end());
  hina_vector.erase(unique(hina_vector.begin(), hina_vector.end()), hina_vector.end());

  if(hina_vector.size() == 3){
    printf("%s", "Three\n");
  }else{
    printf("%s", "Four\n");
  }

   return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
aiが数列mに何回出現するか，がわかれば良い？
左をa個，右をB個見たときに，M=a+B+1として，aiがM//2 +1番目なら良い．
→ai以上の要素が(M+1)//2個以上ある，かつ，此の性質を満たすものの中で最大の数である．
これ辛そう...

でも中央値を求めるのに二分探索は良いよな
結局，答えxの決めうち二分探索で，数列mの中でx以上の要素が何個あるかを知ることができれば解ける．
(x以上のものが(M+1)//2個以上ある中で最大のxを探したい)

つまり，a[l,r]のうち，中央値がx以上になるものはいくつありますか，をときたい
a[l,r]のうちx以上の要素を((r-l+1)+1)/2個以上含むものは何個あるか，がわかれば良いか
x以上ならば+1，そうでなければ-1として，区間の総和が0以上になる区間の個数を探す．
累積和で処理する，S_r-S_(l-1)が0以上ならばOK．このl,rの組を探すのはseg木でできるか，転倒数と同じ要領で．


"""
def main():
    class BIT:
        '''
        0-indexed
        '''
        def __init__(self, N):
            self.size = N
            self.tree = [0] * (N + 1)
            self.depth = N.bit_length()

        def _bitsum(self, i):
            ret = 0
            while i:
                ret += self.tree[i]
                i ^= i & -i
            return ret

        # [l,r)の和
        def sum(self, l, r=None):
            if r is None:
                return self._bitsum(l)
            else:
                return self._bitsum(r) - self._bitsum(l)

        # i番目にxを追加
        def add(self, i, x):
            i += 1
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def lower_bound(self, x):
            sum_ = 0
            pos = 0
            v = 1 << self.depth
            for i in range(self.depth, -1, -1):
                k = pos + v
                if k <= self.size and sum_ + self.tree[k] < x:
                    sum_ += self.tree[k]
                    pos += v
                v >>= 1
            return pos + 1, sum_

    N=I()
    A=LI()
    
    
    def calc(x):
        # xを決めたときに，数列mの中でx以上の要素が何個あるか，を返す
        
        B=[0]*N
        for i in range(N):
            if A[i]>=x:
                B[i]=1
            else:
                B[i]=-1
                
        #累積和
        S=[0]*(N+1)
        for i in range(N):
            S[i+1]=S[i]+B[i]
            
        # S[i]にiの情報を持たせる
        inf=10**6
        for i in range(N+1):
            S[i]=S[i]*inf+i
        S.sort()

            
        # Sの値が小さい順に見ていく，そいつの番号を取り出し，そこよりも左側のbitの個数を答えに足していく&そこのbitを立てる
        bit=BIT(N+1)
        res=0
        for i in range(N+1):
            s=S[i]
            ii=s%inf
            temp=bit.sum(0,ii)
            res+=temp
            bit.add(ii,1)
        return res
    
    A2=sorted(A)
    M=(N*N)//2
    ok=0
    ng=N
    
    def ch(x):
        cnt=calc(x)
        # print(x,cnt)
        return cnt>=(M+1)//2

    while ng-ok>1:
        # print(ng,ok)
        med=(ok+ng)//2
        x=A2[med]
        if ch(x):
            ok=med
        else:
            ng=med
        
            
    print(A2[ok])
                
        
    

main()


Measured memory_bytes: 118672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,D,X;
  cin >> r >> D >> X;
  int ans;
  ans = r*X-D;
  cout << ans << endl;
  for(int i = 0;i<9;i++){
    
    ans = r*ans-D;
    cout << ans << endl;
  }

}


Measured memory_bytes: 256