akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n, i, j, dt, dist;

  scanf("%d", &n);

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

  int flag = 1;
  for(i = 0; i < n; i++){
    dt = point[i + 1][0] - point[i][0]; 
    dist = abs(point[i + 1][1] - point[i][1]) + abs(point[i + 1][2] - point[i][2]);
    if(dist > dt)flag = 0; 
    if(dist % 2 != dt % 2)flag = 0; 
  }

  if(flag)printf("Yes\n");
  else printf("No\n");

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    rep(i, n) cout << "ACL";
    cout << endl;
    return;
}

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

Measured memory_bytes: 3536
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <complex>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <functional>
#include <string>
#include <sstream>
// #include <tuple>
// #include <regex>

using namespace std;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define FOR(i,l,r) for(int i=(int)l;i<(int)r;++i)
#define REP(i,n) FOR(i,0,n)
#define FORr(i,l,r) for(int i=(int)r-1;i>=(int)l;--i)
#define REPr(i,n) FORr(i,0,n)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

template<typename T,typename U> T pmod(T x,U M){return (x%M+M)%M;}

stringstream ss;

const int H=3,W=3;
vector<vector<short>> goal;
vector<vector<short>> ts,ys,xs;

map<vector<vector<short>>,int> vmap;
map<vector<vector<short>>,int> passed;

int INF=1<<28;
int dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
int dfs(const int y,const int x,const int py,const int px,const int dep){
	if(dep>30)return INF;
	int wa=0;REP(_y,H)REP(_x,W)if(goal[_y][_x]!=ts[_y][_x])wa++;
	if(wa==0)return dep;
	if(wa>30-dep+1)return INF;
	
	int res=INF;
	REP(d,4){
		const int ny=y+dy[d],nx=x+dx[d];
		if(!IN(0,ny,H) || !IN(0,nx,W))continue;
		if(ny==py && nx ==px)continue;
		if(y==ny){//rotate X
			swap(xs[ny][nx],ts[y][x]);
			swap(ys[ny][nx],ys[y][x]);
			swap(ts[ny][nx],xs[y][x]);
			res=min(res,dfs(ny,nx,y,x,dep+1));
			swap(xs[ny][nx],ts[y][x]);
			swap(ys[ny][nx],ys[y][x]);
			swap(ts[ny][nx],xs[y][x]);
		}else{//rotate Y
			swap(ys[ny][nx],ts[y][x]);
			swap(xs[ny][nx],xs[y][x]);
			swap(ts[ny][nx],ys[y][x]);		
			res=min(res,dfs(ny,nx,y,x,dep+1));
			swap(ys[ny][nx],ts[y][x]);
			swap(xs[ny][nx],xs[y][x]);
			swap(ts[ny][nx],ys[y][x]);
		}
	}
	return res;
}
short enc(char c){
	if(c=='B')return 0;
	if(c=='W')return 1;
	if(c=='R')return 2;
	return 3;
}

int main(){
 // 	ifstream cin("in");
	// ofstream cout( "out" );
	cin.tie(0);
	ios::sync_with_stdio(false);
	ss   <<fixed <<setprecision(20);
	cout <<fixed <<setprecision(20);
	cerr <<fixed <<setprecision(20);

	while(true){
		int X,Y;cin >> X >> Y;if(Y==0 && X==0)break; Y--;X--;
		ts=vector<vector<short>>(H,vector<short>(W));
		xs=ys=vector<vector<short>>(H,vector<short>(W));
		goal=vector<vector<short>>(H,vector<short>(W));
		REP(y,H)REP(x,W){char c;cin >> c;goal[y][x]=enc(c);}
		REP(y,H)REP(x,W)if(y==Y && x==X) ys[y][x]=3; else ys[y][x]=2;
		REP(y,H)REP(x,W)if(y==Y && x==X) xs[y][x]=3; else xs[y][x]=0;
		REP(y,H)REP(x,W)if(y==Y && x==X) ts[y][x]=3; else ts[y][x]=1;
		int res=dfs(Y,X,-1,-1,0);
		if(res==INF)cout << -1 <<endl;
		else cout << res <<endl;
	}

 	return 0;
 }

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  
#define mp make_pair
#define s second 
#define f first
#define ll long long
#define pb push_back
  
using namespace std;
/*
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  */
const int inf = 2e9+7;
const int N = 2e6;

int used[N];
 
int xx[8]={1, 1, -1, -1, 2, 2, -2, -2};
int yy[8]={2, -2, 2, -2, 1, -1, 1, -1};

