akhauriyash/Code-Regression huggingface dataset:
def counting(num, power, base):
    num2 = 0
    while num >= base:
        if num >= base ** (power - 1):
            num -= base ** (power - 1)
            num2 += 1
        else:
            power -= 1
    return num + num2

def main():
    n = int(input())
    ans = float("inf")
    for n_nine in range(0, n// 9 + 1):
        s = n - 9 * n_nine
        n_six = s // 6
        n_1 = s - 6 * n_six
        pow_nine = 5
        pow_six = 6
        n_9 = counting(n_nine, pow_nine, 9)
        n_6 = counting(n_six, pow_six, 6)
        ans = min(ans, n_1 + n_6 + n_9)

    print(ans)

main()

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  ll N, C, K;
  cin >> N >> C >> K;
  ll T[N];

  for(int i=0;i<N;i++) cin >> T[i];

  sort(T,T+N);

  int i=0;
  int cnt = 0;
  while(i<N){
    int j=0;
    while(i+j<N && T[i+j]<=T[i]+K && j<C){
      j++;
    }
    cnt++;
    i = i+j;
  }
  cout << cnt <<endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  string N;
  cin >> N;
  int sum = 0;
  FOR(i,0,N.size()) sum += N[i] - '0';
  if ((sum % 9) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3688
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c = mi()
k=ii()

for i in range(k):
    if b <= a:
        b*=2
    elif c <= b:
        c *= 2

    if(a < b and b < c):
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long int
#define inf 1450000090
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define nax 100010
#define mp make_pair
#define sz(x) (int)(x.size())
#define pl pair <ll , ll>
#define pii pair < int , pair <int ,int > >
#define MOD 1000000007
using namespace std;
int x[nax];
int y[nax];
ll ans[nax];
int main(int argc, char const *argv[])
{
 // freopen("input.txt","read",stdin);
 // freopen("output.txt","write",stdout);
  int n,m;
  sd2(n,m);
  for (int i = 1; i <= n; ++i)
  {
  		sd(x[i]);
  }
  sort(x+1,x+1+n);
  for (int i = 1; i <= m; ++i)
  {
  		sd(y[i]);
  }
  sort(y+1,y+1+m);
  ll sumy = 0;
  int lft = 1;int rit = n-1;
  for(int i=2;i<=n;i++)
  {
  	ll add = x[i]-x[i-1];
  	sumy= (sumy +((add * 1ll*(rit))%MOD*(lft))%MOD)%MOD;
  	rit--;
  	lft++;
  }
  ll fans = 0;
  for(int i=2;i<=m;i++)
  {
  	ll dist = y[i]-y[i-1];
  	dist = (dist*sumy)%MOD;
  	ans[i] = (ans[i-1]+(dist*(i-1))%MOD)%MOD;
  	fans = (fans+ans[i])%MOD;
  }
  printf("%lld\n",fans);
  return 0;
}

Measured memory_bytes: 1792
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = 0
check = abs(a - (t - h[0]*0.006))
for i in range(n):
  if abs(a - (t - h[i]*0.006)) < check:
    check = abs(a - (t - h[i]*0.006))
    ans = i
print(ans+1)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
using namespace std;

const int MAXN=100000+10;

map<int,int> mp;
set<int> s;

int a[MAXN];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(s.find(a[i])!=s.end())continue;
		else if(s.find(a[i])==s.end()){	
			s.insert(a[i]);
			if(mp[a[i]]<a[i]){
				cnt+=mp[a[i]];
			}
			if(mp[a[i]]>a[i]){
				cnt+=mp[a[i]]-a[i];
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int intLength = int.Parse(Console.ReadLine());
            int[] aryInput = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            Console.WriteLine(string.Join(" ", aryInput));

            for (int i = 1; i < intLength; i++)
            {
                aryInput = Program.InsertionSort(i, aryInput);

                Console.WriteLine(string.Join(" ", aryInput));
            }
            //Console.ReadLine();
        }

        /// <summary>
        /// index-1番目までの要素は整列しているとして、indexの位置にある要素を、左の整列に加える
        /// </summary>
        /// <param name="index"></param>
        /// <param name="aryInput"></param>
        static private int[] InsertionSort(int index, int[] aryInput)
        {
            for (int i = index; 0 < i; i--)
            {
                if (aryInput[i-1] > aryInput[i])
                {
                    int tmp = aryInput[i];
                    aryInput[i] = aryInput[i - 1];
                    aryInput[i - 1] = tmp;
                }
                else
                {
                    break;
                }
            }
            return aryInput;
        }
    }
}



Measured memory_bytes: 18316
import math
from math import gcd
gcd_sum=[0]*201
ans =0 
k=int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd_sum[i]+=gcd(i,j)


for a in range(1,k+1):
    for b in range(1,k+1):
            g=gcd(a,b)
            ans+=gcd_sum[g]
print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

bool sw[10][10];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;
    rep(i,M){
        int K; cin>>K;
        rep(j,K){
            int s; cin>>s;
            sw[i][s-1]=true;
        }
    }
    vi p(M);
    rep(i,M) cin>>p[i];
    int ans=0;
    rep(S,1<<N){
        bool ng=false;
        rep(i,M){
            int sum=0;
            rep(j,N)if(S>>j&1)if(sw[i][j]){
                sum=1-sum;
            }
            if (sum!=p[i]) ng=true;
        }
        if (!ng) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n;
	int point;
	int check;
	int i;
	int t;
	int hantei;
	int count4=0;
	int count2=0;
	int miss=0;
	long int kazu[100002];


	scanf("%d",&n);
	if ((n % 2) == 1) {
		point = 1;
	}
	else {
		point = 0;
	}
	for (i = 1; i <= n; i++) {
		scanf("%d", &kazu[i]);
	}

	for (t = 1; t <= n; t++) {
		hantei = kazu[t] % 4;
		if (hantei == 0) {//４の倍数
			count4++;
		}
		else if (hantei==2) {//2の倍数
			count2++;
		}
		else {				//奇数
			miss++;
		}
	}

	check = miss % 2;

	if (miss == 0) {
		printf("Yes\n");
	}else if (check == 0) {
		if ((point == 1) && (((n + 1) / 2) == miss)) {
			if (miss <= count4+1) {
				printf("Yes\n");
			}
			else {
				printf("No\n");
			}
		}else if (miss <= count4) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else if (check == 1) {
		if (point == 1) {
			if (miss <= count4 + 1) {
				printf("Yes\n");
			}
			else {
				printf("No\n");
			}
		}
		else {
			if (miss <= count4) {
				printf("Yes\n");
			}
			else {
				printf("No\n");
			}

		}
	}
	
		

	return 0;
}

Measured memory_bytes: 896
n=input()
a=sorted(map(int,raw_input().split()))
r=0
b=[0]+[a[j]*(-1)**j%24 for j in range(n)]
s=24
for j in range(n):
 for k in range(j+1,n+1):s=min(s,(b[j]-b[k])%24,(b[k]-b[j])%24)
r=max(r,s)
print r

Measured memory_bytes: 29164
#!/usr/bin/env python3
#ABC77 C

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a,i)
    y = bisect.bisect_right(c,i)
    ans += x*(n-y)
print(ans)


Measured memory_bytes: 105444
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;

    int max = 0, tmp = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') tmp++;
        if (s[i] == 'D') tmp--;
        if (tmp > max) max = tmp;
    }
    cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;


