akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef set <string> SS;
SS SA;
SS SB;

bool checkA( string s ) {
    return SA.count( s ) > 0;
}

bool checkB( string s ) {
    return SB.count( s ) > 0;
}

string solve( string s ) {
    if ( checkA( s ) ) return "A";
    if ( checkB( s ) ) return "B";
    return "NA";
}

int main() {
    for ( int i = 1; i <= 100; ++ i ) {
        SA.insert( ">'" + string( i, '=' ) + "#" + string( i, '=' ) + "~" );
    }
    for ( int i = 1; i <= 100; ++ i ) {
        VS con( i, "Q=" );
        SB.insert( ">^" + accumulate( con.begin(), con.end(), string() ) + "~~" );
    }
    int n;
    cin >> n;
    for ( int i = 0; i < n; ++ i ) {
        string s;
        cin >> s;
        cout << solve( s ) << endl;
    }
    return 0;
}

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define read        freopen("in.txt", "r", stdin)
#define write       freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define PB push_back
#define F first
#define S second
#define MP make_pair

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

const int M = 998244353 ;
const int MAX = (2e5) + 10;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int x, v;

int main() {
    ios::sync_with_stdio(false);
    //read;
    //write;

    cin >> v;
    while(x < v) {
        x += 1000;
    }
    cout << x - v << endl;
    return 0;
}



Measured memory_bytes: 3608
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 200005;
# define INF 1000000001
# define MOD 1000000007
# define pb push_back

string s[55];
int t[55];

int main ()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int ans = 0;
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
        if (flag) ans += t[i];
        if (x == s[i]) {
            flag = true;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	int n,k,a,b,c;
	cin>>n>>k;
	cout<<(n-1)*(k-1)<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void) {
    double r, area, circumference;
    const double PI = 3.141592653589793;
    scanf("%lf", &r);

    area = r * r * PI;
    circumference = (r + r) * PI;

    printf("%lf %lf\n", area, circumference);
    return 0;
}


Measured memory_bytes: 2072
from collections import Counter

n = int(input())
V = list(map(int, input().split()))

even = V[0::2]
odd = V[1::2]
even_max_cnt = Counter(even).most_common(2)
odd_max_cnt = Counter(odd).most_common(2)

if even_max_cnt[0][0] != odd_max_cnt[0][0]:
    ans = len(V) - even_max_cnt[0][1] - odd_max_cnt[0][1]
else:
    if len(even_max_cnt) == 1 or len(odd_max_cnt) == 1:
        ans = len(V) // 2
    else:
        ans = len(V) - max(even_max_cnt[0][1]+odd_max_cnt[1][1],
                           even_max_cnt[1][1]+odd_max_cnt[0][1])

print(ans)


Measured memory_bytes: 15972
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int A, B;
    int count = 1, ans = 0;

    cin >> A;
  	cin >> B;
    while(count<B){
        count = count + A - 1;
        ans++;
    }
  	
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100005;
int n,x,y,cnt[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>x>>y;
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(j<=x||i>=y){
				cnt[j-i]++;
			}else if(i<=x&&j>x&&j<y){
				int res=min(j-i,y-j+x-i+1);
				cnt[res]++;
			}else if(i<=x&&j>=y){
			     cnt[x-i+j-y+1]++;
			}else if(i>x&&i<y&&j<y){
				int res=min(j-i,i-x+y-j+1);
				cnt[res]++;
			}else if(i>x&&i<y&&j>=y){
				int res=min(j-i,i-x+j-y+1);
				cnt[res]++;
			}
		}
	}
	for(int i=1;i<n;i++) cout<<cnt[i]<<endl;
}

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

