akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;

signed main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans=1000000000;
    rep(i,n){
        if(i==0){
            ans=min(ans,k-min(abs(a[i+1]-a[i]),k-abs(a[i+1]-a[i])));
            ans=min(ans,k-min(abs(a[n-1]-a[i]),k-abs(a[n-1]-a[i])));
        }
        else if(i==n-1){
            ans=min(ans,k-min(abs(a[0]-a[i]),k-abs(a[0]-a[i])));
            ans=min(ans,k-min(abs(a[i-1]-a[i]),k-abs(a[i-1]-a[i])));
        }
        else{
            ans=min(ans,k-min(abs(a[i+1]-a[i]),k-abs(a[i+1]-a[i])));
            ans=min(ans,k-min(abs(a[i-1]-a[i]),k-abs(a[i-1]-a[i])));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;

int main()
{
	int K, Q;
	cin >> N >> K >> Q;

	int A;

	vector<int> score(N,0);

	for (int i = 0; i < Q; i++) {
		cin >> A;
		score[A - 1]++;
	}
	for (int i = 0; i < N; i++) {
		if ((score[i]+K-Q) <= 0) {
			cout << "No";
		}
		else {
			cout << "Yes";
		}
		cout << '\n';
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
N, K = map(int, input().split())
D = list(map(str, input().split()))
for tmp in range(N, 10*N+1):
    tmp_l = list(str(tmp))
    cnt = 0
    for t in tmp_l:
        if t in D:
            cnt += 1
    if cnt == 0 and int(tmp) >= N:
        print(tmp)
        exit()

Measured memory_bytes: 3060
#include <stdio.h>
int main(void) {

  int n;
  scanf("%d",&n);

  int ans=0;

  while(n--) {
    int a,i;
    scanf("%d",&a);
    
  for(i=2; i*i<=a; i++) {
    if(a%i==0) 
      break;
    }
    
  if(i*i>a)
    ans++;
  }

  printf("%d\n",ans);

  return 0;

}


Measured memory_bytes: 2140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		long W=sc.nextLong();
		long[][] mono=new long[N][2];
		for(int i=0; i<N; i++) {
			mono[i][0]=sc.nextLong();
			mono[i][1]=sc.nextLong();
		}
		quick_sort(mono,0,N-1);
		long min0=mono[0][0];
		long[][] sina=new long[4][101];
		int[] counter= {0,0,0,0};
		for(int i=0; i<N; i++) {
			sina[(int)(mono[i][0]-min0)][counter[(int)(mono[i][0]-min0)]]=mono[i][1];
			counter[(int)(mono[i][0]-min0)]++;
		}
		for(int i=0; i<4; i++) {
			Arrays.sort(sina[i]);
		}
		long[][] ruiseki=new long[4][103];
		for(int i=0; i<4; i++) {
			ruiseki[i][0]=0;
			for(int j=0; j<=100; j++) {
				ruiseki[i][j+1]=sina[i][100-j];
			}
		}
		for(int i=0; i<4; i++) {
			for(int j=1; j<=101; j++) {
				ruiseki[i][j]+=ruiseki[i][j-1];
				//pl(ruiseki[i][j]);
			}
		}
		long max=0;
		for(long i=0; i<=counter[0]; i++) {
			for(long j=0; j<=counter[1]; j++) {
				for(long k=0; k<=counter[2]; k++) {
					for(long l=0; l<=counter[3]; l++) {
						long omosa=i*min0+j*(min0+1)+k*(min0+2)+l*(min0+3);
						if(omosa<=W) {
							max=Math.max(max, ruiseki[0][(int)i]+ruiseki[1][(int)j]+ruiseki[2][(int)k]+ruiseki[3][(int)l]);
						}
					}
				}
			}
		}
		pl(max);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static void quick_sort(long[][] d, int left, int right) {
		if (left>=right) {
			return;
		}
		long p = d[(left+right)/2][0];
		int l = left, r = right;
		long tmp,tmp1,tmp2;
		while(l<=r) {
			while(d[l][0] < p) { l++; }
			while(d[r][0] > p) { r--; }
			if (l<=r) {
				tmp = d[l][0]; d[l][0] = d[r][0]; d[r][0] = tmp;
				tmp1=d[l][1]; tmp2=d[r][1]; d[l][1]=tmp2; d[r][1]=tmp1;
				l++; r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}

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

int main(){
    ll N, A, B; cin >> N >> A >> B;
    vector<ll> x(N);
    for(int i=0; i<N; i++) cin >> x[i];

    ll ans = 0;
    for(int i=1; i<N; i++){
        if((x[i]-x[i-1])*A < B) ans += A*(x[i]-x[i-1]);
        else ans += B;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import heapq
n,x,y = map(int,input().split())

roots = [[] for _ in range(n)]

for i in range(n):
    if i == 0:
        roots[i].append(1)
    elif i == n - 1:
        roots[i].append(n-2)
    else:
        roots[i].append(i-1)
        roots[i].append(i+1)

roots[x-1].append(y-1)
roots[y-1].append(x-1)
ans = [0] * (n-1)

for i in range(n):
    hq = []
    dis = [-1]* n
    dis[i] = 0
    heapq.heappush(hq, (0,i))
    while hq:
        dis1, place = heapq.heappop(hq)
        for j in roots[place]:
            if dis[j] == -1 or dis[j] > dis1 + 1:
                dis[j] = dis1 + 1
                heapq.heappush(hq, (dis1+1, j))
    for j in dis:
        if j > 0:
            ans[j-1] += 1

for i in ans:
    print(i//2)


Measured memory_bytes: 61532
#include<stdio.h>
#include<string.h>

int main(){
	int i,j,k,l,n;
	int answer;
	while(scanf("%d",&n)!=EOF){
		answer=0;
		if(n>36){
			printf("0\n");
		}else{
			for(i=0;i<10;i++){
				for(j=0;j<10;j++){
					for(k=0;k<10;k++){
						for(l=0;l<10;l++){
							if(n==i+j+k+l) answer++;
						}
					}
				}
			}
			printf("%d\n",answer);
		}
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.*;
import java.io.BufferedInputStream;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner (new BufferedInputStream(System.in));
    int n = sc.nextInt();
    LinkedList<Long> que = new LinkedList<>();
    for(long i = 1; i < 10; ++i) {
      que.offer(i);
    }
    long now = 0;
    int count = 9;
    while(count < n) {
      now = que.poll();
      if(now % 10 != 0) {
        que.offer(now * 10 + now % 10 - 1);
        count++;
      }
      que.offer(now * 10 + now % 10);
      count++;
      if(now % 10 != 9) {
        que.offer(now * 10 + now % 10 + 1);
        count++;
      }
    }
    System.out.println(que.get(que.size() - 1 - (count - n)));
  }
}

Measured memory_bytes: 25940
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
    A[i+1] += A[i]
ans = float("inf")
for i in range(n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)

Measured memory_bytes: 16992
import fractions
N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
    
count = 0
for i in a:
    count += ans//i
print(count%(10**9+7))

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    double r;
    cin >> r;
    printf("%.10f\n", 2 * M_PI * r);

    return 0;
}

Measured memory_bytes: 3808
#140_B
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

x = 0
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        x += c[a[i]-1]
print(sum(b) + x)

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];
  // t is now total value
  ll t = 0;
  ll ans = 0;
  REP(i, m) t += b[i];
  ll j = m;
  REP(i, n+1){
  while (t>k and j>0){
    j--;
    t -= b[j];
  }
  if (t > k and j==0) break;
  ans = max(ans, i+j);
  if (i==n) break;
  t += a[i];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6432
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int dataSet = sc.nextInt();
				for (int i = 0; i < dataSet; i++) {
					String originalNum = sc.next();
					char[] charNum = originalNum.toCharArray();

					// asc
					Arrays.sort(charNum);
					int ascNum = Integer.parseInt(String.valueOf(charNum));

					// desc
					int descNum = Integer.parseInt(String
							.valueOf(desc(charNum)));

					// max-min
					int result = descNum - ascNum;
					System.out.println(result);
				}
			}
		} finally {
			sc.close();
		}
	}

	public static char[] desc(char[] c) {
		char[] after = new char[c.length];

		for (int i = 0; i < c.length; i++) {
			after[i] = c[c.length - (1 + i)];
		}
		return after;
	}
}

Measured memory_bytes: 26200
//ProblemE

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

constexpr int MAXn = 18;
constexpr int MAXN = 1 << MAXn;

//ProblemE
void Solve() {
	int n;
	cin >> n;
	int N = 1 << n;
	int a[MAXN];
	for (int i = 0; i < N; i++) cin >> a[i];

	int max2[MAXN][2];
	max2[0][0] = max2[0][1] = 0;
	for (int i = 1; i < N; i++) {
		max2[i][0] = 0; max2[i][1] = i;
		if (a[0] < a[i]) swap(max2[i][0], max2[i][1]);
		int j = i;
		while (j) {
			int mask = j & -j;
			for (auto x : max2[i & ~mask]) {
				if (max2[i][0] == x || max2[i][1] == x) continue;
				if (a[x] >= a[max2[i][0]]) {
					max2[i][1] = max2[i][0];
					max2[i][0] = x;
				}
				else if (a[x] >= a[max2[i][1]]) {
					max2[i][1] = x;
				}
			}
			j &= ~mask;
		}
	}

	int ans = 0;
	for (int i = 1; i < N; i++) {
		int t = a[max2[i][0]] + a[max2[i][1]];
		ans = max(ans, t);
		cout << ans << '\n';
	}
	cout << flush;
}


Measured memory_bytes: 6144
from itertools import accumulate

k = input()
d = int(input())
dp = [0] * (d + 10)
dp2 = 0
MOD = 10 ** 9 + 7
for c in k:
    c = int(c)
    for e in range(d - 1, -1, -1):
        dp[e + 10] -= dp[e]
    dp[dp2] += 1
    dp[dp2 + c] -= 1
    dp = list(accumulate(dp))
    for e in range(9, -1, -1):
        dp[e] += dp[d + e]
        dp[d + e] = 0
    for e in range(d):
        dp[e] %= MOD
    dp2 = (dp2 + c) % d
ans = dp[0] - 1
if dp2 == 0:
    ans += 1
print(ans % MOD)


Measured memory_bytes: 3064
N, Y=map(int, input().split())
for x in range(N+1):
  for y in range(0, N-x+1):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(x, y, z)
      exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
n = gets.to_i
first_candies = []
second_candies = []
first_candies = gets.chomp.split(" ").map(&:to_i)
second_candies = gets.chomp.split(" ").map(&:to_i)
sum = 0
max = 0
first_candies.each_with_index do |first_candy, index|
  sum += first_candies[0]
  index.times do |num|
    sum += first_candies[num + 1]
  end
  second_candies[index..n].each_with_index do |second_candy, index2|
    sum += second_candy
  end
  if sum > max
    max = sum
  end
  sum = 0
end
puts max

Measured memory_bytes: 1916
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  rep(i,n){
    ll a; cin >> a;
    x.at(i) = y.at(i) = a;
  }

  sort(all(y));
  ll left = y.at(n/2-1),right = y.at(n/2);

  rep(i,n){
    ll b;
    if(x.at(i)>=right) b = left;
    else b = right;

    cout << b << endl;
  }
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int a;
string s;

int main () {
  cin >> a >> s;
  if(a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, K, h, ans = 0;;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> h;
		if (h >= K)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import collections

def main():
    n = int(input())
    A = sorted(map(int, input().split()))

    D = collections.defaultdict(int)
    for a in A:
        D[a] += 1

    m = max(A)
    S = set()

    ans = 0
    for i in range(n):
        a = A[i]

        if a in S:
            continue

        if D[a] == 1:
            ans += 1

        num = a
        while num <= m:
            S.add(num)
            num += a

    print(ans)


main()


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    string s;
    cin >> s;
    int odd_sum = 0; // 奇数を変える
    int even_sum = 0; // 偶数を変える

    for(int i=0; i<s.size(); i++) {
        if(i % 2) { // 奇数の時
            if(s[i] == '0') {
                even_sum++;
            } else {
                odd_sum++;
            }
        } else { // 偶数の時 0, 2, 4 ...
            if(s[i] == '0') { // 1ならば
                odd_sum++;
            } else {
                even_sum++;
            }
        }
    }
    //cout << odd_sum << " " << even_sum;
    cout << min(odd_sum, even_sum) << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
  int a = inputValue();
  int b = inputValue();
  int k = (a+b)/2;
  if (k*2 == a+b) {
    cout << k << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

    
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  UnionFind uf(n);
  rep(i,m){
    ll a,b,z; cin>>a>>b>>z; a--,b--;
    uf.connect(a,b);
  }
  set<ll> s;
  ll ans=0;
  rep(i,n){
    ll v=uf.root(i);
    if(!s.count(v)){
      s.insert(v);
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
   long long a[100010];
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
     cin>>a[i];
   int zero=0;
   for(int i=0;i<n;i++)
     if(a[i]==0)
       zero++;
   if(zero>0){
     cout<<0<<"\n";
     return 0;
   }
  
   long long prod=1;
   for(int i=0;i<n;i++){
     if(a[i]<=1000000000000000000/prod){
       prod*=a[i];
     }else{
        cout<<"-1"<<endl;
        return 0;
     }
   }
   cout<<prod<<"\n";
}

Measured memory_bytes: 4276
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

llong n, m;

bool read()
{
	if (scanf("%lld", &n) != 1)
		return false;

	scanf("%lld", &m);
	return true;
}

bool check(llong x)
{
	if (x <= n)
		return 2 * x <= m;
	else
		return 2 * x <= m - 2 * (x - n);
}

void solve()
{
	llong l = 0, r = 1000000000000ll;

	for (; l < r; )
	{
		llong mid = (l + r + 1) / 2;

		if (check(mid))
			l = mid;
		else
			r = mid - 1;
	}

	printf("%lld\n", l);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


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

#define endl ("\n")

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invaraibly fail
    

    int n;
    cin >> n;
    int arr[n];
    for(int i = 0;i < n;i++)
        cin >> arr[i];
    int count = 0;
    for(int i = 1;i < n-1;i++)
    {
        if((arr[i] > arr[i-1] and arr[i+1] > arr[i]) or (arr[i] < arr[i-1] and arr[i+1] < arr[i]))
        {
            count++;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;


int countYakusu(int x) {
    int count = 2; //1とxはデフォルトで含める。
    for (int i = 2; i < x/2; i++) {
        if (x % i == 0) count++;
    }
    return count;
}

int main() {
    int n;
    cin >> n;
    int count = 0;
    for (int i = 1; i <= n; i = i + 2) {
        if (countYakusu(i) == 8) {
            count++;
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

  vector<int> original(N);
  vector<int> P(N); 
  vector<int> Q(N); 

  int a = 0;
  int b = 0;

  for (int i = 0; i < N; i++) {
    original[i] = i + 1;
    cin >> P[i];
  }

  for (int j = 0; j < N; j++) {
    cin >> Q[j];
  }

  int count = 0;
  do {
    ++count;
    bool match_a = true;  
    bool match_b = true;
    for (int k = 0; k < N; k++) {
      if (original[k] != P[k]) {
        match_a = false; 
        break;
      }
    }
    for (int l = 0; l < N; l++) {
      if (original[l] != Q[l]) {
        match_b = false; 
        break; 
      }
    }
    if (match_a) a = count; 
    if (match_b) b = count;
  } while (next_permutation(original.begin(), original.end()));

  int diff = abs(a - b);
  cout << diff << endl;
}

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

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int h, w, K;
    cin >> h >> w >> K;
    akari<seika> g(h);
    for (auto &s : g)
    {
        cin >> s;
    }
    int ans = 1e9;
    for (int b = 0; b < 1 << (h - 1); b++)
    {
        int res = 0;
        queue<int> q;
        int m = 0;
        for (int i = 0; i < h - 1; i++)
        {
            m++;
            if (b >> i & 1)
            {
                q.push(m);
                q.push(m);
                res++;
            }
        }
        q.push(h);
        int beg = 0;
        set<int> cut;
        akari<pair<int, int>> ps;
        while (1)
        {
            int end = q.front();
            q.pop();
            ps.emplace_back(beg, end);
            if (!q.empty())
            {
                beg = q.front();
                q.pop();
            }
            else
            {
                break;
            }
        }
        m = ps.size();
        akari<int> cur(m);
        for (int j = 0; j < w; j++)
        {
            akari<int> nx(m);
            bool cut = 0;
            for (int k = 0; k < m; k++)
            {
                auto &p = ps[k];
                for (int i = p.first; i < p.second; i++)
                {
                    nx[k] += g[i][j] - '0';
                }
                if (nx[k] > K)
                {
                    res = 1e9;
                }
                if (cur[k] + nx[k] > K)
                {
                    cut = 1;
                }
            }
            for (int k = 0; k < m; k++)
            {
                cur[k] = (cut ? 0 : cur[k]) + nx[k];
            }
            res += cut;
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> A(x), B(y), C(z);
    for(int i = 0; i < x; i++) cin >> A[i];
    for(int i = 0; i < y; i++) cin >> B[i];
    for(int i = 0; i < z; i++) cin >> C[i];
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    vector<ll> D;
    for(int i = 0; i < x; i++)
    {
        for(int j = 0; j < y; j++) D.push_back(A[i] + B[j]);
    }
    sort(D.begin(), D.end(), greater<ll>());
    vector<ll> ans;
    for(int i = 0; i < min(k, x * y); i++)
    {
        for(int j = 0; j < z; j++) ans.push_back(D[i] + C[j]);
    }
    sort(ans.begin(), ans.end(), greater<ll>());
    for(int i = 0; i < k; i++) cout << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 43112
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
    long long int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long int count = 0;
    for(int i = 0; i < N - 1; i++) {
        for(int j = i+1; j < N; j++) {
            if(A[i] > A[j]) {
                count++;
                count %= MOD;
            }
        }
    }
    long long int ans = 0;
    ans = count * K;
    ans %= MOD;
    count = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(A[j] > A[i]) {
                count++;
                count %= MOD;
            }
        }
    }
    ans += ((K * (K-1) / 2) % MOD) * count;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

result = 0

(1..(n-1)).each do |i|
  i2 = ("%#05d" % i).chars.map(&:to_i)
  j = ("%#05d" % (n - i)).chars.map(&:to_i)
  i_sum = 0
  j_sum = 0
  (0..4).each{|k| i_sum += i2[k]; j_sum += j[k] }
  sum = i_sum + j_sum
  if result == 0 || sum < result
    result = sum
  end
end

print result

Measured memory_bytes: 14256
import heapq
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
diff=[]
heapq.heapify(diff)
if n>=m:
    print(0)
else:
    for i in range(m-1):
        heapq.heappush(diff,x[i]-x[i+1]+1)
    temp=0
    for _ in range(n-1):
        temp-=heapq.heappop(diff)
    print(x[m-1]-x[0]+1-temp-n)

Measured memory_bytes: 14088
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


ll div_ceil(ll v, ll d)
{
	return (v+d-1)/d;
}


struct l_t
{
	ll a, d, l;
	l_t(ll a, ll d) : a(a), d(d) {l=div_ceil(a, d);}
	bool operator<(const l_t&rhs) const
	{
		return l<rhs.l;
	}
};


ll div_next(l_t&t)
{
	ll pd=t.d;
	ll x=div_ceil(t.a, t.d)-1;
	t.d=div_ceil(t.a, x);
	t.l=div_ceil(t.a, t.d);
	return t.d-pd;
}

struct solve
{
	solve(){}
	ll operator()(int n, ll k, vll&a) {
		ll a_sum=0;
		for(auto m:a) a_sum+=m;

		ll base=div_ceil(a_sum, k+1);

		priority_queue<l_t> q;
		for(int i=0;i<n;i++)
		{
			ll d=div_ceil(a[i], base);
			q.push(l_t(a[i], d));
			k-=d-1;
		}

		ll ans=a_sum;
		for(;;)
		{
			auto log=q.top();
			q.pop();
			min_u(ans, log.l);
			if(ans==1) break;
			k-=div_next(log);
			if(k<0) break;
			q.push(log);
		}
		return ans;
	}
};

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

	for(;;)
	{
		int n;
		ll k;
		cin >> n >> k;
		if(cin.fail()) break;
		vll a(n);
		for(auto&m:a) cin >> m;
		cout << solve()(n, k, a) << "\n";
	}
	return 0;
}


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

int K,S;
int main(){
  cin >> K >> S;
  int counter =0;
  for(int x=0; x <K+1; ++x){
    for(int y=0; y<K+1; ++y){
      if (S-x-y < K+1  && S-x-y> -1) ++counter;
    }
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,K,a[100010],dep[100010];
int q[100010],head=0,tail=0,cnt[100010];
int main(){
	int i,u,ans=0;
	n=read();K=read();
	a[1]=read();
	if(a[1]!=1) ans++,a[1]=1;
	for(i=2;i<=n;i++) a[i]=read(),cnt[a[i]]++;
//	for(i=1;i<=n;i++) cout<<cnt[i]<<ends;cout<<endl;
	for(i=1;i<=n;i++) if(!cnt[i]) q[tail++]=i;
	while(head<tail){
		u=q[head++];
//		cout<<"topo "<<u<<ends<<dep[u]<<endl;
		if(u==1) break;
		if(a[u]!=1&&dep[u]==K-1) ans++;
		else dep[a[u]]=max(dep[a[u]],dep[u]+1);
		cnt[a[u]]--;
		if(cnt[a[u]]==0) q[tail++]=a[u];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,x,t;cin>>n>>x>>t;
		ll y;
		if(n%x==0){
			y=n/x;
		}
		else{
			y=(n/x)+1;
		}
    cout<<y*t<<endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>
#include <bitset>
using namespace std;

int N,A[2020];
bitset<4000001> t;

int main()
{
	scanf ("%d",&N);
	t.set(0);
	int S = 0;
	for (int i=0;i<N;i++){
		scanf ("%d",&A[i]);
		t |= (t << A[i]);
		S += A[i];
	}

	int x = S;
	for (int i=0;i<=S;i++) if (t[i]){
		if (abs(S-2*x) > abs(S-2*i)) x = i;
	}
	printf ("%d\n",max(x,S-x));

	return 0;
}

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

def main():
    X, Y, A, B, C = list(map(int, input().split()))
    p = sorted(list(map(int, input().split())), reverse=True)[:X]
    q = sorted(list(map(int, input().split())), reverse=True)[:Y]
    r = sorted(list(map(int, input().split())) + p + q, reverse=True)[:(X+Y)]

    print(sum(r))

if __name__ == '__main__':
    main()

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


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;cin>>s;

  n=s.length();
  REP(i,n){
    if (s[i]=='?')s[i]='D';
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3724
package main

import "fmt"

import "strconv"

func main() {
	var S int
	fmt.Scan(&S)
	h := S / 3600
	m := (S / 60) % 60
	s := S % 60
	fmt.Println(strconv.Itoa(h) + ":" + strconv.Itoa(m) + ":" + strconv.Itoa(s))
}



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

using namespace std;

int main() {
    int k, t;
    cin >> k >> t;
    priority_queue<pair<int, int> > pq;
    for (int i=0; i<t; i++) {
        int a;
        cin >> a;
        pq.push(make_pair(a, i));
    }
    int curr = pq.top().second;
    if (pq.top().first == 1) {
        pq.pop();
    } else {
        int amount = pq.top().first;
        pq.pop();
        pq.push(make_pair(amount-1, curr));
    }
    int ans = 0;
    while (!pq.empty()) {
        auto topelem = pq.top();
        if (topelem.second == curr) {
            if (pq.size() > 1) {
                pq.pop();
                curr = pq.top().second;
                if (pq.top().first == 1) {
                    pq.pop();
                } else {
                    int amount = pq.top().first;
                    pq.pop();
                    pq.push(make_pair(amount-1, curr));
                }
                pq.push(topelem);
            } else {
                ans++;
                if (pq.top().first == 1) {
                    pq.pop();
                } else {
                    int amount = pq.top().first;
                    pq.pop();
                    pq.push(make_pair(amount-1, curr));
                }
            }
        } else {
            curr = pq.top().second;
            if (pq.top().first == 1) {
                pq.pop();
            } else {
                int amount = pq.top().first;
                pq.pop();
                pq.push(make_pair(amount-1, curr));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(key=lambda x: x[1], reverse=True)
ans = 0
for b, c in bc:
    b -= 1
    i = bisect.bisect_left(a, c)
    index = min(i - 1, b) + 1
    ans += index * c
    del a[:index]
print(sum(a) + ans)


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s < t){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1])
  exit()
a=a[:-1]
s=0
for k in range(1,len(a)*2+1):
  i,j = a[-k // 2]
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:
      x-=1;s+=1

print(s)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 N, K;
  cin >> N >> K;
  vi64 A(N);
  cin >> A;
  sort(all(A));
  i64 ok = i64(1e18) + 1, ng = -1e18 - 1;
  while (ok - ng > 1) {
    i64 m = (ok + ng) / 2;
    i64 cnt = 0;
    rep(i, N) {
      if (A[i] * A[i] <= m) cnt--;
    }
    int l = 0, r = N;
    if (m >= 0) {
      rrep(i, N) {
        if (A[i] <= 0) break;
        while (l < N && A[i] * A[l] <= m) l++;
        cnt += l;
      }
      rep(i, N) {
        if (A[i] > 0) break;
        while (r > 0 && A[i] * A[r - 1] <= m) r--;
        cnt += N - r;
      }
    } else {
      rrep(i, N) {
        if (A[i] <= 0) break;
        while (r > 0 && A[i] * A[r - 1] > m) r--;
        cnt += r;
      }
      rep(i, N) {
        if (A[i] > 0) break;
        while (l < N && A[i] * A[l] > m) l++;
        cnt += N - l;
      }
    }
    cnt /= 2;
    (cnt >= K ? ok : ng) = m;
  }
  cout << ok << endl;
}


Measured memory_bytes: 1792
using System;


namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split(' ');
            int r = int.Parse(input[0]);
            int c = int.Parse(input[1]);
            int[,] Ap = new int[r, c];
            for (int y = 0; y < r; y++)
            {
                String[] input2 = Console.ReadLine().Split(' ');
                for (int x = 0; x < c; x++)
                {
                    int R = int.Parse(input2[x]);
                    Ap[y, x] = R;
                }
            }
            int[] Asum = new int[r];
            int[] Bsum = new int[c];
            int asu = 0;
            int bsu = 0;
            for (int i = 0; i < r; i++)
            {
                asu = 0;
                for (int j = 0; j < c; j++)
                {
                    asu = asu + Ap[i, j];
                }
                Asum[i] = asu;
            }
            for (int i = 0; i < c; i++)
            {
                bsu = 0;
                for (int j = 0; j < r; j++)
                {
                    bsu = bsu + Ap[j, i];
                }
                Bsum[i] = bsu;
            }
            int Sum = 0;
            for (int i = 0; i < r; i++)
            {
                Sum = Sum + Asum[i];
            }
            int[,] Bout = new int[r + 1, c + 1];
            for (int i = 0; i < (r + 1); i++)
            {
                for (int j = 0; j < (c + 1); j++)
                {
                    if (i < r && j < c)
                    {
                        Bout[i, j] = Ap[i, j];
                    }
                    else if (i < r && j == c)
                    {
                        Bout[i, j] = Asum[i];
                    }
                    else if (i == r && j < c)
                    {
                        Bout[i, j] = Bsum[j];
                    }
                    else if (i == r && j == c)
                        Bout[i, j] = Sum;
                }
            }
            for (int i = 0; i < r + 1; i++)
            {
                for (int j = 0; j < c + 1; j++)
                {
                    Console.Write(Bout[i, j]);
                    if (j < c)
                        Console.Write(" ");
                }
                if (i <= r)
                    Console.WriteLine("");
            }
        }
    }
}

Measured memory_bytes: 9312
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.el = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


def main():
    import sys

    input = sys.stdin.readline

    n = int(input())  # 5 * 10 ** 5
    s = input().rstrip()

    base = ord('a')
    *s, = (ord(c) - base for c in s)

    q = int(input())  # 2 * 10 ** 4

    bits = [BIT(n + 1) for _ in range(26)]
    for i, x in enumerate(s, 1):
        bits[x].add(i, 1)

    ret = []
    for _ in range(q):
        query = iter(input().split())
        if next(query) == '1':
            # 変更
            pos = int(next(query))

            bf = s[pos - 1]
            char = ord(next(query)) - base

            bits[bf].add(pos, -1)
            s[pos - 1] = char

            bits[char].add(pos, 1)

        else:
            # 返答
            l = int(next(query))
            r = int(next(query))

            tt = 0
            for x in range(26):
                if bits[x].get(l - 1, r) > 0:
                    tt += 1
            ret.append(tt)

    print(*ret, sep='\n')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 248012
import math
N = int(input())
saidai = math.sqrt(2*N)
saidai = math.floor(saidai)
if saidai*saidai+saidai == 2*N:
    for i in range(1, saidai+1):
        print(i)
elif saidai*saidai+saidai < 2*N:
    saidai = saidai+1
    huyou = saidai*saidai+saidai-2*N
    if huyou % 2 == 0:
        huyou //= 2
        for i in range(1, saidai+1):
            if i == huyou:
                continue
            print(i)
    else:
        huyou = huyou//2+1
        for i in range(2, saidai+1):
            if i == huyou:
                continue
            print(i)
else:
    for i in range(saidai, 0, -1):
        if i*i+i < 2*N:
            newsaidai = i+1
            break
    saidai = newsaidai
    huyou = saidai*saidai+saidai-2*N
    if huyou % 2 == 0:
        huyou //= 2
        for i in range(1, saidai+1):
            if i == huyou:
                continue
            print(i)
    else:
        huyou = huyou//2+1
        for i in range(2, saidai+1):
            if i == huyou:
                continue
            print(i)

Measured memory_bytes: 9228