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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class LazySegmentTree {
    private:
        int N;
        const T ZERO;
        std::vector<T> dat, lazy;
    public:
        LazySegmentTree(int n) : ZERO(static_cast<T>(0)) {
            N = 1;
            while (N < n) N *= 2;
            dat.assign(2*N, ZERO);
            lazy.assign(2*N, ZERO);
        }
        // a is 0-indexed
        void set(int a, const T v) { dat[a+N] = v; }
        void build() { for (int i=N-1; i>0; --i) dat[i] = dat[2*i] + dat[2*i+1]; }
        void eval(int k, int l, int r) {
            if (lazy[k] == ZERO) return;

            dat[k] += lazy[k] * (r - l);
            if (r - l > 1) {
                lazy[2*k] += lazy[k];
                lazy[2*k+1] += lazy[k];
            }
            lazy[k] = ZERO;
        }
        // add v to [a, b)
        // a and b are 0-indexed
        void add(int a, int b, const T v) { return add (a, b, v, 1, 0, N); }
        void add(int a, int b, const T v, int k, int l, int r) {
            eval(k, l, r);

            if (b <= l || r <= a) return;
            if (a <= l && r <= b) {
                lazy[k] += v;
                eval(k, l, r);
            } else {
                add(a, b, v, 2*k, l, (l+r)/2);
                add(a, b, v, 2*k+1, (l+r)/2, r);
                dat[k] = dat[2*k] + dat[2*k+1];
            }
        }
        // get min of [a, b)
        // a and b are 0-indexed
        T get(int a, int b) { return get(a, b, 1, 0, N); }
        T get(int a, int b, int k, int l, int r) {
            eval(k, l, r);

            if (b <= l || r <= a) return ZERO;
            if (a <= l && r <= b) return dat[k];
            T vleft = get(a, b, 2*k, l, (l+r)/2);
            T vright = get(a, b, 2*k+1, (l+r)/2, r);
            return vleft + vright;
        }
};

