akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = list(input())[::-1]
stack = []
ans = S[::1]
add = 0
r, l = 0, 0
for c in S:
    if c == ")":
        l += 1
    if c == "(":
        if l > 0:
            l -= 1
        else:
            ans.insert(0, ")")
for i in range(l):
    ans.append("(")
print("".join(ans[::-1]))

Measured memory_bytes: 3064
#!/usr/bin/env python3

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')


N, W = map(int, input().split())
v_list = []
w_list = []
for _ in range(N):
    v, w = map(int, input().split())
    v_list.append(v)
    w_list.append(w)

# dp[w] := 重さがwを超えないように品物をいくつか選んだときの価値の和の最大値
# dp[w] = max(dp[w], dp[w-w_list[i]] + v_list[i])

dp = [0 for w in range(W + 1)]

for w in range(1, W + 1):
    for i in range(N):
        if w - w_list[i] < 0:
            continue
        dp[w] = max(dp[w], dp[w-w_list[i]] + v_list[i])

# pprint(dp)
print(dp[W])



Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1e16
#define MOD 1e9+7
#define gcd __gcd //最大公約数,gcd(x,y)
int lcm(int a, int b){return a/gcd(a, b)*b;} //(int)最小公倍数,lcm(x,y)
ll llcm(ll a, ll b){return a/gcd(a, b)*b;}//(ll)最小公倍数,lcm(x,y)


int main(){
  string b;
  cin >> b;
  if(b == "A"){
  	cout << "T" << endl;
  }else if(b == "T"){
  	cout << "A" << endl;
  }else if(b == "C"){
  	cout << "G" << endl;
  }else{
  	cout << "C" << endl;
  }


}


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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int n, m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,r,p;
    cin>>a>>b>>c;
    r=a-b;
    if(c>r){
    p=c-r;
    cout<<p<<endl;
    }
    else{
      cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

ll su[MAXN];
ll fac[MAXN];
ll inverse[MAXN];

ll mypow(ll n,ll m)
{
    if(!m)return 1;
    ll ans = mypow(n,m/2);
    ans = ans*ans;
    ans%= MOD;
    if(m%2)ans*=n,ans%=MOD;
    return ans;
}

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    ll cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m>>k;

    fac[0] = 1;

    for(int i=1;i<=n*m;i++)
        fac[i] = (i*fac[i-1])%MOD;

    inverse[n*m] = mypow(fac[n*m],MOD-2);

    for(int i=n*m-1;i>=0;i--)
        inverse[i] = ((i+1)*inverse[i+1])%MOD;

    ll res = 0;

    for(int i=1;i<=max(n,m);i++)
        su[i] = (su[i-1]+(ll)i)%MOD;

    for(int i=1;i<=n;i++){
        cur = (su[i-1]);
        cur = (cur*((m*m)%MOD))%MOD;
        res = (res+cur)%MOD;
    }

    for(int i=1;i<=m;i++){
        cur = (su[i-1]);
        cur = (cur*((n*n)%MOD))%MOD;
        res = (res+cur)%MOD;
    }

    ll ncr = fac[n*m-2];
    ncr = (ncr*inverse[k-2])%MOD;
    ncr = (ncr*inverse[n*m-k])%MOD;

    res = (res*ncr)%MOD;

    cout<<res<<"\n";

    return 0;
}


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

using namespace std;

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

int main()
{
	int a, b;
	cin >> a >> b;
	int c = a + b;
	if (c >= 10) cout << "error" << endl;
	else cout << c << endl;
}


Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
A, B = [], []
for i in range(N):
    a, b = MAP()
    A.append(a)
    B.append(b)

max_a = max(A)
B = sorted(B, reverse=True)

ans = 0