int m[3003][3003];

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
	string s, t;
	cin >> s >> t;
	string ans="";
	int k=0;
	for(int i=0; i<s.size(); i++){
		for(int j=0; j<t.size(); j++){
			if(s[i]==t[j]){
				m[i][j]+=1;
			}	
			if(i!=0 && j!=0)
					m[i][j]=max(m[i-1][j-1]+m[i][j], max( m[i-1][j], m[i][j-1]));	
			else if(i==0)
				m[i][j]=max(m[i][j], m[i][j-1]);
			else if(j==0)
				m[i][j]=max(m[i][j], m[i-1][j]);
			
			
		}
	
	}
	
	int i=s.size()-1, j=t.size()-1;
	while(i>=0 && j>=0){
		if(m[i][j]==0)
			break;
		if(i==0){
			if(j==0){
				ans+=s[i];
				break;	
			}
			if(m[i][j-1]==0){
				ans+=s[i];
				break;
			}
			else{
				j--;
				continue;	
			}
		}	
		if(j==0){
			if(m[i-1][j]==0){
				ans+=t[j];
				break;
			}
			else{
				i--;
				continue;
			}
		}
		if(m[i-1][j-1]==m[i][j]){
			i--;
			j--;	
		}
		else if(m[i][j-1]==m[i][j])
			j--;
		else if(m[i-1][j]==m[i][j]){
			i--;
		}
		else{
			ans+=s[i];
			i--;
			j--;	
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}



Measured memory_bytes: 37120
let () =
  let n = read_int () in
  let rec doit i m ans =
    if i >= n then ans
    else let r = read_int () in let x = r - m in doit (i + 1) (min m r) (max ans x)
  in
  Printf.printf "%d\n" (doit 1 (read_int ()) min_int)

Measured memory_bytes: 4488
//arc079_c.cpp
//Fri Jun  8 08:08:00 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int ship[n] = {};

	for (int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		if (a==0){
			ship[b]++;
		}if (b==n-1){
			ship[a]++;
		}
	}

	int flag = 0;

	for (int i=0;i<n;i++){
		if (ship[i] == 2){
			flag = 1;
			cout << "POSSIBLE" << endl;
			break;
		}
	}

	if (flag == 0){
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 1024
//Sorting Three Numbers
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String[] abc = in.readLine().split(" ");

		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);

		if (a <= b && b <= c) {
			System.out.println(a + " " + b + " " + c);
		} else if (a <= c && c <= b) {
			System.out.println(a + " " + c + " " + b);
		} else if (b <= a && a <= c) {
			System.out.println(b + " " + a + " " + c);
		} else if (b <= c && c <= a) {
			System.out.println(b + " " + c + " " + a);
		} else if (c <= a && a <= b) {
			System.out.println(c + " " + a + " " + b);
		} else if (c <= b && b <= a) {
			System.out.println(c + " " + b + " " + a);
		}
	}
}

Measured memory_bytes: 17076
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long  ll ;
#pragma GCC optimize "trapv"
#define     endl                        '\n'
#define     fi                          first
#define     sec                         second
#define     pb                          push_back
#define 	fio 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define 	sz(x) 						(int)x.size()
void solve(){
    fio;
    string s;
	cin>>s;
	int rem=0;
	for(auto ch:s){
		rem+=ch-'0';
	}
	rem%=9;
	if(rem==0){cout<<"Yes"<<endl;return;}
	cout<<"No"<<endl;return;

}
int main(){
    fio;
    
    int test;
    // cin>>test;
    test=1;
    while(test--){
        solve();
    }
    return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

vector<string>S(3);
REP(i,3) cin >> S.at(i);

REP(i,3) cout << S.at(i).at(i);

cout << endl;

}

Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    ans = ""
    
    while True:
        n = int(f_i.readline())
        
        if n == 0:
            break
        
        result = []
        
        for i in range(n):
            score = f_i.readline()
            
            t = score[0]
            win = score.count('0')
            lose = score.count('1')
            
            result.append((-win, lose, i, t))
        
        result.sort()
        
        ans += '\n'.join(map(lambda x: x[-1], result))
        ans += '\n'
    
    print(ans, end='')

solve()


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int m, n;
	cin>>n>>m;
	int a[n][n];
	memset(a,0x3f,sizeof(a));
	set<array <int,3> >s;
	for(int i = 0;i <n; i++)
		a[i][i]=0;

	for(int i = 0,j,k,c ;i<m;i++)
	{
		cin>>j>>k>>c ,--j, --k;
		a[j][k]= c;
		a[k][j]= c;
		s.insert({j,k,c});
	}

    int ans=m;
	for(int k = 0; k<n;k++)
		for(int i = 0;i <n; i++)
			for(int j = 0; j<n; j++)
				a[i][j] = min(a[i][j],a[i][k]+a[k][j]);

	for(auto it:s)
	{
		int flag = 0;
		for(int i = 0;i<n; i++)
			for(int j =0; j<n; j++)
			{
				if((a[i][it[0]]+a[it[1]][j]+it[2])==a[i][j])
				{
					flag =1 ;
					break;
				}
			}
		if(flag)
			ans--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1005;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m,x;cin>>n>>m>>x;
    ll c[n],a[n][m];
    for(ll i=0;i<n;i++){
        cin>>c[i];
        for(ll j=0;j<m;j++)cin>>a[i][j];
    }
    ll ans = (1e15);
    for(ll mask=0;mask<(1ll<<n);mask++){
        vector<ll> skill(m,0);
        ll cur = mask , cost = 0 ,pos = 0;
        while(cur){
            if(cur&1){
                for(ll j=0;j<m;j++)skill[j]+=a[pos][j];
                cost+=c[pos];
            }
            cur>>=1;
            pos++;
        }

        bool f=1;
        for(ll j=0;j<m;j++)if(skill[j]<x)f=0;
        if(f)ans=min(ans,cost);
    }

    if(ans>=(1e15))cout<<"-1";
    else cout<<ans;
}