int main() {
    
    int n,Q;
    cin>>n>>Q;
    queue<pair<string,int>> q;
    vi ans(n);
    vs str(n);
    map<string,int> m;
    rep(i,n){
        string s;
        int t;
        cin>>s>>t;
        m[s]=i;
        str[i]=s;
        q.push(mp(s,t));
    }
    int time=0;
    while(!q.empty()){
        time+=min(q.front().second,Q);
        if(q.front().second<=Q){
            ans[m[q.front().first]]=time;
            q.pop();
        } else {
            auto t=q.front();
            t.second-=Q;
            q.push(t);
            q.pop();
        }
    }
    vector<pair<int,string>> a;
    rep(i,n){
        a.pb(mp(ans[i],str[i]));
    }
    Sort(a);
    rep(i,n){
        cout<<a[i].second<<" "<<a[i].first<<endl;
    }
    
}


Measured memory_bytes: 10820
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    bnt = 0
    for j in range(m):
        cnt = 0
        for l in range(1, len(ks[j])):
            if (i>>(ks[j][l]-1))&1 == 1:
                cnt += 1
        if cnt%2 == p[j]:
            bnt += 1
    if bnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 9148
<?php
fscanf(STDIN, "%d", $n);
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$odd = 1;
foreach($A as $a){
  if($a%2==0){
    $odd*=2;
  }
}
printf("%d", pow(3,$n) - $odd);


