akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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


ll nC2(ll n){
    if(n<2) return 0;
    return n*(n-1)/2;
}


void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H; cin >> H;
    int pow2 = 0;
    while(pow(2,pow2) < H) pow2++;
    if(pow(2,pow2)>H) pow2--;
    
    
    ll ans = 0;
    for (int i = 0; i <= pow2; i++) {
        ans += pow(2,i);
    }
    
    
    cout << ans << endl;
    
}



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



Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, m;
        
        n = sc.nextInt();
        m = sc.nextInt();
        
        int A[][] = new int[n][m];
        int b[] = new int[m];
        
        for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
        	int a = 0;
			for (int j = 0; j < m; j++) {
				a += A[i][j]*b[j];
			}
			System.out.println(a);
		}
    }
}



Measured memory_bytes: 41064
#include<bits/stdc++.h>
#define M 1000005
#define P 998244353
#define LL long long
using namespace std;
struct node {
	int x,y;
} s[M];
bool cmpx(node A,node B) {
	return A.x<B.x;
}
bool cmpy(node A,node B) {
	return A.y<B.y;
}
int F2[M];
void Add(LL &x,int y) {
	x+=y;
	if(x<0)x+=P;
	if(x>=P)x-=P;
}
int X[M],Y[M],n;
struct BIT {
	int C[M];
	void clear() {
		for(int i=1; i<=n; i++)C[i]=0;
	}
	void Add(int x) {
		while(x<=n) {
			C[x]++;
			x+=x&-x;
		}
	}
	int Query(int x) {
		int res=0;
		while(x>0) {
			res+=C[x];
			x-=x&-x;
		}
		return res;
	}
} bit;
int main() {
	cin>>n;
	F2[0]=1;
	for(int i=1; i<=n; i++)F2[i]=F2[i-1]*2%P;
	for(int i=0; i<n; i++) {
		scanf("%d %d",&s[i].x,&s[i].y);
		X[i]=s[i].x;
		Y[i]=s[i].y;
	}
	sort(X,X+n);
	sort(Y,Y+n);
	for(int i=0; i<n; i++) {
		s[i].x=lower_bound(X,X+n,s[i].x)-X+1;
		s[i].y=lower_bound(Y,Y+n,s[i].y)-Y+1;
	}
	LL ans=1LL*n*(F2[n]-1)%P;
	bit.clear();
	for(int i=0; i<n; i++) {
		Add(ans,-(F2[i]-1));
		Add(ans,-(F2[n-1-i]-1));
		Add(ans,-(F2[i]-1));
		Add(ans,-(F2[n-1-i]-1));
	}
	sort(s,s+n,cmpy);
	for(int i=0; i<n; i++) {
		Add(ans,F2[bit.Query(s[i].x)]-1);//<x,<y
		Add(ans,F2[i-bit.Query(s[i].x)]-1);//>x,<y
		bit.Add(s[i].x);
	}
	bit.clear();
	for(int i=n-1; i>=0; i--) {
		Add(ans,F2[bit.Query(s[i].x)]-1);//<x,>y
		Add(ans,F2[n-1-i-bit.Query(s[i].x)]-1);//>x,>y;
		bit.Add(s[i].x);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17408
#include <stdio.h>

int cnt = 0;
int leap(int y){
    int result = 0;
    if (y % 4 == 0) {
        result = 1;
        if (y % 100 == 0 && y % 400 != 0) {
            result = 0;
        }
    }
    return result;
}

int main(int argc, const char * argv[])
{

    int a, b;
    int i;
    int l;
    int j = 0;
    
    while (1) {
        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) {
            break;
        }
        if (j != 0) {
            printf("\n");
        }
        for (i = a; i <= b; i++) {
            l = leap(i);
            if (l) {
                printf("%d\n", i);
                cnt++;
            }
        }
        if (cnt == 0) {
            printf("NA\n");
        }
        cnt = 0;
        j++;
    }
    return 0;
}

Measured memory_bytes: 616
#include<stdio.h>

int main(){
	int N;
	int i, j, v, k;
	int A[100];
	
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	for(k = 0; k < N - 1; k++){
		printf("%d ", A[k]);
	}
        printf("%d\n", A[N - 1]);
	for(i = 1; i < N; i++){
		v = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		
		for(k = 0; k < N - 1; k++){
		printf("%d ", A[k]);
		}
		
	        printf("%d\n", A[N - 1]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int n;cin>>n;
  int now = 0;//1=zoka;
  int a[n];
  int kekka = 0;
  rep(i,n)cin >> a[i];
  for(int i = 1; n > i; i++){
    if(a[i-1] < a[i]){
      if(now == 0 || now == 1)now=1;
      else kekka++,now=0;
    }else if(a[i-1] > a[i]){
      if(now == 0 || now == 2)now=2;
      else kekka++,now=0;
    }
  }
  cout << kekka+1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> que;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int h, w, ans;
vector<string> table;
bool inRange(int y, int x)
{
    if(y < 0 or x < 0 or y >= h or x >= w) return false;
    return true;
}
int solve()
{
    int res = 0;
    bool flag;
    while(true)
    {
        flag = false;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if(table[i][j] != '.') continue;
                map<char, vector<P>> mp;
                for(int k = 0; k < 4; k++)
                {
                    int ny = i + dy[k], nx = j + dx[k];
                    while(inRange(ny, nx))
                    {
                        if(table[ny][nx] != '.')
                        {
                            mp[table[ny][nx]].push_back(make_pair(ny, nx));
                            break;
                        }
                        ny += dy[k];
                        nx += dx[k];
                    }
                }
                for(auto x : mp)
                {
                    if(x.second.size() == 2)
                    {
                        flag = true;
                        for(int k = 0; k < x.second.size(); k++)
                        {
                            P p = x.second[k];
                            table[p.first][p.second] = '.';
                        }
                        res += x.second.size();
                    }
                }
            }
        }
        if(flag == false) break;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    table.resize(h);
    for(int i = 0; i < h; i++) cin >> table[i];
    cout << solve() << endl;
    return 0;
}




Measured memory_bytes: 3372
from heapq import heappop, heappush


def solve_b(n, l_list, r_list):

    l_max = max(l_list)
    r_min = min(r_list)

    # l_max and r_min in same contest
    res_1 = max(0, r_min - l_max + 1)
    # one problem contest
    res_1 += max([r_list[i] - l_list[i] + 1 for i in range(n)])

    # l_max in one, r_min in the other
    hr = []
    for i in range(n):
        if r_list[i] > r_min:
            heappush(hr, (r_list[i], i))
    r_need = min([r_list[i] for i in range(n) if l_list[i] == l_max])
    l_temp = max([l_list[i] for i in range(n) if r_list[i] == r_min])

    res_2 = 0
    while len(hr) > 0:
        r, i = heappop(hr)
        res_2 = max(res_2, max(0, min(r, r_need) - l_max + 1) + max(0, r_min - l_temp + 1))
        l_temp = max(l_temp, l_list[i])
    res_2 = max(res_2, max(0, r_need - l_max + 1) + max(0, r_min - l_temp + 1))

    return max(res_1, res_2)


def main():
    n = int(input())
    l_list = [0] * n
    r_list = [0] * n
    for i in range(n):
        l, r = map(int, input().split())
        l_list[i] = l
        r_list[i] = r
    res = solve_b(n, l_list, r_list)
    print(res)


def test():
    assert solve_b(4, [4, 1, 5, 2], [7, 4, 8, 5]) == 6
    assert solve_b(4, [1, 2, 3, 4], [20, 19, 18, 17]) == 34


if __name__ == "__main__":
    test()
    main()


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

using namespace std;

char a[110][110];
int b[110],c[110],flag;

int main()
{
    int n,m,i,j;
    cin >> n >> m;
    for(i = 0; i < n; i ++)
    {
        for(j = 0; j < m; j ++)
        {
            cin >> a[i][j];
            if(a[i][j] != '.') flag = 1;
        }
        if(flag == 0) b[i] = 1;
        else flag = 0;
    }
    for(j = 0; j < m; j ++)
    {
        for(i = 0; i < n; i ++)
        {
            if(a[i][j] != '.') flag = 1;
        }
        if(flag == 0) c[j] = 1;
        else flag = 0;
    }
    for(i = 0; i < n; i ++)
    {
        for(j = 0; j < m; j ++)
        {
            if(b[i] || c[j]) continue;
            else printf("%c",a[i][j]);
        }
        if(!b[i]) printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	static int[] parent;
	static int[] height;
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] tmp = s.nextLine().split(" ");
		int edgeCnt = Integer.parseInt(tmp[0]);
		parent = new int[edgeCnt];
		height = new int[edgeCnt];
		for(int k=0 ; k<edgeCnt ; k++) {
			parent[k] = -1;
		}
		int direCnt = Integer.parseInt(tmp[1]);
		for(int i=0 ; i<direCnt ; i++) {
			String[] tmp1 = s.nextLine().split(" ");
			if("0".equals(tmp1[0])) {
				unite(Integer.parseInt(tmp1[1]), Integer.parseInt(tmp1[2]));
			}else {
				System.out.println(same(Integer.parseInt(tmp1[1]), Integer.parseInt(tmp1[2])));
			}
		}

	}

	public static void unite(int formmer, int latter) {
		while(parent[formmer]!=-1) {
			formmer = parent[formmer];
		}
		while(parent[latter]!=-1) {
			latter = parent[latter];
		}
		if(formmer==latter)
			return;
		if(height[formmer]==height[latter] && formmer>latter) {
			parent[formmer] = latter;
			height[latter]++;
		}else if(height[formmer]==height[latter] && formmer<latter) {
			parent[latter] = formmer;
			height[formmer]++;
		}else if(height[formmer]>height[latter]) {
			parent[latter] = formmer;
		}else if(height[formmer]<height[latter]) {
			parent[formmer] = latter;
		}
	}

	public static int same(int formmer, int latter) {
		while(parent[formmer]!=-1) {
			formmer = parent[formmer];
		}
		while(parent[latter]!=-1) {
			latter = parent[latter];
		}
		if(formmer==latter)
			return 1;
		else
			return 0;
	}

}

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

int times(int x) {
  int ret = 0;
  while(x % 2 == 0){
    x /= 2;
    ret++;
  }
  return ret;
}

using ll = long long;

// 再帰関数による最大公約数
ll gcd(ll x, ll y) {
  if(y == 0) return x;
  return gcd(y, x % y);
}

// gcdを利用した最小公倍数
ll lcm(ll x, ll y) {
  return x / gcd(x, y) * y;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  
  vector<ll> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(i) = times(a.at(i));
    a.at(i) /= 2;
  }
  
  sort(b.begin(), b.end());
  
  if(b.at(0) != b.back()){
    cout << 0 << '\n';
    return 0;
  }
  
  ll keep = 1;
  for(int i = 0; i < n; i++){
    keep = lcm(keep, a.at(i));
  }
  
  ll ans = m / keep;
  ans = (ans + 1) / 2;
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#define NIL (-1)
#define m 1046527
char T[m][14];
int h1(int key) {return key%m;}
int h2(int key) {return 1+key%(m-1);}


int getChar(char ch){
    if (ch=='A') return 1;
    else if (ch=='C') return 2;
    else if (ch=='G') return 3;
    else if (ch=='T') return 4;
    else return 0;
}

long long getKey(char moji[]){
    long long sum=0,p=1,i;
    for(i=0;i<strlen(moji);i++){
        sum+=p*(getChar(moji[i]));
        p*=5;
    }
    return sum;
}


int search(char moji[]){
    long long key,i,h;
    key=getKey(moji);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%m;
        if(strcmp(T[h],moji)==0) return 1;
        else if(strlen(T[h])==0) return 0;
    }
    return 0;
}

int insert(char moji[]){
    long long key,i,h;
    key=getKey(moji);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%m;
        if(strcmp(T[h],moji)==0) return 1;
        else if(strlen(T[h])==0){
            strcpy(T[h],moji);
            return 0;
        }
    }
    return 0;
}