int main(){
  int N,D;
  cin >> N >> D;
  if(N % (2 * D + 1) == 0)
  cout << N / ( 2 * D + 1 ) << endl;
  else cout << N / ( 2 * D + 1 ) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

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

Measured memory_bytes: 26124
#include <iostream>
#include <cctype>
#include <algorithm>
#include <string>

using namespace std;

struct myStack {
    int value;
    struct myStack *under;
    
};

int main(void){
    // Your code here!
    string str;
    struct myStack *top = new myStack;
    top->value = 0;
    top->under = NULL;
    while(cin >> str){
        if(str == "+"){
            int val1 = top->value;
            int val2 = top->under->value;
            struct myStack *nextTop = new myStack;
            nextTop->value = val1 + val2;
            nextTop->under = top->under->under;
            delete top;
            delete top->under;
            top = nextTop;
        }else if(str == "-"){
            int val1 = top->value;
            int val2 = top->under->value;
            struct myStack *nextTop = new myStack;
            nextTop->value = val2 - val1;
            nextTop->under = top->under->under;
            delete top;
            delete top->under;
            top = nextTop;
        }else if (str == "*"){
            int val1 = top->value;
            int val2 = top->under->value;
            struct myStack *nextTop = new myStack;
            nextTop->value = val1 * val2;
            nextTop->under = top->under->under;
            delete top;
            delete top->under;
            top = nextTop;
            
        }else{
            int val = std::stoi(str);
            struct myStack *sp = new myStack;
            sp->value = val;
            sp->under = top;
            top = sp;
        }
        //cout << top->value<<endl;
    }
    
    cout << top->value <<endl;
    delete top;
    return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <math.h>
#include <map>
using namespace std;
int a,b,c,m=0;
int main() {
    scanf("%d%d%d",&a,&b,&c);
    for(int i=a; i<=b; i++){
      if(c%i==0){m++;}
      }
    printf("%d\n",m);
}

Measured memory_bytes: 1176
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

def x(a,b):
    m = (b+1-a)//2
    if m%2==0:
        return 0
    else:
        return 1

A,B=intinput()
if A%2==0:
    if B%2==1:
        print(x(A,B))
    else:
        print(x(A,B-1)^B)
else:
    if B%2==1:
        print(A^x(A+1,B))
    else:
        print(A^x(A+1,B-1)^B)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int ball[10];

bool dfs (int n, int a, int b)
{
    if (n==10) return true; //no ball left
    if (ball[n]>a) return dfs(n+1,ball[n],b); //search further
    if (ball[n]>b) return dfs(n+1,a,ball[n]);
    return false;
}

int main()
{
    //DFS for the first time
    int n;
    cin>>n;
    bool ret[n];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++) cin>>ball[j];
        ret[i]=dfs(0,0,0);
    }
    for (int i=0; i<n; i++)
    {
        if (ret[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int H,W;
  cin>>H>>W;
  vector<string>a(H);
  for(int i=0;i<H;i++)cin>>a[i];
  map<char,int>m;
  for(auto it:a)for(auto it2:it)m[it2]++;
  vector<int>c(3,0);
  for(auto&it:m){
    c[2]+=it.second/4*4;
    it.second%=4;
    c[1]+=it.second/2*2;
    it.second%=2;
    c[0]+=it.second;
  }
  if(H%2==1&&W%2==1){
    if(c[2]>H*W-1-(H-1+W-1)){
      c[1]+=(c[2]-(H*W-1-(H-1+W-1)));
      c[2]=(H*W-1-(H-1+W-1));
    }
    if(c[0]==1&&c[1]==H-1+W-1&&c[2]==H*W-1-(H-1+W-1))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else if(H%2==0&&W%2==1){
    if(c[2]>H*W-H){
      c[1]+=(c[2]-(H*W-H));
      c[2]=(H*W-H);
    }
    if(c[1]==H&&c[2]==H*W-H)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else if(H%2==1&&W%2==0){
    if(c[2]>H*W-W){
      c[1]+=(c[2]-(H*W-W));
      c[2]=(H*W-W);
    }
    if(c[1]==W&&c[2]==H*W-W)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else if(H%2==0&&W%2==0){
    if(c[2]==H*W)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  int h,n;cin>>h>>n;
  int s = 0;
  for(int i = 0; n > i; i++){
    int t;cin>>t;s+=t;
  }
  if(s < h)cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
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();
		char[] s = sc.next().toCharArray();
		StringBuilder ans = new StringBuilder();
		int[] d = new int[N+1];
		Arrays.fill(d, -1);
		d[N] = 0;
		Queue<Integer> q = new ArrayDeque<>();
		q.add(N);
		while(q.size() > 0) {
			boolean first = true;
			int x = q.poll();
			for(int i = M; i >= 1; i--) {
				if(x-i <= 0) {
					d[0] = d[x] + 1;
					break;
				}
				if(d[x-i] == -1 && s[x-i] == '0') {
					d[x-i] = d[x] + 1;
					if(first) {
						q.add(x-i);
						first= false;
					}
				}
			}
		}
		if(d[0] == -1) {
			System.out.println(-1);
			return;
		}
		int now = 0, prev = d[0];
		while(true) {
			for(int i = 1; i <= M; i++) {
				if(now+i == N) {
					System.out.println(ans.append(i));
					return;
				}
				if(d[now+i] != -1 && d[now+i] != prev) {
					ans.append(i + " ");
					prev = d[now+i];
					now += i;
					break;
				}
			}
		}
	}

}

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

long long max(long long a, long long b) {
  if (a >b){
    return a;
  }
  return b;
}

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

  long long aa = max(0, a - k);
  k = k - a + aa;
  long long bb = max(0, b - k);

  cout << aa << ' ' << bb << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
const int MAXN=5e3+10;

int N,K;
int len,a[MAXN];


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif

    cin>>N>>K;
    len=0;
    int ans=N;
    for(int i=1;i<=N;i++){
         int x;
         cin>>x;
         if(x>=K){
             ans--;
         }else{
             a[len++]=x;
         }
    }
    sort(a,a+len);
    int tmp=0;
    while(len>=2){
    /*    for(int i=1;i<ni;i++){
            tmp+=a[len-i];
        }*/
        tmp+=a[len-1];
        if(a[len-2]+tmp<K){
            len--;
            continue;
        }
        if(a[0]+tmp>=K){
            ans=0;
             break;
        }
        int l=0,r=len-2;
        while(l+1<r){
             int mid=(l+r)/2;
             if(tmp+a[mid]>=K){
                 r=mid;
             }else{
                 l=mid;
             }
        }

        ans=ans-(len-r);
        len=r;
    }
    cout<<ans<<endl;

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  if(L>0)
    cout << ((N-1)*(2*(L+1)+(N-2)))/2 << endl;
  else if(L<=0 && L+N>=1) 
    cout << ((N)*(2*(L)+(N-1)))/2<< endl;
  else if(L < 0 && L+N<1)
    cout << ((N-1)*(2*(L)+(N-2)))/2 << endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int a[maxn], N, Q;
int x;
ll sum[maxn], hsum[maxn];
int pos;

bool check(int posr)
{
    int numr = N - posr + 1;
    int numl = posr - (lower_bound(a+1, a+1+N, 2*x-a[posr]) - a);
    if (numr - numl <= 1) return true;
    return false;
}

void solve(void)
{
    cin >> x;
    pos = lower_bound(a+1, a+1+N, x) - a;
    int l = pos-1, r=N, mid;
    while (l <= r){
        mid = (l + r) / 2;
        if (check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    ll res = sum[N] - sum[l-1];
    int len = N - l + 1;
    int posl = l-1 - len;
    res += hsum[posl];
    cout << res;
}

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    cin >> N >> Q;
    for (int i=1; i<=N; ++i){
        cin >> a[i];
    }
    sort(a+1, a+1+N);
    for (int i=1; i<=N; ++i){
        sum[i] = sum[i-1] + a[i];
        hsum[i] = a[i];
        if (i >= 2) hsum[i] += hsum[i-2];
    }
    while (Q--){
        solve();
        cout << '\n';
    }
}


Measured memory_bytes: 3712
// C - Modulo Summation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vl A(N); rp(i, 0, N) cin>>A[i];
	ll ans = 0;
	rp(i, 0, N) ans += A[i] - 1;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n, m;
	cin >> n >> m;

	if (2 * n >= m) {
		cout << m / 2 << endl;
		return 0;
	}

	m -= 2 * n;
	cout << n + m / 4 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <cmath>
#include<vector>
#include <utility>
using namespace std;

#define C

#ifdef C
bool isprime(int x)
{
	if (x == 2)return true;
	if (x < 2) return false;
	if ((x & 1) == 0) return false;
	int i = 3;
	for (int i = 3; i <= sqrt(x); i = i + 2)
	{
		if (x % i == 0)
			return false;
	}
	
	return true;
}


int main(void)
{
	int cunt = 0;
	int n,in;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> in;
		if (isprime(in))
			cunt++;
	}
	cout << cunt << endl;
	return 0;
}
#endif // C

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define Mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;

int n,m,S,T;
ll Ans;
int U[200001],V[200001],D[200001];
int h[100001],nxt[400001],to[400001],w[400001],tot;
void ins(int x,int y,int z){nxt[++tot]=h[x];to[tot]=y;w[tot]=z;h[x]=tot;}

ll d1[100001],d2[100001],g1[100001],g2[100001];bool v1[100001],v2[100001];
priority_queue<pli,vector<pli>,greater<pli> > pq;

void Dij(ll*d,ll*g,bool*v,int s){
	d[s]=0ll;
	pq.push(pli(0ll,s));
	g[s]=1;
	while(!pq.empty()){
		pli P=pq.top(); pq.pop();
		int u=P.second; ll du=P.first;
		if(v[u]||d[u]<du) continue;
		v[u]=1;
		eF(i,u){
			if(d[to[i]]==du+w[i])
				g[to[i]]=(g[to[i]]+g[u])%Mod;
			if(d[to[i]]>du+w[i])
				g[to[i]]=g[u],
				d[to[i]]=du+w[i], pq.push(pli(d[to[i]],to[i]));
		}
	}
}

int main(){
	int x,y,z;
	scanf("%d%d",&n,&m);
	scanf("%d%d",&S,&T);
	F(i,1,m) scanf("%d%d%d",&x,&y,&z), ins(x,y,z), ins(y,x,z), U[i]=x, V[i]=y, D[i]=z;
	memset(d1,0x3f,sizeof d1);
	Dij(d1,g1,v1,S);
	memset(d2,0x3f,sizeof d2);
	Dij(d2,g2,v2,T);
	ll Dist=d1[T];
	Ans=g1[T]*g1[T]%Mod;
	F(i,1,n){
		if(d1[i]+d2[i]==Dist&&d1[i]==d2[i])
			Ans=(Ans-g1[i]*g1[i]%Mod*g2[i]%Mod*g2[i]%Mod)%Mod;
	}
	int u,v,d;
	F(i,1,m){
		u=U[i], v=V[i], d=D[i];
		if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
			Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
		}
		u=V[i], v=U[i], d=D[i];
		if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
			Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
		}
	}
	printf("%lld",(Ans%Mod+Mod)%Mod);
	return 0;
}

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

int main(){

  int a, b;
  cin >> a >> b;

  if (a>9 || b>9){
    cout << -1 << endl;
    return 0;
  }

  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i, j, cnt=0;
    int n, q;
    int S[10000], T[500];

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    for(i=0;i<q;i++) scanf("%d", &T[i]);

    for(i=0;i<q;i++){
        for(j=0;j<n;j++){
            if(S[j]==T[i]){
                cnt++;
                break;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
#define INF 1e18
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int main(void){
  vector<ll> v(6);
  int i;
  ll min=INF,res=5;
  REP(i,6){
    cin >> v[i];
    if(i!=0&&min > v[i]) min = v[i];
  }
  res += v[0]/min-1;
  if(v[0]%min!=0)res++;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#import sys
#input = sys.stdin.readline
def main():
    Q = 10**9+7
    X, Y = map( int, input().split())
    if (X+Y)%3 != 0:
        print(0)
        return
    H = (X+Y)//3
    if (X < H) or (Y < H):
        print(0)
        return
    N = X+Y - (X+Y)//3*2
    K = X -N
    L = Y-N
    ans = 1
    s = 1
    t = 1
    for i in range(1, N+1):
        ans *= i
        ans %= Q
    for i in range(1, K+1):
        s *= i
        s %= Q
    for i in range(1, L+1):
        t *= i
        t %= Q
    ans *= pow(s, Q-2, Q)
    ans %= Q
    ans *= pow(t, Q-2, Q)
    ans %= Q
    print(ans)
if __name__ == '__main__':
    main()


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

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n, m; cin >> n >> m&&n;) {
		vector<string> N(n);
		vector<int> M(n);
		rep(i, 0, n) { cin >> N[i] >> M[i]; }
		int ans = 0;
		rep(i, 0, m) {
			string s; cin >> s;
			rep(j, 0, n) {
				rrep(k, 0, s.size()) {
					if (s[k] != N[j][k] && N[j][k] != '*')break;
					if (k == 0 || N[j][k] == '*') {
						ans += M[j];
						break;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int H, W;
   cin >> H >> W;
   char s[H][W];
   for (int h = 0; h < H; h++) {
      string tmp;
      cin >> tmp;
      for (int w = 0; w < tmp.size(); w++) {
         s[h][w] = tmp[w];
      }
   }
   for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
         int cnt = 0;
         if (s[h][w] == '#') {
            cout << '#';
            continue;
         }
         for (int x = -1; x <= 1; x++) {
            for (int y = -1; y <= 1; y++) {
               if (x == 0 && y == 0) continue;
               if (h + y < 0 || h + y >= H) continue;
               if (w + x < 0 || w + x >= W) continue;
               if (s[h + y][w + x] == '#') cnt++;
            }
         }
         cout << cnt;
      }
      cout << endl;
   }
   return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;

ll fac[maxn], ifac[maxn];

ll modpow(ll, ll);
ll inv(ll);
ll nck(ll, ll);
void build();
void testlib();



int h,w,a,b;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  build();
  testlib();
  cin>>h>>w>>a>>b;
  ll all = nck(h+w-2, h-1);

  for (int i=h-a; i<=h-1; i++) {
    ll right = b - 1;

    ll rm = nck(i+right,right);
    rm %= mod;
    ll dd = h-1-i;
    ll rr = w-1-(b-1)-1;
    ll rest = nck(dd+rr,dd);
    rest %= mod; rest += mod; rest %= mod;

    rm *= rest;
    rm %= mod; rm += mod; rm %= mod;

    
    all -= rm;
    all %= mod; all += mod; all %= mod;
  }

  cout<<all<<endl;
  return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////


ll modpow(ll x, ll y) {
  x %= mod;
  ll res = 1;
  while (y > 0) {
    if (y%2 == 1) {
      res *= x;
      res %= mod;
    }
    x = x * x;
    x %= mod;
    y = y / 2;
  }
  return res;
}

ll inv(ll x) {
  assert(x != 0);
  return modpow(x, mod-2);
}

void build() {
  fac[0] = ifac[0] = 1;
  for (int i=1; i<maxn; i++) {
    fac[i] = fac[i-1] * i;
    fac[i] %= mod;
    ifac[i] = inv(fac[i]);
    ifac[i] %= mod;
  }
}

ll nck(ll n, ll k) {
  assert(n>=0 && k>=0);
  if (k > n) return 0;
  return (((fac[n] * ifac[k]) % mod) * ifac[n-k]) % mod;
}

void testlib() {
  assert(modpow(1,1) == 1);
  assert(modpow(4,2) == 16);
  assert(modpow(2,5) == 32);
  assert(fac[3] == 6);
  assert(nck(4,2) == 6);
  assert(nck(10,2) == 45);
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll =long long;

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

ll lcm(ll a,ll b){
    ll d=gcd(a,b);
    return a/d*b;
}
int main(){
    ll A,B,C,D; cin>>A>>B>>C>>D;
    A--;
    ll l=lcm(C,D);
    ll sa=A/C+A/D-A/l;
    ll sb=B/C+B/D-B/l;

    cout<<(B-sb)-(A-sa)<<endl;
}


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

int main(){
  int n,m,c,a[5000],b[5000],sum=0,ans=0;
  cin>>n>>m>>c;
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a[j];
    }
    for(int j=0;j<m;j++){
      sum+=a[j]*b[j];
    }
    if(sum+c>0){
      ans++;
    }
    sum=0;
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    float N;
    cin >> N ;
    cout << ceil(N/2) << endl;
    return 0;

}

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

#define pb         push_back

const int INF = 1000000000;
const int MOD = 1000000007;

int ans;
int ma[100][100];
int w, h;

void rec(int y, int x);

int main(void) {
	while(1){
		ans = 0;
		cin >> w >> h;
		if(w == 0 && h == 0) break;

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				int t;
				cin >> t;
				ma[i][j] = t;
			}
		}

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(ma[i][j] == 1){
					ans++;
					rec(i, j);
				}
			}
		}
		printf("%d\n", ans);

	}
	
	return 0;
}

void rec(int y, int x){
	for(int i=-1; i<=1; i++){
		for(int j=-1; j<=1; j++){
			if(i == 0 && j == 0) continue;

			int ny = y+i;
			int nx = x+j;
			if(ny >= 0 && ny < h && nx >= 0 && nx < w && ma[ny][nx] == 1){
				ma[ny][nx] = 0;
				rec(ny, nx);
			}
		}
	}
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  
  for (int n = 0; n <= N; ++n)
  {
    int num = n;
    int div = 0;
  	while(num != 0)
    {
      div += num%10;
      num = num/10;
    }
    if (A <= div && div <= B) total += n;
  }
  
  cout << total << endl;
  return 0;
}

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

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans << "\n";
}



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


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

int main()
{
    long long weight,cost,n,capacity;
    cin>>n>>capacity;
    vector<long long>dp(capacity+1,0);
    for(int a=0;a<n;a++)
    {
        cin>>weight>>cost;
        for(int b=capacity;b>=weight;b--)
        {
            dp[b]=max(dp[b],dp[b-weight]+cost);
        }
    }
    cout<<dp[capacity]<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int sum = 0;
		for (int i = 0; i < x; i++) {
			int n = scanner.nextInt();
			if (isPrime(n)) {
				sum++;
			}
		}
		System.out.println(sum);
	}

	public static boolean isPrime(int i) {
		if (i == 2)
			return true;
		if (i % 2 == 0)
			return false;
		if (i < 8)
			return true;
		if (i % 3 == 0)
			return false;
		int k = 5;
		while (k * k <= i) {
			if (i % k == 0)
				return false;
			if (i % (k + 2) == 0)
				return false;
			k += 6;
		}
		return true;
	}
}

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

int yaku(int n){
  int ans = 0;
  for(int i=1;i*i<=n;i++){
    if(n%i == 0){
      if(i*i == n) ans += 1;
      else ans += 2;
    }
  }
  return ans;
}

int main(){
  
  int n;
  cin >> n;
  
  int ans = 0;
  for(int c=1;c<n;c++){
    int d = n-c;
    ans += yaku(d);
  }
  
  cout << ans << endl;
  
}


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

int main() {
  int N, l, r;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3620
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n, a, b = invr()

p = int(n/(a+b))
r = n % (a+b)

res = a*p
res += min(r, a)
print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
 
 	int L;
	cin >> L;
	double a,b,c;
	
	int r = L%3;
	switch(r)
	{
		case 0:
			{
				a = L/3;
				b = a;
				c = a;
				break;
			}
		case 1:
			{
				a = L/3+0.333333;
				b = a;
				c = a+0.000001;
				break;
			}
		case 2:
			{
				a = L/3+0.666666;
				b = a+0.000001;
				c = b;
				break;
			}
	}
	cout << fixed << setprecision(6) << a*b*c << endl;
	   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int		main(void)
{
	vector<ll> S(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> S[i];
	}
	int odd = 0;

	for (int i = 0; i < 3; i++)
	{
		if (S[i] % 2 == 1)
			odd++;
	}
	if (odd == 3)
	{
		sort(all(S));
		cout << S[0] * S[1] << endl;
		return (0);
	}
	cout << 0 << endl;
}


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

class DAG
{
    int n;
    vector<vector<int>> adj;
    vector<int> visited;
    vector<int> dp;
    void dfs(int v)
    {
        if (visited[v] == 2)
        {
            is_acyclic = false;
            return;
        }
        else if (!visited[v])
        {
            visited[v] = 2;
            for (int s : adj[v])
            {
                dfs(s);
            }
            visited[v] = 1;
            sorted.push_back(v);
        }
    }

public:
    vector<int> sorted;
    DAG(int n) : n(n), adj(n), visited(n), dp(n) {}
    bool is_acyclic = true;
    int longest_path = 0;

    void add_arc(int a, int b)
    {
        assert(0 <= a && a < n && 0 <= b && b < n);
        adj[a].push_back(b);
    }

    void tsort()
    {
        for (int i = 0; i < n; i++)
        {
            if (!visited[i])
                dfs(i);
        }
        reverse(sorted.begin(), sorted.end());
    }
    void build()
    {
        for (auto i : sorted)
        {
            for (auto j : adj[i])
            {
                dp[j] = max(dp[j], dp[i] + 1);
                longest_path = max(longest_path, dp[j]);
            }
        }
    }
};
vector<int> v[1000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    DAG dag = DAG((n) * (n));
    rep(i, n)
    {
        rep(j, n - 1)
        {
            int x;
            cin >> x;
            v[i].push_back(--x);
        }
    }
    rep(i, n)
    {
        rep(j, n - 2)
        {
            int t = min(i, v[i][j]) * (n) + max(i, v[i][j]);
            dag.add_arc(t, min(i, v[i][j + 1]) * (n) + max(i, v[i][j + 1]));
        }
    }
    dag.tsort();
    if (dag.is_acyclic == false)
    {
        cout << -1 << endl;
    }
    else
    {
        dag.build();
        cout << dag.longest_path+1 << endl;
    }
}

Measured memory_bytes: 56944
/**
 *    author:  tourist
 *    created: 13.12.2019 06:53:08       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  for (int i = 0; i < 2 * n; i++) {
    ans += (long long) a[i] * i;
  }
  cout << fixed << setprecision(17) << (double) ans / (2 * n - 1) << '\n';
  return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
    if (N %2 != 0){
        cout << "No" << endl;
        return;
    }
    int halfN = N/2;
    for(int i=0;i<halfN;i++){
        if(S[i] != S[i+halfN]){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int h, w;
    cin >> h >> w;
    vector<string> graph(h);
    REP(i, h) cin >> graph[i];

    vector<string> ans = graph;
    REP(i, h) REP(j, w){
        if(graph[i][j] == '.'){
            int cnt = 0;
            if(i > 0 && graph[i-1][j] == '#') cnt++;
            if(i < h-1 && graph[i+1][j] == '#') cnt++;
            if(j > 0 && graph[i][j-1] == '#') cnt++;
            if(j < w-1 && graph[i][j+1] == '#') cnt++;
            if(i > 0 && j > 0 && graph[i-1][j-1] == '#') cnt++;
            if(i > 0 && j < w-1 && graph[i-1][j+1] == '#') cnt++;
            if(i < h-1 && j > 0 && graph[i+1][j-1] == '#') cnt++;
            if(i < h-1 && j < w-1 && graph[i+1][j+1] == '#') cnt++;
            ans[i][j] = (char)('0' + cnt);
        }
    }
    
    REP(i, h) cout << ans[i] << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;



int main(){
   int n;
   string s,t;
   cin >> n >> s >> t;
   REP(i,n){
      cout << s[i] << t[i];
   }
   
   return 0;
}

Measured memory_bytes: 256
K=int(input())

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        g=gcd(a,b)
        for c in range(1,K+1):
            ans+=gcd(g,c)

print(ans)

Measured memory_bytes: 9196
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main()
{
    ll N, tmp;   cin >> N;
    vector<ll> v(N+1,0);
    for(ll i=1; i < 150; i++){
        for(ll j=1; j<150; j++){
            for(ll k=1; k<150; k++){
                tmp = i*i+j*j+k*k+i*j+j*k+k*i;
                if(tmp <= N){
                    v[tmp]++;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        cout << v[i] << '\n';
    }
}

Measured memory_bytes: 3564
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
#N = I()
#A = [LI() for _ in range(N)]

a, b = list(map(int,sys.stdin.readline().rstrip().split()))

if a > 0:
    print('Positive')
elif a <= 0 and b >= 0:
    print('Zero')
else:
    if (a+b)%2 == 0:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 12256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pl;
#define pi pair<int,int>
#define MM 1000000000
#define MOD MM+7
#define initial_value -1
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,-1,0,1,1,1,-1,-1};
struct edge{ll to,cost;};
ll ans = 1LL;
int main(){
    int a,b; cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
import sys

def f1(m):
    j=0
    num=0
    for x in ap[::-1]:
        while j<minus and x*am[j]<m:
            j+=1
        num+=j
    return plus*minus-num
            
def f2(m):
    return f3(m,ap)+f3(m,am)


def f3(m,l):
    nagasa=len(l)
    if nagasa<2: return 0
    j=nagasa-1
    num=0
    for i in range(nagasa):
        while j>-1 and l[i]*l[j]>m:
            j-=1
        num+=j+1
        if i<=j: num-=1
    return num//2

n,k=map(int,input().split())
a=list(map(int,input().split()))
ap=sorted([a[i] for i in range(n) if a[i]>0])
am=sorted([-a[i] for i in range(n) if a[i]<0])
az=sorted([a[i] for i in range(n) if a[i]==0])

plus,minus,zero=len(ap),len(am),len(az)
pz=plus*minus+zero*(zero-1)//2+zero*(n-zero)


if plus*minus>=k:
    h,l=0,10**18
    while l-h>1:
        md=(h+l)//2
        p=f1(md)
        if p>=k: h=md
        else: l=md
    print(-h)

elif pz>=k:
    print(0)

else:
    k-=pz
    h,l=10**20,0
    while h-l>1:
        md=(h+l)//2
        p=f2(md)
        if p>=k: h=md
        else: l=md
    print(h)

Measured memory_bytes: 111108
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int n;
    cin >> s;
    while(s!="-") {
        cin >> n;
        for(int i = 0;i < n;i++) {
            int h;
            cin >> h;
            s = s.substr(h,s.size()-h)+s.substr(0,h);
        }
        cout<<s<<endl;
        cin>>s;
    }
}


Measured memory_bytes: 3200
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int,input().split())))
p = []
for _ in range(n):
    p.append(list(map(int,input().split())))

jo = []
for a1 in range(2):
    for a2 in range(2):
        for a3 in range(2):
            for a4 in range(2):
                for a5 in range(2):
                    for a6 in range(2):
                        for a7 in range(2):
                            for a8 in range(2):
                                for a9 in range(2):
                                    for a10 in range(2):
                                        if a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 != 0:
                                            jo.append([a1,a2,a3,a4,a5,a6,a7,a8,a9,a10])

a = []

for j in jo:
    ans = 0
    for i in range(n):
        li = []
        for k in range(10):
            li.append(f[i][k]+j[k])
        ans += p[i][li.count(2)]
    a.append(ans)

print(max(a))

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xにyをつなげる
        x=root(x);
        y=root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main() {
    int N,M; cin >> N >> M;
    vector<int> P(N);
    REP(i,N){
        int p; cin >> p;
        P[i] = p-1;
    }

    UnionFind uf(N);

    REP(i,M){
        int x,y; cin >> x >> y;
        x--; 
        y--;
        uf.union_set(x,y);
    }

    int ans = 0;
    REP(i,N){
        if(uf.find_set(i, P[i])) ans++;
    }

    cout << ans << endl;





    return 0;
}

Measured memory_bytes: 3984
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
a = a + a
ans = 10 ** 18
for i in xrange(n):
    for j in xrange(n):
        if b[j] > a[j+n-i]:
            b[j] = a[j+n-i]
    t = sum(b) + x * i
    if ans > t:
        ans = t
print ans


Measured memory_bytes: 2820
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int a=ni(),b=ni(),h=ni(),m=ni();
        
        double ang_h=h/12.0d*360.0d+m/2.0d,ang_m=m/60.0d*360.0d;
        double ang=Math.abs(ang_h-ang_m);
        ang=Math.min(360-ang,ang);
        // System.out.println("pos h and m "+ang_h+" "+ang_m);
        // System.out.println("ang "+ang);
        double res=a*a+b*b-2*a*b*Math.cos(Math.toRadians(ang));
        res=Math.sqrt(res);
        pn(res);
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
       // t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
 
    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;


  for(int i = sx;i < tx;i++) cout << 'R';
  for(int i = sy;i < ty;i++) cout << 'U';
  for(int i = sx;i < tx;i++) cout << 'L';
  for(int i = sy;i < ty;i++) cout << 'D';
  cout << 'D';
  for(int i = sx;i < tx+1;i++) cout << 'R';
  for(int i = sy;i < ty+1;i++) cout << 'U';
  cout << 'L';
  cout << 'U';
  for(int i = sx;i < tx+1;i++) cout << 'L';
  for(int i = sy;i < ty+1;i++) cout << 'D';
  cout << 'R';
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
/* ?????¢????????¨?????? 586 + 79 = 665(KiB) ??????????????????????????? */
/* ????´°??????????????§ */
#include <iostream>
#include <vector>
#include <cstdio>

struct JobRecord
{
	int staff;
	int job;
	int count;
};

int main(void)
{
	using namespace std;

	int num_of_staffs, num_of_jobs;
	cin >> num_of_staffs >> num_of_jobs;

	vector<JobRecord> v_job_record;
	vector<int> v_staff, v_job, v_count;

	/* ??\???????¨?????????????????????? */
	/* ?????§ 50000 ?????????????????? */
	/* ????????§?????¢????????¨?????? 50000(???) * 3(??????, ??????????¨????, ?????°) * 4(Bytes) = 600000(Bytes) ==> ?´?586KiB */
	while(1)
	{
		JobRecord input;
		cin >> input.staff >> input.job >> input.count;
		if( input.staff == 0 && input.job == 0 && input.count == 0 )
		{
			break;
		}
		
		/* ??\??????????????? */
		v_job_record.push_back(input);
	}

	int num_of_calc;
	cin >> num_of_calc;

	/* ???????¨???? */
	for(int calc_count = 0; calc_count < num_of_calc; calc_count++)
	{
		/* ???????¨???????????????§?????¢????????¨??????????¨??????¨?????? */
		/*   v_unit_price : 10000(??\???????¨?????????§) * 4 = 40000 Bytes */
		/*   v_salary     : 10000(????????°?????§)     * 4 = 40000 Bytes */
		/* ????¨???§ 80000 Bytes ==> ?´? 79 KiB */
		vector<int> v_unit_price(num_of_jobs);	/* ???????????¨????????? */
		vector<int> v_salary(num_of_staffs, 0);	/* ???????????¨?????????. ????????? 0 ????????????????¨???? */

		/* ??\??? */
		for(int job = 0; job < num_of_jobs; job++)
		{
			cin >> v_unit_price[job];
		}

		/* ?¨???? */
		for(int i = 0; i < v_job_record.size(); i++)
		{
			/* ???????????\???????¨??????? 1????????????????????§?????????????????????????????¨???????????? 0??????????????????????????? */
			int staff      = v_job_record[i].staff;
			int job        = v_job_record[i].job;
			int count      = v_job_record[i].count;
			int unit_price = v_unit_price[ job - 1 ];
			
			v_salary[ staff - 1 ] += unit_price * count;
		}
		
		/* ?????? */
		
		for(int i = 0; i < num_of_staffs; i++)
		{
			if( i != 0 )
			{
				cout << " ";
			}
			cout << v_salary[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3832