Measured memory_bytes: 4604
#include<stdio.h>
typedef long long ll;
ll func(ll);
ll memo[21];

int main(void){
  ll x;
  scanf("%lld",&x);
  printf("%lld\n",func(x));
  return 0;
}

ll func(ll n){

  if(n==0)return 1;
  if(memo[n]!=0)return memo[n];
  return n * func(n-1);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = long long;

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

    int res = 10000;
    rep(i, sqrt(n) + 1){
        if(i == 0) continue;
        if(n % i == 0){
            ll x = n / i;
            int cur = 0;
            while(x != 0){
                cur++;
                x /= 10;
            }
            if(cur < res) res = cur;
        }
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*; 
	public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextInt();
					long s = 0;
					
					for(long i = 1;i<=a;i++) {
						if(i%3 != 0 && i%5 != 0) {
							s += i;
						}
					}
					System.out.println(s);
					
			}}

Measured memory_bytes: 35772
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int h, w;
	while (cin >> h >> w && h > 0) {
		for (int i = 0; i < h; ++i)
			cout << string(w, '#') << endl;
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      System.out.println(Math.max(a*b,c*d));
    }
}

Measured memory_bytes: 21844
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

int dp[N], mmax;
vector<int> g[N];
bool us[N];

int dfs(int v) {
	us[v] = 1;
	for(int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if(!us[to]) dfs(to);
		dp[v] = max(dp[v], dp[to] + 1);
	}
	return dp[v];
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++) {
		if(!us[i]) dfs(i);
	}
	for(int i = 1; i <= n; i++) {
 		mmax = max(mmax, dp[i]);
 		//cout << dp[i] << " ";
	}
	cout << mmax;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    map<int, int> mp;

    for(int i=0; i<N; ++i){
        int a; cin >> a;
        ++mp[a];
    }

    int ans = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
        if(itr->second >= itr->first) ans += (itr->second - itr->first);
        if(itr->second < itr->first) ans += itr->second;
    }

    cout << ans << endl;
}

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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll d[N], pass[N], p[N];
vector<ll> node[N];
void bfs(ll u){
        queue<pair<ll, ll>> q;
        q.push({u, d[u]});
        while (q.size()){
                pair<ll, ll> now = q.front();
                q.pop();
                for (auto j : node[now.first]){
                        if (d[j] > (now.second + 1 - pass[now.first])){
                                d[j] = now.second + 1 - pass[now.first];
                                q.push({j, d[j]});
                        }
                }
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("BONUS.INP", "r")){
                freopen("BONUS.INP", "r", stdin);
                freopen("BONUS.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i <= n * n; i++){
                cin >> p[i];
                ll row = p[i] / n;
                ll col = p[i] % n;
                if (col){
                        row++;
                } else {
                        col = n;
                }
                d[p[i]] = min(min(row - 1, col - 1), min(n - row, n - col));
                if (row > 1){
                        node[p[i]].push_back(p[i] - n);
                }
                if (row < n){
                        node[p[i]].push_back(p[i] + n);
                }
                if (col > 1){
                        node[p[i]].push_back(p[i] - 1);
                }
                if (col < n){
                        node[p[i]].push_back(p[i] + 1);
                }

        }
        ll ans = 0;
        for (int i = 1; i <= n * n; i++){
                ans += d[p[i]];
                pass[p[i]] = 1;
                bfs(p[i]);
        }
        cout << ans;
}


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

const int N = 20005;
int A[N];

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

    for(int i = 0; i < n; ++i)
        cin>>A[i];

    int ans = INT_MAX;
    for(int i = 0; i < n; ++i) {
        int X = A[i];
        multiset<int> s;
        multiset<int> temp;
        for(int j = 0; j < n; ++j) {
            if(A[j] < X) {
                while(temp.size() >= k) {
                    s.insert(*temp.begin());
                    temp.erase(temp.begin());
                }
                temp.clear();
                continue;
            }
            temp.insert(A[j]);
        }
        while(temp.size() >= k) {
            s.insert(*temp.begin());
            temp.erase(temp.begin());
        }
        int tempv;
        if(s.size() >= q) {
            for(int j = 0; j < q; ++j) {
                tempv = *s.begin();
                s.erase(s.begin());
            }
            ans = min(ans, tempv - X);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long slove(string s,char R,char G,char B)
{
	long long sum=0;
    long long sumB=0,sumG=0;
    int n=s.length();
    for(int i=n-1;i>=0;i--)
    {
    	if(s[i]==B)sumB++;
    	else if(s[i]==G)sumG+=sumB;
    	else if(s[i]==R)sum+=sumG;
	}
//	cout<<sumB<<endl;
	return sum;
}
int main()
{
   int n;cin>>n;
    string s;cin>>s;
    long long sum=0;
    sum+=slove(s,'R','G','B');
   // cout<<sum<<endl;
    sum+=slove(s,'R','B','G');
    //cout<<sum<<endl;
    sum+=slove(s,'B','R','G');
    sum+=slove(s,'B','G','R');
    sum+=slove(s,'G','B','R');
    sum+=slove(s,'G','R','B');
   // cout<<sum<<endl;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(s[j]!=s[i])
			{
				if(j+j-i<n)
				if(s[j+j-i]!=s[j]&&s[j+j-i]!=s[i])sum--;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  long long ans=0;
  long long q,h,s,d,n;cin>>q>>h>>s>>d>>n;
  //2L分
  long long want2 = n/2;
  if(want2 != 0){
	ans += min(min(q*8,h*4),min(s*2,d))*want2;
  }
  //1L分
  long long want1 = n%2;
  if(want1 != 0){
	ans += min(s,min(q*4,h*2));
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;


int main () {

    int N;
    cin >> N;

    int cnt = 0;

    for (int i = 1; i <= N; i++) {
        int a = i;
        set < int > div;
        for (int j = 1; j <= a; j++) {
          	if (a % j == 0) {
				div.insert(a / j);
            	div.insert(j);
            }
        }
        if (div.size() == 8 && a % 2 == 1) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define ld long double
 	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =3e5+5;
	 const int lg=20;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }
	   
	   
	   
mi mp;	   


void solve() {
	   int n;
	   cin>>n;
	
	  int cnt=0;
	  int n1=n;
	  for(int i=2;i*i<=n;i++) {
		     while(n1%i==0) {
				   n1/=i;
				   mp[i]++;
				 }		  
		  }
		   
		  if(n1!=1) mp[n]++;
		  vi a(1e6);
		  rep(i,0,1e6+1) a[i]=(i*(i+1))/2;
		  
		  for(auto to:mp) {
			    int ind=ub(all(a),to.se)-a.begin()-1;
			    cnt+=ind;
			  }
		  	  
		  cout<<cnt<<endl;      
	}
 
int32_t main() {
	cool;
	int t=1;	
	   //~ cin>>t;
	while(t--)
	   solve();		   
	   
	   return 0;	   
}


Measured memory_bytes: 11124
#include <iostream>

using namespace std;

int main(){
  int k, s;
  cin >> k >> s;
  int ans = 0;
  
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      if(0 <= s - i - j && s - i - j <= k) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

int main(){
	int h,n;
	scanf("%d%d",&h,&n);
	int a[n],b[n];
	for(int i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);
	int dp[10005];
	for(int i=0;i<10005;i++)dp[i]=2000000010;
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=a[i];j<10005;j++){
			dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
		}
	}
	int ans=2000000010;
	for(int i=h;i<10005;i++)ans=min(ans,dp[i]);
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;

int main() {
	long long int n, ans1, ans2;
	vector<int> list;
	cin >> n;
	
	for(int i=sqrt(n)+1; i>0; i--) {
		if (n % i == 0) {	
			ans1 = i;
			break; 
		} 
	} 
	
	ans2 = n / ans1;
	cout << (ans1-1) + (ans2 - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    char c[2][3];
    for(int i=0;i<2;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    if(c[0][0]==c[1][2]){
        if(c[0][1]==c[1][1]){
            if(c[0][2]==c[1][0]){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 100001

inline int add(int a, int b) {a += b; if (a < 0) a += mod; return a;}
inline int sub(int a, int b) {a -= b; if (a < 0) a += mod; return a;}
inline int mul(int a, int b) {return (a * 1ll * b) % mod;}
inline int pwr(int x, ll y) {
    int ans = 1 % mod;
    while (y) {
        if (y & 1) ans = mul(ans, x);
        x = mul(x, x);
        y >>= 1;
    }
    return ans;
}
inline int inv(int a) {return pwr(a, mod - 2);}

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

    int n, a, b;
    cin >> n >> a >> b;
    if (a < b) swap(a, b);
    cout << b << " " << max((a + b) - n, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import queue
movable=[(0,1),(1,1),(1,0),(0,-1),(-1,-1),(-1,0)]
while 1:
    t,n=map(int,input().split())
    if t==n and n==0:
        break
    field=[[0 for i in range(200)] for i in range(200)]
    for i in range(n):
        x,y=map(int,input().split())
        field[x+100][y+100]=1
    x_st,y_st=map(int,input().split())
    q=queue.Queue()
    q.put((x_st+100,y_st+100,0))
    ans=0
    while not q.empty():
        x,y,c=q.get()
        if c>t:
            continue
        if field[x][y]<0:
            continue
        field[x][y]=-1
        ans+=1
        for x_nxt,y_nxt in movable:
            if field[x+x_nxt][y+y_nxt]!=1 and field[x+x_nxt][y+y_nxt]>=0:
                q.put((x+x_nxt,y+y_nxt,c+1))
    print(ans)



Measured memory_bytes: 7644
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    vector<ll> X(N), Y(N);
    rep(i,N) cin>>X[i]>>Y[i];
    rep(i,N){
        double L=-1010, R=0;
        vector<double> D;
        rep(j,N)if(i!=j){
            ll dx=X[j]-X[i];
            ll dy=Y[j]-Y[i];
            D.push_back(atan2(dx,dy));
        }
        sort(all(D));
        D.push_back(D[0]+2*pi);
        double ret=0;
        rep(j,D.size()-1){
            if(D[j+1]-D[j]>=pi) ret=(D[j+1]-D[j])-pi;
        }
        printf("%.12lf\n",ret/(2*pi));
    }
}

Measured memory_bytes: 384
#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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<ll> v(N);
  rep (i, N) {
    ll tmp;
    cin >> tmp;

    if (tmp == 0) {
      cout << 0 << '\n';
      return 0;
    }

    v.at(i) = tmp;
  }

  ll result = 1;
  rep (i, N) {
    if (v[i] <= 1000000000000000000 / result) {
      result *= v[i];
    } else {
      cout << -1 << '\n';
      return 0;
    }
  }

  cout << result << '\n';

  return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

//x^y
int64_t power(int64_t x, int64_t y){
  if(y < 0)
    return 0;
  else{
    int64_t n = 1ll;
    for(int64_t i = 0; i < y; i++)
      n *= x;
    return n;
  }
}

int main() {
    int n;
    cin >> n;
    vector<int64_t> t(n);
    rep(i,n) cin >> t[i];
    int64_t ans = 1;
    int64_t l = power(10,18)/2;
    rep(i,n){
        int64_t ti = t[i];
        ans = ans/__gcd(ans,ti)*ti;
        //if(ans > l) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }

// 高速入出力

constexpr int N = 500005;
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int c[N], ans[N], last[N], dat[N];

inline void dec(int k) {
    for(++k; k < N; k += k & -k) --dat[k];
}
int res;
inline int sum(int k) {
    res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) q[i].l = read(), q[i].r = read() + 1, q[i].idx = i;
    sort(q, q + Q);
    int now = 1;
    rep(i, Q) {
        for(; now < q[i].r; ++now) {
            if(last[c[now]]) dec(last[c[now]]);
            last[c[now]] = now;
        }
        ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    }
    rep(i, Q) write(ans[i], '\n');
}

Measured memory_bytes: 26700
MOD = 10**9+7
module ModInt
  refine Fixnum do
    def +(b); (super b) % MOD; end
    def *(b); (super b) % MOD; end
  end
end

n = gets.to_i
cnt = Array.new(26,0)
gets.chomp.chars.each do |s|
  i = s.ord - 'a'.ord
  cnt[i] += 1
end

using ModInt
ans = 1
cnt.each do |n|
  ans = ans * (n + 1)
end
puts ans - 1

Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;



int main(){
  int n;
  cin >> n;
  double d;
  cin >> d;
  int ans=0;
  rep(i,n){
    double x,y;
    cin >> x >>y;
    if(sqrt(x*x+y*y)<=d)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef pair< int, int > Pi;
#define MAX_V 202
int n;
class Primal_Dual{
private:
  struct edge{
    int to, cap, cost, rev;
  };
  int V;
  vector< edge > info[MAX_V];
  int h[MAX_V], dist[MAX_V], prevv[MAX_V], preve[MAX_V];
public:
  void add_edge(int from,int to,int cap,int cost){ //from,to,容量,コスト
    info[from].push_back((edge){to,cap,cost,info[to].size()});
    info[to].push_back((edge){from,0,-cost,info[from].size()-1});
  }
  Primal_Dual(){};
  Primal_Dual(int size):V(size){};
  int min_cost_flow(int s,int t,int f){ //sからtへの最小費用流
    int ret = 0;
    fill_n( h, V, 0);
    while(f > 0){
      priority_queue< Pi, vector< Pi >, greater< Pi > > que;
      fill_n( dist, V, INF);
      que.push(Pi(0,s));
      dist[s] = 0;
      while(!que.empty()){
        Pi p = que.top(); que.pop();
        if(dist[p.second] < p.first) continue;
        for(int i = 0; i < info[p.second].size(); i++){
          edge& e = info[p.second][i];
          if(e.cap > 0 && dist[e.to] > dist[p.second] + e.cost + h[p.second] - h[e.to]){
            dist[e.to] = dist[p.second] + e.cost + h[p.second] - h[e.to];
            prevv[e.to] = p.second, preve[e.to] = i;
            que.push(Pi(dist[e.to],e.to));
          }
        }
      }
      if(dist[t] == INF) return -1;
      for(int v = 0; v < V; v++) h[v] += dist[v];
      int d = f;
      for(int v = t; v != s; v = prevv[v]){
        d = min( d, info[prevv[v]][preve[v]].cap);
      }
      f -= d;
      ret += d * h[t];
      for(int v = t; v != s; v = prevv[v]){
        edge& e = info[prevv[v]][preve[v]];
        e.cap -= d;
        info[v][e.rev].cap += d;
      }
    }
    return ret;
  }
  void dump(char F[][100]){
    vector< string > ret;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < info[i].size(); j++){
        if(info[i][j].cap == 0){
          const int pos = info[i][j].to - n;
          if(F[i][pos] == '.'){
            stringstream ss;
            ss << i + 1 << " " <<  pos + 1 << " write";
              ret.push_back(ss.str());
          }
          for(int k = 0; k < n; k++){
            if(k == pos) continue;
            if(F[i][k] == 'o'){
              stringstream ss;
              ss << i + 1 << " " << k + 1 << " erase";
              ret.push_back(ss.str());
            }
          }
          break;
        }
      }
    }
    cout << ret.size() << endl;
    for(int i = 0 ; i < ret.size(); i++){
      cout << ret[i] << endl;
    }
  }
};

int main(){

  int n, p[100];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }

  const int from = n * 2, to = n * 2 + 1;

  Primal_Dual java(2 + 2 * n);

  for(int i = 0; i < n; i++){
    java.add_edge( from, i, 1, 0);
    java.add_edge( n + i, to, 1, 0);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(p[i] != j + 1){
        java.add_edge( i, n + j, 1, p[i] * abs( i - j));
      }
    }
  }
  cout << java.min_cost_flow( from, to, n) << endl;
}

Measured memory_bytes: 1672
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int wb = 0, bw = 0;
    rep(i, s.size())
    {
        if ((i % 2 == 0 && s[i] == '0') || (i % 2 == 1 && s[i] == '1'))
        {
            wb++;
        }
        if ((i % 2 == 1 && s[i] == '0') || (i % 2 == 0 && s[i] == '1'))
        {
            bw++;
        }
    }
    cout << min(wb, bw) << endl;
    return 0;
}


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

int main() {
  long H, W;
  cin >> H >> W;
  if (H % 3 == 0 || W % 3 == 0) return cout << 0 << "\n", 0;
  long ans = min(H, W);
  for (int h = 0; h < H - 1; h++) {
    long a = (h + 1) * W;
    long b = (H - h - 1) * (W / 2);
    long c = (H - h - 1) * (W - W / 2);
    ans = min(ans, max({a, b, c}) - min({a, b, c}));
  }
  swap(H, W);
  for (int h = 0; h < H - 1; h++) {
    long a = (h + 1) * W;
    long b = (H - h - 1) * (W / 2);
    long c = (H - h - 1) * (W - W / 2);
    ans = min(ans, max({a, b, c}) - min({a, b, c}));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3560
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var ans = ((N - M) * 100 + M * 1900) * Pow(2, M); ;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int main(){
    int N, K;
    double score = 0;
    cin >> N >> K;
    Rep(i, 1, Min2(N + 1, K)){
        score += pow(0.50, ceil(log2((double) K / i))) / N;
    }
    if(N >= K){
        score += (double)(N - K + 1) / N;
    }
    printf("%.12f\n", score);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int N; cin >> N;
    ll x; cin >> x;
    vector<ll> a(N); FOR(i, 0, N) cin >> a[i];

    sort(a.begin(), a.end());
    ll sum = accumulate(a.begin(), a.end(), 0);

    ll ret = 0;
    size_t idx = 0;
    ll x_ = x;
    while (x > 0 && idx < N) {
        x -= a[idx];
        if (x >= 0) ++idx;
    }
    if (idx == N) {
        ret = N-1;
    } else {
        ret = idx;
    }

    if (ret == N-1 && sum == x_) ret = N;

    cout << ret << endl;
}

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

Measured memory_bytes: 256
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    n,q=map(int,readline().split())
    G=[[] for _ in range(n)]
    for i in range(n-1):
        a,b=map(lambda x:int(x)-1,readline().split())
        G[a].append(b)
        G[b].append(a)

    p=[0]*n
    for i in range(q):
        tmp,x=map(int,readline().split())
        p[tmp-1]+=x

    cnts=[0]*n
    flags=[False]*n
    flags[0]=True
    d=deque([[0,p[0]]])
    while len(d)>0:
        tmp=d.popleft()
        now=tmp[0]
        p_now=tmp[1]
        cnts[now]=p_now
        for nex in G[now]:
            if flags[nex]==False:
                flags[nex]=True
                d.append([nex,p_now+p[nex]])

    print(*cnts)
if __name__=="__main__":
    main()

Measured memory_bytes: 73712
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
int  main(){
  ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
  double l,m;
  cin>>l;
  m=(l/3)*(l/3)*(l/3);
  cout<<fixed<<setprecision(10)<<m<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
 
int main(){
	
	int n; cin>>n;
	ll ans{1};
	vector<ll> a(n);
	for(int i=0; i<n; i++){
		cin>>a.at(i);
		if(a.at(i)==0) {
			cout<<0<<endl;
			return 0;
		}
	}
	for(int i=0; i<n; i++){
		double k=log10(a.at(i));
		double l=log10(ans);
		if(k+l>18.01){ 
			cout << -1 << endl;
			return 0;
		}
		ans *= a.at(i);
		if(ans>(ll)1e18){
			cout <<-1<<endl;
			return 0;
		}
	}
	cout << ans << endl;
	
	
}

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

int N, K, H[100000];
int dp[100000];

int umin(int *x, int y) {
    if (*x > y) *x = y;
}

int main() {
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%d", H + i);
        dp[i] = 2e9;
    }
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K && i + j < N; j++) {
            umin(&dp[i + j], dp[i] + abs(H[i + j] - H[i]));
        }
    }
    printf("%d\n", dp[N - 1]);
    return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int N;
  std::string X;
  std::cin >> N >> X;
  const int popcount = std::count(X.begin(), X.end(), '1');
  std::map<int, int> x_map;
  std::vector<std::map<int, int>> digit_map(N);
  for (int mod = std::max(1, popcount - 1); mod <= popcount + 1; ++mod) {
    int remainder = 0;
    for (const char digit : X) {
      remainder = (remainder * 2 + digit - '0') % mod;
    }
    x_map[mod] = remainder;
    int digit = 1;
    for (int i = 0; i < N; ++i) {
      digit_map[N - i - 1][mod] = digit;
      digit = digit * 2 % mod;
    }
  }
  for (int i = 0; i < N; ++i) {
    const int mod = popcount + (X[i] == '0' ? 1 : -1);
    int f = 0;
    if (mod > 0) {
      f = 1;
      int n = x_map[mod];
      if (X[i] == '0') {
        n = (n + digit_map[i][mod]) % mod;
      } else {
        n = (n - digit_map[i][mod] + mod) % mod;
      }
      while (n > 0) {
        ++f;
        n = n % __builtin_popcount(n);
      }
    }
    std::cout << f << std::endl;
  }
  return 0;
}


Measured memory_bytes: 40800
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let diff = b - a;
    let height = (1..diff + 1).fold(0, |sum, i| sum + i);
    let ans = height - b;
    println!("{}", ans);
}


Measured memory_bytes: 4352