int main(void){
    int i,n;
    char order[9],moji[14];
     for ( i = 0; i < m; i++ ) T[i][0] = '\0';
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s%s",order,moji);
        if(order[0]=='i') insert(moji);
        else if(search(moji)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 16048
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define  pi               acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    ans+=(n/500)*1000;
    n-=((n/500)*500);
    ans+=(n/5)*5;
    cout<<ans<<endl;
    End
}
/* pray for me
Do before die
*/






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)
using namespace std;

int main()
{
	LL n; scanf("%lld", &n);
	LL ans = 0;
	for (LL x = 1; x <= sqrt(n + 0.5); x++)
	{
		LL m = n / x - 1;
		if (m == 0) continue;
		if ((n / m) == (n % m)) ans += m;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
module Main (main) where

import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.List
import Data.Maybe

main :: IO ()
main =
  readInts >>= print . showAnswer . solve

type Input  = [Int]
type Output = Int

solve :: Input -> Output
solve = minimum . map (sum . take 2) . permutations

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | ByteString ByteString
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)       = bool "No" "Yes"  b
  show (YESNO b)       = bool "NO" "YES"  b
  show (AB b)          = bool "B"  "A"    b
  show (Number i)      = show i
  show (String s)      = s
  show (ByteString bs) = C8.unpack bs
  show (Compare o)     = ordering "<" "=" ">" o
  show (Compare2 o)    = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

indexMapBS :: Int -> (Char -> Char) -> ByteString -> ByteString
indexMapBS k f s = C8.concat [s1, C8.singleton (f c), s3]
  where
    (s1, s2) = C8.splitAt (k-1) s
    c = C8.head s2
    s3 = C8.tail s2

Measured memory_bytes: 380
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool flag=true;


int main() {
ll A;
  cin >> A;
ll V1[A/2];
ll V2[A/2];
ll N1[100001];
ll N2[100001];
ll N1max=-1;
ll N2max=-1;
ll N1num;
ll N2num;
ll ans;
FOR(i,0,(A-1)/2){
  cin >> V1[i];
  cin >> V2[i];
}
FOR(i,0,100000){
  N1[i]=0;
  N2[i]=0;
}
FOR(i,0,A/2-1){
  N1[V1[i]]++;
  N2[V2[i]]++;
}



FOR(i,0,A/2-1){
  if(N1max<N1[V1[i]]){N1max=N1[V1[i]];N1num=V1[i];}
  if(N2max<N2[V2[i]]){N2max=N2[V2[i]];N2num=V2[i];}
}

sort(N1, N1+100001);
sort(N2, N2+100001);
if(N1num!=N2num){
ans=A-N1[100000]-N2[100000];
}else{
ans=A-N1[99999]-N2[100000];
if(ans>(A-N1[100000]-N2[99999])){
    ans=A-N1[100000]-N2[99999];
}

}
//cout <<A<< endl;
//cout <<N1max<< endl;
//cout <<N2max<< endl;
//cout <<N1num<< endl;
//cout <<N2num<< endl;

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


Measured memory_bytes: 2560
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;
long long int gcd(long long int a, long long int b) {
	while (a % b != 0 && b % a != 0) {
		if (a > b)
			a %= b;
		else
			b %= a;
	}
	return min(a, b);
}

int main(int argc, char *argv[]) {
	long long int a, b;
	cin >> a >> b;
	long long int c = gcd(a, b);

	long long int index = 2; 
	int res = 1;
	while (c > 1 && index * index <= c) {
		if (c % index == 0) {
			res++;
			while (c % index == 0)
				c /= index;
		}
		index++;
	}
	if (c > 1) res++;
	cout << res << endl;
}














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

using namespace std;

const int mod = 1e9 + 7;

int main(){
	int n; cin >> n;
	bool v[n][n];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> v[i][j];
		}
	}
	vector<int> dp(1<<n); dp[0] = 1;
	// mask means for the women match...
	for(int mask = 0; mask < (1<<n) - 1; ++mask){
		int a = __builtin_popcount(mask); // this will calculate no. of men match with women and we assume that first 'a' men match
		if(!dp[mask]) continue; 
		// now we check which women don't match till now....
		for(int b = 0; b < n; b++){
			if(v[a][b] && !(mask & (1<<b))){
				int x = mask^(1<<b);
				dp[x] += dp[mask]; dp[x] %= mod;
			}
		}
	}
	cout << dp[(1<<n) - 1];
}

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