void solve() {
    int N;
    cin >> N;
    Graph la(N+1), sm(N+1);
    for (int i=0; i<N-1; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        la[a].push_back(b);
        sm[b].push_back(a);
    }

    LazySegmentTree<ll> st(N+1);
    ll sum = 0;
    for (int i=1; i<N+1; ++i) {
        sum -= (int)sm[i].size() - 1;
        st.set(i, sum);
    }
    st.build();

    ll res = 0;
    for (int i=1; i<N+1; ++i) {
        res += st.get(i, N+1);
        for (int x : la[i]) st.add(x, N+1, 1);
        st.add(i, N+1, -1);
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 33100
N=int(input())
rate=[list(map(int,input().split())) for i in range(2)]

def solve(d,r):
    l=len(r)
    if l==1:
        d=d//r[0][0]*r[0][1]+d%r[0][0]
    elif l==2:
        a=0
        w=[r[0][0],r[1][0]]
        v=[r[0][1]-r[0][0],r[1][1]-r[1][0]]
        for i in range(d//w[0]+1):
            a=max(a,v[0]*i+v[1]*((d-w[0]*i)//w[1]))
        d+=a
    elif l==3:
        a=[0]*(N+1)
        w=[r[0][0],r[1][0],r[2][0]]
        v=[r[0][1]-r[0][0],r[1][1]-r[1][0],r[2][1]-r[2][0]]
        for i in range(N+1):
            for j in range(l):
                if i>=w[j]:
                    a[i]=max(a[i],a[i-w[j]]+v[j])
        d+=a[-1]
    return d
r=[]
for i in range(3):
    if rate[0][i]<rate[1][i]:
        r.append((rate[0][i],rate[1][i]))
d=solve(N,r)
r=[]
for i in range(3):
    if rate[0][i]>rate[1][i]:
        r.append((rate[1][i],rate[0][i]))
d=solve(d,r)
print(d)

Measured memory_bytes: 40336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/
ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

//素因数分解
map<ll,ll> prime_factor(ll n){
    map<ll,ll> res; //res[2] = 4は、素因数2が4個あることを表す
    for(ll i = 2;i*i <= n;i++){//小さい素因数から順に割っていく
        while(n % i == 0){//i = 2が素因数だとすると、割り切れる限り2で割る
            res[i]++;//割り切れる回数をres[i]に格納
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;//nが素数の場合、上のループ後もnは元のままなので、res[n] = 1とする。
    return res;
}
int main() {
 ll N,P;
 cin >> N >> P;
 map<ll,ll> res = prime_factor(P);
 ll ans = 1;

 // Keyの値が小さい順にループ
 for(auto p : res){
     auto key = p.first;//素因数
     auto value = p.second;//素因数の個数
     if(value >= N){//Pの素因数の個数がN以上の時
        ans *= kzyou(key,value/N);
     }
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 07/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  double A,B; cin>>A>>B;
  auto minans = max((int)ceil(A*100/8), (int)ceil(B*100/10));
  auto maxans = min((int)ceil((A+1)*100/8), (int)ceil((B+1)*100/10));
  cerr << minans << " " << maxans << endl;
  if (minans < maxans) {
    cout << minans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int N; cin >> N;
	int ans = 800 * N - 200 * (N / 15);
	cout << ans << "\n";
	return 0;
}

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

int main(){
	long long n,a,b,r,ind;
	long long ans = 0;
	
	cin >> n >> a >> b;
	
	cin >> r;
	n--;
	while(n--){
		cin >> ind;
		if((ind-r)*a>b) ans+=b;
		else ans+=(ind-r)*a;
		r = ind;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}


long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}

class Point{
public:
	long long x;
	long long y;
};
long long N,M;
vector<long long>X(100006,0);
bool isOK(long long N){
	string s=to_string(N);
	set<char>set;
	for(int i=0;i<s.length();i++){
		set.insert(s[i]);
	}
	return set.size()==1;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	double N,T,A;
	cin>>N>>T>>A;
	double tem=1000;
	int ans=0;
	for(int i=0;i<N;i++){
		double H;
		cin>>H;
		if(abs(T-H*0.006-A)<tem){
			tem=abs(T-H*0.006-A);
			//cout<<tem<<endl;
			ans=i+1;
		}
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(),p.end());
    int ans=0;
    rep(i,k)ans+=p[i];
    cout<<ans;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int h,w;
   cin>>h>>w;
   char a[h][w];
   for(int i=0;i<h;i++)
   {
       for(int j=0;j<w;j++)
            cin>>a[i][j];
   }
   for(int i=1;i<=(w+2);i++)
   {
       cout<<"#";
   }
   cout<<endl;
   for(int i=0;i<h;i++)
   {
       cout<<"#";
       for(int j=0;j<w;j++)
            cout<<a[i][j];
        cout<<"#"<<endl;
   }
   for(int i=1;i<=(w+2);i++)
   {
       cout<<"#";
   }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct st{int idx,v;};
int n;
int in[100010];
st ev[100010];
st od[100010];
int anw;
bool cmp(st X,st Y){return X.v>Y.v;}
int main(){
    cin>>n;
    for(int i=0;i<=1e5;i++) ev[i].idx=od[i].idx=i;
    for(int i=0;i<n;i++){
        cin>>in[i];
        if(i%2) od[in[i]].v++;
        else ev[in[i]].v++;
    }
    sort(od,od+100000,cmp);
    sort(ev,ev+100000,cmp);
    if(od[0].idx==ev[0].idx) anw=min(n-od[0].v-ev[1].v,n-od[1].v-ev[0].v);
    else anw=n-od[0].v-ev[0].v;
    cout<<anw;
}


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

#define f first
#define s second
#define pb push_back

using namespace std;

const int maxk = 17 + 1;
const int maxn = 1 * 1e5 + 17;

int N;
string text;

int main()
{
    cin >> text >> N;
    for (int i = 0; i < text.size(); i += N) cout << text[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
T.sort()
 
count=1
cus=0
pre=T[0]
for t in T:
    if C>cus and pre+K>=t:
        cus+=1
    else:
        cus=1
        pre=t
        count+=1
print(count)

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

using namespace std;

int main(void){

  int N;
  cin >> N;

  int res = 0;

  for (int i = 1; i < 10; i++){
    if (i <= N){
      ++ res;}
    }

  for (int i = 100 ; i < 1000; i++){
    if (i <= N){
      ++ res;
    }}

  for (int i = 10000; i < 100000; i++){
    if (i <= N){ ++ res; }
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, d, x;
    cin >> n >> d >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll res = 0;

    rep(i, n) {
        rep(j, d) {
            if (j % a[i] == 0) res++;
        }
    }

    cout << res + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    vector<int> ans(n);
    rep(i,n) {
        int a; cin >> a;
        ans[a-1] = i+1;
    }
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
//    .------------------------------------------------------------.
//    |     ___   ___   _____     _     ___   ___    ___   ___     |
//    |    | _ \ | __| |_   _|   /_\   | _ \ |   \  | __| |   \    |
//    |    |   / | _|    | |    / _ \  |   / | |) | | _|  | |) |   |
//    |    |_|_\ |___|   |_|   /_/ \_\ |_|_\ |___/  |___| |___/    |
//    |                                                            |
//    |              ___    ___    ___    ___   ___                |
//    |             / __|  / _ \  |   \  | __| | _ \               |
//    |            | (__  | (_) | | |) | | _|  |   /               |
//    |             \___|  \___/  |___/  |___| |_|_\               |
//    |                                                            |
//    |------------------------------------------------------------|
//    |                      .------------.                        |
//    |                      | KerakTelor |                        |
//    |                      |------------|                        |
//    |                      | 2019-11-07 |                        |
//    |                      '------------'                        |
//    '------------------------------------------------------------'

#include <bits/stdc++.h>

#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("tune=native")

#define fi first
#define se second

using namespace std;

using ll=long long;
using ld=long double;

template<class T>
using vec=vector<T>;
template<class T>
using v2d=vector<vector<T>>;
template<class T>
using prq=priority_queue<T>;
template<class T>
using rpq=priority_queue<T,vector<T>,greater<T>>;

vec<ll> arr;
v2d<ll> dp;

ll solve(int l,int r,bool f)
{
    if(l>r)
        return 0;
    if(dp[l][r])
        return dp[l][r];
    ll res;
    if(f)
        res=max(solve(l+1,r,f^1)+arr[l],solve(l,r-1,f^1)+arr[r]);
    else
        res=min(solve(l+1,r,f^1)-arr[l],solve(l,r-1,f^1)-arr[r]);
    return dp[l][r]=res;
}

int main()
{
    int n;
    scanf("%d",&n);
    arr.assign(n,0);
    dp.assign(n,vec<ll>(n,0));
    for(auto &i:arr)
        scanf("%lld",&i);
    printf("%lld\n",solve(0,n-1,1));
}



Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
int cnt=0;
int dp[200005][3];
P prv[200005][3];

int main(void){
	cin >> s;
	int n=s.size();
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<s.size();i++){
		for(int j=0;j<2;j++){
			if(dp[i][j]==-1)continue;
			if(s[i]=='P' || s[i]=='?'){
				dp[i+1][1]=max(dp[i+1][1],dp[i][j]);
				if(dp[i+1][1]==dp[i][j]){
					prv[i+1][1]=P(i,j);
				}
			}
			if(s[i]=='D' || s[i]=='?'){
				if(j==0){
					dp[i+1][0]=max(dp[i+1][0],dp[i][j]+1);
					if(dp[i+1][0]==dp[i][j]+1){
						prv[i+1][0]=P(i,j);
					}
				}else{
					dp[i+1][0]=max(dp[i+1][0],dp[i][j]+2);
					if(dp[i+1][0]==dp[i][j]+2){
						prv[i+1][0]=P(i,j);
					}
				}
			}
		}
	}
	int i=n,j=0;
	if(dp[n][0]<dp[n][1]){
		j=1;
	}
	while(i>0){
		P pr=prv[i][j];
		if(s[i-1]=='?'){
			if(j==0){
				s[i-1]='D';
			}else{
				s[i-1]='P';
			}
		}
		i--;
		j=pr.second;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 6148
#include<stdio.h>
main()
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a+b==c||a+c==b||c+b==a){
		printf("Yes");}
	else{
		printf("No");}
		return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n , h, w;
	cin >> n  >> h >> w;
	int yoko = n - w + 1;
	int tate = n - h + 1;
	cout << yoko * tate << endl;
}


Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long N, H;
	scanf("%ld %ld", &N, &H);
	long a[100001], b[100001];
	long a_max = 0, b_min = 1e9 + 1;
	for (long i = 0; i < N; i++) {
		scanf("%ld %ld", &a[i], &b[i]);
		if (a[i] > a_max) {
			a_max = a[i];
		}
		if (b[i] < b_min) {
			b_min = b[i];
		}
	}

	long ans = 0;
	long D = 0;
    sort(b,b+N);
    reverse(b,b+N);

	for (long i = 0; i < N; i++) {
		if (a_max < b[i]) {
			D += b[i];
			ans++;
			if (D >= H) {
				printf("%ld\n", ans);
				return 0;
			}
		}
	}

	while (1) {
		if (D >= H) {
			printf("%ld\n", ans);
			break;
		}
		else {
			D += a_max;
			ans++;
		}
	}
	return 0;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//io
#define s(x) scanf(" %d",&x)
#define si(x) scanf(" %d",&x)
#define sll(x) scanf(" %lld",&x)
#define sf(x) scanf(" %lf",&x)
#define ss(x) scanf(" %s",x)
#define sl(x) scanf(" %[^\n]",x)
#define sc(x) scanf("%c",&x)
#define p(x) printf(x)
#define pi(x) printf("%d",x)
#define ps(x) printf("%s",x)
#define pll(x) printf("%lld",x)
#define pf(x) printf("%lf",x)
#define pc(x) printf("%c",x)
#define endl "\n"
#define pn() printf("\n")
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL)
//loops
#define F(x,n) for(int i=x;i<n;i++)
#define Fr(x,n,c) for(int i=x;i<n;i+=c)
#define R(x,n) for(int j=x;j<n;j++)
#define Rr(x,n,c) for(int j=x;j<n;j+=c)
#define V(x,n) for(int k=x;k<n;k++)
#define Vr(x,n,c) for(int k=x;k<n;k+=c)
//ds
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define test() int __T;scanf("%d",&__T);for(int __t=1;__t<=__T;__t++)
#define mem0(x) memset(x,0,sizeof(x))
#define memdp(x) memset(x,-1,sizeof(x))
#define mp(x,y) make_pair(x,y)
bool prime(int n) {
	if(n%2==0) return false;
	for(int i=3;i<=sqrt(n);i+=2)
	if(n%i==0) return false;
	return true;
}
int32_t main() {
	int h,n,x;
  cin>>h>>n;
  int s=0;
  while(n--) {
    cin>>x;
    s+=x;
  }
  if(s>=h) cout<<"Yes"; else cout<<"No";
	return 0;
}























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

const long double PI = acos(-1.0);

int main() {
  long double A, B, H, M;
  cin >> A >> B >> H >> M;
  long double hour = (PI + PI) * (H * (long double) 60.00 + M) / ((long double) 60.00 * (long double) 12.00);
  long double minute = (PI + PI) * M / ((long double) 60.00);
  long double diff = hour > minute ? hour - minute : minute - hour;
  if (diff > PI) diff = PI + PI - diff;
  long double dist = sqrt((A * A) + (B * B) - A * B * (long double) cos(diff) - A * B * (long double) cos(diff));
  cout << setprecision(15) << fixed << dist << '\n';
  return 0;
}

Measured memory_bytes: 4156
/**
 *    author:  zjsdut
 *    created: 2020/03/28 20:30:40
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#define rep(n)                                                                 \
  for (int TOKENPASTE2(_iter_, __LINE__) = 0,                                  \
                               TOKENPASTE2(_num_, __LINE__) = (int)(n);        \
       TOKENPASTE2(_iter_, __LINE__) < TOKENPASTE2(_num_, __LINE__);           \
       ++TOKENPASTE2(_iter_, __LINE__))
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL && !defined DUIPAI
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int k, n;
  scan(k, n);
  vi a(n);
  scan(a);
  int ma = abs(a[0] + k - a.back());
  rng (i, 1, n) {
    chkmax(ma, a[i] - a[i - 1]);
  }
  println(k - ma);

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
signed main(){
    int n;
    cin>>n;
    vector<pair<int, int> > a(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a[i]=make_pair(x, y);
    }
    int ans=n;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i==j)continue;
            int p=a[i].first-a[j].first;
            int q=a[i].second-a[j].second;
            int t=n;
            for(int k=0;k<n;k++){
                if(k==j)continue;
                for(int l=0;l<n;l++){
                    if(a[k].first-p==a[l].first&&a[k].second-q==a[l].second)t--;
                }
            }
            ans=min(ans,t);
        }
    }
    cout<<ans<<endl;
    return 0;
}




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

ll n;
const ll mod=1e9+7;
ll dp[101][4][4][4];

int main(){
    cin >> n;
    for(ll i=0;i<4;i++){
        for(ll j=0;j<4;j++){
            for(ll k=0;k<4;k++){
                if(i==0&&j==2&&k==1) dp[3][i][j][k]=0;
                else if(i==2&&j==0&&k==1) dp[3][i][j][k]=0;
                else if(i==0&&j==1&&k==2) dp[3][i][j][k]=0;
                else dp[3][i][j][k]=1;
            }
        }
    }
    for(ll memo=4;memo<=n;memo++){
        for(ll i=0;i<4;i++){
            for(ll j=0;j<4;j++){
                for(ll k=0;k<4;k++){
                    for(ll l=0;l<4;l++){
                        if(j==0&&k==2&&l==1) continue;
                        if(j==2&&k==0&&l==1) continue;
                        if(j==0&&k==1&&l==2) continue;
                        if(i==0&&k==2&&l==1) continue;
                        if(i==0&&j==2&&l==1) continue;
                        dp[memo][j][k][l]+=dp[memo-1][i][j][k];
                        dp[memo][j][k][l]%=mod;
                    }
                }
            }
        }
    }
    ll res=0;
    for(ll i=0;i<4;i++){
        for(ll j=0;j<4;j++){
            for(ll k=0;k<4;k++){
                res+=dp[n][i][j][k];
                res%=mod;
            }
        }
    }
    cout << res << endl;
}  


Measured memory_bytes: 3604
def check(arr)
  a =[0,9,12,15,18,21,30]
  a.each_cons(2){|s,t| return false if (s...t).any?{ |i| arr[i] != arr[s] } }
  true
end

MV = [[0,1,2,14,18,27,28,29,15,20],
      [6,7,8,12,9,21,22,23,17,11],
      [0,3,6,9,15,23,26,29,20,17],
      [2,5,8,11,12,21,24,27,18,14]]
  
gets.to_i.times do
  cube = gets.split(" ").map(&:to_i)
  q = []
  q << [cube, 0]
  until q.empty?
    tmp, cnt = q.shift
    if check tmp
      p cnt
      break
    end
    MV.each do |arr|
      tmp2 = tmp.dup
      arr[0,5].zip(arr[5,5]).each do |a, b|
        tmp2[a], tmp2[b] = tmp2[b], tmp2[a]
      end
      q << [tmp2, cnt+1] 
    end
  end
end

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


const int N = 1e5 + 5, M = 1e9 + 7, oo = -1e9;

int n, arr[N][3], dp[N][3];

int solve(int ind,int take) {
	if (ind == n) return 0;
	int& re = dp[ind][take];
	if (re != -1)return re;
	if (take != 0)re = max(re, arr[ind][0] + solve(ind + 1, 0));
	if (take != 1)re = max(re, arr[ind][1] + solve(ind + 1, 1));
	if (take != 2)re = max(re, arr[ind][2] + solve(ind + 1, 2));
	return re;
}
int main() {


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


	cin >> n;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++)
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];

	cout << solve(0, 3) << endl;

	return 0;
}


Measured memory_bytes: 8832
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int n,i,x,y,min;
    scanf("%lld",&n);
    min = n;
    for(i=2;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
               x=i;
               y=n/i;
               if(min>x+y-2)
                min = x+ y-2;
             
            }

        }
        if(min !=n)
        printf("%lld",min);
        else
        printf("%lld",n-1);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int people[][] = new int[4][2];
		int a = 1;
		while (sc.hasNext())
		{
			double x = sc.nextDouble();
			a = (a + 1) % 2;
			if (x < 0.2)
			{
				people[3][a]++;
			}
			else if (x < 0.6)
			{
				people[2][a]++;
			}
			else if (x < 1.1)
			{
				people[1][a]++;
			}
			else
			{
				people[0][a]++;
			}
		}
		for (int i = 0; i < 4; i++)
		{
			System.out.printf("%d %d\n", people[i][0], people[i][1]);
		}
	}
}

Measured memory_bytes: 12000
D = [[1, 3, 4, 2], [5, 3, 0, 2], [5, 1, 0, 4], [5, 4, 0, 1], [2, 0, 3, 5], [1, 2, 4, 3]]
n = int(input())
d = [[int(i) for i in input().split()] for _ in range(n)]
for x in range(n - 1):
    a = d[x]
    for y in range(x + 1, n):
        b = d[y]
        count = 0
        if set(a) != set(b):
            break
        for i in range(6):
            if a[i] == b[i]:
                count += 1
                continue
            A = [a[k] for k in D[i]]
            B = [b[k] for k in D[b.index(a[i])]]
            if set(A) != set(B):
                break
            if A != B:
                for j in range(4):
                    if A[j] != B[j]:
                        dif = (B.index(A[j]) - j)
                        B = B[dif:] + B[:dif]
                        break
            if A == B:
                count += 1
            else:
                break
        if count == 6:
            print("No")
            exit()
print("Yes")



Measured memory_bytes: 5616
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String[] s = sc.next().split("");
        int count = 0;
        for(int i =0;i<s.length-2;i++){
            if(s[i].equals("A") && s[i+1].equals("B") && s[i+2].equals("C")){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    string N; cin >> N;
    cout << N[0] << N[1] << N[2] <<endl;
    return 0;
}

Measured memory_bytes: 3620
<?php

fscanf(STDIN, "%d", $n);

switch (strlen($n)) {
case 1:
    echo $n;
    break;
case 2:
    echo 9;
    break;
case 3:
    echo 9 + ($n - 100 + 1);
    break;
case 4:
    echo 9 + 900;
    break;
case 5:
    echo 9 + 900 + ($n - 10000 + 1);
    break;
case 6:
    echo 9 + 900 + 90000;
    break;
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 1000005

int n, c, k;
ll a[maxn];

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

	cin >> n >> c >> k;
	For(i, 1, n) cin >> a[i];
	sort(a + 1, a + n + 1);
	int run = 1, num = 1;
	For(i, 2, n){
		if(i - run + 1 > c || a[i] - a[run] > k){
			num++;
			run = i;
		}
	}
	cout << num << endl;

    return 0;
}


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

int main() {
	int a, b;
	char op;
	
	while(1){
		cin >> a >> op >> b;
		if (op == '?') break;
		if (op == '+') cout << a+b << endl;
		else if ( op == '-') cout << a-b <<endl;
		else if ( op == '*') cout << a*b << endl;
		else if ( op == '/') cout << a/b << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
int main()
{
    int N,R,S;
    scanf("%d",&N);
    if(N%1000==0){
        printf("0\n");}


    else if (N%1000>0){
           R=N%1000;
           S=1000-R;
        printf("%d\n",S);
    }
    return 0;
}

Measured memory_bytes: 1700
n,m = map(int, input().split())
start = set()
goal = set()
for i in range(m):
    a,b = map(int, input().split())
    if a == 1:
        start.add(b)
    elif  b == n:
        goal.add(a)

ans = start & goal
if len(ans) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 57944
n,m=map(int,input().split())
d={}
for i in range(n):
      a,b=map(int,input().split())
      if a in d:
            d[a]+=b
      else:
            d[a]=b
d = list(sorted(d.items(), key=lambda x:x[0]))

dd=[]
for i in d:
      dd.append([i[0],i[1]])

ans=0
i=0
c=0
while m>c:
      if dd[i][1]!=0:
            dd[i][1]+=-1
            ans+=dd[i][0]
            c+=1
      else:
            i+=1
     
print(ans)


Measured memory_bytes: 26812
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define N 10000
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];


int main()
{
    fast_cin;
    ll t,n;
    cin>>t>>n;
    ll sum=t+1-n;
    cout<<sum<<endl;
}



Measured memory_bytes: 256
def calc(A):
    # i桁目の偶奇を調べる
    ans = 0
    for i in range(50):
        # 0桁目 -> 周期2
        # 1桁目 -> 周期4
        # 2桁目 -> 周期8
        # ...
        loop = 1 << (i+1)
        cnt = (A // loop) * (loop // 2)
        cnt += max(0, (A % loop) - (loop // 2) + 1)

        # その桁の１の数が奇数だったら足す
        if cnt % 2 == 1:
            ans += 1 << i

    return ans


A, B = map(int, input().split())

ans = calc(B) ^ calc(A-1)

print(ans)


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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, M, ans;
   cin >> N >> M;
   vector<int> X(M);
   rep(i, M) cin >> X.at(i);
   if (M <= N) ans = 0;
   else {
     vector<int> Y(M - 1);
     sort(X.begin(), X.end());
     rep(i, M - 1) Y.at(i) = X.at(i + 1) - X.at(i);
     sort(Y.begin(), Y.end(), greater<int>());
     ans = X.at(M - 1) - X.at(0);
     if (N > 1) {
       rep(i, N - 1) ans -= Y.at(i);
     }
   }
   cout << ans << endl;
 }


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

#define pb push_back

using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;

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

    int n;
    cin >> n;
    map<int,int> xs;
    for(int i=0; i<n; ++i) {
        int x;
        cin >> x;
        ++xs[x];
    }
    if (xs.size() > 3)
        cout << "No\n";
    else if (xs.size() == 3) {
        if (xs.begin()->second != next(xs.begin())->second || xs.begin()->second != next(next(xs.begin()))->second
            || ((xs.begin()->first ^ next(xs.begin())->first) != next(next(xs.begin()))->first))
            cout << "No\n";
        else
            cout << "Yes\n";
    }
    else if (xs.size() == 2) {
        if (2*xs.begin()->second != next(xs.begin())->second || xs.begin()->first != 0)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
    else {
        assert(xs.size() == 1);
        if (xs.begin()->first != 0)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
}


Measured memory_bytes: 3840
#include<cstdio>
int a,b;
int main()
{
	while(~scanf("%d %d",&a,&b))
	{
		if((a+b)%2!=0)
		{
			printf("%d\n",(a+b)/2+1);
		}
		else
		{
			printf("%d\n",(a+b)/2);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  cout << min(A, B) + min(C, D) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#define ll long long
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n,Q,q[200010],dp;
ll seg[1000010],up[1000010],down[1000010],lazy[1000010];
void add(ll cur,ll val){
	if(seg[cur]==1e15) return;
	seg[cur]+=val;up[cur]+=val;down[cur]+=val;lazy[cur]+=val;
}
void update(ll cur){
	seg[cur]=min(seg[cur<<1],seg[cur<<1|1]);
	up[cur]=min(up[cur<<1],up[cur<<1|1]);
	down[cur]=min(down[cur<<1],down[cur<<1|1]);
}
void push(ll l,ll r,ll cur){
	if(l==r||!lazy[cur]) return;
	add(cur<<1,lazy[cur]);
	add(cur<<1|1,lazy[cur]);
	lazy[cur]=0;
	return;
}
void build(ll l,ll r,ll cur){
	if(l==r){seg[cur]=up[cur]=down[cur]=1e15;lazy[cur]=0;return;}
	ll mid=(l+r)>>1;
	build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);
	update(cur);
}
void change(ll l,ll r,ll cur,ll pos,ll val){
	if(l==r){
		if(val<seg[cur]){seg[cur]=val;up[cur]=val+r;down[cur]=val-r;}
		return;
	}
	push(l,r,cur);
	ll mid=(l+r)>>1;
	if(mid>=pos) change(l,mid,cur<<1,pos,val);
	else change(mid+1,r,cur<<1|1,pos,val);
	update(cur);
}
ll query(ll l,ll r,ll ql,ll qr,ll cur,ll tp){
	if(ql>qr) return 1e15;
//	cout<<"query "<<l<<' '<<r<<' '<<ql<<' '<<qr<<' '<<cur<<' '<<tp<<' '<<seg[cur]<<' '<<up[cur]<<' '<<down[cur]<<'\n';
	if(l>=ql&&r<=qr) return (tp?up[cur]:down[cur]);
	push(l,r,cur);
	ll mid=(l+r)>>1,re=1e15;
	if(mid>=ql) re=min(re,query(l,mid,ql,qr,cur<<1,tp));
	if(mid<qr) re=min(re,query(mid+1,r,ql,qr,cur<<1|1,tp));
	return re;
}
int main(){
	n=read();Q=read();ll i,op1,op2;
	op1=read();op2=read();
	for(i=1;i<=Q;i++) q[i]=read();
	build(1,n,1);
	change(1,n,1,op1,abs(q[1]-op2));
	change(1,n,1,op2,abs(q[1]-op1));
	for(i=2;i<=Q;i++){
		dp=min(query(1,n,1,q[i],1,0)+q[i],query(1,n,q[i]+1,n,1,1)-q[i]);
		add(1,abs(q[i]-q[i-1]));change(1,n,1,q[i-1],dp);
//		cout<<"check seg1 "<<i<<' '<<seg[1]<<'\n';
	}
	printf("%lld\n",seg[1]);
}

Measured memory_bytes: 26880
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.PriorityQueue;
import java.math.BigInteger;
    
public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static final long LINF=Long.MAX_VALUE/2;
static int n;
static String str;

public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
n=ir.nextInt();
str=ir.next();
int len=str.length();
int cnt=0;
lo1: while(n-->0){
String old=ir.next();
lo2: for(int i=0;i<=old.length()-len;i++){
if(old.charAt(i)!=str.charAt(0)) continue;
lo3: for(int j=1;;j++){
if(i+(len-1)*j>=old.length()) continue lo2;
for(int k=0;k<len;k++){
if(old.charAt(i+j*k)!=str.charAt(k)) continue lo3;
if(k==len-1){
cnt++;
continue lo1;
}
}
}
}
}
out.println(cnt);
out.flush();
}

static class InputReader {
private InputStream in;
private byte[] buffer=new byte[1024];
private int curbuf;
private int lenbuf;

public InputReader(InputStream in) {this.in=in;}
  
public int readByte() {
if(lenbuf==-1) throw new InputMismatchException();
if(curbuf>=lenbuf){
curbuf= 0;
try{
lenbuf=in.read(buffer);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(lenbuf<=0)
return -1;
}
return buffer[curbuf++];
}

public boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

private int skip() {int b; while((b = readByte())!=-1&&isSpaceChar(b)); return b;}

public String next() {
int b=skip();
StringBuilder sb=new StringBuilder();
while(!isSpaceChar(b)){
sb.appendCodePoint(b);
b=readByte();
}
return sb.toString();
}
 
public int nextInt() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
int res=0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public long nextLong() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
long res = 0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public int[] toIntArray(int n){
int[] a=new int[n];
for(int i=0;i<n;i++) a[i]=nextInt();
return a;
}
}
}

Measured memory_bytes: 18276
N,M,X = map(int,input().split())
dictionary = list()
for i in range(N):
    dictionary.append(list(map(int,input().split())))
# print(dictionary)

n = len(dictionary)
bit_list =list()
s = 1
for i in range(2 ** n):
    bit = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bit.append(j)  # フラグが立っていたら bag に果物を詰める
    s+=1
    # print(bit)
    bit_list.append(bit)
skill = [0]*M
skill_list = list()

cost_list=list()
# print(bit_list)

for i in range(len(bit_list)):
    ran = len(bit_list[i])
    # print(ran,"range")
    skill = [0]*M
    cost=0
    for j in range(ran):
        for k in range(M):
            skill[k] += dictionary[bit_list[i][j]][k+1]
        cost+=dictionary[bit_list[i][j]][0]

    cost_list.append(cost)
    skill_list.append(skill)
# print(skill_list)

min_cost = 10000000000000
tf = 0
for i in range(len(skill_list)):
    f = 0
    for k in range(len(skill_list[i])):
        # print(skill_list[i][k],i,k)
        if(skill_list[i][k]<X):
            # print("F")
            f = 1
            break
    # print("flag",f)
    if(f == 0):
        tf = 1
        min_cost= min(min_cost,cost_list[i])
if(tf == 0):
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 11852
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <list>
#include <queue>

using namespace std;

static const int INFTY = 2001;

int H;
int A[101];
int NodeNum[101];
int IndexInA[100];


int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return 2 * i + 1;
}

void minHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int smallest = i;
	if (l <= H && A[l] < A[i]) {
		smallest = l;
	}
	if (r <= H && A[r] < A[smallest]) {
		smallest = r;
	}
	if (smallest != i) {
		int temp = A[i];
		A[i] = A[smallest];
		A[smallest] = temp;
		temp = NodeNum[i];
		NodeNum[i] = NodeNum[smallest];
		NodeNum[smallest] = temp;
		IndexInA[NodeNum[i]] = i;
		IndexInA[NodeNum[smallest]] = smallest;

		minHeapify(smallest);
	}
}

void insert(int d, int nodeNum) {
	int i = ++H;
	A[i] = d;
	NodeNum[i] = nodeNum;
	IndexInA[nodeNum] = i;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int heapExtractMinNodeNum() {
	int minNodeNum = NodeNum[1];
	A[1] = A[H];
	NodeNum[1] = NodeNum[H];
	IndexInA[NodeNum[1]] = 1;
	H--;
	minHeapify(1);

	return minNodeNum;
}

void decrese(int i, int value) {
	A[i] = value;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int main() {
	int Dist[101];
	int AdjacenceyList[100][100];
	int AdjacenceyWeightList[100][100];
	int Degree[100];
	int i, j;
	int N;
	int W;
	int Deg;
	int MinTotalWeight = 0;
	int u, v;
	bool inT[100];

	cin >> N;

	for (i = 0; i < N; i++) {
		inT[i] = false;
		Dist[i] = INFTY;
		Deg = -1;
		for (j = 0; j < N; j++) {
			cin >> W;
			if(W != -1){
				AdjacenceyList[i][++Deg] = j;
				AdjacenceyWeightList[i][Deg] = W;
			}
		}
		Degree[i] = Deg + 1;
	}
	Dist[100] = INFTY;



	H = 0;
	u = 0;
	inT[u] = true;
	Dist[u] = 0;
	for (i = 1; i <= N - 1; i++) {
		for (j = 0; j < Degree[u]; j++) {
			v = AdjacenceyList[u][j];
			if (inT[v] == false) {
				W = AdjacenceyWeightList[u][j];
				if (Dist[v] == INFTY) {
					Dist[v] = W;
					insert(W, v);
				}
				else if (W < Dist[v]) {
					Dist[v] = W;
					decrese(IndexInA[v], W);
				}
			}
		}

		int minNodeNum = heapExtractMinNodeNum();
		inT[minNodeNum] = true;
		MinTotalWeight += Dist[minNodeNum];
		u = minNodeNum;

		////DEBUG
		////printf("%d\n", minNodeNum);
		//for (int k = 1; k <= H; k++) {
		//	printf("(%d, %d) ", A[k], NodeNum[k]);
		//}
		//printf("\n");
	}

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

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a;

int get(int x){
   int low = 0, high = 1e6, ans = 0;
   while(low <= high){
      int mid = (low + high) >> 1;
      int func = (mid * (mid + 1)) / 2;
      if (func <= x){
         ans = mid;
         low = mid + 1;
      }
      else{
         high = mid - 1;
      }
   }
   return ans;
}

int factorize(int n){
   int ans = 0;
   for (int i = 2; i*i <= n; ++i)
   {
      if(n%i)continue;
      int expo = 0;
      while(n%i == 0){
         expo++;
         n/= i;
      }
      ans += get(expo);
   }
   if(n > 1){
      ans += 1;
   }
   return ans;
}

int32_t main(){_

   cin >> n;   

   cout<<factorize(n);

   return 0;
}

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

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

bool visited[MAX_SIZE + 2][MAX_SIZE + 2];
bool used[MAX_SIZE + 2][MAX_SIZE + 2][4];

int solve() {
	int dir[128];
	memset(dir, -1, sizeof(dir));
	dir['^'] = 0;
	dir['>'] = 1;
	dir['v'] = 2;
	dir['<'] = 3;

	int h, w;
	cin >> h >> w;

	int x, y, d;
	vector<string> field(h + 2, string(w + 2, '#'));

	for(int i = 1; i <= h; ++i) {
		string s;
		cin >> s;
		field[i] = '#' + move(s) + '#';

		for(int j = 1; j <= w; ++j) {
			if(dir[field[i][j]] != -1) {
				x = j;
				y = i;
				d = dir[field[i][j]];
			}
		}
	}

	int ans = 0;
	while(!used[y][x][d]) {
		used[y][x][d] = true;

		if(!visited[y][x]) {
			visited[y][x] = true;
			++ans;
		}

		if(field[y][x] == 'G') return ans;

		const int right = (d + 1) & 0x3;
		if(field[y + dy[right]][x + dx[right]] != '#') {
			d = right;
			x += dx[d];
			y += dy[d];
		}
		else if(field[y + dy[d]][x + dx[d]] == '#') {
			d = (d + 3) & 0x3;
		}
		else {
			x += dx[d];
			y += dy[d];
		}
	}

	return -1;
}

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

	cout << solve() << endl;

	return EXIT_SUCCESS;
}

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

int power(int cardinalNum, int index);

int main(){
    int N,K;
    cin >> N >> K;
    // cout << power(3,4) << endl;
    // cout << "N - 1 is " << N - 1 << "K - 1 is " << K - 1 << endl;
    // cout << power((N-1),(K-1)) << endl;

    if(N - 1 == 0) cout << K;
    else cout << K * power((K-1),(N-1)) << endl;
}

int power(int cardinalNum, int index){
    int ans = 1;
    for(int i = 0; i < index; i++){
        ans *= cardinalNum;
    }
    return ans;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string as;
    cin >> as;
    int n = as.size();

    int ans = 0;
    rep(i, n) {
        if(as[i] == '0') ans++;
    }

    ans = max(ans, n-ans);

    cout << 2*n-2*ans << endl;
}

Measured memory_bytes: 512
//20:05
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;
char A[N];
map<string,int>Q;
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	scanf("%s",A);int len=strlen(A);
	int k;scanf("%d",&k);
	string a=A;
	for(int i=0;i<len;i++){
		for(int j=1;j<=min(len-i,5);j++){
			Q[a.substr(i,j)]++;
		}
	}
	int cnt=0;
	for(auto j:Q){
		if(++cnt==k)return cout<<j.first<<'\n',0;
	}
}


Measured memory_bytes: 1920
from itertools import product

# 入力
N, M = map(int, input().split())
k, s = zip(
    *(
        (k, s)
        for _ in range(M)
        for k, *s in [map(int, input().split())]
    )
)
p = list(map(int, input().split()))

# 全探索で解を求める
ans = sum(
    all(
        sum(t[j - 1] for j in S) % 2 == P
        for S, P in zip(s, p)
    )
    for t in product(range(2), repeat=N)
)

# 出力
print(ans)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var k int
	var s string
	fmt.Scan(&k)
	fmt.Scan(&s)
	if len(s) <= k {
		fmt.Println(s)
	} else {
		s = s[0:k] + "..."
		fmt.Println(s)
	}
}

Measured memory_bytes: 1756