akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
  int n = 6, d[ n+1 ];
  for( int i = 1; i <= n; i++ ) {
    cin >> d[i];
  }

  string cmd;
  cin >> cmd;
  for( int i = 0; i <= cmd.size(); i++ ) {
    char c = cmd[i];
    int tmp;

    if( c == 'N' ){
      tmp = d[1]; d[1] = d[2]; d[2] = d[6]; d[6] = d[5]; d[5] = tmp;
    }
    if( c == 'S' ){
      tmp = d[1]; d[1] = d[5]; d[5] = d[6]; d[6] = d[2]; d[2] = tmp;
    }
    if( c == 'E' ){
      tmp = d[1]; d[1] = d[4]; d[4] = d[6]; d[6] = d[3]; d[3] = tmp;
    }
    if( c == 'W' ){
      tmp = d[1]; d[1] = d[3]; d[3] = d[6]; d[6] = d[4]; d[4] = tmp;
    }
  }
  cout << d[1] << endl;

  return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int w, a, b;
    cin >> w >> a >> b;

    if((a <= b && b <= a+w) || (a <= b+w && b+w <= a+w)) {
        cout << 0 << endl;
    } else {
        cout << min(abs(a-b),min(abs(a+w-b), abs(a-(b+w))));
    }
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
S = str(input())
T = str(input())
S_d = {}
T_d = {}
trans_d = {}
for i,j in zip(S,T):
    if i in S_d and j in T_d:
        if S_d[i] == T_d[j]:
            if trans_d[i] == j:
                pass
            else:
                print("No")
                break            
        else:
            print("No")
            break
    else:
        if i in S_d or j in T_d:
            print("No")
            break
        else:
            if S.count(S) == T.count(T):
                S_d[i] = S.count(S)
                T_d[j] = T.count(T)
                trans_d[i] = j
            else:
                print("No")
                break
        
else:
    print("Yes")

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

int main() {
	char c[5][5];

	for (int i = 0;i<3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}

	cout << c[0][0] << c[1][1] << c[2][2] << endl;

	return 0;
}

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

using namespace std;

int main()
{
    int a, b, k;
    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: 3632
#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;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int n, k;
		cin >> n >> k;
		if(cin.fail()) break;
		vi p(n);
		for(auto&m:p) cin >> m;

		sort(p.begin(), p.end());
		int ans=0;
		for(int i=0;i<k;i++) ans+=p[i];
		cout << ans << "\n";
	}
	return 0;
}


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

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

using namespace std;
using lint=long long;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