int main(){
	int N,M;
	cin >> N >> M;
	int ans = 1;
	for(int A=1;A*A<=M;A++){
		if(M%A!=0) continue;
		int B = M/A;

		if((long)A*N<=M) ans = max(ans,A);
		if((long)B*N<=M) ans = max(ans,B);
	}
	cout << ans <<endl;
	return 0;
}


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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> b(n);
  map<ll,ll> book;
  for(ll i=0;i<n;i++) {
    cin >> a[i] >> b[i];
    book[a[i]]+=b[i];
  }
  for(auto p:book) {
    k-=p.second;
    if(k<=0) {
      cout << p.first << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;



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

	int n, i, j, k, x;
	cin >> n;
	vector<int> ct(n + 1, 0);
	for (i = 2; i <= n; i++) {
		cin >> x;
		ct[x]++;
	}

	for (i = 1; i <= n; i++) cout << ct[i] << "\n";

	return 0;
}


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

N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


A.sort()
B.sort()
if N%2 == 1:
    m = A[N//2]; M = B[N//2]
    print(M-m+1)
else:
    m1 = A[N//2-1]; m2 = A[N//2]
    M1 = B[N//2-1]; M2 = B[N//2]
    ans = M1 + M2 - (m1+m2) + 1
    print(ans)

Measured memory_bytes: 89876
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 998244353
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e6 + 5;
const int M=2e5 + 5;
 
ll tot[N],dp[N];
ll cnt[N];
ll mod_exp(ll cur,ll power)
{
    ll res=1;
    while(power>0){
        if(power%2==0){
            cur=(cur*cur)%mod;
        }
        else{
            res=(res*cur)%mod;
            cur=(cur*cur)%mod;  
        }
        power/=2;
    }
    return res;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    int i,j;
    
     
    for(i=0;i<N;i++){
        tot[i]=0;
        dp[i]=0;
    }
    ll s[M];
    int n;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s[i];
        cnt[s[i]]++;
    }
    for(i=1;i<N;i++){
        for(j=i;j<N;j+=i){
            
            ll c = cnt[j];
            ll f = j;
            ll bar = (c*f)%mod;
            ll foo = (tot[i]*bar)%mod;
            ll nc = (c*(c-1))/2;
            nc%=mod;
            ll sq = (f*f)%mod;
            foo = (foo + nc*sq)%mod;
            dp[i]=(dp[i]+foo)%mod;
            tot[i]=(tot[i]+bar)%mod;
        }
    }
    for(i=N-1;i>=1;i--){
        for(j=2*i;j<N;j+=i){
            dp[i]=(dp[i]-dp[j]+mod)%mod;
        }
    }
    ll ans = 0;
    for(i=1;i<N;i++){
        ll foo = mod_exp(i,mod-2);
        ans = (ans + foo*dp[i])%mod;
    }
    cout << ans << endl;

 
    return 0;
}

Measured memory_bytes: 25216
import sys
sys.setrecursionlimit(10**6)

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1)
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")



Measured memory_bytes: 96912
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include <math.h>
using namespace std;

int main()
{
    int N, ans = 0;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++)
    {
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    for(int i = 0; i < N - 2; i++)
    {
        for(int j = i + 1; j < N - 1; j++)
        {
            for(int k = j + 1; k < N; k++)
            {
                if(L.at(k)<L.at(i)+L.at(j)) ans++;
                else break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "map"
 
using namespace std;

long long int N, K, L, F, S;
 
class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node) return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v) return;
		if (rank[u] < rank[v]) parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v]) rank[u]++;
		}
	}
	bool Check(int u, int v) {
		return Find(u) == Find(v);
	}
};
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> K >> L;
	UnionFind road(N);
	UnionFind railway(N);
	for (int i = 0; i < K; i++) {
		cin >> F >> S;
		F--, S--;
		road.Unite(F, S);
	}
	for (int i = 0; i < L; i++) {
		cin >> F >> S;
		F--, S--;
		railway.Unite(F, S);
	}

	vector<pair<int, int>> parents(N);
	map<pair<int, int>, int> pair_map;
	for (int i = 0; i < N; i++) {
		parents[i].first = road.Find(i);
		parents[i].second = railway.Find(i);
		if (pair_map.count(parents[i]) == 0)
			pair_map.insert(make_pair(parents[i], 0));
		pair_map[parents[i]]++;
	}
	for (int i = 0; i < N; i++) {
		cout << pair_map[parents[i]] << " ";
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 16640
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define FORi(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FOR(i,n) FORi(i,1,n)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
using pdd=pair<double, double>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
    os<<'[';
    for(auto& p: c) os << p << " ";
    return os<<']';
}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
    print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}