Measured memory_bytes: 3668
#!/usr/bin/env ruby

n = gets.chomp.to_i

list = []
n.times do
  action, num = gets.chomp.split

  case action
  when 'insert'
    list.unshift(num.to_i)
  when 'delete'
    i = list.index(num.to_i)
    list.delete_at(i) if i
  when 'deleteFirst'
    list.shift
  when 'deleteLast'
    list.pop
  end
end

puts list * ' '

Measured memory_bytes: 21296
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

total=0
for i in range(n):
    if b[i]>=a[i]:
        total+=a[i]
        x=min(b[i]-a[i],a[i+1])
        a[i+1]-=x
        total+=x
    else:
        total+=b[i]
print(total)

Measured memory_bytes: 19244
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		while(a[i]%2==0){
			a[i]/=2;
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3648
#include <stdio.h>

int cnt = 0;
int p = 0;
char c;

int main(void){
    while(true){
       c = getchar();
       if(c == EOF or c == '\n' or c == '\0') break;
       if(c == 'p') p++;
       cnt++; 
    }
    printf("%d\n", cnt/2 - p);
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, D int
	fmt.Scanf("%d %d", &N, &D)
	X := make([][]int, N)
	for i := 0; i < N; i++ {
		X[i] = make([]int, D)
		for j := 0; j < D; j++ {
			fmt.Scanf("%d", &X[i][j])
		}
	}

	count := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			d := 0
			for k := 0; k < D; k++ {
				d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
			}
			for n := 1; n*n <= d; n++ {
				if n*n == d {
					count++
					break
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define rrep1(i,x) for(int i = x ; i > 0 ; i --)
#define fr first
#define sc second
#define pb push_back

int main(){
	int n,m,k=0;
	int s[50010],t[50010],e[50010];
	scanf("%d%d",&n,&m);
	while(1){
		scanf("%d%d%d",&s[k],&t[k],&e[k]);
		if(s[k] == 0)break;
		k ++;
	}
	int l;
	scanf("%d",&l);
	rep(ppp,l){
		int b[10010];
		for(int i = 1 ; i <= m ; i ++){
			scanf("%d",&b[i]);
		}
		int c[10010] = {};
		for(int i = 0 ; i < k ; i ++){
			c[s[i]] += b[t[i]] * e[i];
		}
		for(int i = 1 ; i <= n ; i ++){
			printf("%d%c",c[i],(i != n)?' ':'\n');
		}
	}
}

Measured memory_bytes: 1860
#include <stdio.h>
int main()
{
	int x,y,z,t,i,n;
	scanf("%d %d %d",&x,&y,&z);
	n=x/y;
	for(i=n;i>=1;i--)
	{
		if(i*y+(i+1)*z<=x)
		{
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
        "fmt"
)

func main() {
        var (
                c500, c100, c50, given_amount int
        )

        fmt.Scan(&c500, &c100, &c50, &given_amount)
        count := 0
        for i := 0; i <= c500; i++ {
                for j := 0; j <= c100; j++ {
                        for k := 0; k <= c50; k++ {
                                sum := i*500 + j*100 + k*50
                                if sum == given_amount {
                                        count += 1
                                }
                        }
                }
        }
        fmt.Println(count)
}

Measured memory_bytes: 512
//By Koios1143
#include<bits/stdc++.h>
#define LL long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
using namespace std;
const int MaxN = 100005;
int n,now,dp[MaxN][3];
int main(){
	IOS
	while(cin>>n){
		for(int i=1 ; i<=n ; i++){
			for(int j=0 ; j<3 ; j++){
				cin>>now;
				dp[i][j]=max(dp[i-1][(j+1)%3], dp[i-1][((j+2)%3)]) + now;
			}
		}
		int ans=0;
		for(int i=0 ; i<3 ; i++){
			ans=max(ans, dp[n][i]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 4748
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        long[] A = new long[N+1];
        long[] B = new long[M+1];
        for (int i = 0; i < N; i++) {
            A[i+1] = A[i]+sc.nextInt();
        }
        for (int i = 0; i < M; i++) {
            B[i+1] = B[i]+sc.nextInt();
        }

        int ans = 0;
        for (int i = 0; i <=N ; i++) {

            if(A[i]>K){
 //               ans = Math.max(ans,i);
            }else if(A[i]==K){
                  ans = Math.max(ans,i);
            }else{
                int books = binarySearch(A[i],K,B);
                ans = Math.max(ans,books+i);
            }
        }

        System.out.println(ans);
    }

    //a-B[i]<= K , find max books
    static
    int binarySearch(long a,int K, long[] B){

        int l = 0;
        int r = B.length;

        while(l+1<r){
            int mid = (l+r)/2;
            if(a+B[mid]<=K){ //OK
                l=mid;
            }else{//NG
                r=mid;
            }
        }


        return l;

    }
}

Measured memory_bytes: 63724
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e6+10;
char s[maxn];
int n;
int dp[maxn][2];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s+1;
	n=strlen(s+1);
	reverse(s+1,s+n+1);
	dp[1][0]=s[1]-'0';
	dp[1][1]=10-s[1]+'0';
	s[n+1]='0';
	for(int i=2;i<=n+1;i++){
		dp[i][0]=min(dp[i-1][0]+s[i]-'0',dp[i-1][1]+s[i]-'0'+1);
		dp[i][1]=min(dp[i-1][0]+10-s[i]+'0',dp[i-1][1]+9-s[i]+'0');
	}
	cout<<min(dp[n+1][0],dp[n+1][1])<<endl;
	return 0;
}
/*
1020
919

*/

Measured memory_bytes: 9088
import Control.Monad
import Data.Functor

main :: IO ()
main = do
  n <- readLn
  as <- join <$> (replicateM n $ map read . words <$> getLine) :: IO [Int]
  print . length . filter isPrime $ as


isPrime :: Int -> Bool
isPrime 1 = False
isPrime 2 = True
isPrime n = all (\i -> not $ n `mod` i == 0) (2:[3,5..(1 + (truncate . sqrt $ fromIntegral n))])



Measured memory_bytes: 9888
#include<iostream>

using namespace std;

int main(){

    string S;
    cin >> S;
    char c = S[0];
    int count = 0;
    for (int i = 1; i < S.size(); i++){
        if(c != S[i]){
            count++;
        }
        c = S[i];
    }
    if(count == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int n,i;
char c[500005];
unsigned long long h,s[250005],ans,t;
map<unsigned long long,unsigned long long> m;
unsigned long long qpow(unsigned long long a,unsigned long long b)
{
	unsigned long long ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a;
		a=a*a;
		b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",c+1);
	unsigned long long inv=qpow(250001,9223372036854775807ull);
	s[0]=1;
	for(i=1;i<=n;++i)
	{
		s[i]=s[i-1];
		if(c[i]=='<')
			s[i]*=inv;
		if(c[i]=='>')
			s[i]*=250001;
	}
	for(i=n;i>=1;--i)
	{
		if(c[i]=='+')
			++t;
		if(c[i]=='-')
			--t;
		if(c[i]=='<')
			t=t*inv;
		if(c[i]=='>')
			t=t*250001;
	}
	++m[0];
	for(i=n;i>=1;--i)
	{
		if(c[i]=='+')
			++h;
		if(c[i]=='-')
			--h;
		if(c[i]=='<')
			h=h*inv;
		if(c[i]=='>')
			h=h*250001;
		ans+=m[(h-t)*s[i-1]];
		++m[h*s[i-1]];
	}
	cout<<ans;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int modPow(long long a, long long n, long long p) {
    if (n == 0) return 1;
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}

int main() {
	string S; cin >> S;
	int size = S.size();
	vector<ll> right(size);
	map<int, int> m;
	for(int i = size - 1; i >= 0; i--) {
		if(i == size - 1) {
			right[size - 1] = S[size - 1] - '0';
			m[right[size - 1]] = 1;
			continue;
		}
		right[i] = (right[i + 1] + (S[i] - '0') * modPow(10, size - 1 - i, 2019)) % 2019;
		if(!m.count(right[i])) m[right[i]] = 1;
		else m[right[i]]++;
	}
	int ans = 0;
	for(auto p: m) {
		ans += (p.second * (p.second - 1)) / 2;
		if(p.first == 0) ans += p.second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5076
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 14 17:08:52 2018
ABC076C
@author: maezawa
"""

sp = list(input())
t = list(input())

def can_replace(s, t):
    for i in range(len(t)):
        if t[i] == s[i] or s[i] == '?':
            continue
        else:
            return False
    return True

lt = len(t)
i = len(sp)-lt
ok = False
while i >=0:
    spc = sp[i:i+lt]
    if can_replace(spc,t):
        sp[i:i+lt] = t
        ok = True
        break
    i -= 1
if ok:
    for i in range(len(sp)):
        if sp[i] == '?':
            sp[i] = 'a'

    s = ''.join(sp)
    print(s)
else:
    print('UNRESTORABLE')
        

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>


void calc(int **a,int *d,int *nusuke,int k,int n);


void calc(int **a,int *d,int *nusuke,int k,int n){
  int i,j;
  int count=0;
  
  for(i=0; i<k; i++){
    scanf("%d",&d[i]);
    a[i] = (int*)calloc(d[i],sizeof(int));
    for(j=0; j<d[i]; j++){
      scanf("%d",&a[i][j]);
    }
  }
  
  for(i=0; i<k;i++){
    for(j=0; j<d[i]; j++){
      nusuke[a[i][j]-1] += 1;
    }
  }
  
  for(i=0; i<n; i++){
    if (nusuke[i] == 0) count++;
  }
  printf("%d\n",count);
  return ;
}


int main (void){
  int n,k;
  int **a;
  int *d;

  int *nusuke;

  if (scanf("%d %d",&n,&k) == 2){
    a = (int**) calloc(k,sizeof(int*));
    d = (int*) calloc(k,sizeof(int));
    nusuke = (int*) calloc(n,sizeof(int));

    calc(a,d,nusuke,k,n);
   
    free(nusuke);
    free(a);
    free(d);
  }
  


  return 0;
  
}


Measured memory_bytes: 1736
from sys import exit
N = int(input())
H = [int(n) for n in input().split()]
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
tmp = H[0]
ans = 1
for i in range(1,len(H)):
    if(tmp <= H[i]):
        ans+=1
        tmp = H[i]
print(ans)


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

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double x = x2 - x1;
	double y = y2 - y1;

	cout << fixed << setprecision( 10 );
	cout << sqrt( x*x + y*y ) << endl;
}



Measured memory_bytes: 3276
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bits/stdc++.h>
#include <set>
#include <vector>
#include <queue>
#include <bitset>
#define NL << endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define fill(x, y) memset(x, y, sizeof(y))
#define debug(x)                          \
    {                                     \
        cerr << #x << " = " << x << endl; \
    }
#define inarr(arr, n)                            \
    {                                       \
        for(int i =0;i<n;i++){              \
            cin >> arr[i];                  \
        }                                   \
    }
typedef long long ll;
const int MOD = 1e9 + 7;
using namespace std;

void solve()
{
    ll n, w;
    cin >> n >> w;

    ll wei[n];
    ll val[n];


    for(int i =0 ;i <n;i++){
        ll wi, vi;  cin >> wi >> vi;
        wei[i] = wi;
        val[i] = vi;
    }

    ll dp[n+1][w+1];

    for(int i =0;i<= w;i++){
        dp[0][i] = 0;
    }

    for(int i =1;i<=n;i++){
        
        for(int j=0;j<= w;j++){
            if(j - wei[i-1] >= 0){
                dp[i][j] = max(dp[i-1][j], val[i-1] + dp[i-1][j - wei[i-1]]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[n][w] << endl;
    



}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; t = 1; 
    // int t; cin >> t;
    while (t--)
        solve();
}


Measured memory_bytes: 82440
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    int ans=0;
    int high=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        high=max(a,high);
        if(a==high) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

def main():
    n = int(input())
    colA, colB, colC = map(int, input().split())
    for i1 in range(1, n):
        a, b, c = map(int, input().split())
        colA, colB, colC = a + max(colB, colC), b + max(colA, colC), c + max(colA, colB)
    print(max(colA, colB, colC))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()

typedef unsigned long long ll;

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){ 
ll L,R; cin >> L >> R;

if(R - L >=2018){
	cout << 0 << endl;
}
else{
	int x = L % 2019;
	int y = R % 2019;
	
	if(x >= y){
		cout << 0 << endl;
	}
	else{
		int ans = 2018;
		for(int i = x; i < y; i++){
			for(int j = i+1; j <= y; j++){
				ans = min(ans,i*j %2019);
			}
		}
		cout << ans << endl;
	}
}
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n <= k){
    cout << n*x << endl;
  }else{
    cout << k*x + (n-k)*y << endl;
  }
  return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b); 
    int64_t ans;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) ans = 0;
    else ans = (int64_t)a * b;
    cout << ans << endl;
}

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

int main(){
  string S ; 
  cin >> S ; 
  
  int N = S.size() ; 
  
  if( S.at(N-1) == 's'){
    for(int i = 0 ; i < N ; i++) cout << S.at(i) ;
    cout << "es" << endl ; 
  }
  else {
    cout << S << "s" << endl ; 
  }

}

Measured memory_bytes: 3632
#include<cstdio>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}p;
p Q[LEN];
int tail, head, n;
void initialize()
{
    tail = 0;
    head = 0;
}
void enqueue(p temp)
{
    Q[tail] = temp;
    tail = (tail + 1) % LEN;
}
p dequeue()
{
    p temp = Q[head];
    head = (head+1) % LEN;

    return temp;
}
int min(int a,int b)
{
    return a > b ? b : a;
}
int main()
{
    int elaps = 0, c;
    int i,q;
    p u;
    scanf("%d %d", &n, &q);

    for(i = 1; i <= n; i++)
    {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    // Initialize
    head = 1;
    tail = n + 1;

    while( head != tail)
    {
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0)
            enqueue(u);
        else
            printf("%s %d\n",u.name,elaps);
    }

    return 0;
}



Measured memory_bytes: 12840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
  int N; cin >> N;
  vector<vector<int>> seat(N, vector<int>(N));
  vector<vector<bool>> on(N, vector<bool>(N, true));
  vector<pair<int, int>> P(N * N);
  rep(a, N * N) {
    int x; cin >> x; x--;
    P[a] = make_pair(x / N, x % N);
  }

  rep(a, N) rep(b, N) {
    seat[a][b] = min({a, N - 1 - a, b, N - 1 - b});
  }

  long long ans = 0;
  rep(i, N * N) {
    int a, b;
    tie(a, b) = P[i];
    ans += seat[a][b];
    on[a][b] = false;
    queue<pair<int, int>> q;
    q.emplace(a, b);
    while(!q.empty()) {
      int x, y;
      tie(x, y) = q.front(); q.pop();
      int minnext = seat[x][y] + 1;
      if (!on[x][y]) minnext--;

      rep(d, 4) {
        int nx = x + dx[d], ny = y + dy[d];
        if (min(nx, ny) < 0 || max(nx, ny) >= N) continue;
        if (seat[nx][ny] > minnext) {
          seat[nx][ny] = minnext;
          q.emplace(nx, ny);
        }
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
    int N;
    long long x;
    cin >> N >> x;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    long long result = 0;
    if (a[0] > x) result += a[0] - x, a[0] = x;
    for (int i = 0; i+1 < N; ++i) {
        if (a[i] + a[i+1] > x) {
            result += a[i] + a[i+1] - x;
            a[i+1] = x - a[i];
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	// 入力
	ll N;
	cin >> N;
	vec A(N);
	
	ll ans=1;
	ll dec=false;
	ll inc=false;

	REP(i, N) {
		cin >> A[i];
	}

	REP(i,N-1){
		if(!dec && !inc){
			if(A[i+1]>A[i]) inc=true;
			else if(A[i+1]<A[i]) dec=true;
		}

		if(dec && A[i+1]>A[i]) {
			ans++;
			dec=false;
			inc=false;
		}
		if(inc && A[i+1]<A[i]) {
			ans++;
			dec=false;
			inc=false;
		}
	}



	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string N; cin>>N;
	ote("ABC"+N);
}


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

using namespace std;

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

    vector<int> B(N), ans(N);
    for (int i = 0; i < N; ++i) cin >> B[i];

    bool ok = true;
    for (int n = N - 1; n >= 0; --n) {
        ans[n] = 0;
        for (int i = B.size() - 1; i >= 0; --i) {
            // cout << n << ' ' << B[i] << endl;
            if (B[i] == i + 1) {
                B.erase(B.begin() + i);
                ans[n] = max(ans[n], i + 1);
                break;
            }
            if (B[i] > i + 1) {
                ok = false;
                break;
            }
        }
        if (!ok)
            break;
    }

    if (ok) {
        for (int i = 0; i < N; ++i)
            cout << ans[i] << endl;
    } else {
        cout << -1 << endl;
    }
}

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

namespace ABC118
{
    class Program
    {
        static void Main(string[] args)
        {
             
           int A, B,C;
            var word = Console.ReadLine().Split(' ');
            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            if (B % A == 0)
                C = A + B;
            else
                C = B - A;

            Console.WriteLine(C);
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void){

int n,ai,i,min,max;

long sum;

sum=0;

min=1000000;

max=-1000000;

scanf("%d",&n);

for(i=1;i<=n;i++){

scanf("%d ",&ai);

sum += ai;

if(min>ai){

min =ai;

}

if(min>ai){

min=ai;

} if(max<ai){

max=ai;

}

}

printf("%d %d %lld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 604
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;



int main( int argc , char ** argv ){
	
	string S;
	cin >> S;

	vector<string> add;
	add.push_back("dreameraser");
	add.push_back("dreamerase");
	add.push_back("dreamer");
	add.push_back("dream");
	add.push_back("eraser");
	add.push_back("erase");


	int str_count = 0;
	while(1){

		if(str_count == S.length()) {
			cout << "YES" << endl;
			break;
		}
		bool change = false;
		for(auto _add : add){

			string mini_S = S.substr( str_count ,  _add.length());
			//cout << _add << " , " << mini_S << endl;
			if( mini_S == _add ){
				str_count += mini_S.length();
				change = true;
				break;
			}
		}
		if(!change){
			cout << "NO" << endl;
			break;
		}
	}



}



Measured memory_bytes: 512
from collections import deque

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

togo = deque()
togo.append((0, 0))

reached = [[float('inf') for _ in range(W)] for _ in range(H)]
reached[0][0] = 1

while len(togo):

    h, w = togo[0][0], togo[0][1]
    togo.popleft()

    for d in range(4):
        nh, nw = h + dy[d], w + dx[d]
        if nh < 0 or nw < 0 or nh >= H or nw >= W:
            continue
        if maze[nh][nw] == '#':
            continue
        if reached[nh][nw] != float('inf'):
            continue
        togo.append((nh, nw))
        reached[nh][nw] = reached[h][w] + 1

if reached[H-1][W-1] == float('inf'):
    print(-1)
else:
    n_wall = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '#':
                n_wall += 1

    n_road = H * W - n_wall
    print(n_road - reached[H-1][W-1])


Measured memory_bytes: 3444
table = {alphabet: "-" for alphabet in "abcedfghijklmnopqrstuvwxyz"}
rev_table = {alphabet: "-" for alphabet in "abcedfghijklmnopqrstuvwxyz"}

s = str(input())
t = str(input())

flag = True

for i in range(len(s)):
    if table[s[i]] == t[i]:
        continue
    elif table[s[i]] == "-":
        table[s[i]] = t[i]
    else:
        flag = False
        break

for i in range(len(t)):
    if rev_table[t[i]] == s[i]:
        continue
    elif rev_table[t[i]] == "-":
        rev_table[t[i]] = s[i]
    else:
        flag = False
        break

if flag is True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 41584
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int func(int n,int m,vector<vector<char> >v)
{
    int ans[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            ans[i][j]=0;
    }
    if(v[0][0]=='#')
        ans[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i==0 and j==0)
                continue;
            if(i==0)
            {
                if(v[i][j]=='#')
                {
                    if(v[i][j-1]=='.')
                        ans[i][j]=ans[i][j-1]+1;
                    else
                        ans[i][j]=ans[i][j-1];
                }
                else
                    ans[i][j]=ans[i][j-1];
            }
            else
            {
                if(j==0)
                {
                    if(v[i][j]=='#')
                    {
                        if(v[i-1][j]=='.')
                            ans[i][j]=ans[i-1][j]+1;
                        else
                            ans[i][j]=ans[i-1][j];
                    }
                    else
                        ans[i][j]=ans[i-1][j];
                }   
                else
                {
                    int tans=min(ans[i-1][j],ans[i][j-1]);
                    if(v[i][j]=='#')
                    {
                        int a,b;
                        if(v[i-1][j]=='#')
                            a=ans[i-1][j];
                        else
                            a=ans[i-1][j]+1;
                        if(v[i][j-1]=='#')
                            b=ans[i][j-1];
                        else
                            b=ans[i][j-1]+1;
                        ans[i][j]=min(a,b);
                    }
                    else
                        ans[i][j]=tans;
                }
            }
        }
    }
    return ans[n-1][m-1];
}

int main()
{
    fastio;
    int n,m;
    cin >> n >> m;
    vector<vector<char> >v(n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            char c;
            cin >> c;
            v[i].push_back(c);
        }
    }
    int ans1=func(n,m,v);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(v[i][j]=='#')
                v[i][j]='.';
            else
                v[i][j]='#';
        }
    }
    int ans2=func(n,m,v);
    cout << min(ans1,ans2+1) << endl;
}

Measured memory_bytes: 384
d, g = gets.split.map(&:to_i)
num_problems = []
bonus = []
d.times { |i| num_problems[i], bonus[i] = gets.split.map(&:to_i) }

ans = 1000000000
(2**d).times do |pattern|
  cnt = 0
  score = 0
  d.times do |i|
    next if pattern[i] == 0

    score += num_problems[i] * 100 * (i + 1) + bonus[i]
    cnt += num_problems[i]
  end

  next if cnt > ans

  if score < g
    id = nil
    (d - 1).downto(0) do |i|
      if pattern[i] == 0
        id = i
        break
      end
    end
    diff = (g - score - 1) / (id + 1) / 100 + 1
    next if diff > num_problems[id]

    cnt += diff
  end
  ans = cnt if ans > cnt
end

puts ans

Measured memory_bytes: 1788
use input::*;
use std::cmp::*;
use std::f64::consts::PI;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let r = int() as f64;
    println!("{}", r * 2.0 * PI)
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 100000000000000000000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define nl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll c2(ll n){
	return (n*(n-1))/2;
}
ll solveneg(vector<ll>vec,ll neg,ll pos,ll k){
	ll n,i,z,j;
	n=vec.size();
	vector<ll>negs(vec.begin(),vec.begin()+neg);
	vector<ll>poss(vec.begin()+n-pos,vec.end());
	
	ll lo=negs[0]*poss.back();
	ll hi=poss[0]*negs.back();
	
	reverse(negs.begin(), negs.end());
	reverse(poss.begin(), poss.end());
	while(lo<=hi){
		ll mid=(lo+hi)/2;
		ll c=0;
		for(i=0,j=0;i<negs.size();i++){
			for(;j<poss.size() && negs[i]*poss[j]<=mid;j++);
			c+=j;
		}
		if(c<k){
			lo=mid+1;
		}else{
			hi=mid-1;
		}
	}
	return lo;
}
ll solvepos(vector<ll>vec,ll neg,ll pos,ll k){
	ll n,i,j;
	n=vec.size();
	vector<ll>negs(vec.begin(),vec.begin()+neg);
	vector<ll>poss(vec.begin()+n-pos,vec.end());
	reverse(negs.begin(), negs.end());
	ll lo=INT_MAX;
	ll hi=INT_MIN;
	if(negs.size()>=2){
		lo=min(lo,negs[0]*negs[1]);
		hi=max(hi,negs[neg-1]*negs[neg-2]);
	}
	if(poss.size()>=2){
		lo=min(lo,poss[0]*poss[1]);
		hi=max(hi,poss[pos-1]*poss[pos-2]);
	}
	while(lo<=hi){
		ll mid=(lo+hi)/2;
		ll c=0;
		for(i=pos-1,j=0;i>=0;i--){
			for(;j<i&&poss[i]*poss[j]<=mid;j++);
			c+=min(i,j);
		}
		for(i=neg-1,j=0;i>=0;i--){
			for(;j<i&&negs[i]*negs[j]<=mid;j++);
			c+=min(i,j);
		}
		if(c<k){
			lo=mid+1;
		}else{
			hi=mid-1;
		}
	}
	return lo;
}
void solve(){
	ll n,i,k,pos=0,neg=0,z=0;
	in2(n,k);
	vll vec(n);
	nfl(i,n){
		in(vec[i]);
		if(vec[i]==0)
			z++;
		if(vec[i]>0)
			pos++;
		if(vec[i]<0)
			neg++;
	}
	sort(vec.begin(), vec.end());
	ll negp=pos*neg;
	ll zerp=c2(z)+z*(n-z);
	ll posp=c2(pos)+c2(neg);
	ll ans;
	if(k<=negp){
		ans=solveneg(vec,neg,pos,k);
	}else if(k<=zerp+negp){
		ans=0;
	}else{
		ans=solvepos(vec,neg,pos,k-zerp-negp);
	}
	cout<<ans<<nl;
}	
int main(){
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	


Measured memory_bytes: 4864
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextLong

  val divs = 0 +: (1 to 10).flatMap(i => Array.fill(i + 1)(i))
  val primes: LazyList[Int] = 2 #:: (LazyList.from(3, 2) filter {n =>
    primes takeWhile {_ <= Math.sqrt(n).toInt} forall {n % _ != 0}
  })

  def div(n: Long, ps: LazyList[Int], c: Int): Int = {
    if (n == 1L) c
    else if (ps.head >= 1000000) c + 1
    else {
      def divCount(n0: Long, p: Long, c0: Int): (Long, Int) = {
        if (n0 % p == 0) divCount(n0 / p, p, c0 + 1)
        else (n0, c0)
      }
      val (n0, c0) = divCount(n, ps.head, 0)
      div(n0, ps.tail, c + divs(c0))
    }
  }

  println(div(N, primes, 0))
}

Measured memory_bytes: 62608
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var N = Read().ToInt64();
            var l = new List<long>();
            var r = ReadSplit();
            for (int i = 0; i < N; i++)
            {
                l.Add(r[i].ToInt64());
            }

            var mod = 1000000007;
            double ans = 0;
            for (int i = 0; i < 60; i++)
            {
                double x = 0;
                double y = 0;
                for (int j = 0; j < N; j++)
                {
                    if ((l[j] >> i & 1) == 1)
                    {
                        x++;
                    }
                    else y++;
                }
                double tmp = (x * y) % mod;
                ans += (tmp * Math.Pow(2, i)) % mod;
            }
            WriteRead(ans % mod);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToInt64(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 50632
import collections
n=int(input())
s=[]
a=0

for i in range(n):
    b=list(input())
    b.sort()
    b=str(b)
    s.append(b)

c=collections.Counter(s)

for i in c.values():
    if i>1:
        a+=i*(i-1)//2

print(a)

Measured memory_bytes: 28816
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    y, m, d = input().split('/')
    ymd = int(y + m + d)
    if ymd <= 20190430:
        print('Heisei')
    else:
        print('TBD')


if __name__ == '__main__':
    main()


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

long long INF = (1 << 31) - 1;

class LazySegmentTree {
private:
	long long Size;
	vector<long long> Node, Lazy;
public:
	LazySegmentTree(long long N) {
		Size = 1;
		while (Size < N) Size <<= 1;
		Node.assign(Size * 2, 0);
		Lazy.assign(Size * 2, 0);
	}
	void Eval(long long K, long long L, long long R) {
		if (Lazy[K] != 0) {
			Node[K] += Lazy[K];
			if (R - L > 1) {
				Lazy[K * 2] += Lazy[K];
				Lazy[K * 2 + 1] += Lazy[K];
			}
			Lazy[K] = 0;
		}
	}
	void Update(long long A, long long B, long long X, long long K, long long L, long long R) {
		Eval(K, L, R);
		if (B <= L || R <= A) return;
		if (A <= L && R <= B) {
			Lazy[K] += X;
			Eval(K, L, R);
			return;
		}
		Update(A, B, X, K * 2, L, (L + R) / 2);
		Update(A, B, X, K * 2 + 1, (L + R) / 2, R);
		Node[K] = min(Node[K * 2], Node[K * 2 + 1]);
	}
	void Update(long long A, long long B, long long X) {
		Update(A, B, X, 1, 0, Size);
		return;
	}
	long long Query(long long A, long long B, long long K, long long L, long long R) {
		Eval(K, L, R);
		if (B <= L || R <= A) return INF;
		if (A <= L && R <= B) return Node[K];
		return min(Query(A, B, K * 2, L, (L + R) / 2), Query(A, B, K * 2 + 1, (L + R) / 2, R));
	}
	long long Query(long long A, long long B) {
		return Query(A, B, 1, 0, Size);
	}
};

int main() {
	long long N, Q;
	cin >> N >> Q;
	LazySegmentTree Seg(N);
	for (int i = 0; i < Q; i++) {
		long long Mode;
		cin >> Mode;
		if (Mode == 0) {
			long long A, B, X;
			cin >> A >> B >> X;
			Seg.Update(A, B + 1, X);
		}
		else {
			long long A, B;
			cin >> A >> B;
			cout << Seg.Query(A, B + 1) << endl;
		}
	}
}


Measured memory_bytes: 7064