int main(){
	lint n,a,b,k; cin>>n>>a>>b>>k;

	mint ans=0;
	rep(i,n+1) if(i*a<=k && (k-i*a)%b==0) {
		int j=(k-i*a)/b;
		ans+=choose(n,i)*choose(n,j);
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int binary_search(int s[], int n, int k)
{
    int head = 0;
    int tail = n-1;
    int middle = (head+tail)/2;

    while(head <= tail){
        if (s[middle] == k){
            return 1;
        }else if (s[middle] > k) {
            tail = middle - 1;
            middle = (head+tail)/2;
        }else {
            head = middle + 1;
            middle = (head + tail) / 2;
        }
    }
    return 0;
}

int main()
{
    int n, q;
    scanf("%d", &n);
    int s[n];
    for (int i = 0; i < n; i++){
        scanf("%d", &s[i]);
    }
    scanf("%d", &q);
    int t[q];
    int cnt = 0;
    for(int i = 0; i < q; i++){
        scanf("%d", &t[i]);
        if(binary_search(s, n, t[i])) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[101][4][2];
// dp[i][j][k]
// i個までの桁を見ている時
// j個の非ゼロを使い
// k:0なら今の所Nと一致
// k:1ならすでにN以下が確定している

int main(){
  string s;cin>>s;
  int k;cin>>k;
  int n=s.size();
  dp[0][0][0]=1;

  rep(i, s.size())rep(j, 4)rep(kk, 2){
    int c = s[i]-'0';
    rep(d, 10){
      int ni=i+1, nj=j, nk=kk;

      if(d != 0) nj++;
      if(nj>k)continue;

     if(kk==0){
        // 前のTまでNと一致していて、見ている桁がNよりも大きいならN超過確定なので無視
        if(d>c)continue;
        if(d<c)nk=1;
      }

      dp[ni][nj][nk] += dp[i][j][kk];

    }
  }

  cout<<dp[n][k][0]+dp[n][k][1]<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int ans=0,b=0,n,m,d,a[550][550],i,j,k;
char x;
scanf("%d %d %d\n",&n,&m,&d);
for(i=0;i<500;i++){
for(j=0;j<500;j++){
a[i][j]=1;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%c",&x);
if(x=='.'){
a[i][j]=0;
}
}
scanf("\n");
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
for(k=j;k<j+d;k++){
if(a[i][k]==1){
b=1;
break;
}
}
if(b==0){
ans++;
}
b=0;
}
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
for(k=j;k<j+d;k++){
if(a[k][i]==1){
b=1;
break;
}
}
if(b==0){
ans++;
}
b=0;
}
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 2812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=10001;
char a[N][N];
int main()
{
	int x,y,i,j;
	cin>>x>>y;
 	for(i=1;i<=x;i++)
 	{
 		for(j=1;j<=y;j++)
 		{
 			cin>>a[i][j];
		 }
	 }
	 for(i=1;i<=y+2;i++)
	 {
	 	cout<<'#'; 
	 }
	 cout<<endl;
	 for(i=1;i<=x;i++)
	 {
	 	cout<<"#";
	 	for(j=1;j<=y;j++)
	 	{
	 		cout<<a[i][j];
		 }
		 cout<<"#";
		 cout<<endl;
 }
	 for(i=1;i<=y+2;i++)
	 {
	 	cout<<'#'; 
	 }
	 return 0;
}


Measured memory_bytes: 640
;

import java.io.*;
import java.util.*;

public class Main {

	static int n;
	static long [][]dp;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new  BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int h = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
		char [][] g = new char [h][w];
		for (int i=0;i<h;i++)
		{
			String s = br.readLine();
			for(int j=0;j<s.length();j++)
			{
				g[i][j]=s.charAt(j);
			}
		}
		dp=new long [h][w];
		for(int i=0;i<h;i++)
		{
			Arrays.fill(dp[i], -1);
		}
		long ans = path(g,h-1,w-1);
		ans = ans%(7+1000000000L);
		System.out.println(ans);
		
	}	public static long path(char [] [] g , int h, int w)
	{
		if(h==0&&w==0)
			return 1;
		else
		{
			long s1=0;
			long s2=0;
			if(h-1>-1)
				if(g[h][w]=='.')
					if(dp[h][w]==-1)
					{
						s1=path(g, h-1, w)%(7+1000000000L);
					}
					else
						return dp[h][w];
			if(w-1>-1)
					if(g[h][w]=='.')
						if(dp[h][w]==-1)
						{
							s2=path(g,h,w-1)%(7+1000000000L);
						}
						else
							return dp[h][w];
			dp[h][w]=(s1+s2)%(7+1000000000L);
			return dp[h][w];
		}
		
	}
}

Measured memory_bytes: 37140
N = input()
A = input()
B = input()

A = [int(i) for i in A.split(" ")]
B = [int(i) for i in B.split(" ")]

count = 0
remaining_num = 0
for i in range(0, len(A)):
    if i > 0:
        if A[i] <= B[i-1]:
            count += A[i]
            B[i-1] -= A[i]
            A[i] = 0
        else:
            count += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0
    if i < len(B):
        if A[i] <= B[i]:
            count += A[i]
            B[i] -= A[i]
            A[i] = 0
        else:
            count += B[i]
            A[i] -= B[i]
            B[i] = 0

print(count)

Measured memory_bytes: 19520
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long


/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1e9 + 7;
vector<char> s;
int memor[5000],memog[5000],memob[5000];
int main() {
    INIT();

    string s;
    char ic, jc,kk;
    int n = 0,i = 0,j;
    ll result = 0;
    cin >> n;
    cin >> s;
    REP(i, n) {
        memor[n - i] = memor[n - i + 1];
        memog[n - i] = memog[n - i + 1];
        memob[n - i] = memob[n - i + 1];
        if(*(s.end() - i - 1) == 'R') {
            memor[n - i]++;
        } else if(*(s.end() - i - 1) == 'G') {
            memog[n - i]++;
        } else {
            memob[n - i]++;
        }
    }
    while(i < n - 2) {
        j = i + 1;
        ic = s[i];
        while(j < n - 1) {
            jc = s[j];
            if(ic != jc) {
                if((jc == 'R' || ic == 'R') && (jc == 'G' || ic == 'G')) {
                    kk = 'B';
                    result += memob[j + 1];
                } else if((jc == 'R' || ic == 'R') && (jc == 'B' || ic == 'B')) {
                    kk = 'G';
                    result += memog[j + 1];
                } else {
                    kk = 'R';
                    result += memor[j + 1];
                }
                
                if(s.begin() + j + j - i < s.end() && s[j + j - i] == kk) {
                    result--;
                }
            }
            j++;
        }
        i++;    
    }
    cout << fixed << result;
    return 0;
}

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

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int ans;
	ans = A + B + C;

	int m = max(A, max(B, C));
	ans += m * 10 - m;

	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##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    const ll d[][2] = {{0, 1}, {1, 0}};
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    queue<pair<ll, ll>> q;
    q.push(make_pair(0, 0));
    vector<vector<ll>> dist(h, vector<ll>(w, inf));
    dist[0][0] = 0;
    while(!q.empty()) {
        pair<ll, ll> p = q.front(); q.pop();
        ll cnt = 0;
        rep(i, 2) {
            ll nx = p.first + d[i][0];
            ll ny = p.second + d[i][1];
            ll nd = dist[p.second][p.first] + 1;
            if ((nx < 0) || (nx >= w) || (ny < 0) || (ny >= h)) continue;
            if (s[ny][nx] != '#') continue;
            if (dist[ny][nx] <= nd) continue;
            dist[ny][nx] = nd;
            q.push(make_pair(nx, ny));
            cnt++;
        }
        if (cnt > 1) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    bool f = true;
    rep(i, h) {
        rep(j, w) {
            if ((s[i][j] == '#') && (dist[i][j] == inf)) {
                f = false;
            }
        }
    }
    cout << (f ? "Possible" : "Impossible") << endl;
    return 0;
}


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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i, h) cin >> c[i];
  // int tot = 0;
  // rep(i, h) rep(j, w) if (c[i][j] == '#') tot++;
  int ans = 0;
  for (int hb = 0; hb < (1 << h); hb++) {
    for (int wb = 0; wb < (1 << w); wb++) {
      vector<string> tc = c;
      for (int th = 0; th < h; th++) {
        for (int tw = 0; tw < w; tw++) {
          
          if (hb & (1 << th)) {
            rep(i, w) tc[th][i] = 'x';
          }
          
          if (wb & (1 << tw)) {
            rep(i, h) tc[i][tw] = 'x';
          }
        }
      }
      int cnt = 0;
      rep(i, h) rep(j, w) {
        if (tc[i][j] == '#') cnt++;
      }
      if (cnt == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,h,w,a,b,sum=0;
	cin>>n>>h>>w;
	rep(i,n/2){
		cin>>a>>b;
		b=w-b;
		sum+=abs(a-b);
	}
	ll ans=h*((n/2)*w-sum);
	cout<<ans<<endl;

}


Measured memory_bytes: 3188
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    const MAX: usize = 100_000;
    let primes = enumerate_primes(MAX);
    let mut s: Vec<usize> = vec![0; MAX + 1];
    let mut i = 3;
    while i <= MAX {
        if primes.contains(&i) && primes.contains(&((i + 1) / 2)) {
            s[i] = s[i - 2] + 1;
        } else {
            s[i] = s[i - 2];
        }
        i += 2;
    }

    let q: usize = iterator.next().unwrap().parse().unwrap();
    let mut result = String::new();
    for _ in 0..q {
        let l: usize = iterator.next().unwrap().parse().unwrap();
        let r: usize = iterator.next().unwrap().parse().unwrap();

        let sl = if l == 1 {
            0
        } else {
            s[l - 2]
        };
        let sr = s[r];
        result.push_str(&format!("{}\n", sr - sl));
    }
    return result.trim().to_string();
}

fn enumerate_primes(n: usize) -> std::collections::HashSet<usize> {
    let mut primes = std::collections::HashSet::new();
    for i in 2..(n + 1) {
        primes.insert(i);
    }
    for i in 2..(n + 1) {
        if primes.contains(&i) {
            let mut j = i * 2;
            while j <= n {
                primes.remove(&j);
                j += i;
            }
        }
    }
    return primes;
}


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

int main(){
    int a,b,c; cin >> a >> b >> c;
    if(a!=b && b==c){
        cout << "Yes" << endl;
    }else if(a==b && b!=c){
        cout << "Yes" << endl;
    }else if(a==c && b!=a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

vector<bool> ise(1001, false);
void calc() {
  for (int i=2; i<=9; i++) {
    int j = 1;
    while(pow(j,i)<=1000) {
      ise[pow(j,i)] = true;
      j++;
    }
  }
  return;
}

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

  calc();

  while(true) {
    if(ise[X]) break;
    X--;
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())

vol = a * a * b

if x <= vol // 2:
    tmp = 2 * x / (a*b)
    ans = math.atan(b / tmp)
else:
    tmp = 2 * x / (a**2) - b
    tmp = b - tmp
    ans = math.atan(tmp / a)
print(math.degrees(ans))


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

int main(){
    string s;
    cin >> s;
    int c,d;
    char a;
    for(int i=0;i<4;i++){
        if(s[0]==s[i]){
            c++;
        }else{
            a=s[i];
        }
    }
    for(int i=0;i<4;i++){
        if(a==s[i]){
            d++;
        }
    }
    if(c==2&&d==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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


int main() {
    int A, B;
    cin >> A >> B;
    int ans;
    if (B % A == 0) ans = A + B;
    else ans = B - A;
    cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  double heikin=0;
  rep(i,n) {
    cin >> a[i];
    heikin+=a[i];
  }
  heikin/=n;
  double div=10000000;
  int ans=0;
  rep(i,n) {
    if (abs(heikin-a[i])<div) {
      div=abs(heikin-a[i]);
      ans=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
N,K,S = map(int,input().split())
rand_val = 10**6+3534
A = []
for i in range(K):
    A.append(S)
for i in range(N-K):
    A.append(rand_val)
s = ''
for i in range(N):
    s += '%i '%(A[i])
print(s[:-1])

Measured memory_bytes: 8216
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	char pc, c;
	ll L[N]={};
	rep(i, N){
		if (i==0){
			pc=S[0];
			continue;
		}
		c = S[i];
		L[i] = L[i-1];
		if (pc=='A' && c=='C'){
			L[i]++;
		}
		pc = c;
	}
	rep(i, Q){
		ll l, r;
		cin >> l >> r;
		cout << L[r-1]-L[l-1] << endl;
	}

}








Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,k,w[100001];
bool test(ll d){
    int cnt=1;
    ll sum=0;
    rep(i,n){
        if(sum+w[i]>d){
            ++cnt;
            if(d>=w[i])sum=w[i];
            else return false;
        }
        else sum+=w[i];
    }
    if(cnt<=k) return true;
    else return false;
}
int main(){
    cin>>n>>k;
    rep(i,n) cin>>w[i];
    ll lb=0,ub=1000100010001000;
    while(ub-lb>1){
        ll mid=(lb+ub)/2;
        if(test(mid)) ub=mid;
        else lb=mid;
    }
    cout<<ub<<endl;
    return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if (b - a <= x) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int count = 0;

void quick_sort(int a[],int first,int last){

  int temp,k;
  int flag=1;
  int p=a[first];
  int i=first;
  int j=last;

  while(flag){
    while(a[i]<p)
      i++;
    
    while(p<a[j])
      j--;
    
    if(i<j){
      temp=a[i];  a[i]=a[j];  a[j]=temp;
      count++;
      i++;  j--;
    }
    else
      flag=0;
  }

  if(count ==2)
    return ;

  if(first<i-1)
    quick_sort(a,first,i-1);
  
  if(j+1<last)
    quick_sort(a,j+1,last);
  
}


int main(void){
  int N, i;
  scanf("%d", &N);
  int p[N];
  for(i=0; i<N; i++)
    scanf("%d", &p[i]);

  quick_sort(p, 0, N-1);

  if(count == 1 || count == 0)
    printf("YES\n");
  else if(count > 1)
    printf("NO\n");


  return 0;
}


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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    if ((n & (n - 1)) == 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    vector<pair<int, int>> res;
    res.push_back({n + 1, 2});

    for (int i = 2; i + 1 <= n; i += 2) {
        res.push_back({i, i + 1});
        res.push_back({i + 1, 1});
        res.push_back({1, n + i});
        res.push_back({n + i, n + i + 1});
    }
    if (n % 2 == 0) {
        int x = 1;
        while (x * 2 <= n) x *= 2;
        int y = n - x;
        res.push_back({n, x + 1});
        res.push_back({n + n, y + n});
    }

    for (auto e : res) {
        cout << e.first << " " << e.second << "\n";
    }
//    for (auto e : res) {
//        cout << (e.first - 1) % n + 1 << " " << (e.second - 1) % n + 1 << "\n";
//    }

    return 0;
}

Measured memory_bytes: 4080
#include <iostream>
using namespace std;
int N;
int main(){
	cin >> N;
	int ans = 0;
	for(int i=2;i<=N;i++){
		int num = 1,n = i;
		for(int j=2;j*j<=N;j++){
			int t = j,count = 0;
			while(n%t==0){
				count++;
				n /= t;
			}
			num *= count+1;
		}
		if(num==8 && i%2==1){
//			cout << i << endl;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	int m,n,count=0,a;
	while(true){
		cin>>m;
		if(m==0){
			break;
		}
		else{
			cin>>n;
			for(int i=m;i<n+1;i++){
				a=i;
				while(true){
					if(a%2==0){
					a/=2;
					}
					if(a%3==0){
					a/=3;
					}
					if(a%5==0){
					a/=5;
					}
					if(a%2!=0&&a%3!=0&&a%5!=0){
					break;
					}
				}
					if(a==1){
					count++;
					}
			}
			cout<<count<<endl;
			count=0;
		}
	}
}

Measured memory_bytes: 1160
n=int(input())
s=input()
ans=0
anss=0
for i in range(1,n):
    migi=list(set(list(s[:i])))
    hidari=list(set(list(s[i:])))
    for j in migi:
        if j in hidari:
            anss+=1
    ans=max(ans,anss)
    anss=0
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int inf = 1e18;

signed main(){
    
    int n,k;
    cin>>n>>k;

    int ar[n];

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

    sort(ar,ar+n);

    int L = -inf,R = +inf;

    while(L+1<R){
          
          int MID = (L + R)/2;

          int cnt =0;

          for(int i=0;i<n;i++){
               
               if(ar[i] < 0 ){
                 
                  int l = i,r = n;

                  while(l+1 < r){
                      
                      int mid = (l+r)/2;
                      if(ar[i]*ar[mid] <= MID)r = mid;
                     else l = mid;
                  }

                  cnt += n - r;

               }else{
                 
                  int l = i,r = n;

                  while(l+1 < r){
                      
                      int mid = (l+r)/2;
                      if(ar[i]*ar[mid] <= MID)l = mid;
                     else r = mid;
                  }

                  cnt += l -i;

               }

          }

          if(cnt < k)L = MID;
         else R = MID;           

    }

    cout<<R<<endl;

	return 0;
}

Measured memory_bytes: 1792
from sys import stdin
input = stdin.readline

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

start = 0
money = 1000

for i in range(N - 1):
    if A[i + 1] > A[i]:
        tmp = 10 ** 3
        for k in range(i, start - 1, -1):
            tmp = min(A[k], tmp)
        buy = money // tmp
        money -= tmp * buy
        money += buy * A[i + 1]
        start = i + 1

print(money)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = abs(a[n-1]-w);
    if (n>1) {
        chmax(ans, abs(a[n-1]-a[n-2]));
    } 
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll b[N + 1]{};
    for (int i = 0; i < N; i++) {
        b[i + 1] = b[i] + A[i];
    }
    ll A_MAX = 2 * 100000 + 1;
    ll d[A_MAX]{}; // d[i]: パワーi以上を持つ人の数
    for (int i = 0; i < N; i++) {
        d[A[i]]++;
    }
    for (int i = A_MAX - 1; i >= 1; i--) {
        d[i - 1] += d[i];
    }
    ll l = -1;
    ll r = A_MAX;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll s = 0;
        for (int i = 0; i < N; i++) {
            s += d[max(0ll, m - A[i])];
        }
        if (s >= M) {
            l = m;
        } else {
            r = m;
        }
    }
    
    ll ans = 0;
    ll s = 0; // 握手した人の合計 
    for (int i = 0; i < N; i++) {
        int v = max(0, (int)(r - A[i]));
        ll t = max(0ll, min(d[v], M - s));
        ans += b[t] + t * A[i];
        s += t;
    }
    ans += l * (M - s);
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3328
H, W = map(int, input().split())
S = [input() for i in range(H)]

ans = []
for i in S:
    ans.append(list(i))

dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]

for y in range(H):
    for x in range(W):
        if S[y][x] == '#':
            continue
        c = 0
        for dx, dy in dxy:
            if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1:
                continue
            if S[y + dy][x + dx] == '#':
                c += 1
        ans[y][x] = c

for row in ans:
    print(''.join(list(map(str, row))))

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;

int n;
pair<ll, int> A[2000 + 10];

ll dp[2000 + 10][2000 + 10];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> A[i].first, A[i].second = i;

	sort(A, A + n, greater<pair<ll, int>>());

	for (int i = 0; i <= n; i++)for (int j = 0; j <= n; j++)dp[i][j] = -1;
	dp[0][0] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; i + j <= n; j++) {
			if (dp[i][j] == -1)continue;
			int banme = i + j;
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A[banme].first * (A[banme].second - i));
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + A[banme].first * (n - 1 - A[banme].second - j));
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ans = max(ans, dp[i][n - i]);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;


int N, M;
vector<int>A, B;
vector<int>C;

constexpr auto INF = 1000000001;


int main()
{

	cin >> N;
	cin >> M;

	A = vector<int>(M);
	B = vector<int>(M);
	C = vector<int>(M);

	for (int i = 0; i < M; i++) {
		cin >> A[i];
		cin >> B[i];

		int c = 0;
		for (int j = 0; j < B[i]; j++) {
			int tmp;
			cin >> tmp;
			c |= (1 << tmp-1);		
		}
		C[i] = c;
	}

	int S = 1 << N;
	

	auto dp = vector<int>(S,INF);
	dp[0] = 0;


	for (int i = 0; i < M; i++) {
		for (int s = 0; s < S; s++) {
			dp[s | C[i]] = min(dp[s | C[i]], dp[s] + A[i]);
		}
	}

	int ans = dp[S-1];

	cout << (ans == INF ? -1 : ans) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200005
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
using namespace std;
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}
int n,m,fa[N],sg[N],x,y;
int nedge,Next[N*2],head[N],to[N*2];
void add(int a,int b){
	Next[++nedge]=head[a];head[a]=nedge;to[nedge]=b;
}
#define V to[i]
void dfs(int x){
	for (int i=head[x];i;i=Next[i]){
		if (V!=fa[x]){
			fa[V]=x;
			dfs(V);
			sg[x]^=(sg[V]+1);
		}
	}
}
signed main(){
	n=read();
	for (int i=1;i<n;i++){
		x=read();y=read();add(x,y);add(y,x);
	}
	dfs(1);
	if (sg[1]==0) puts("Bob");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
double dist(double x, double y){
  return sqrt(x * x + y * y);
}

int main(){
  int N;
  int CASE = 1;
  while(cin>>N && N){
    printf("Case %d: ", CASE++);
    double x[14][2], y[14][2];
    double d[14];
    double ds[14][14][2][2];
    REP(i, N){
      REP(j, 2) cin>>x[i][j]>>y[i][j];
      d[i] = dist(x[i][0] - x[i][1] , y[i][0] - y[i][1]);
    }
    REP(i, N)FOR(j, i + 1, N){
      REP(k, 2)REP(l, 2){
        ds[i][j][k][l] = ds[j][i][l][k] = dist(x[i][k] - x[j][l], y[i][k] - y[j][l]);
      }
    }
    double dp[1<<14][14][2];
    REP(i, 1<<N)REP(j, N)REP(k, 2) dp[i][j][k] = INF;
    REP(i, N)REP(k, 2) dp[1<<i][i][k] = d[i];
    REP(S, 1<<N){
      REP(from, 2 * N){
        int f_i = from / 2;
        int f_j = from % 2;
        if(!(S & 1 << f_i)){
          from++;
          continue;
        }
        REP(to, 2 * N){
          int t_i = to / 2;
          int t_j = to % 2;
          if(S & 1<<t_i){
            to++;
            continue;
          }
          dp[S | (1<<t_i)][t_i][t_j] = min(dp[S | (1<<t_i)][t_i][t_j],
              //dp[S][f_i][f_j] + dist(x[f_i][f_j] - x[t_i][(t_j + 1) % 2], y[f_i][f_j] - y[t_i][(t_j + 1) % 2]) + d[t_i]);
              dp[S][f_i][f_j] + ds[f_i][t_i][f_j][(t_j + 1) % 2] + d[t_i]);
        }
      }
    }
    double ans = 1e16;
    REP(i, N)REP(j, 2) ans = min(ans, dp[(1<<N) - 1][i][j]);
    
    printf("%.5f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#define int long long
using namespace std;

int search(string s,int pos){
	int cnt=0;
	while (pos < s.size() and s[pos] == '.'){
		++pos;
		++cnt;	
	}
	return cnt;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h,w;
	cin >> h >> w;
	vector<string> v(h);
	for (int i=0; i<h; ++i){
		cin >> v[i];
	}
	vector<vector<int>> vv(h,vector<int>(w,-1));
	vector<vector<int>> vh(h,vector<int>(w,-1));
	for (int i=0; i<h; ++i){
		for (int j=0; j<w; ++j){
			if (v[i][j] == '.'){
				if (j == 0 or vh[i][j-1] == -1){
					vh[i][j] = search(v[i],j);
				}
				else vh[i][j] = vh[i][j-1];
			}
		}
	}
	for (int i=0; i<w; ++i){
		string s;
		for (int j=0; j<h; ++j) s += v[j][i];
		for (int j=0; j<h; ++j){
			if (v[j][i] == '.'){
				if (j == 0 or vv[j-1][i] == -1){
					vv[j][i] = search(s,j);
				}
				else vv[j][i] = vv[j-1][i];
			}
		}
	}
	int maxi=0;
	for (int i=0; i<h; ++i){
		for (int j=0; j<w; ++j){
			if (v[i][j] == '.') maxi=max(maxi,vv[i][j]+vh[i][j]-1);
		}
	}
	cout << maxi;
	return 0;
}

Measured memory_bytes: 67200
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	ll n , k  ;
	cin>> n >> k  ;
	vector<ll> a(n) ;
//	ll neg = 0 , pos = 0 , zero = 0 ;  
	for(ll &x : a) {
		cin>> x ; 
		
	}
	sort(a.begin() , a.end()) ; 
	ll p1 = -1e18 ; 
	ll p2 = 1e18 ; 
   while(p2 !=  p1 +  1){
	   ll mid  = (p1 + p2)/2 ; 
	   ll cnt = 0 ; 
	   for(int i = 0 ; i < n ; ++i){
		   if(a[i] < 0 ){
			   ll l = i  , en = n ; 
			   while(l + 1 != en){
				   ll m = (l + en)/2 ; 
				   if(a[i]*a[m] <= mid) en = m ; 
				   else l = m ; 
			   }
			   cnt+=(n-en) ; 
			   
		   }
		   else{
			   ll l = i  , en = n ; 
			   while( l + 1 != en ){
				  ll  m = (l + en)/2 ; 
				  if(a[i]*a[m] <= mid) l = m ; 
				  else en = m ; 
			  }
			  cnt+=(l -i );    
			   
		   }
	  
}
  if(cnt <  k){
	      p1 = mid ; 
	  }
	      else 
	      p2 = mid ; 
	   
   } 
  cout<<p2<<endl;
 
 
 
}



Measured memory_bytes: 1792
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;

long long int N,M,A[200200]={},memo[100040]={},res=0,cou=0,num,fi=0,se=0;
string S;
int main()
{
    cout << fixed << setprecision(18);
	cin>>N;
	if(N==1e18){
		cout<<0<<" "<<0<<" "<<1000000000<<" "<<0<<" "<<0<<" "<<1000000000<<endl;
	}else{
		cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" "<<1000000000-1-(N-1)%1000000000<<" "<<((N-1)/1000000000+1)<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int i,j,H,W;
	while(scanf("%d %d",&H,&W)!=EOF)
	{
		if(H==0&&W==0)
		{
			break;
		}
		for ( i = 0; i < H; i++ )
		{
		for ( j = 0; j < W; j++ )
			{
				printf("#");
			}
			
			printf("\n");
		}
		printf("\n");
	}
	return(0);
}


Measured memory_bytes: 2120
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var d=int.Parse(Console.ReadLine());
			if(d==0)break;
			Sol mySol=new Sol(d);
			mySol.writeAns();
		}
	}
}


class Sol{
	int sizeofA;
	int cnt;
	int colors;
	public void writeAns(){
		if(cnt>sizeofA/2)Console.WriteLine(colors);
		if(cnt<=sizeofA/2)Console.WriteLine("NO COLOR");
	}
	
	public Sol(int d){
		sizeofA=d;
		int[] arr=Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
		Dictionary<int,int> Dict=new Dictionary<int,int>();
		
		for(int i=0;i<arr.Length;i++){
			if(Dict.ContainsKey(arr[i])==false){
				Dict.Add(arr[i],0);
			}
			Dict[arr[i]]+=1;
		}
		cnt=0;
		foreach(KeyValuePair<int,int> kvp in Dict){
			if(kvp.Value>=cnt){
				cnt=kvp.Value;
				colors=kvp.Key;
			}
		}
	}
}

Measured memory_bytes: 94636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = null;
            while (true) {
                line = reader.readLine();
                if (line == null) {
                    return;
                }
                if (!line.isEmpty()) {
                    break;
                }
            }
            int[][] map = new int[14][14];
            for (int y = 1; y <= 12; y++) {
                for (int x = 1; x <= 12; x++) {
                    map[y][x] = line.charAt(x - 1) - '0';
                }
                line = reader.readLine();
            }
            int result = 0;
            for (int y = 1; y <= 12; y++) {
                for (int x = 1; x <= 12; x++) {
                    if (map[y][x] == 0) {
                        continue;
                    }
                    erase(map, x, y);
                    result++;
                }
            }
            out.println(result);
        }
    }

    private static void erase(int[][] map, int x, int y) {
        if (map[y][x] == 0) {
            return;
        }
        map[y][x] = 0;
        erase(map, x + 1, y);
        erase(map, x - 1, y);
        erase(map, x, y + 1);
        erase(map, x, y - 1);
    }
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int solve(int a, int b) {
    int n = sqrt(a*b);
    int ans = 2*(n-1)-1;
    if (n == a && n == b) ans++;
    if (n*n < a*b) ans++;
    if (n*(n+1) < a*b) ans++;
    return ans;
}

int32_t main() {
    int q; cin >> q;
    while (q--) {
        int a,b; cin >> a >> b;
        cout << solve(a,b) << endl;
    }
}


Measured memory_bytes: 256