template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
    os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
    print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
    print_tuple<0,Args...>(os<<'(',t);
    return os<<')';
}


constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
constexpr int maxw=31;
constexpr int maxn=1001;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string a;
	while(cin>>a) {
		if(a.size() < 4 || a.substr(0, 4) != "YAKI")
			cout <<"No"<<endl;
		else cout <<"Yes" << endl;
	}
	return 0;
}


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

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

typedef long long ll;
ll N, times, Ans;

int main() {
  scanf("%lld", &N);
  times = 1, Ans = 0;
  while(N) {
    Ans += times;
    times <<= 1;
    N >>= 1;
  }
  printf("%lld\n", Ans);
  return 0;
}


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

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
	int X=int.Parse(Console.ReadLine());
      if(X<=599){
        Console.WriteLine(8);
      }else if(X<=799){
        Console.WriteLine(7);
      }else if(X<=999){
        Console.WriteLine(6);
      }else if(X<=1199){
        Console.WriteLine(5);
      }else if(X<=1399){
        Console.WriteLine(4);
      }else if(X<=1599){
        Console.WriteLine(3);
      }else if(X<=1799){
        Console.WriteLine(2);
      }else if(X<=1999){
        Console.WriteLine(1);
      }
    }
    
  }

}

Measured memory_bytes: 27524
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    TreeMap<Integer, Integer> count = new TreeMap<>();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      count.put(a, count.getOrDefault(a, 0) + 1);
    }

    Integer[] keys = count.keySet().toArray(new Integer[0]);
    int num = count.get(keys[0]);
    for (int i = 1; i < keys.length; i++) {
      int c = count.get(keys[i]);
      if (keys[i - 1] + 1 == keys[i])
        c += count.get(keys[i - 1]);
      if (i < keys.length - 1 && keys[i + 1] == keys[i] + 1)
        c += count.get(keys[i + 1]);
      num = Math.max(num, c);
    }
    System.out.println(num);
  }
}


