akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <bitset>
using namespace std;

const int MAXN = 2005;
const int MAXSUM = 2000 * 2000 + 5;

int N, A[MAXN];
bitset<MAXSUM + 5> dp;

int main() {
    int i, Sum = 0, Avg;

    scanf("%d", &N);
    for(i = 1; i <= N; i++) scanf("%d", &A[i]), Sum += A[i];
    Avg = Sum / 2; if(Sum & 1) Avg++;

    dp[0] = 1; for(i = 1; i <= N; i++) dp |= (dp << A[i]);
    for(i = Avg; i < MAXSUM; i++) if(dp[i]) { printf("%d", i); break; }
}

Measured memory_bytes: 1792
def comb_mod(n,r,mod):
    ans = 1
    lis = []
    for i in range(r):
        ans *= n+i
        ans *= pow(i+1,mod-2,mod)
        ans %= mod
        lis.append(ans)
    return lis
def solve():
    ans = 1
    mod = 10**9+7
    K = int(input())
    S = input()
    s = len(S)
    lis = comb_mod(s,K,mod)
    for k in range(K):
        ans *= 26
        ans += lis[k]*pow(25,k+1,mod)
        ans %= mod
    return ans
print(solve())

Measured memory_bytes: 192284
#include <iostream>
#include <vector>

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