for i in range(N):
    if max_a >= B[i]:
        ans += -(-H//max_a)
        H = 0
    else:
        H -= B[i]
        ans += 1
    if H <= 0:
        print(ans)
        break
if H > 0:
    ans += -(-H//max_a)
    print(ans)


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0) {
        No;
    }
    else {
        Yes;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

const ULL M = 998244353;

ULL dp[3001][3001] = {};

int main() {
	UL w, h, W, H; cin >> w >> h >> W >> H;
	dp[w][h] = 1;
	for (UL x = w; x <= W; x++)
		for (UL y = h; y <= H; y++) {
			if (x == w && y == h) continue;
			ULL tmp = 0;
			tmp += dp[x - 1][y] * y;
			tmp += dp[x][y - 1] * x;
			tmp += M * ((x - 1) * (y - 1));
			tmp -= dp[x - 1][y - 1] * ((x - 1) * (y - 1));
			tmp %= M;
			dp[x][y] = tmp;
		}
	cout << dp[W][H] << endl;
	return 0;
}


Measured memory_bytes: 73928
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = GetNumbersInt();

            var n = nums[0];
            var m = nums[1];
            var l = nums[2];

            var a = new ulong[n, m];
            var b = new ulong[m, l];
            var c = new ulong[n, l];

            for (int i = 0; i < n; i++)
            {
                var line = GetNumbersInt();
                for (int j = 0; j < m; j++)
                {
                    a[i, j] = (ulong)line[j];
                }
            }

            for (int j = 0; j < m; j++)
            {
                var line = GetNumbersInt();
                for (int k = 0; k < l; k++)
                {
                    b[j, k] = (ulong)line[k];
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    for (int k = 0; k < l; k++)
                    {
                        c[i, k] += a[i, j] * b[j, k];
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                var line = string.Join(" ", Enumerable.Range(0, l).Select(x => c[i, x].ToString()).ToArray());
                System.Console.WriteLine(line);
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	ll a, b, c;
	scanf("%lld%lld.%lld", &a, &b, &c);
	ll ans = (a*(b*100+c))/100;
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 3764
"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const args_lines = arg_str.split('\n')
const N = args_lines[0]
const anagrams = args_lines.slice(1)

const anagrams_sort = anagrams.map(x=>{
  return x.split('').sort((a,b)=>a>b).join('')
})

const result_dict = {}
anagrams_sort.map(x=>{
  if(result_dict[x] > -1){
    result_dict[x]++
  }else{
    result_dict[x] = 0
  }
})

let result = 0

Object.keys(result_dict).forEach( function(key) {
  const v = result_dict[key]
  result += v * (v+1) / 2
})

console.log(result)

Measured memory_bytes: 61520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
     int n, k;
     cin >> n >> k;
     double p = 1.0 / n, mul = 1, ans = 0;;
     for(int i = n; i > 0; i--){
         while(i * mul < k) mul *= 2;
         ans += p / mul;
     }

    cout << fixed << setprecision(10);
     cout << ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
mod=10**9+7
isbroken=[1 for i in range(N+1)]
dp=[0 for i in range(N+1)]
dp[0]=1
for i in range(M):
    ai=int(input())
    isbroken[ai]=0
for i in range(N):
    dp[i+1]=isbroken[i]*dp[i]+isbroken[i-1]*dp[i-1]
    dp[i+1]%=mod
print(dp[N])


Measured memory_bytes: 47280
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	map<string, int> mc;
	int n;
	cin >> n;
	while (n--)
	{
		string str;
		cin >> str;
		mc[str]++;
	}
	cin >> n;
	while (n--)
	{
		string str;
		cin >> str;
		mc[str]--;
	}
	int ans = 0;
	for (auto& p : mc)
	{
		ans = max(ans, p.second);
	}
	cout << ans << 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<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	ll n, k; cin >> n >> k;
	string s; cin >> s;
	ll cntlr = 0;
	ll cntrl = 0;
	ll ans = 0;
	FOR(i,1,n){
		if (s[i-1]=='L'&&s[i]=='R') cntlr++;
		else if (s[i-1]=='R'&&s[i]=='L') cntrl++;
		else if (s[i-1]=='L'&&s[i]=='L') ans++;
		else if (s[i-1]=='R'&&s[i]=='R') ans++;
	}
	if (cntrl>cntlr){
		if (cntlr>=k){
			cout << ans+2*k << endl;
		}
		else if (s[0]=='R'||s[n-1]=='L'){
			cout << ans+2*cntlr+1 << endl;
		}
		else{
			cout << ans+2*cntlr << endl;
		}
	}
	else if (cntlr>cntrl){
		if (cntrl>=k){
			cout << ans+2*k << endl;
		}
		else if (s[0]=='L'||s[n-1]=='R'){
			cout << ans+2*cntrl+1 << endl;
		}
		else{
			cout << ans+2*cntlr << endl;
		}
	}
	else{
		if (cntlr>=k){
			cout << ans+2*k << endl;
		}
		else{
			cout << ans+2*cntlr << endl;
		}
	}
}

Measured memory_bytes: 512
/*
  AOJ 0538
  Title: IOI
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int n,m;
char s[1000001];
int solve()
{
        char *p,c,c1;
        int i,cnt,n2;

        n2=n*2+1;
        p=s+n2-1;
        cnt=0;
        while(p<s+m)
        {
                //printf("POS=%d\n",p-s);


                c ='I';
                c1='O';
                if(*p == c1)
                {
                        p++;
                        goto NEXT;
                }
                else if(*p!=c)
                {
                        p+=n2;
                        goto NEXT;
                }
                for(i=1;i<n2;i++)
                {
                        c ="IO"[i % 2];
                        if(*(p-i) != c)
                        {
                                //printf("i=%d %c (%c)\n",i,*(p-i),c);
                                p+= (n2-((i-1)/2)*2-1);
                                goto NEXT;
                        }
                }
                cnt++;
                p+=2;
        NEXT:
                ;
        }
        return(cnt);
}

main()
{
        int ret;

        while(EOF!=scanf("%d",&n) && n)
        {
                scanf("%d",&m);
                scanf("%s",s);

                ret=solve();
                printf("%d\n",ret);
        }

  return(0);
}

Measured memory_bytes: 1580
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

vll fac(2,1),inv(2,1),finv(2,1) ;

void nCr_set(ll n){
	for(int i=2;i<=n;i++){
		fac.emplace_back(fac.at(fac.size()-1)*i%mod) ;
		inv.emplace_back(mod-inv.at(mod%i)*(mod/i)%mod) ;
		finv.emplace_back(finv.at(finv.size()-1)*inv.at(i)%mod) ;
	}
}

ll nCr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll nHr(ll n,ll r) {
	return nCr(n+r-1,n-1) ;
}

int main(){
	ll n,a,b,k ;
	cin >> n >> a >> b >> k ;
	nCr_set(n) ;
	ll ans = 0 ;
	for(int i=0;i<=n;i++){
		if((k-a*i)%b!=0) continue ;
		ans += nCr(n,i)*nCr(n,(k-a*i)/b)%mod ;
		ans %= mod ;
	}
	cout << ans << endl ;
}


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

using ll = long long;

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

    vector<int> dp(1 << n);
    for(int S = 1; S < (1 << n); ++S) {
        int max_v = -1e9;
        for(int T = S; ; T = (T - 1) & S) {
            dp[S] = max(dp[S], a[T] + max_v);
            max_v = max(max_v, a[T]);
            if(T == 0) break;
        }
    }
    for(int i = 1; i < (1 << n); ++i) {
        dp[i] = max(dp[i], dp[i - 1]);
    }

    for(int i = 1; i < (1 << n); ++i) {
        cout << dp[i] << endl;
    }
}

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
// #define int long long 

using namespace std;

int32_t main()
{
	fio;
	int s,w;
	cin>>s>>w;
	if(w>=s)
	{
		cout<<"unsafe"<<endl;
	}
	else
	{
		cout<<"safe"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;
import java.io.*;
class Main {
    static long[] maskCount;
    static long[] dp;
    static long recurse(long[][] a, int mask) {
        if(Integer.bitCount(mask)==a.length)
            return 0;
        int n = a.length;
        if(dp[mask]!=-1)
            return dp[mask];
        long res = Long.MIN_VALUE;
        int remMask = (1<<n)-1-mask;
        for(int i = remMask; i>0; i=(i-1)&remMask) {
            long x = recurse(a, mask|i);
            if(x==Long.MIN_VALUE) continue;
            res = Math.max(res, x+maskCount[i]);
        }
        return dp[mask] = res;
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n][n];
        dp = new long[1<<n];
        Arrays.fill(dp, -1);
        for(int i = 0; i<n; i++) {
            for(int j = 0; j<n; j++)
                a[i][j] = sc.nextInt();
        }
        maskCount = new long[1<<n];
        for(int i = 0; i<(1<<n); i++) {
            int mask = i;
            long ans = 0;
            for(int j = 0; j<n; j++) {
                for(int k = j+1; k<n; k++) {
                    int bit1 = (mask>>k)&1;
                    int bit2 = (mask>>j)&1;
                    if(bit1==1 && bit2==1)
                        ans+=a[j][k];
                }
            }
            maskCount[mask] = ans;
        }
        System.out.println(recurse(a, 0));
    }
}

Measured memory_bytes: 24784
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i+1<s.size()&&s[i]==s[i+1]){
            cout<<i+1<<' '<<i+2<<endl;
            return 0;
        }
        if(i+2<s.size()&&s[i]==s[i+2]){
            cout<<i+1<<' '<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<' '<<-1<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>k>>n;
    int *a=new int[n+1];
    for(int i=0;i<n;i++) cin>>a[i+1];
    int ans=k-a[n]+a[1]; //默认答案
    for(int i=0;i<n;i++){
        ans=max(ans,a[i+1]-a[i]);//寻找一个最大的区间,跨度越大，答案越小
    }
    cout<<k-ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_b;ase::sync_with_stdio(NULL)
#define fin freopen("allcodefs.in", "r", stdin)
#define fout freopen("allcodefs.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
int N, f;

bool areDistinct(vector<int> arr)
{
    int n = arr.size();
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(arr[i]);
    }
    return (s.size() == arr.size());
}

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> N;
    vector <int> arr;
    for (int i = 0 ; i < N ; ++ i) {
        cin >> f;
        arr.PUBG(f);
    }
    if (areDistinct(arr)) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    ///time;
    return 0;
}


Measured memory_bytes: 10008
# エラトステネスの篩
#############################################################
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
#############################################################


primes = set(get_sieve_of_eratosthenes(10**5))

cumsum = [0]
for i in range(1, 10**5 + 1):
    if i % 2 == 1 and i in primes and (i + 1) // 2 in primes:
        cumsum.append(cumsum[-1] + 1)
    else:
        cumsum.append(cumsum[-1])

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    ans = cumsum[r] - cumsum[l - 1]
    print(ans)


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

int main(void) {
    int N, L;
    cin >> N >> L;
    string S[N];
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }
    vector< pair< string, int > > rank(N);
    for (int i = 0; i < N; ++i) {
        rank[i] = make_pair(S[i], i);
    }
    sort(rank.begin(), rank.end());
    for (int i = 0; i < N; ++i) {
        cout << S[rank[i].second];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int cnt = 0;
    string s; cin >> s;
    for(auto& c : s){
        cnt += c == 'x';
    }
    cout << (cnt < 8 ? "YES" : "NO") << '\n';
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

bool done[100001];
vector< vector<int> > path;
vector<int> p;
int count_node = 0;

int func( int c, int n ) { 
    
    done[c] = true;
    
    if ( c == n ) {
        p.push_back(c);
        return 1;
    }
    
    for ( auto& next : path[c] ) {
        
        if ( done[next] ) { continue; }
        int ret = func( next, n );

        if ( ret ) {
            p.push_back(c);
            return ret;
        }
        
    }
    
    
    
    return 0;
}

void func2( int c, int x, int y ) {
    
    done[c] = true;
    count_node++;
    
    
    for ( auto& next : path[c] ) {
        
        if ( c == x && next == y ) { continue; }
        if ( c == y && next == x ) { continue; }
        
        if ( !done[next] ) {
            func2( next, x, y );
        }
        
    }
    
}


int main() {
    
    int N;
    cin >> N;
    
    vector<int> f, s;
    
    path.resize(N);
    
    for ( int i = 0; i < N; i++ ) { 
        done[i] = false;
    }
    
    for ( int i = 0; i < N-1; i++ ) { 
        int a,b;
        cin >> a;
        cin >> b;
        a--;
        b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    
    func(0,N-1);
    
    int x,y;
    
    x = p[(p.size()/2)];
    y = p[p.size()/2-1];
    
    
    // cout << "x: " << x << endl;
    // cout << "y: " << y << endl;
    
    for ( int i = 0; i < N; i++ ) { 
        done[i] = false;
    }
   
    func2( x, x, y );
    
    int f_n, s_n;
    
    f_n = count_node;
    count_node = 0;
    
    for ( int i = 0; i < N; i++ ) { 
        done[i] = false;
    }
    
    
    func2( y, x, y );
    
    s_n = count_node;
    
    // cout << f_n << endl;
    
    if ( f_n > s_n ) { cout << "Fennec" << endl; }
    else { cout << "Snuke" << endl; }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> as(100000);
    for (int i = 0; i < n; i++) cin >> as[i];
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        vector<int> bs;
        int g = 0;
        for (int j = 0; j < i * 100; j++) {
            g = __gcd(g, as[j]);
        }
        for (int j = i * 100; j < (i + 1) * 100; j++) {
            bs.push_back(as[j]);
        }
        for (int j = (i + 1) * 100; j < 100000; j++) {
            g = __gcd(g, as[j]);
        }
        for (int j = 0; j < 100; j++) {
            int gg = g;
            for (int k = 0; k < 100; k++) {
                if (k != j) {
                    gg = __gcd(gg, bs[k]);
                }
            }
            ans = max(ans, gg);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#include<stdio.h>

int main(){
  int n, m, l;
  scanf("%d %d %d", &n, &m, &l);

  int a[n][m];
  int b[m][l];
  long c[n][l];

  for(int i = 0; i< n; i++){
    for(int j = 0; j < l; j++){
      c[i][j] = 0;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
	  scanf("%d", &a[i][j]);
    }
  }

  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
	  scanf("%d", &b[i][j]);
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      for(int k = 0; k < m; k++){
		c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
	  printf("%ld", c[i][j]);
      if(j < l - 1){printf(" ");}
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <climits>
#include <queue>
#include <functional>
#include <cstring>
int field[30][30] = { 0 };
int m[4][30][30]; //[??????][y][x] = ????°??????????
int costs[4] = { 0 };
int dx[] = { 1, 0, -1, 0, 1, 0, -1, 0 }, dy[] = {0, 1, 0, -1, 0, 1, 0, -1 };

struct Node{
	int x, y, cost = 0, d;
	bool operator < (const Node& rhs) const {
		return cost < rhs.cost;
	}
	bool operator < (Node&& rhs) const {
		return cost < rhs.cost;
	}
	bool operator > (const Node& rhs) const {
		return cost > rhs.cost;
	}
	bool operator > (Node&& rhs) const {
		return cost > rhs.cost;
	}
};

int main() {
	int w, h;
	while (std::cin >> w >> h && (w || h)) {
		std::memset(m, 0x7f, sizeof(int) * 4 * 30 * 30);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				std::cin >> field[i][j];
			}
		}
		for (int i = 0; i < 4; i++) std::cin >> costs[i];

		std::priority_queue<Node, std::vector<Node>, std::greater<Node>> q;
		q.push({0, 0, 0, 0});
		bool isOk = false;
		int minCost = INT_MAX;
		while (!q.empty() && !isOk) {
			Node node = q.top(); q.pop();
			if (node.x == w - 1 && node.y == h - 1) {
				isOk = true;
				minCost = node.cost;
			}

			for (int i = 0; i < 4; i++) {
				Node next = node;
				if (i == 1) next.d++;
				else if (i == 2) next.d += 2;
				else if (i == 3) next.d--;
				if (next.d < 0) next.d = 4 + next.d;
				else if (next.d >= 4) next.d = next.d - 4;

				next.x += dx[next.d];
				next.y += dy[next.d];
				if (field[node.y][node.x] != i) next.cost += costs[i];

				if (next.x < 0 || next.x >= w || next.y < 0 || next.y >= h) continue;
				if (m[next.d][next.y][next.x] <= next.cost) continue;
				m[next.d][next.y][next.x] = next.cost;
				q.push(next);
			}
		}
		std::cout << minCost << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3100
import sys
input_num = int(input())

div_cnt = 0
if input_num > (9 * 9):
    print('No')
else:
    for i in reversed(range(1, 10)):
        if (input_num % i) == 0 and (input_num / i) < 10:
            print('Yes')
            sys.exit()
    print('No')

Measured memory_bytes: 2940
n = int(input())
card = [[False for i in range(13)] for j in range(4)]

for i in range(n) :
    mark, suit = input().split()
    if mark == "S" :
        mark_num = 0
    elif mark == "H" :
        mark_num = 1
    elif mark == "C" :
        mark_num = 2
    elif mark == "D" :
        mark_num = 3
    card[mark_num][int(suit)-1] = True

for j in range(4) :
    for i in range(13) :
        if card[j][i] == False :
            if j == 0 :
                print("S", i+1)
            elif j == 1 :
                print("H", i+1)
            elif j == 2 :
                print("C", i+1)
            elif j == 3 :
                print("D", i+1)





Measured memory_bytes: 5612
#include<stdio.h>
unsigned int c;
int n,m;
int X[3]={-1,0,1};
int main(){
  int i,j,k;
  while(1){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)break;
    int d[17][15]={{0}};
    int p[17][15]={{0}};
    for(i=0;i<m;i++){
      for(j=0;j<n;j++){
	scanf("%d",&d[i][j]);
      }
    }
    for(i=0;i<n;i++)if(d[0][i]==0)p[0][i]=1;
    for(i=0;i<m-1;i++){
      for(j=0;j<n;j++){//printf("%5d",p[i][j]);
	if(d[i][j]==0){
	  for(k=0;k<3;k++){
	    if(0<=j+X[k]&&j+X[k]<n){
	      if(d[i+1][j+X[k]]==0||(k==1&&d[i+1][j]==2)){
		p[i+1][j+X[k]]+=p[i][j];
	      }
	    }
	  }
	}
	else if(d[i][j]==2){
	  p[i+2][j]+=p[i][j];
	}
      }
    }
    c=0;
    for(;i<m+1;i++){
      for(j=0;j<n;j++){//printf("%5d",p[i][j]);
	if(d[i][j]!=1){
	  c+=p[i][j];
	}
      }//printf("\n");
    }
    printf("%d\n",c);
  }
  return 0;
}

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

int main(){
  int nin;
  while(1){ 
    scanf("%d",&nin);
    if(!nin)break;

    long long int human[4002]={0};
    long long int no[4002],tanka,kazu,outflag=0;
    
    for(int i=0;i<nin;i++){
      scanf("%d %d %d",&no[i],&tanka,&kazu);
      human[no[i]]+=tanka*kazu;
    }
    
    for(int i=0;i<nin;i++){
      if(human[no[i]]>=1000000 && human[no[i]]!=-1){
	printf("%d\n",no[i]);
	human[no[i]]=-1;
	outflag=1;
      }
    }
    
    if(outflag==0)printf("NA\n");
    
  }
}

Measured memory_bytes: 3244
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char a = sc.next().charAt(0);
    char b = sc.next().charAt(0);
    
    System.out.println((a == 'H' && b == 'H')
                       || (a == 'D' && b == 'D')
                      ? "H" : "D");
  }
}

Measured memory_bytes: 21972
#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>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

int main() {
    int S;
    cin >> S;
    if (S < 3) {
        cout << 0 << endl;
        return 0;
    }

    int a = S / 3;
    mint ans = 1;
    for (int i = 2; i <= a; i++) {
        ans += c(S - (i * 3) + i - 1, i - 1);
    }

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


Measured memory_bytes: 6124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double v;

int main()
{
	while (cin >> v)
	{
		int ans = 1.0 * v * v / (5 * 19.6) + 1.0;
		cout << ans + 1 << endl;
	}
	
	return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK";
      return 0;
    }
  }
  
  cout << "NG";
  
  return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

#define  ff           first
#define  ss           second
#define  pb           push_back
#define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D(x)         cout << #x << " - " << x << endl;
#define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
#define  all(x)       (x).begin(), (x).end()
#define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
#define  ps(x,y)      fixed<<setprecision(y)<<x
#define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)
#define  sz(x)		  x.size();

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll MAXN = 1e6 + 4;


void solve(){
  int n,k;
  cin >> n >> k;
  ll prod=1;
  vll v(n);
  for(int i=0;i<n;i++){
  	cin >> v[i];
  }
  int j=0;
  for(int i=k;i<n;i++){
  	 if(v[j++] >= v[i] )cout <<"No\n";
  	 else cout << "Yes\n";
  }

}

int main(){
  IOS
     solve();
     cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying

Measured memory_bytes: 4772
#include <iostream>

using namespace std;

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

// 0: 海, 1: 陸
int board[50][50] = {{0}};

void DFS(int i, int j, int w, int h) {
  if (board[i][j] == 0) return;
  board[i][j] = 0;  // mark as visited

  for (int d = 0; d < 8; ++d) {
    const int ny = i + dy[d];
    const int nx = j + dx[d];
    if (ny >= 0 && ny < h && nx >= 0 && nx < w) {
      DFS(ny, nx, w, h);
    }
  }
}

int main() {
  int w, h;

  for (;;) {
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> board[i][j];
      }
    }

    int ans = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (board[i][j] == 1) {
          DFS(i, j, w, h);
          ++ans;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3208
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

vector<bool> eratosthenes(int N)
{ 
    vector<bool> v(N + 1, true);
    v.at(1) = false;
    for (int i = 2; i * i < N + 1; i++)
    {
        if (v.at(i) == true)
        {
            for (int j = i * i; j < N + 1; j += i)//i^2からスタートしてよい
            {
                v.at(j) = false;
            }
        }
    }
    return v;
}

template<typename T>
vector<T> finddivisor(T x){//整数xの約数が入ったvectorを返すよ(xを含む)  
    vector<T> divisor;
    for(T i=1; (i*i)<=x ;i++)
    {
        if(x%i==0){
            divisor.push_back(i);
            if(i*i!=x){
                divisor.push_back(x/i);
            }//約数はペアを持つことを利用

        }
    }
    sort(divisor.begin(),divisor.end());
    return divisor;
}


//BEGIN CUT HERE
template<typename T> 
map<T, ll> factorize(T x){//mapを返す関数
  map<T, ll> res;
  for(ll i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;//xが素数だった時用
  return res;
}


signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  V<bool> pri=eratosthenes(1000010);
  ll n;cin>>n;
  V<ll> div=finddivisor(n);
  auto ma=factorize(n);

  ll ans=0;
  for(auto&& i:ma){
    ll st=1,ue=100,mid;
    while(abs(ue-st)>1){
      mid=(ue+st)/2;
      if(mid*(mid+1)/2<=i.sc)st=mid;
      else ue=mid;
    }
    ans+=st;
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3800
readInt() = parse.(Int,split(readline()))
comb2(x) = div((x-1)x,2)

function f(x,neg,pos)
    ret = 0
    n=length(neg); p=length(pos)
    j=1
    for i in 1:n
        while j<=p && neg[i]*pos[j]>x
            j+=1
        end
        
        ret+=p-j+1
    end
    return ret
end

g(x,neg,pos) = h(x,neg)+h(x,pos)

function h(x,a)
    ret = 0
    sz=length(a)
    j=sz
    for i in 1:sz
        while j>i && a[i]*a[j]>x
            j-=1
        end
        j<=i && break
        ret+=j-i
    end
    return ret
end

function answer(K,neg,pos,fc)
    lo=-10^18; hi=10^18
    while hi-lo>1
        c = div(lo+hi,2)
        K <= fc(c,neg,pos) ? (hi=c) : (lo=c)
    end
    println(hi)
end

function solve()
    N,K = readInt()
    A = readInt()
    sort!(A)
    zero=0
    neg=Int[]; pos=Int[]
    for i in 1:N
        if A[i]==0
            zero+=1
            continue
        end
        push!((A[i]<0 ? neg : pos), A[i])
    end
    n=length(neg); p=length(pos)
    α = n*p
    γ = comb2(n)+comb2(p)
    β = comb2(N)-α-γ
    if K<=α
        answer(K,neg,pos,f)
    elseif K<=α+β 
        println(0)
    else
        reverse!(neg); neg*=-1
        answer(K-α-β,neg,pos,g)
    end
end
solve()

Measured memory_bytes: 208692
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n,m,x;cin>>n>>m>>x;
    int cnt1 = 0,cnt2 = 0;
    rep(i,m){
        int a;
        cin>>a;
        if(a>x)cnt2++;
        if(a<x)cnt1++;
    }
    cout<<min(cnt1,cnt2);
}



Measured memory_bytes: 256
def main():
    n,m = map(int, input().split())
    H = list(map(int,input().split()))
    array = [list(map(int,input().split())) for _ in range(m)]

    pool = []
    for i in range(m):
        a,b = array[i]
        if H[a-1] == H[b-1]:
            pool.append(a)
            pool.append(b)
        elif H[a-1] <= H[b-1]:
            pool.append(a)
        else:
            pool.append(b)
    ans = len(set(range(1, n+1)) - set(pool))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125332
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
typedef vector<vector<int > > vec2int;
typedef vector<vector<bool > > vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
////////////////////////////////////////////////
const ll size = 510001;// 1e6 + 1
const ll MOD = 1e9 + 7;
vector<ll> fac(size, 0); //n!(mod M)
vector<ll> ifac(size, 0); //k!^{M-2} (mod M)
vector<ll> inv(size, 0); //k!^{M-2} (mod M)
// vector<int> fac(size, 0); //n!(mod M)
// vector<int> ifac(size, 0); //k!^{M-2} (mod M)
// vector<int> inv(size, 0); //k!^{M-2} (mod M)
////////////////////////////////////////////////
void fac_mod(){ 
  // fac[i] = i! (mod M)
  fac[0] = 1;
  fac[1] = 1;
  inv[1] = 1;
  for(ll i = 2;i < size; i++){
    inv[i] = MOD - inv[MOD%i] * (MOD/i) %MOD;
    fac[i] = fac[i - 1]*i%MOD;
  }
}
////////////////////////////////////////////////
void ifac_mod(){ 
  // ifac[i] = 1/i! (mod M)
  ifac[0] = 1;
  ifac[1] = 1;
  for(ll i = 2;i < size; i++){
    ifac[i] = ifac[i - 1] * inv[i] %MOD;
  }
}
////////////////////////////////////////////////
ll nCk_mod(ll n, ll k){
  //nCk (mod M)
  if(n < k) return 0;
  if(n < 0 || k < 0)return 0;
  if(n == k)return 1;
  return fac[n]*(ifac[n -k] * ifac[k] %MOD) % MOD;
}
////////////////////////////////////////////////
int main()
{
  ll n, k;
  cin >> n >> k;
  vecll a(n,0);
  REP(i,n){cin >> a[i];}
  sort(all(a));
  fac_mod();
  ifac_mod();
  ll ans = 0;
  for(ll i = k - 1; i < n; i++){
    ans += a[i]*nCk_mod(i,k - 1)%MOD;
    ans %= MOD;
  }
  REP(i, n - k + 2){
    ans -= a[i]*nCk_mod(n - i - 1,k - 1)%MOD;
    ans %= MOD;
  }
  ans = (ans + MOD)%MOD;
  cout << ans << endl;
}


Measured memory_bytes: 13056
K,N = map(int,input().split())
A = list(map(int,input().split()))

B = sorted(A)
M = 0
for i in range(N-1):
    M = B[i+1]-B[i] if B[i+1]-B[i]>M else M
M = K-B[N-1]+B[0] if K-B[N-1]+B[0]>M else M

print(K-M)


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

using namespace std;

int main(void)
{
	int n;
	int cnt=0;
	int ans=0;

	cin>>n;

	if(n%2==0) n-=1;

	while(n>0){
		for(int i=1;i<=n;i++){
			if(n%i==0) cnt++;
		}

		if(cnt==8) ans++;
		cnt=0;
		n-=2;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
	public static long knapsack(int[] weights,int[] values,int capacity,int n,long[][] memo){
		if(memo[n][capacity]!=-1){
			return memo[n][capacity];
		}
		if(n==0 || capacity==0){
			return 0l;
		}
		if(weights[n-1]<=capacity){
			memo[n][capacity]=Math.max(values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo),knapsack(weights,values,capacity,n-1,memo));
			return memo[n][capacity];
		}
		memo[n][capacity]=knapsack(weights,values,capacity,n-1,memo);
		return memo[n][capacity];

	}

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int capacity=Integer.parseInt(st.nextToken());
		int[] weights=new int[n];
		int[] values=new int[n];
		for(int i=0;i<n;i++){
			st = new StringTokenizer(br.readLine());
			weights[i]=Integer.parseInt(st.nextToken());
			values[i]=Integer.parseInt(st.nextToken());
		}
		long[][] memo=new long[n+1][capacity+1];
		for(int i=0;i<n+1;i++){
			Arrays.fill(memo[i],-1l);
		}
		System.out.println(knapsack(weights,values,capacity,n,memo));
	}
}

Measured memory_bytes: 131720
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {


  string s;
  cin >> s;
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    string t;
    cin >> t;
    int a, b;
    if( t == "replace" ){
      string ss;
      cin >> a >> b >> ss;
      for(int i=0; i<=b-a; i++){
        s[i+a] = ss[i];
      }
    }else if( t == "reverse" ){
      cin >> a >> b;
      // string tmp = s;
      reverse(s.begin()+a, s.begin()+b+1 );
    }else if( t == "print" ){
      cin >> a >> b;
      for(int i=a; i<=b; i++){
        cout << s[i];
      }
      cout << endl;
    }
    // cerr << s << endl;
  }

  return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x7fffffff,MAXN=1<<17;
int main()
{
    int n,k;
    double ans,temp;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        int tt=i;
        temp=(double) 1/n;
        while(tt<k)
        {
            tt*=2;
            temp/=2;
        }
        ans+=temp;
    }
    printf("%.12lf",ans);
    return 0;
}


Measured memory_bytes: 256