Measured memory_bytes: 60100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
#include <list>

using namespace std;

#define NIL -1
#define MAX 26

struct Node {
    int parent;
    int left;
    int right;
};

Node T[MAX];
int D[MAX];
int H[MAX];

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
	h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
	h2 = setHeight(T[u].right) + 1;
    }
    return H[u]=max(h1, h2);
}

void setDepth(int u,int depth) {
    D[u] = depth;
    if (T[u].left != NIL) {
	setDepth(T[u].left, depth + 1);
    }
    if (T[u].right != NIL) {
	setDepth(T[u].right, depth + 1);
    }
}

int getSibling(int u) {
    if (T[u].parent == NIL) {
	return NIL;
    }
    if (T[T[u].parent].left == u&&T[T[u].parent].right != NIL) {
	return T[T[u].parent].right;
    }
    if (T[T[u].parent].right == u&&T[T[u].parent].left != NIL) {
	return T[T[u].parent].left;
    }
    return NIL;
}

int getDegree(int u) {
    int degree = 0;
    if (T[u].left != NIL) {
	degree++;
    }
    if (T[u].right != NIL) {
	degree++;
    }
    return degree;
}

void print(int i) {
    printf("node %d: ", i);
    printf("parent = %d, ", T[i].parent);
    printf("sibling = %d, ", getSibling(i));
    printf("degree = %d, ", getDegree(i));
    printf("depth = %d, ", D[i]);
    printf("height = %d, ", H[i]);
    if (T[i].parent == NIL) {
	printf("root");
    }
    else if (getDegree(i) == 0) {
	printf("leaf");
    }
    else {
	printf("internal node");
    }
    printf("\n");
}

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


    int n;
    int id, left, right,root=0;
    scanf("%d", &n);


    //??\???
    for (int i = 0; i < n; i++) {
	T[i].parent = -1;
    }
    for (int i = 0; i < n; i++) {
	scanf("%d %d %d", &id, &left, &right);
	T[id].left = left;
	T[id].right = right;
	if (left != -1) {
	    T[left].parent = id;
	}
	if (right != -1) {
	    T[right].parent = id;
	}
    }
    for (int i = 0; i < n; i++) {
	if (T[i].parent == NIL) {
	    root = i;
	}
    }

    //?????\
    setHeight(root);
    setDepth(root, 0);
    
    //print
    for (int i = 0; i < n; i++) {
	print(i);
    }

}