int main(){
    ll n;
    cin >> n;
    ll nodd = 0;
    REP(i, n){
        ll ai;
        cin >> ai;
        nodd += ai % 2;
    }
    if(nodd % 2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(N):
    D[i + 1] = A[i]
C = []
for k, v in D.items():
    [C.append(k) for _ in range(v)]
h = 0
while True:
    h += 1
    for i in range(W):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break
    h += 1
    for i in reversed(range(W)):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break

Measured memory_bytes: 9768
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for y,z in zip(X[i],X[j]):
            tmp += pow(y - z, 2)
        tmp = tmp ** 0.5
        if tmp.is_integer():
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

const MOD: usize = 1_000_000_007;

struct ModComb {
    max: usize,
    modulus: usize,
    fact: Vec<usize>,
    finv: Vec<usize>,
    inv: Vec<usize>,
}

impl ModComb {
    fn new(max: usize, modulus: usize) -> Self {
        let mut mc = ModComb {
            max: max,
            modulus: modulus,
            fact: vec![1; max],
            finv: vec![1; max],
            inv: vec![0; max],
        };
        mc.init_table();
        mc
    }

    fn init_table(&mut self) {
        self.inv[1] = 1;
        for i in 2..self.max {
            self.fact[i] = self.fact[i-1] * i % self.modulus;
            self.inv[i] = self.modulus - self.inv[self.modulus%i] * (self.modulus / i) % self.modulus;
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.modulus;
        }
    }

    fn comb(&self, n: usize, k: usize) -> usize {
        if n < k {
            0
         } else {
            self.fact[n] * (self.finv[k] * self.finv[n-k] % self.modulus) % self.modulus
        }
    }
}


fn main() {
    let input = read_vec::<usize>();
    let (n, k) = (input[0], input[1]);

    let mc = ModComb::new(std::cmp::max(n-k+2, k * 2), MOD);

    let mut ans = vec![];
    for i in 1..k+1 {
        let x = mc.comb(n-k+1, i) * mc.comb(k-1, i-1) % MOD;
        ans.push(x);
    }

    let ans = ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join("\n");
    println!("{}", ans);

}

Measured memory_bytes: 4352
N, M = list(map(int, input().split()))

check = [0]*N
count_W = 0
count_A = 0
for i in range(M):
    p, S = input().split()
    p = int(p)
    if check[p-1] != -1:
        if S == "WA":
            check[p-1] = check[p-1] + 1
        else:
            count_A = count_A + 1
            count_W = count_W + check[p-1]
            check[p-1] = -1
print(count_A, count_W)


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int H, W;
    cin >> H >> W;

    vector<string> a;
    inputVector(a, H);

    cout << string(W + 2, '#') << endl;
    rep(i, H) cout << '#' << a[i] << '#' << endl;
    cout << string(W + 2, '#') << endl;

    return 0;
}


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

int main(){

  int n;
  cin >>n;
  if(n<=111) cout << 111 << endl;
  else if(n<=222) cout << 222 << endl;
  else if(n<=333) cout << 333 << endl;
  else if(n<=444) cout << 444 << endl;
  else if(n<=555) cout << 555 << endl;
  else if(n<=666) cout << 666 << endl;
  else if(n<=777) cout << 777 << endl;
  else if(n<=888) cout << 888 << endl;
  else cout << 999 << endl;
  
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
const int MAX_N=1e5;
int main(){
    int N,L,trr[MAX_N],dp[MAX_N]={0},Max=0;
    cin>>N>>L;
    for(int i=0;i<N;i++)
        cin>>trr[i];

    dp[0]=L-trr[0];
    for(int i=1;i<N;i++){
        dp[i]=L-trr[i];
        if(trr[i-1]>trr[i])dp[i]+=dp[i-1];
        Max=max(Max,dp[i]);
    }

    dp[N-1]=L-trr[N-1];
    for(int i=N-2;i>=0;i--){
        dp[i]=L-trr[i];
        if(trr[i+1]>trr[i])dp[i]+=dp[i+1];
        Max=max(Max,dp[i]);
    }

    cout<<Max<<endl;



    return 0;


}

Measured memory_bytes: 1948
import bisect
n = int(input())
l_li = [int(x) for x in input().split()]
l_li.sort()

count = 0
  
for i in range(n):
  for j in range(i+1,n):
    wa = l_li[i] + l_li[j]
    count += bisect.bisect_left(l_li, wa) - j - 1
    
print(count)

Measured memory_bytes: 3188
n, k = gets.split.map(&:to_f)

ans = 0
(1..n).each do |i|
  cnt = 0
  while i < k do
    i *= 2
    cnt += 1
  end
  p = 0
  if cnt == 0
    p = 1
  else
    p = (1.0/2.0)**cnt
  end
  ans += (1.0/n) * p
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
			int n;
			cin>>n;
			if(n>=400&&n<=599) cout<<8;
			else if(n>=600&&n<=799) cout<<7;
			else if(n>=800&&n<=999) cout<<6;
			else if(n>=1000&&n<=1199) cout<<5;
			else if(n>=1200&&n<=1399) cout<<4;
			else if(n>=1400&&n<=1599) cout<<3;
			else if(n>=1600&&n<=1799) cout<<2;
			else cout<<1;        	  
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


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

// merge [left, mid) and [mid, right)
template <typename T>
long long merge(std::vector<T> &A, std::size_t left, std::size_t mid, std::size_t right) {
    std::vector<T> L(mid - left), R(right - mid);
    for(std::size_t i = 0; i < L.size(); ++i) L[i] = A[left + i];
    for(std::size_t j = 0; j < R.size(); ++j) R[j] = A[mid + j];

    long long inversion = 0;
    std::size_t pos = left;
    std::size_t posL = 0, posR = 0;

    while(pos < right) {
        if(posL == L.size() || posR == R.size()) break;
        if(L[posL] > R[posR]) {
            inversion += L.size() - posL;
            A[pos++] = R[posR++];
        } else {
            A[pos++] = L[posL++];
        }
    }
    if(posL == L.size()) {
        while(posR < R.size()) A[pos++] = R[posR++];
    } else {
        while(posL < L.size()) A[pos++] = L[posL++];
    }

    return inversion;
}

template <typename T>
long long inversion_number(std::vector<T> &A, std::size_t left, std::size_t right) {
    if(right - left < 2) return 0;
    int mid = (left + right) / 2;  // divide
    long long inversion          // conquer
        = inversion_number<T>(A, left, mid) + inversion_number<T>(A, mid, right);
    inversion += merge<T>(A, left, mid, right);  // merge
    return inversion;
}


long long N;
vector<int> A;

bool ok(int x) {
    vector<int> C(N + 1, 0);
    for(int i=0; i<N; ++i) C[i + 1] = C[i] + (A[i] > x ? 1 : -1);
    return inversion_number<int>(C, 0, N + 1) > (N * (N + 1) / 2) / 2;
}

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

    int l = 0, r = 1000000000;
    ok(2);
    ok(3);
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(ok(m)) r = m;
        else l = m;
    }
    cout << r << endl;
}

