akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;

int N, Q;
string s;
vector<char> t, d;

// 0に到達するかどうか
bool check0(int pos) {
  for (int i = 0; i < Q; i++) {
    char c = s[pos];
    if (c == t[i]) {
      d[i] == 'L' ? pos-- : pos++;
    }

    if (pos == 0) {
      return true;
    } else if (pos == N + 1) {
      return false;
    }
  }
  return false;
}

// N+1に到達するかどうか
bool checkN1(int pos) {
  for (int i = 0; i < Q; i++) {
    char c = s[pos];
    if (c == t[i]) {
      d[i] == 'L' ? pos-- : pos++;
    }

    if (pos == 0) {
      return false;
    } else if (pos == N + 1) {
      return true;
    }
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Q;
  cin >> s;
  s = "x" + s + "x"; // 0, N+1に番兵をつける
  t.resize(Q);
  d.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> t[i] >> d[i];
  }

  // 0に到着するゴーレムの内、一番右のindexを求める
  int ansL = 0;
  int l = 0, r = N + 1;
  while (true) {
    if (r - l <= 1) {
      ansL = l;
      break;
    }

    int mid = (l + r) / 2;
    if (check0(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }

  // N+1に到着するゴーレムの内、一番左のindexを求める
  int ansR = N + 1;
  l = 0, r = N + 1;
  while (true) {
    if (r - l <= 1) {
      ansR = r;
      break;
    }

    int mid = (l + r) / 2;
    if (checkN1(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << ansR - ansL - 1 << endl;
  return 0;
}

Measured memory_bytes: 952
import sys
import math

def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    Adiff = sorted([a - i for i, a in enumerate(A)])
    if N % 2 == 0:
        print(min(
            sum([abs(ad - Adiff[N//2]) for ad in Adiff]),
            sum([abs(ad - Adiff[N//2+1]) for ad in Adiff])
        ))
    else:
        print(sum([abs(ad - Adiff[N//2]) for ad in Adiff]))

if '__main__' == __name__:
    resolve()

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

int main(){

    std::vector<int> num(3);
    for(int i = 0; i < 3; ++i){
        std::cin >> num[i];
    }

    std::sort(num.begin(), num.end());

    for(int i = 0; i < 3; ++i){
        std::cout << num[i];
        if(i == 2){
            std::cout << std::endl;
        }
        else{
            std::cout << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 3156
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Array.ST
import Control.Monad.ST
import Data.STRef

asSTUArray :: ST s (STUArray s i a) -> ST s (STUArray s i a)
asSTUArray = id

main = do
  [h,w] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  -- 1 <= h <= 1000, 1 <= w <= 1000
  initialState <- V.replicateM h BS.getLine
  -- for all (i, j), ((a ! i) `BS.index` j) `elem` "#."
  let answer :: Int
      answer = runST $ do
        arr <- asSTUArray $ newArray ((0,0),(h-1,w-1)) False
        let initCells :: [(Int,Int)]
            initCells = [(i,j) | i <- [0..h-1], j <- [0..w-1], (initialState V.! i) `BS.index` j == '#']
        forM_ initCells $ \p ->
          writeArray arr p True
        let -- loop :: Int -> [(Int,Int)] -> m Int
            loop !k xs = do
              ref <- newSTRef []
              let doCell p@(!i,!j) | 0 <= i && i < h && 0 <= j && j < w = do
                                       b <- readArray arr p
                                       when (not b) $ do
                                         writeArray arr p True
                                         modifySTRef' ref (p :)
                                   | otherwise = return ()
              forM_ xs $ \(i,j) -> do
                doCell (i-1,j)
                doCell (i+1,j)
                doCell (i,j-1)
                doCell (i,j+1)
              ys <- readSTRef ref
              case ys of
                [] -> return k
                _ -> loop (k+1) ys
        loop 0 initCells
  print answer


Measured memory_bytes: 86396
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

def calc(a, b, d, n, mod)
  return 0 if n == 0
  acs, bcs, ms = [0, 0, 0]
  aa, bb, m = [0, 0, 0]
  while n > 0 do
    aa, bb, m = calc2(aa, bb, m, aa, bb, m, d, mod)
    aa, bb, m = [1, 0, 1] if m == 0
    acs, bcs, ms = calc2(aa, bb, m, acs, bcs, ms, d, mod) if n.odd?
    n >>= 1
  end
  (acs * a + bcs * b) % mod
end

def calc2(ac1, bc1, m1, ac2, bc2, m2, d, mod)
  [((pow(10, d * m2, mod) * ac1) % mod + ac2) % mod, ((pow(10, d * m2, mod) * bc1) % mod + ((m1 * ac2) % mod) + bc2) % mod, m1 + m2]
end

L, A, B, M = gets.chomp.split(" ").map(&:to_i)

E = []
a = Math.log10(A+1).ceil
s, i = [0, -1]
while(s < L) do
  s = ((10 ** a) - A - 1) / B
  E << (s >= L ? [a, L - 1, (L - 1 - i) * a] : [a, s, (s - i) * a])
  a += 1
  i = s
end

l = -1
ans = 0
E.each{|e|
  a, d, n, l = [A + (l + 1) * B, e[0], e[1] - l, e[1]]
  z = E.select{|e| e[0] > d}.inject(0){|rst, e| rst + e[2]}
  ans = ((calc(a, B, d, n, M) * pow(10, z, M)) % M + ans) % M
}

puts (ans % M)


Measured memory_bytes: 1788
/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/

/*#### modular_arithmetic */
class modular_arithmetic{
public:
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	void set_mod(int _mod){mod = _mod;}
	int add(int x,int y){return (x+y)%mod;}
	int sub(int x,int y){return (x-y+mod)%mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int x,int y){
		int r = 1;
		while(1){
			if(y&1)r=mul(r,x);
			if(y>>=1)x=mul(x,x);else
				break;
		}
		return r;
	}
};
/*####*/

modular_arithmetic ma;

int res,S;
void proc1(){
	int cur = 0;
	int i,j,lenj = 1,leni = 1,pj = 10, pi = 10;
	for(i = 1, j = 0; i < 10000000; i++){
		while(cur < S){
			++j;if(j == pj){
				pj *= 10;
				lenj++;
			}
			cur += lenj;
		}
		if(cur == S)res ++;
		if(i == pi){
			pi *= 10;
			leni ++;
		}
		cur -= leni;
	}
}
int calc(int len, int cnt){
	return ma.sub(ma.mul(ma.pw(10, len-1),9), cnt-1);
}
void proc2(){
	for(int i=1; i*i<=S; i++){
		if(S%i)continue;
		if(i >= 8)
			res = ma.add(res, calc(i, S/i));
		if(i*i<S && S/i >= 8){
			res = ma.add(res, calc(S/i, i));
		}
	}
}
bool chk(int Lp1, int XpY, int X){
	int L = Lp1 - 1;
	int Y = XpY - X;
	return Y>=1 && L>=8;
}
void proc3_1(){
	for(int x=1; x<=100; x++){
		int S2 = S+x;
		for(int i=1; i*i <= S2; i++){
			if(S2%i)continue;
			if(chk(i,S2/i, x))res++;
			if(i*i < S2 && chk(S2/i, i, x))res++;
		}
	}
}

void proc3_2(){
	for(int L=8; L*100 < S; L++){
		long long int x, y;
		x = -S;
		y = S;
		long long int t = (x - 101) / (L+1);
		while(x - t * (L+1) < 101)t --;
		while(x - (t+1) * (L+1) >= 101)t++;
		long long int t2 = (1 - y) / L;
		while(y + t2 * L < 1)t2 ++;
		while(y + (t2-1)*L >= 1)t2--;
		if(t>=t2)
			res = ma.add(res, (int)((t-t2+1)%ma.mod));
	}
}
int main(){
	scanf("%d",&S);
	res = 0;
	proc1();
	proc3_1();
	proc2();
	proc3_2();
	printf("%d\n",res);
	return 0;
}

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

using namespace std;

int main(){
	string s; cin >> s;
	int k; cin >> k;
	
	vector<int> a;
	int la=0;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[la]){
			a.push_back(i-la);
			la=i;
		}
	}
	a.push_back((int)s.size()-la);
	
	if(a.size()==1){
		cout << (1ll*s.size()*k)/2 << endl;
	}
	else if(s.back()==s.front()){
		int sum=0;
		for(int i=1;i<a.size()-1;i++){
			a[i]/=2;
			sum+=a[i];
		}
		cout << (1ll*sum*k)+a.front()/2+a.back()/2+(1ll*((a.front()+a.back())/2)*(k-1)) << endl;
	}
	else{
		int sum=0;
		for(int i=0;i<a.size();i++){
			a[i]/=2;
			sum+=a[i];
		}
		cout << 1ll*sum*k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

bool gb(ll bit, ll n) {
    return ((bit & (1 << n)) != 0);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    ll ans = 0;
    rep(hbit, 1 << h) {
        rep(wbit, 1 << w) {
            ll cnt = 0;
            rep(i, h) {
                rep(j, w) {
                    if (gb(hbit, i) || gb(wbit, j) || (c[i][j] == '.')) continue;
                    cnt++;
                }
            }
            if (cnt == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <queue>

using namespace std;

long long lunlun_number(int k) {
  int count = 0;
  queue<long long> que;

  for(int i=1;i<=9;i++) {
    que.push(i);
  }

  long long ans;

  while(count < k) {
    ans = que.front();
    que.pop();
    count++;
    // minus;
    if(ans % 10 != 0) {
      que.push(10*ans + (ans % 10) - 1);
    }
    que.push(10*ans + (ans % 10));

    if(ans % 10 != 9) {
      que.push(10*ans + (ans % 10) + 1);
    }
  }
  return ans;
}

int main() {
  int k;
  cin >> k;

  cout << lunlun_number(k);
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    ll n,m;
    cin >> n >> m;
    ll a,b;
    vector <int> k(n);
    rep(i,m){
        cin >> a >> b;
        ++k[a-1];
        ++k[b-1];


    }

    rep(i,n){
        if(k[i]%2==1){
            cout << "NO" << endl;
            break;
        }
        if(i==(n-1)){
            cout << "YES" << endl;
        }

    }
    

    return 0;
}

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

int main(){

const int MAX_NO=100000;
int m[MAX_NO],f[MAX_NO],r[MAX_NO];
char hyouka[MAX_NO];
int a=0;
int b=0;

for(int i=1;i<20000000;i++){
b++;
}

for(int i=1;i<MAX_NO;i++){

cin>>m[i]>>f[i]>>r[i];
a++;

if(m[i]==-1 && f[i]==-1 && r[i]==-1){
goto aa;
}

if(m[i]==-1 || f[i]==-1){
hyouka[i]='F';
}

else if((m[i]+f[i])>=80){
hyouka[i]='A';
}
else if((m[i]+f[i])>=65){
hyouka[i]='B';
}

else if((m[i]+f[i])>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])>=30 && r[i]<50){
hyouka[i]='D';
}
else if((m[i]+f[i])>=30 && r[i]>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])<30){
hyouka[i]='F';
}

}

aa:;

for(int i=1;i<a;i++){

cout<<hyouka[i]<<endl;

}

return 0;
}

Measured memory_bytes: 1168
N = int(input())
C = [list(map(int,input().split())) for _ in range(N)]

DP = [[0 for _ in range(3)] for _ in range(N)]

# DP[i][j] ・・・　最後にj+1番目(j=0,1,2)を選んだ時のi+1日目(i=0,1,…)の最大値
DP[0] = C[0]

for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if j != k:
                DP[i][j] = max(DP[i][j],DP[i-1][k]+C[i][j])

print(max(DP[N-1]))

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main(){
    string s,t;
    cin>>s>>t;
    ll n = s.size();
    ll m = t.size();
    vector<ll> v[26];
    for (ll i = 0; i < n; i++)
    {
        v[s[i]-'a'].push_back(i);
    }
    for (ll i = 0; i < m; i++)
    {
        if(v[t[i]-'a'].size()==0) 
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    
    ll syukai = 0;
    ll pnt = 0;
    for (ll i = 0; i < m; i++)
    {
        ll nowc = t[i]-'a';
        auto it = lower_bound(all(v[nowc]), pnt);
        if(it==v[nowc].end())
        {
            syukai++;
            it = lower_bound(all(v[nowc]), 0);
        }
        pnt = *it;
        pnt++;
        if(pnt>=n)
        {
            syukai++;
            pnt%=n;
        }
        //cout<<i<<":\t"<<pnt<<endl;
    }
    

    cout<<syukai*n+pnt<<endl;

    return 0;
}


Measured memory_bytes: 1724
//this is a program that find out the answer remainder and the exact value of a division;
#include <stdio.h>
int main(){
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%d %d %.5lf\n", d, r, f);
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <iostream>
using namespace std;
int count=1;
int A,B;
void f(int a,int b){
    if(a>=b) return;
    if(a<b){
        f(a+A-1,b);
        count++;
    }
}
int main(){
    scanf("%d%d",&A,&B);
    if(B==1){
        printf("%d",0);
    }else{
        f(A,B);
        printf("%d",count); 
    } 
}


Measured memory_bytes: 256
import java.util.*;

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

        for (int i=0; i<=n; i++) {
            for (int j=0; j<=n-i; j++) {
                int k = n-i-j;
                if (1000*i+5000*j+10000*k==y) {
                    System.out.println(k+" "+j+" "+i);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
        sc.close();
    }
}

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

using namespace std;

set< vector<int> > seen;

int main() { 

	int a, b, c, ans = 0;
	int na, nb, nc;
	cin >> a >> b >> c;

	while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		ans ++;
		na = b / 2 + c / 2;
		nb = a / 2 + c / 2;
		nc = a / 2 + b / 2;
		vector<int> temp;
		temp.push_back(na);
		temp.push_back(nb);
		temp.push_back(nc);
		sort(temp.begin(), temp.end());
		if(seen.count(temp)) {
			ans = -1;
			break;
		}
		seen.insert(temp);
		a = na;
		b = nb;
		c = nc;
	}

	cout << ans;
}


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

int main(){
    
    vector<int> a(3),x(3);
    for(int i=0; i<3; i++){
        cin >> a[i];
    }
    int k; cin >> k;
    
    
    for(int i=0; i<3; i++){
        x[i] = min(k,a[i]);
        k -= x[i];
    }
    
    cout << x[0] - x[2] << endl;
    
    return 0;
}

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

using namespace std;
#define ll long long
const int N=5000,mod=1e9+7;
long long f[N+5];
long long inv[N+5];
long long fp(long long b,long long p)
{
    if(p==0) return 1;
    long long tmp=fp(b,p/2);
    if(p%2) return (((tmp*tmp)%mod)*b)%mod;
    return (tmp*tmp)%mod;
}
long long ncr(int n,int r)
{
    return (((f[n]*inv[r])%mod)*inv[n-r])%mod;
}
ll solve(int slots,int balls)
{
    if(balls<0) return 0;
    return ncr(slots+balls-1,slots-1);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    f[0]=1;
    for(int i=1;i<=N;i++) f[i]=(f[i-1]*i)%mod;
    for(int i=0;i<=N;i++) inv[i]=fp(f[i],mod-2);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
        cout<<solve(i,k-i)*solve(i+1,(n-k)-(i-1))%mod<<endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
B = [[0,0] for _ in range(N)]
ans = [0]*N

for i in range(N):
    B[i][0]=A[i]
    B[i][1]=i+1
B.sort()

for i in range(N):
    ans[i] = B[i][1]

print(" ".join(map(str,ans)))

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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int solve(int i, vector<int> v, int n, int k)
{
	if (i == n - 1) return 0;

	int cur = INT_MAX;

	for (int jump = 1; jump <= k && i + jump <= n - 1; jump++)
	{
		cur = min(cur, abs(v[i] - v[i + jump]) + solve(i + jump, v, n, k));
	}

	return cur;

}

int main()
{
	FASTIO;

	int n, k;
	cin >> n >> k;

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

	// recursive
	// cout << solve(0, v, n,k);

	vector<int> dp(n);
	dp[n - 1] = 0;

	for (int i = n - 2; i >= 0; i--)
	{
		int cur = INT_MAX;
		for (int jump = 1; jump <= k && i + jump <= n - 1; jump++)
		{
			cur = min(cur, abs(v[i] - v[i + jump]) + dp[i+jump]);
		}

		dp[i] = cur;
	}

	cout << dp[0];


}

Measured memory_bytes: 1024
#include <algorithm>
#include <vector>

template <typename T>
struct BIT {
  using value_type = T;
  using Index1 = int;
  std::vector<value_type> A;
  const int N, N2;
  BIT(int N) : A(N + 1, 0), N(N), N2(1 << std::__lg(N)) {}
  void add(Index1 a, value_type w) {
    for (Index1 x = a; x <= N; x += x & -x) {
      A[x] += w;
    }
  }
  value_type sum(Index1 a) const {
    value_type ret = 0;
    for (Index1 x = a; x > 0; x -= x & -x) {
      ret += A[x];
    }
    return ret;
  }
  Index1 lower_bound(value_type w) const {
    if (w <= 0) return 0;
    Index1 x = 0;
    for (int k = N2; k > 0; k >>= 1) {
      if (x + k <= N && A[x + k] < w) {
        w -= A[x + k];
        x += k;
      }
    }
    return x + 1;
  }
};
#include <cstdio>

#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

template<typename T=int>T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
template<typename T=int>void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}

int main() {
  int N = rd(), Q = rd();
  BIT<int> bit(N);
  for (int i = 0; i < Q; i++) {
    int c = rd(), x = rd(), y = rd();
    if (c == 0) {
      bit.add(x, y);
    } else {
      wr(bit.sum(y) - bit.sum(x - 1));
    }
  }
}

Measured memory_bytes: 2616
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int right = 0;
	int left = 0;
	int point = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') {
			point = point + 1;
		}
		else {
			point = point - 1;
			if (point == -1) {
				left = left + 1;
				point = 0;
			}
		}
	}
	right = right + point;
	for (int i = 0; i < left; i++) {
		cout << "(";
	}
	cout << s;
	for (int i = 0; i < right; i++) {
		cout << ")";
	}

}

Measured memory_bytes: 256
n = int(input())
ans = 0
aaa = 2
maxi = 2
def prime(aaa):
    global primemode
    if n != 1:
        i = 2
        while i*i <= aaa:
            if aaa % i == 0:
                primemode = False
                return False
            i += 1
        return True
    else:
        return False
def make_divisors(n):
    if prime(n):
        return True
    a = 0
    i = 2
    while i <= n:
        if n % i == 0:
            if a == 0:
                a = i
                n /= i
                i -= 1
                if n == 1:
                    return True
            elif a == i:
                n /= i
                i -= 1
                if n == 1:
                    return True
                pass
            else:
                return False
        i += 1
    return True
def divisors(a, i):
    global ans, aaa, maxi, primemode
    while i <= n and i <= a:
        if i * i <= a and primemode:
            if prime(a):
                ans += 1
                break
        if a % i == 0:
            if make_divisors(i):
                primemode = True
                ans += 1
                num = a / i
                aaa = num
                if maxi <= i:
                    maxi = i
                divisors(num, i+1)
                break
        i += 1
if n == 1:
    print(0)
else:
    if prime(n):
        print(1)
    else:
        divisors(n, 2)
        print(ans)

Measured memory_bytes: 9356
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a == b)
			System.out.println("a == b");
		else if (a > b)
			System.out.println("a > b");
		else
			System.out.println("a < b");

		sc.close();

	}

}

Measured memory_bytes: 26224
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, a[2010], i, ans=0, j, cnt[2010]={0}, tmp=0, cnt2[2100]={0};
    cin >> n >> k;
    if(k%2==0) tmp=(k/2)*(k-1);
    else tmp=((k-1)/2)*k;
    tmp=tmp%1000000007;
    k=k%1000000007;
    for(i=0;i<n;i++){
        cin >> a[i];
    }

    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(a[i]>a[j]) cnt[i]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(a[i]>a[j] && i!=j) cnt2[i]++; 
        }
    }
    for(i=0;i<n;i++){
        ans=ans+cnt[i]*k;
        ans=ans%1000000007;
        ans=ans+cnt2[i]*tmp;
        ans=ans%1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 2e5+100;
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    n=n%10;
    if(n==3)
    cout<<"bon";
    else if(n==0||n==1||n==6||n==8)
    cout<<"pon";
    else cout<<"hon";
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

int main(){
	int N,K;
	long long x[100000];

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

	ll d[N-1];
	for(int i=0;i<N-1;i++){
		d[i] = x[i+1] - x[i];
	}
	ll sum[N];
	sum[0] = 0;
	for(int i=1;i<N;i++){
		sum[i] = sum[i-1] + d[i-1];
	}

	ll ans = 1e13;
	for(int i=0;i<=N-K;i++){
		ll tmp = sum[i+K-1] - sum[i];
		tmp += min(abs(x[i]),abs(x[i+K-1]));
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}

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

const int mod = 998244353;
const int MN = 4010;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int fact[MN], invf[MN];
int comb(int n, int k) {
    if(n < k) return 0;
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}
int H(int n, int k) {
    return comb(n + k - 1, k);
}

int N, K;

int main() {
    fact[0] = 1;
    for(int i = 1; i < MN; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < MN; i++) {
        invf[i] = inv(fact[i]);
    }

    cin >> K >> N;

    for(int i = 2; i <= 2 * K; i++) {
        int a = i <= K + 1? 1 : i - K;
        int b = i / 2;

        int ans = 0;
        for(int j = 0; j <= b - a + 1; j++) {
            if(N < 2 * j) break;

            if(j % 2) {
                ans += mod - 1LL * comb(b - a + 1, j) * H(K, N - 2 * j) % mod;
                ans %= mod;
            }
            else {
                ans += 1LL * comb(b - a + 1, j) * H(K, N - 2 * j) % mod;
                ans %= mod;
            }
        }
        printf("%d\n", ans);
    }
}


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

int C[300005];
vector<int> X[300005], Y;

bool allPresent(int indx)
{
    int ptr = 0;

    for (auto x : X[indx])
    {
        if (x < Y[ptr])
            continue;
        
        if (x > Y[ptr])
            return false;
        
        ptr++;

        if (ptr == Y.size())
            return true;
    }

    return false;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

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

    int maxx = 0;

    while (m--)
    {
        int x, y;
        cin >> x >> y;

        X[x].push_back(y);
        C[y]++;
        maxx = max(maxx, C[y]);
    }

    for (int i=1; i<=w; i++)
        if (C[i] == maxx)
            Y.push_back(i);

    sort(Y.begin(), Y.end());
    int ans = 0;

    for (int i=1; i<=h; i++)
    {
        int curr = X[i].size() + maxx;
        sort(X[i].begin(), X[i].end());

        if (allPresent(i))
            curr--;
        
        ans = max(ans, curr);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 22876
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int h, w;
	cin>>h>>w;
	string s[100][100];
	rep(i, h) rep(j, w){
		cin>>s[i][j];
	}
	rep(i, h) rep(j, w){
		if(s[i][j] == "snuke"){
			cout<<(char)('A'+j)<<i+1<<endl;
		}
	}
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <string>
#include <cstring>

using namespace std;
typedef long long ll;
const int maxn=1000007;
const int mod=1000007;


int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    int sum=0;
    sum=x+y+z-max(x,max(y,z));
    cout<<sum;
    return 0;
}
/*

*/


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt(), M = sc.nextInt();
        int[][] route = new int[M][2];
        for(int i=0;i<M;i++){
            route[i][0] = sc.nextInt()-1;   //最後に1を足せ
            route[i][1] = sc.nextInt()-1;
        }

        List<Integer>[] destination = new List[N];
        for(int i=0; i<destination.length; i++) {
            destination[i]= new ArrayList<Integer>();
        }
        for(int i=0; i<M; i++) {
            destination[route[i][0]].add(route[i][1]);
            destination[route[i][1]].add(route[i][0]);
        }

        int[] clear = new int[N];
        for(int i=0; i<clear.length; i++) {
            if(i!=0) {
                clear[i]=-1;
            }
        }

        List<Integer> queue = new ArrayList<Integer>();
        queue.add(0);

        for(int i=0; i<queue.size(); i++) {
            for(int j=0; j<destination[queue.get(i)].size(); j++) {
                if(clear[destination[queue.get(i)].get(j)]==-1) {
                    queue.add(destination[queue.get(i)].get(j));
                    clear[destination[queue.get(i)].get(j)]=queue.get(i);
                }
            }
        }
        if(queue.size()==N) {
            System.out.println("Yes");
        }
        for(int i=1; i<clear.length; i++) {
            System.out.println(clear[i]+1);
        }
    }

}


Measured memory_bytes: 76584
#include<bits/stdc++.h>
#define rep(i,n,m) for(ll i = (n); i <(m); i++)
#define rrep(i,n,m) for(ll i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

class UnionFind
{
    public:
        const int n;
        ll num_ok;
        vector<ll> parent;
        vector<ll> rank;
        vector<ll> sizes;
    
    UnionFind(int _n): n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 0);
        sizes.assign(n, 1);
        num_ok = 0LL;
    }

    int find(int a)
    {
        if (parent[a] == -1) 
            return a;
        else
            return parent[a] = find(parent[a]);
    }

    void unite(int a, int b)
    {
        assert (0 <= a and a < n);
        assert (0 <= b and b < n);

        a = find(a);
        b = find(b);

        if (a == b) return;
        num_ok += (ll) sizes[a] * sizes[b];

        if (rank[a] == rank[b])
        {
            parent[a] = b;
            sizes[b] += sizes[a];
            ++rank[b];
        }
        else
        {
            if (rank[a] > rank[b]) swap(a, b);
            parent[a] = b;
            sizes[b] += sizes[a];
        }
    }
    bool is_same(int a, int b)
    {
        return find(a) == find(b);
    }
};

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

    vector<pii> edges;
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        edges.emplace_back(a, b);
    }

    reverse(edges.begin(), edges.end());

    UnionFind ufind(n);
    vector<ll> ans;
    ll total = (ll)n * (n - 1) / 2;
    // ans.push_back(total);
    for (auto edge: edges)
    {
        ans.push_back(total - ufind.num_ok);
        ufind.unite(edge.first, edge.second);
    }
    reverse(ans.begin(), ans.end());
    for (auto a : ans)
        cout << a << endl;
    return 0;
}

Measured memory_bytes: 7024
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    int a[maxn+2]={0};
    int cnt=0;
    int n,m;
    cin >> n>>m;
    
    rep(i,m){
        int r,l;
        cin >> l>>r;
        a[l]+=1;
        a[r+1]-=1;
    }
    
    for(int i=1;i<=n;i++){
        a[i]+=a[i-1];
        if(a[i]==m)cnt++;
    }
    
    cout << cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,s,c,k,MOD; 
int p(long long u,long long v){
	if(v==1) return u%MOD;
	//cout<<v<<endl;
	if(v%2==0) {
		long long y=p(u,v/2);
		return (y*y)%MOD;
		
	}
	return (p(u,v-1)*u)%MOD;
}
int main(){
	cin>>n>>a>>b;
     MOD=1000000000+7;
	s=p(2,n)-1; 
	s=s%MOD; 
	c=1; 
	for(k=max(n-a,a)+1;k<=n;k++)
	{
		c*=k;
		c%=MOD;
	} 
	long long f=1;
	for(k=1;k<=min(n-a,a);k++){
		f*=k;
		f%=MOD;
	}
	long long x=(c*p(f,MOD-2))%MOD;	
	s-=x; s+=MOD;
	s%=MOD;
c=1;
		for(k=max(n-b,b)+1;k<=n;k++)
	{
		c*=k;
		c%=MOD;
	} 
	f=1;
	for(k=1;k<=min(n-b,b);k++){
		f*=k;
		f%=MOD;
	}
	 x=(c*p(f,MOD-2))%MOD;	
	s-=x; s+=MOD;
	s%=MOD;
	 cout<<s;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF=1e18;

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

    ll N, K;
    cin >> N >> K;
    vector<ll> height(N + 10);
    vector<ll> dp(N);

    for (int i=0; i<N; i++) cin >> height[i];
    for (int i=0; i<N; i++) dp[i] = INF;

    dp[0] = 0;
    for (int i=1; i<N; i++) {
        for (int j=1; j<=K; j++) {
            if (j > i) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(height[i] - height[i-j]));
        }
    }

    cout << dp[N-1] << '\n';

    return 0;
}

Measured memory_bytes: 1792
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;

ll lcn[2010],rcn[2010],ans;

int main(){
    ll N,K;cin>>N>>K;
    ll a[2010];
    rep(i,0,N)cin>>a[i];
    rep(i,0,N){
        rep(j,i+1,N){
            if(a[i]>a[j])rcn[i]++;
        }
    }
    rep(i,0,N){
        rep(j,0,i){
            if(a[i]>a[j])lcn[i]++;
        }
    }
    rep(i,0,N){
        ans+=rcn[i]*((K*(K+1)/2)%1000000007);
        ans+=lcn[i]*((K*(K-1)/2)%1000000007);
        ans=ans%1000000007;
    }
    cout<<ans<<endl;
}






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

    typedef long long int ll;

    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin >> t;while(t--)
    #define forn(i,n) for (int i = 0; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }
  

    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL); 
      int n,m,x;
      cin>>n>>m>>x;
      vector<int> c(n);
      vector<vector<int>> a(n);
      for (int i = 0; i < n; ++i)
      {
        cin>>c[i];
        forn(j,m){
            int x;
            cin>>x;
            a[i].push_back(x);
        }
      }
      int minsum = 1200001;

      for (int i = 1; i < 1<<n; ++i)
      {
        vector<int> sum(m,0);
        int cost = 0;
        int y = i;
        int idx = 0;
        while(y){
          //cout<<(y&1)<<" ";
          if(y&1){
            cost += c[idx];
            forn(j,m){
              sum[j] += a[idx][j];
            }
          }
          y = y>>1;
          idx++;
        }
        /*cout<<endl;
        cout<<cost<<endl;*/
        bool flag = 1;
        forn(j,m){
          if(sum[j] < x)
            flag = 0;
        }
        if(flag)
          minsum = min(minsum,cost);
      }
      if(minsum == 1200001)
        cout<<"-1"<<endl;
      else
        cout<<minsum<<endl;
    }
    //read the question correctly (ll vs int)


Measured memory_bytes: 3664
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int res = 0;
int main() {
	int n, p;
	cin >> n >> p;
	vector<long long> nums(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	vector<vector<long long>> dp(n + 1, vector<long long>(2, 0));
	dp[0][0] = 1;
	dp[0][1] = 0;
	for (int i = 1; i <= n; i++) {
		if (nums[i - 1] % 2 == 1) {
			dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
			dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
		}
		else {
			dp[i][0] = dp[i - 1][0] * 2;
			dp[i][1] = dp[i - 1][1] * 2;
		}
	}
	cout << dp[n][p] << endl;
}

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

int OSP(vector<vector<int> > graph, vector<int> c, int now, int n, int count, int x){
  if(count == 0) return 1;

  int sum = 0;
  bool flag = false;
  for(int i = 0; i < graph[now].size(); i++){
    if(c[graph[now][i]] == 0){
      flag = true;
      c[graph[now][i]] = 1;
      sum += OSP(graph, c, graph[now][i], n, count-1, x*10+graph[now][i]);
      c[graph[now][i]] = 0;
    }
  }
  if(flag == false) return 0;
  return sum;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m),b(m),c(n, 0);
  c[0] = 1;
  vector<vector<int> > graph(n);
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
    graph[a[i]].push_back(b[i]);
    graph[b[i]].push_back(a[i]);
  }



  cout << OSP(graph, c, 0, n, n-1, 0) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	ll MOD = 998244353;
	int n; cin >> n;
	int one; cin >> one;
	if (one != 0)
	{
		cout << 0 << endl;
		return 0;
	}
	vector<ll> b(n, 0);
	b[0] = 1;
	for (int i = 1; i < n; ++i)
	{
		ll d; cin >> d;
		if(d==0)
		{
			cout << 0 << endl;
			return 0;
		}
		++b[d];
	}
	ll ans = 1;
	rep(i, 1, n - 1)
	{
		for (int j = 0; j < b[i]; ++j)
		{
			ans = ans * b[i - 1] % MOD;
		}
	}
	cout << ans << endl;
}

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

/** Problem0077 : Run Length **/
int main()
{
	char str[100];
	
	while (cin >> str) {
		for (int i=0; str[i] != '\0'; i++) {
			if (str[i] != '@')
				cout << str[i];
			else {
				for (int j=0; j<str[i+1]-'0'; j++)
					cout << str[i+2];
				i+=2;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1132
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=305,INF=~0u>>2;
int n;
ll ans,dis[N][N];
bool vis[N][N];
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void floyed(){
	rep(k,n)
	  rep(i,n)
	    rep(j,n){
	    	if(i==j||j==k||i==k) continue;
	    	if(dis[i][j]>dis[i][k]+dis[k][j]){
	    		printf("-1");
	    		exit(0);
			}
			if(dis[i][j]==dis[i][k]+dis[k][j]) vis[i][j]=vis[j][i]=1;
		}
}
int main(){
//	freopen("ex.in","r",stdin);
	n=(int)read();
	rep(i,n) rep(j,n) dis[i][j]=read();
	floyed();
	rep(i,n) rep(j,n) if(!vis[i][j]) ans+=dis[i][j],vis[j][i]=1;
	printf("%lld",ans);
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1<<16

ll n,k;
ll a[10100];
ll dp[5005];

bool ok(ll x){
  memset(dp,0,sizeof(dp));
  dp[0]=1;
  rep(i,n){
    if(i==x)continue;
    for(ll j=k;j>=0;j--){
      if(j-a[i]>=0&&dp[j-a[i]])dp[j]=1;
    }
  }
  bool res=false;
  rep(i,k){
    if(i>=k-a[x]&&dp[i])res=true;
  }
  return res;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>k;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  ll lb=-1,ub=n;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(ok(mid))ub=mid;
    else lb=mid;
  }
  cout<<ub<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(i, a, n) for (int i = a; i < n; i++)
#define f1(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvpii vector<vpii>
#define vbl vector<bool>
#define upb upper_bound
#define lwb lower_bound
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define umap unordered_map
#define uset unordered_set
#define gcd __gcd
const ll MOD = 1e9 + 7;
#define INF INT_MAX
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n, m; cin >> n >> m;
    ll ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val n = sc.nextInt()
    var ans = 0
    for (ai in 0..n) {
        for (bi in 0..n) {
            val sumAB = ai * a + bi * b
            val rem = n - sumAB
            if (rem >= 0 && rem % c == 0) {
                ans++
            }
        }
    }
    println(ans)
}


Measured memory_bytes: 31516
fun main(args: Array<String>) {
    val (A,B) = readLine()!!.split(" ").map(String::toInt)
    for (x in A..B) {
        val s = x.toString()

    }
    val ans = (A..B).map { it.toString() }.count {
        if (it.length%2==0) {
            it.substring(0, it.length/2) == it.substring(it.length/2).reversed()
        } else {
            it.substring(0, it.length/2) == it.substring(it.length/2+1).reversed()
        }
    }
    println(ans)
}

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

#define int long long
using namespace std;

int32_t main() {

    string s, t;
    cin >> s >> t;

    int a = s.size(), b = t.size();
    int dp[a + 1][b + 1] = {};

    for (int i = 1; i <= a; i++) {
        for (int j = 1; j <= b; ++j) {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string ans;
    int i = a, j = b;
    while (i > 0 and j > 0) {
        if (s[i - 1] == t[j - 1]) {
            ans += s[i - 1];
            i--;
            j--;
        } else {
            if (dp[i - 1][j] > dp[i][j - 1])
                i--;
            else
                j--;
        }
    }
    reverse(ans.begin() ,ans.end());

    cout << ans << endl;
}



Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 21972
using System;

namespace atcoder_ABC096C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
			string[] array = Console.ReadLine().Split(' ');
			int height = int.Parse(array[0]);
			int width = int.Parse(array[1]);

			char[][] grid = new char[height][];
			for (int i = 0; i < height; i++)
			{
				grid[i] = new char[width];
				grid[i] = Console.ReadLine().ToCharArray();
			}

			int[] moveCount_i = {0, 1, 0, -1};
			int[] moveCount_j = {1, 0, -1, 0};
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					if (grid[i][j] == '#')
					{
						bool checkOK = false;
						for (int k = 0; k < moveCount_i.Length; k++)
                        {
                            int ni = i + moveCount_i[k];
							int nj = j + moveCount_j[k];
                            if (ni < 0 || nj < 0 || ni > height - 1 || nj > width - 1) continue;

                            if (grid[ni][nj] == '#')
							{
								checkOK = true;
								break;
							}
						}

                        if (!checkOK)
						{
							Console.WriteLine("No");
							return;
						}
					}
				}
			}

			Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

vector<vint> vv;
vector<vint> vis;
int B,W;
int x,y;
bool f1,f2;
int foo(int a,int b){
	int ret=0;
	// cout<<a<<" "<<b<<endl;
	if(vv[a][b]==1) f1=true;
	if(vv[a][b]==2) f2=true;
	if(vis[a][b]) return 0;
	vis[a][b]=1;
	ret++;
	if(a>0){
		ret+=foo(a-1,b);
	}
	if(a<x-1){
		ret+=foo(a+1,b);
	}
	if(b>0){
		ret+=foo(a,b-1);
	}
	if(b<y-1){
		ret+=foo(a,b+1);
	}

	return ret;
}

int main(){
	// int x,y;
	while(cin>>y>>x,x||y){
		initvv(vv,x,y);
		initvv(vis,x,y);
		B=0;
		W=0;
		rep(i,x){
			rep(j,y){
				vis[i][j]=0;
				char t;
				cin>>t;
				if(t=='B'){
					vv[i][j]=1;
					vis[i][j]=1;
				}
				else if(t=='.'){
					vv[i][j]=0;
				}
				else{
					vv[i][j]=2;
					vis[i][j]=1;
				}
				// cout<<vv[i][j];
			}
			// cout<<endl;
		}
		// initvv(vis,x,y);
		rep(i,x){
			rep(j,y){
				if(vis[i][j]==0){
					f1=false;
					f2=false;
					int tt=foo(i,j);
					if(f1&&!f2){
						B+=tt;
					}
					if(!f1&&f2){
						W+=tt;
					}
				}
			}
		}
		cout<<B<<" "<<W<<endl;

	}
	return 0;
}

Measured memory_bytes: 1440
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string n;
	cin >> n;
	bool ans = false;
	rep(i, 3) if(n[i] == '7') ans = true;
	cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;


signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector < int > a(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(all(a));
    vector < int > l = a;
    for(int i = 1 ; i < sz(l) ; ++i) l[i] += l[i - 1];
    int ans = 3e18;
    for(int i = 0 ; i < n ; ++i){
        int adL = l[i];
        int adR = l.back() - adL;
        int L = i + 1;
        int R = n - L;
        ans = min(ans, adR - adL + L * a[i] - R * a[i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3328