Measured memory_bytes: 3248
// C - Ubiquity
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define MOD 1000000007

// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
ll modpow(ll a,ll n){return n?modpow(a*a%MOD,n/2)*(n%2?a:1)%MOD:1;}

int main(){
	int N; cin>>N;
	ll ans = modpow(10, N);
	ans -= modpow(9, N) * 2 % MOD;
	ans %= MOD;
	ans += modpow(8, N);
	ans %= MOD;
	cout<< (ans + MOD) % MOD <<endl;
}


Measured memory_bytes: 3600
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    n, m = map(int, input().split())
    ac_status = defaultdict(int)
    wa_count = defaultdict(int)
    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if s == "AC":
            ac_status[p] = 1
        else:
            if ac_status[p] != 1:
                wa_count[p] += 1
    ac = len([v for v in ac_status.values() if v == 1])
    wa = sum([v for k,v in wa_count.items() if ac_status[k] == 1])
    #print(ac_status)
    #print(wa_count)
    print(ac, wa)


input = lambda: stdin.readline().rstrip()
main()

Measured memory_bytes: 15444
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll ;
long double dp[3000][3000] ;

void probability(long double *arr , int n)
{
    dp[0][0] = 1.0 ;

    for(int i =1 ; i<=n ; i++)
    {
        dp[i][0] = dp[i-1][0]*(1 - arr[i-1] );
    }

    for(int i= 1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=n ; j++)
        {
            dp[i][j] = arr[i-1]*dp[i-1][j-1] + (1 - arr[i-1])*dp[i-1][j] ;
        }
    }
    long double ans = 0.0;
    for(int i=n/2+1 ; i<=n ; i++)
    {
        ans +=dp[n][i] ;
    }
    cout<<setprecision(10)<<ans<<endl;
}

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

    int n;
    cin>>n;
    long double *arr = new long double[n] ;
    for(int i= 0; i<n ; i++)
    {
        cin>>arr[i];
    }
    for(int i= 0; i<=n ; i++)
    {
        for(int j=0 ; j<=n ; j++)
        {
            dp[i][j] =0;
        }
    }
    probability(arr , n ) ;
    return 0;
}