Measured memory_bytes: 1544
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

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

int isPrime (int n)
{
    int i;

    if (n < 2)
        return 0;
    else if (n == 2)
        return 1;

    if (n % 2 == 0)
        return 0;

    for (i = 3; i <= n / i; i += 2)
        if (n % i == 0)
            return 0;
    return 1;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll n = gcd(a, b);
    ll cnt = 1;
    if(n%2 == 0){
        while(n%2 == 0){
            n /= 2;
        }
        cnt++;
    }
    ll sqrtNum = sqrt(n);
    for (int i=3; i<=sqrtNum; i+=2) {
        if (n % i == 0) {
            cnt++;
            while(n % i == 0) n/= i;
        }
    }
    if (n > 1) {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void)
{
    string n; cin >> n;
    int d = 0;
    int l = n.length();
    for (int i = 0; i < l; i++)
    {
        d += (n[i] - '0');
        d %= 9;
    }
    if (d == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3720
//============================================================================
// Name        : hoba.cpp
// Author      : omar  osama
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace std;
const int N = 1e2 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
multiset<ll> mst;
vl v;
int main() {
#ifdef ONLINE_JUDGE
    FAST;
#endif
	ll n, t;
	cin >> n >> t;
	lp(i,1,n)
	{
		ll x;
		cin >> x;
		v.pb(x);
		mst.insert(x);
	}
	ll ans = 0, mx = 0;
	for (auto u : v) {
		if (mst.size() == 1)
			break;
		mst.erase(mst.find(u));
		ll z = *mst.rbegin();
		ll dif = z*t/2 - u*t/2;
		if (dif > mx) {
			mx = dif;
			ans = 1;
		} else if (dif == mx)
			ans++;
	}
	f(ans);
	return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

  	int n;
  	cin >> n;
  	ll a, b;
  	cin >> a >> b;
  	vi li(n);
  	for(int i = 0; i < n; i++){
  		cin >> li[i];
  	}
  	sort(all(li));
  	ll total = 0;
  	for(int i = 0; i < n - 1; i++){
  		total += min(b, abs(li[i+1] - li[i]) * a);
  	}
  	cout << total << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
int a,b=0,r=0;
  string s;
  cin>>a>>s;
  for(int i=0;i<a;i++){
    if(s[i]=='R') r++;
    else b++;
  }
  if(r>b) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())
result = 0.0
for n in range(1, N + 1):
    if K <= n:
        result += 1 / N
        continue
    t = (K + n - 1) // n
    x = math.ceil(math.log2(t))
    result += 1 / N * (0.5 ** x)
print(result)


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

int main(){
  int n; cin >> n;
  vector<vector<pair<int,int>>> con(n);
  for (int i = 0; i < n-1; i++){
    int u, v, w; cin >> u >> v >> w;
    u--; v--;
    con.at(u).push_back(make_pair(v, w));
    con.at(v).push_back(make_pair(u, w));
  }
  vector<int> ans(n, -1);
  ans.at(0) = 0;
  queue<int> q;
  q.push(0);
  while (q.size()){
    int i = q.front(); q.pop();
    for (pair<int,int> p : con.at(i)){
      int c = p.first, d = p.second;
      if (ans.at(c) != -1) continue;
      q.push(c);
      if (d % 2) ans.at(c) = (ans.at(i) ? 0 : 1);
      else ans.at(c) = (ans.at(i) ? 1 : 0);
    }
  }
  for (int i = 0; i < n; i++){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 6784
N = int(input())
h = list(map(int, input().split()))
dp = [0] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(N-2):
    j = i+2
    dp[j] = min(dp[j-2]+abs(h[j-2] - h[j]), dp[j-1]+abs(h[j-1] - h[j]))
print(dp[N-1])

Measured memory_bytes: 13928
import sys
import numpy as np
TYPE_NUM = 26
WEIGHT = 2

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = (np.sum(-c*(d+1-last)) + val)*WEIGHT
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        last[opt_idx] = d+1
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

Measured memory_bytes: 27512
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int ans = 0;
	char a;
	REP(i, 6) {
		cin >> a;
		if (a == '1')ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	static long calc(long a){
		long ret=a/3*4+a/5*4;
		int l=0;
		for(long p=1;a>=p;p*=10){
			l++;
			long R=Math.min(a,p*10);
			long L=p-1;
			ret+=((R-R/3-R/5+R/15)-(L-L/3-L/5+L/15))*l;
		}
		return ret;
	}
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		long a=s.nextLong();
		long left=0L;
		long right=200000000000000000L;
		while(left+1<right){
			long M=(left+right)/2;
			if(calc(M)>=a)right=M;
			else left=M;
		}
		String str="";
		long M=left;
		for(int i=1;i<20;i++){
			if((M+i)%15==0)str+="FizzBuzz";
			else if((M+i)%3==0)str+="Fizz";
			else if((M+i)%5==0)str+="Buzz";
			else str+=""+(M+i);
		}
		int ss=(int)(a-calc(M)-1);
		String ret="";
		for(int i=0;i<20;i++)ret+=str.charAt(i+ss);
		System.out.println(ret);
	}
}

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

using namespace std;

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

map<char, int> m1;
string parse;

string make2(char c) {
	string res;
	int x = m1[c];

	REP(i, 5) {
		res.push_back((x & 1) + '0');
		x >>= 1;
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	parse = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?";
	REP(i, parse.size()) m1[parse[i]] = i;
	
	string sec[32] = {
		"100101","10011010","0101","0001","110","01001","10011011","010000",
		"0111","10011000","0110","00100","10011001","10011110","00101","111",
		"10011111","1000","00110","00111","10011100","10011101","000010","10010010",
		"10010011","10010000","101","010001","000011","10010001","000000","000001"	
	};
	map<string, int> m2;
	REP(i, 32) m2[sec[i]] = i;
	
	string str;
	while (getline(cin, str)) {
		string tmp;
		REP(i, str.size()) tmp += make2(str[i]);
		
		string ans;
		int pos = 0;
		REP(i, tmp.size()) {
			string s;
			FOR(j, i, tmp.size()) {
				s += tmp[j];
				i = j;
				if (m2.find(s) != m2.end()) {
					ans.push_back(parse[m2[s]]);
					break;
				}
			}
			pos += i;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	public class Book
	{
		public int Index{get;set;}
		public int Value{get;set;}
		public int[] Grow{get;set;}
	}
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var n = p[0];
		var m = p[1];
		var x = p[2];
		var books = new Book[n];
		for(int i = 0; i < n; i++)
		{
			var d = new Book(){Index = i, Grow= new int[m]};
			p = Input().ToInt();
			d.Value = p[0];
			for(int j = 0; j < m; j++)
			{
				d.Grow[j] = p[j+1];
			}
			books[i] = d;
		}
		
		int maxBit = 1 << (n);
		
		bool firstUpdate = false;
		long kingaku = DpInf;
		for(int bit = 0; bit < maxBit; bit++)
		{
			long amount = 0;
			var skill = new int[m];
			for(int i = 0; i < n; i++)
			{
				if(((bit >> i) & 1) == 1)
				{
					//Console.WriteLine("{0} notoki {1} on", bit, i);
					
					var book = books[i];
					for(int j = 0; j < m; j++)
					{
						skill[j] += book.Grow[j];
					}
					amount += book.Value;
				}
			}
			
			bool flag = true;
			for(int j = 0; j < m; j++)
			{
				//Console.WriteLine("{0} {1} skill:{2}", bit, j, skill[j]);
				if(skill[j] < x)
				{
					flag = false;
					break;
				}
			}
			//Console.WriteLine("flag {0} / {1}", flag, amount);
			if(flag)
			{
				firstUpdate = true;
				kingaku = Math.Min(kingaku, amount);
			}
		}
		
		if(!firstUpdate)
		{
			Console.WriteLine(-1);
			return;
		}
		Console.WriteLine(kingaku);
		
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27844
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int count=0;
	int maxi=0;
	string s;
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i]=='R')
		{
			count++;
		}
		else
		{
			maxi=max(count,maxi);
			count=0;
		}
	}
	maxi=max(count,maxi);
	cout<<maxi;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string sa,sb ;cin>>sa>>sb; 
  long long a,b;cin>>a>>b;
  string sc;cin>>sc;
  if (sa==sc) cout <<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
  
}

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

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

int main()
{
    ll x,k = 100;
    cin >> x;
    ll ans = 0;
    while( x > k )
    {
        k = k * 1.01;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;

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

    double L;
    cin >> L;

    double x = L / 3.0;

    cout << fixed << setprecision(15) << x * x * x << endl;
}

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

typedef long long ll;

vector<ll> s;

bool check(ll k,int n){
    int left=0,right = n;
    while(right-left>1){
        int mid = (left + right)/2;
        if(s[mid]>k){
            right = mid;
        }else{
            left = mid;
        }
    }
    if(s[left] == k)return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a;
    for(int i=0;i<n;i++){
        cin >> a;
        s.push_back(a);
    }
    sort(s.begin(),s.end());
    unique(s.begin(),s.end());

    int q;
    cin >> q;

    ll t,cou=0;;
    for(int i=0;i<q;i++){
        cin >> t;
        if(check(t,n))cou++;
    }
    cout << cou << endl;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

char S[100];

int main() {
  // ios_base::sync_with_stdio(0);

  scanf("%s", S);
  REP(i,strlen(S)-1) if (string(S+i, 2) == "AC") {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
    int a, b;

    cin >> a;
    cin >> b;

    int x[] = {
        a+b,
        a-b,
        a*b
    };
    int max = x[0];

    for(int i=1; i<3; i++)
        max = (max < x[i])? x[i] : max;

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    al = [(i, int(input())) for i in range(n)]

    al.sort(key = itemgetter(1), reverse = True)

    for i in range(n):
        print(al[0][1] if i != al[0][0] else al[1][1])


Measured memory_bytes: 33480
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

const ll INF = 1LL << 60;

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

int main() {
	vt n, k;
	cin >> n >> k;
	vector<vt> h(n);
	rep(i, n) cin >> h.at(i);
	vector<vt> dp(n, INF);
	dp.at(0) = 0;
	dp.at(1) = abs(h.at(0) - h.at(1));
	if (n == 2) {
		cout << dp.at(1);
		return 0;
	}
	rep(i, n) {
		vt j = 0;
		while(i - j >= 0 && j <= k) {
			chmin(dp.at(i), dp.at(i - j) + abs(h.at(i - j) - h.at(i)));
			j++;
		}
	}
	cout << dp.at(n - 1);
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    int ans = 0;
    rep(i, n) {
        cin >> A[i];
    }
    vector<int> B = A;
    sort(all(B));
    int now = B[0], cnt = 0;
    for (int i = 0; i < n;) {
        while(now == B[i]) {
            cnt++, i++;
            if (i >= n) break;
        }
        chmax(ans, cnt);
        if (i >= n) break;
        now = B[i];
        cnt = 0;
    }
    vector<pii> X;
    rep(i, (int)A.size()) {
        X.push_back({A[i], i});
    }
    auto compare = [](pii a, pii b) {
        if (a.fi > b.fi) return true;
        else if (a.fi == b.fi) return a.se < b.se;
        else return false;
    };
    sort(all(X), compare);
    vector<int> dp(n + 1, INF);
    rep(i, (int)X.size()) {
        int idx = X[i].se;
        *lower_bound(all(dp), idx) = idx;
    }
    chmax(ans, (int)(lower_bound(all(dp), INF) - dp.begin()));
    cout << ans << endl;
}

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


Measured memory_bytes: 5308
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

l = list(range(10))

while True:
    n,s = list(map(int, input().split()))
    if n + s < 1:
        break
    print(len([a for a in itertools.combinations(l, n) if sum(a) == s]))

Measured memory_bytes: 13524
def floor_sum(n,m,a,b):
    res = 0
    while True:
        if a >= m:
            res += (a//m)*n*(n-1)//2
            a %= m
        if b >= m:
            res += n*(b//m)
            b %= m
        if a*n+b < m:
            break
        u = (a*n+b)//m
        v = u*m-b
        res += (n-(v+a-1)//a)*u
        n,m,a,b = u,a,m,(a-v)%a
    return res

import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
    n,m,a,b = map(int,input().split())
    print(floor_sum(n,m,a,b))

Measured memory_bytes: 70744
# coding: utf-8
import sys
sys.setrecursionlimit(1000000)

N = int(input())

MAX_N=10**6
MOD=10**9+7

fac=[None for i in range(MAX_N)]
finv=[None for i in range(MAX_N)]
inv=[None for i in range(MAX_N)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


#a**n mod p を再帰的に求める
def modPow(a,n,p):

    if n==0:
        return 1
        
    if n == 1:
        
        #n=1ならaを返す
        return a % p

    elif n % 2 == 1:
        #nが奇数ならば a * modPow(a,n-1(偶数),p)を返す
        return a * modPow(a,n-1,p) % p

    else:
        #nが偶数なら modPow(a,n//2,p) * modPow(a,n//2,p)とすると速い
        t = modPow(a,n//2,p)
        return t * t % p

COMinit(MAX_N)

if N>2:
    ans = (modPow(10,N,MOD) - 2*modPow(9,N,MOD) + modPow(8,N,MOD))%MOD
elif N == 1:
    ans = 0
elif N == 2:
    ans = 2

print(ans)


Measured memory_bytes: 209056
from math import gcd

#####segfunc#####
def segfunc(x, y):
    return gcd(x,y)
#################

#####ide_ele#####
ide_ele = 0#gcd(8,0)=8　だからね
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

N = int(input())
A = list(map(int,input().split()))

seg = SegTree(A,segfunc,ide_ele)

ans = 1
for i in range(0,N+1,1):
    ans = max(ans,gcd(seg.query(0,i),seg.query(i+1,N)))
print(ans)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    while (1) {
        bool ok = true;
        for (int i=2; i*i<=x; i++) {
            if (x%i==0) {
                ok = false;
                break;
            }
        }
        if (ok) break;
        x++;
    }
    cout << x << endl;
    return 0;
}



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

using namespace std;

typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;
const ll S2=2*SM;
ll dp[S2][S2];
pll a[M];
ll cm[2*S2][S2];
ll n;
int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    LL res=0;
    For(i,0,2*S2)
    {
        cm[i][0]=1;
        if (i<S2)
            cm[i][i]=1;
        For(j,1,min(i,S2))
        {
            cm[i][j]=(cm[i-1][j]+cm[i-1][j-1])%mod;
        }
    }
    For(i,0,n)
    {
        cin >> a[i].X >> a[i].Y;
        res-=cm[2*(a[i].X+a[i].Y)][2*a[i].X];
    }     
    For(i,0,n)
    {
        dp[SM-a[i].X][SM-a[i].Y]++;
    }
    For(i,1,S2) For(j,1,S2)
    {
        dp[i][j]+=dp[i-1][j]+dp[i][j-1];
        dp[i][j]%=mod;
    }

    For(i,0,n)
    {
        res+=dp[SM+a[i].X][SM+a[i].Y];
    }
    res%=mod;
    res+=mod;
    res%=mod;
    cout << (res*((mod+1)/2))%mod;         
}

Measured memory_bytes: 188800
//https://atcoder.jp/contests/abc095/tasks/arc096_a
//C - Half and Half
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,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 (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-3.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;    
    ll ans=INT64_MAX;
    FOR(c,0,max(2*X+1,2*Y+1)){
        ll a=max(X-c/2,0LL);
        ll b=max(Y-c/2,0LL);
        ll val=a*A+b*B+c*C;
        ans = min(val,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
ans = 0
for i in range(n):
    a = input()
    s.append(list(a))
for i in range(n):
    s[i].sort()
s.sort()
anslist = []
p = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        p += 1
    else:
        anslist.append(p)
        p = 0
anslist.append(p)
for i in range(len(anslist)):
    ans += anslist[i]*(anslist[i]+1)//2
print(ans)

Measured memory_bytes: 102360
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    string S; cin >> S;
    VI freq(26, 0);
    REP(i, S.length())
        ++freq[S[i] - 'a'];
    priority_queue<int, VI, greater<int>> que;
    REP(i, 26)
        if(freq[i]) que.push(freq[i]);
    if(que.size() == 1){
        cout << S.length() << endl;
        return 0;
    }
    ll ans = 0;
    while(que.size() > 1){
        ll p = que.top(); que.pop();
        ll q = que.top(); que.pop();
        ans += p + q;
        que.push(p + q);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

const int N = 200012;
const int LOGN = 18;

int n;
ll a[N];

ll sum = 0,cur = 0;
int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d",&n);
	for (int i = 1 ; i <= n; ++i){
		scanf("%lld",&a[i]);
		sum += a[i];
	}
	ll mn = 1e18;
	for(int i = 1 ; i < n ; i++){
		sum -= a[i];
		cur += a[i];
		mn = min(mn,abs(sum-cur));
	}
	printf("%lld\n", mn);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin >> n;
  int x = n%10;
  set<int>s1={2,4,5,7,9};
  set<int> s2={0,1,6,8};
  set<int> s3={3};
  if(s1.find(x)!=s1.end())
    cout<<"hon"<<endl;
  else if(s2.find(x)!=s2.end())
    cout<<"pon"<<endl;
  else
    cout<<"bon"<<endl;
  return 0;
}

Measured memory_bytes: 3632
/* ex6_2
   KKOO  */

#include <stdio.h>
#include <string.h>

#define SIZE 256

int main(void){
    int length;
    char word[SIZE];

    //英単語を入力
    fgets(word, SIZE, stdin);

    //文字列の長さ
    length = strlen(word);

    //”lengthー３”・・・単語の前後の文字とnull文字を引いた長さ
    //”word[lengthー2]”・・・word[lengthー1]はnull文字なので-2にする
    printf("%c%d%c\n", word[0], length-3, word[length-2]);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main(void)
{
    int k,n,i,sum;

    sum = 0;
    
    cin >> n >> k;

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

    sort(a, a+n);

    for(i=0;i<k;i++){
        sum += a[i];
    }
   

    cout << sum << endl;
   
    return 0;
}

Measured memory_bytes: 3592
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     pii             pair<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n, x)     (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     nshow(x,n)      for(int zz=0;zz<n;++zz)cout<<x[zz]<<" ";cout<<"\n";
#define     show2(x)        for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

int div(int n)
{
    int res=0;
    for(int i=1;i*i<=n;++i)
    {
        if(n%i==0)
        {
            ++res;

            if(i!=n/i)
                ++res;
        }
    }

    --res;
    return res;
}

int check(int n,int d)
{
    while(n%d==0)
        n/=d;

    return (n%d==1);
}

void solve()
{
    int n;
    cin>>n;

    int cnt=div(n-1);

    for(int i=2;i*i<=n;++i)
    {
        if(n%i==0)
        {
            cnt+=check(n,i);

            if(i!=n/i)
                cnt+=check(n,n/i);
        }
    }

    ++cnt;
    cout<<cnt<<"\n";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    string st;
    cin>>st;
    n=st.size();
    x=0;
    for(i=0;i<n;i++)
    {
        if(st[i]=='R')
        {
            y=0;
            while(st[i]=='R' && i<n)
            {
                i++;
                y++;
            }
            i--;
            x=max(x,y);
        }
    }
    cout<<x<<endl;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int X=0,w=0;
    char ch=0;
    while(!isdigit(ch)) {
        w|=ch=='-';
        ch=getchar();
    }
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline double dbread() {
    double X=0,Y=1.0;
    int w=0;
    char ch=0;
    while(!isdigit(ch)) {
        w|=ch=='-';
        ch=getchar();
    }
    while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
    ch=getchar();
    while(isdigit(ch)) X+=(Y/=10)*(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int main()
{
   std::ios::sync_with_stdio(false);
   cin.tie(0);
   int s[3];
   s[0]=read();
   s[1]=read();
   s[2]=read();
   sort(s,s+3);
   write(s[0]+s[1]);
   return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,m;
            int[] c = new int[20];
            int[,] dp = new int[50001,20];

            string[] nm = Console.ReadLine().Split(' ');
            n = int.Parse(nm[0]);
            m = int.Parse(nm[1]);

            string[] C = Console.ReadLine().Split(' ');

            for (int a = 0; a < m;a++)
            {
                c[a] = int.Parse(C[a]);
            }

            Array.Sort(c);

            

            for(int a = 0;a<n+1;a++)
            {
                dp[a,20-m] = a;
            }

            for(int a = 0;a<m;a++)
            {
                dp[0,20-m+a] = 0;
            }

            for (int a = 21-m; a < 20;a++ )
            {
                for (int b = 1; b < n+1;b++)
                {
                    if (c[a] > b)
                    {
                        dp[b, a] = dp[b, a-1];
                    }
                    else
                    {
                        dp[b, a] = Math.Min(dp[b, a-1], Math.Min(dp[b-c[a],a],dp[b-1,a])+1);
                    }
                }
            }

            Console.WriteLine(dp[n, 19]);
        }
    }
}

Measured memory_bytes: 13232
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int count = 0;
    for(int i=1; i<=N; i++){
        if(i < 10){
            count++;
        }
        if(i > 99 && i < 1000){
            count++;
        }
        if(i > 9999 && i < 100000){
            count++;
        }
    }
    cout << count << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int n, a;
  cin >> n >> a;

  int rest = n;

  while (500 <= rest) {
    rest = rest - 500;
  }
  if (rest == 0) {
    cout << "Yes" << endl;
  } else if (0 < rest && rest <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, k;

	cin>>n>>k;

	vll h(n);

	rep(i, n) cin>>h[i];

	sort(all(h));

	ll min=1e18;
	k--;
	rep(i, n-k){
		ll d=h[i+k]-h[i];
		if(min>d) min=d;
	}
	cout<<min<<endl;
}


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

int main(){
  int l,r,d;
  cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include<stdio.h>

int main(void){

int a,b,c,B,C;

scanf("%d %d %d",&a,&b,&c);

	if(a>b){
	B=b;
	b=a;
	a=B;
	}
	if(a>c){
	C=c;
	c=a;
	a=C;
	}
    if(b>c){
    C=c;
    c=b;
    b=C;
    }
	printf("%d %d %d\n",a,b,c);
return 0;

}

Measured memory_bytes: 596