Measured memory_bytes: 140928
#!/usr/bin/env python3
#dp3 #Vacation
n = int(input())
dpa = [0]*n
dpb = [0]*n
dpc = [0]*n

a,b,c = list(map(int,input().split()))
dpa[0] = a
dpb[0] = b
dpc[0] = c
for i in range(1,n):
    a,b,c = list(map(int,input().split()))
    dpa[i] = max(dpb[i-1] + a,dpc[i-1] + a)
    dpb[i] = max(dpa[i-1] + b,dpc[i-1] + b)
    dpc[i] = max(dpa[i-1] + c,dpb[i-1] + c)
print(max(dpa[-1],dpb[-1],dpc[-1]))


Measured memory_bytes: 51416
//ABC093A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	sort(s.begin(),s.end());
	if(s == "abc"){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int n = N-1;
        int[][] ary = new int[n][3];
        int[] ans = new int[N];
        ans[n] = 0;
        for(int i = 0; i < n; i++){
        	ary[i][0] = sc.nextInt();
        	ary[i][1] = sc.nextInt();
        	ary[i][2] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
        	ans[i] = ary[i][1] + ary[i][0];
        	for(int j = i+1; j < n; j++){
        		ans[i] = Math.max(ans[i], ary[j][1]);
        		ans[i] = ((ans[i] - 1) / ary[j][2] + 1) * ary[j][2];
            	ans[i] += ary[j][0];
        	}
        }
        for(int num : ans){
        	System.out.println(num);
        }
    }
}

Measured memory_bytes: 26180
X,N=map(int,input().split())
if(N==0):
  print(X)
  exit()
p=list(map(int,input().split()))
#0~100
flag=False
for i in range(200):
  if(X-i not in p):
    print(X-i)
    exit()
  elif(X+i not in p):
    print(X+i)
    exit()

Measured memory_bytes: 9184
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int answer =1;
    for(int i=0;i<N;i++){
      if(answer>=K){
        answer = answer +K;
      }else{
        answer = answer +answer;
      }
    }
    System.out.println(answer);
  }
  

  
}

Measured memory_bytes: 21844
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll, ll>
#define ALL(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define forab(i,a,b) for(ll i=a;i<b;i++)
#define clr(x) memset(x, 0, sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define endl "\n"
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define eps 1e-10
#define nedl endl
const ll sz = 1e6;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;

ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}

int main() {
    IOS;
    
    ll x[sz];
    forn(i,sz){
		if((i+1)%3 == 0 && (i+1)%5==0)x[i]=0;
		else if((i+1)%3 == 0)x[i]=0;
		else if((i+1)%5 == 0)x[i]=0;
		else x[i]=(i+1);
		
	}
	
    ll T = 1; //cin >> T;
    while (T--) {
		ll n;cin>>n;
		ll sum=0;
		forn(j,n)sum+=x[j];
		cout<<sum<<endl;
		
		
		
    }
    return 0;
}


Measured memory_bytes: 11460
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A;
    int tmp;
    REP(i, N) {
        cin >> tmp;
        if(tmp < K) {
            A.push_back(tmp);
        }
    }
    sort(A.begin(), A.end(), greater<int>());
    /*for(auto x: A) {
        cout << x << endl;
    }*/
    long long sum = 0;
    int able[(int)A.size()];
    vector<bool> res((int)A.size(), false);
    /*REP(i, A.size()) {
        memset(able, 0, sizeof able);
        able[i] = 1;
        sum = A[i];
        RANGE(j, i + 1, ++j) {
            ++able[j];
            if(able[j] == 1) {
                sum += A[j];
            }else {
                sum[i] = 0;
                --i;
            }
            if(sum >= K) {
                REP(k, able.size()) {
                    res[k] = (able[k] == 1 ? true : (res[k] | false));
                }
                sum -= A[i];
                able[i] = 0;
                if()
            }
        }
    }*/

    memset(able, 0, sizeof able);
    REP(i, A.size()) {
        sum += A[i];
        able[i] = 1;
        if(sum >= K) {
            REP(k, A.size()) {
                res[k] = (able[k] == 1 ? true : (res[k] | false));
            }
            sum -= A[i];
            able[i] = 0;
            continue;
        }
    }

    int ans = 0;
    /*cout << able.size() << endl;*/
    REP(i, A.size()) {
        if(!res[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A < 10 && B < 10 ? A * B : -1) << endl;
    return 0;
}


Measured memory_bytes: 256
n,m,k = map(int,input().split())
mod = 998244353
if m == 1:
  if k == n-1:
    print(1)
  else:
    print(0)
  exit()
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
#print(inv(2))
now = int(m)
for _ in range(n-1):
  now *= m-1
  now %= mod
ans = int(now)
for i in range(k):
  now *= inv(m-1)
  now *= n-1-i
  now *= inv(i+1)
  now %= mod
  #print(now)
  ans += now
  ans %= mod
print(ans)

Measured memory_bytes: 67952
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static int gcd(int a, int b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int array[] = new int[n + 1];
        forl_1(n, array, sc);
        int count = 0;
        int j = 1;
        boolean b = false;
        for (int i = 1; i <= n; i++) {
            count++;
            if (array[j] == 2) {
                b = true;
                break;
            }
            j = array[j];
        }
        System.out.println((b == true) ? count : -1);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }
}


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

int main() {

	int a, b, k; cin >> a >> b >> k;
	vector<int> c;
	for (int i = 1; i <= max(a,b); i++) {
		if (a % i == 0 && b % i == 0) {
			c.push_back(i);
		}
	}
	sort(c.rbegin(), c.rend());
	cout << c[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 3632
#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()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n,l; cin >> n >> l; ll nearzero = 0;
  
  ll sum = l*n +n*(n+1)/2 - n;
  
  if(l > 0) cout << sum - l << endl;
  else if(l+n-1 < 0) cout << sum - (l+n-1) << endl;
  else cout << sum << endl;
}

Measured memory_bytes: 256