akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using ll = long long;

int n;
const vector<string> ans{"Vacant", "Male", "Female"};

int judge(int q) {
    cout<<q<<endl;
    string s; cin>>s;
    for (auto i=0;i<3;i++) {
        auto &stus = ans[i];
        if (s == stus)
            return i;
    }
    return -1;
}

bool vs(int l, int r, int ls, int rs) {
    if (((r-l)%2==0 && ls==rs) ||
        ((r-l)%2==1 && ls!=rs)) {
        return false;
    }
    auto c=(l+r)/2;
    auto cs=judge(c);
    if (cs==0) return true;
    return (vs(l, c, ls, cs) || vs(c, r, cs, rs));
}

int main() {
    
    cin>>n;
    
    auto ls=judge(0);
    if (ls==0) return 0;
    auto rs=judge(n-1);
    if (rs==0) return 0;
    
    vs(0, n-1, ls, rs);
    
    return 0;
}



Measured memory_bytes: 852
//
//  025A.cpp
//  c++test
//
//  Created by 森敦史 on 2018/06/03.
//  Copyright © 2018年 森敦史. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define rep(i, n) for(int i=0; i< (n); i++)
#define reps(i, a, n) for(int i=a; i < (n); i++)

const int INF{1001001001};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

int main(){
    int n;
    cin >> n;
    
    int sum = INF;;
    
    reps(i, 1, n){
        int a = i;
        int b = n - i;
        int suma = 0;
        int sumb = 0;
        while(a > 0){
            suma += a % 10;
            a = a / 10;
        }
        while(b > 0){
            sumb += b % 10;
            b = b / 10;
        }
        sum = min(sum, suma + sumb);
        
    }
    cout << sum;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int temp = 0;
		
		for(int i = 0; i < b; i++){
			temp = temp + sc.nextInt();
		}
		
		if(temp >= a){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 49304
// 20151002




#include<stdio.h>




int main() {
  int i, j;
  int aaa;
  int Yama[10];




  /* ?±±????????? 10 ???????????? Yama ????????????????´?*/
  scanf("%d", &Yama[0]);
  for (i = 1; i < 10; i ++) { // ????´??????°
    scanf("%d", &Yama[i]);
    for (j = 0; j < i; j ++) { // ???????????°
      if (Yama[j] < Yama[i]) {
	aaa = Yama[j];
	Yama[j] = Yama[i];
	Yama[i] = aaa;
      }
    }
  }




  /* ?????? */
  for (i = 0; i < 3; i ++) {
    printf("%d\n",Yama[i]);
  }




  /* ?????? */
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,w;
	cin >> n >> w;
	vector<vector<long long> > a(n,vector<long long>(2));
	for(int i=0;i<n;i++)
		cin >> a[i][0] >> a[i][1];
	vector<vector<long long> > dp(n+1,vector<long long>(w+1,0));
	for(int i=0;i<=n;i++)
		dp[i][0] = 0;
	for(int i=0;i<=w;i++)
		dp[0][i] = 0;
	for(int item=1;item<=n;item++)
		for(int capacity=1;capacity<=w;capacity++)
			if(capacity >= a[item-1][0])
				dp[item][capacity] = max(dp[item-1][capacity],dp[item-1][capacity-a[item-1][0]] + a[item-1][1]);
			else
				dp[item][capacity] = dp[item-1][capacity];
	cout << dp[n][w];
}


Measured memory_bytes: 83036
#include <iostream>

using namespace std;

int main()
{
    int a ,b ,c ,d;
    cin>>/**<  */ a >> b >> c >> d;
    string result;
    if(a+b > c+d){
       result = "Left" ;
    }else if (a+b < c+d){
    result = "Right";}else { result = "Balanced";}
    cout << result;
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
	string a;
	int ans=700;
	cin >> a;
	for (int i = 0; i < 3; ++i)
	{
		if (a[i]=='o')
		{
			ans+=100;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}
const int nax=2e5+5;
vector<int>adj[nax];
bool visited[nax];

void init(){
for(int i=0;i<nax;i++)visited[i]=false;
}

int  dfs(int s){
    int r=1;
visited[s]=true;
for(auto u:adj[s]){
    if(!visited[u])
       r+= dfs(u);
}
return r;
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    init();
    int ans=0;
    for(int i=1;i<=n;i++){
        if(!visited[i]){
            int q=dfs(i);
            ans=max(ans,q);
        }

    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 24068
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

w, h, x, y, r = map(int, input().split())

if x < 0 or y < 0:
    print("No")
    exit(0)

flg1 = x >= r and y >= r
flg2 = w-x >= r and h-y >= r

if flg1 and flg2:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 6888
import numpy as np


def main():
    length = int(input())
    numbers = np.array(list(map(int, input().split())))
    mod = 10 ** 9 + 7
    answer = 0
    for d in range(60):
        count_one = np.count_nonzero((numbers >> d) & 1)
        answer = (answer + pow(2, d) * count_one * (length - count_one)) % mod
    print(answer)


if __name__ == '__main__':
    main()



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

#define DEBUG 0
 


int main() {

    int N;

    cin >> N;

    vector <int> counter_n(N+1,0);

    for(int num = 1; num < N+1; num++){
       
        for(int i = 1 ; i < (int)(sqrt(num)*1.4); i++){
            for(int j = i; j < (int)(sqrt(num)*1.4); j++){
                for(int k = j; k < (int)(sqrt(num)*1.4); k++){
                    if(i * i + j * j + k * k == 2 * num){
                        #if DEBUG
                            cout << i << j << k << num << endl;
                        #endif

                            int x2 = i + j - k;
                            int y2 = i - j + k;
                            int z2 = -i + j + k;

                            if((x2 > 0) && !(x2 & 1) && (y2 > 0) && !(y2 & 1) && (z2 > 0) && !(z2 & 1) ){
                                if((x2 == y2) && (y2 == z2)){
                                    counter_n.at(num)++;
                                }else if((x2 != y2) && (x2 != z2) && (y2 != z2)){
                                    counter_n.at(num) += 6;
                                }else{
                                    counter_n.at(num) += 3;
                                }
                            }





                        
                    }


                }
            }
        }



    }

    for(int i = 1; i < N+1; i++){
        cout << counter_n.at(i) << endl;
    }






    return 0;

 
}



Measured memory_bytes: 3596
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	ll h, n;
	cin >> h >> n;
	vector<P> vs(n);
	rep(i, n) {
		cin >> vs[i].first >> vs[i].second;
	}
	const ll INF = 1e15;
	vector<ll> dp(h + 1, INF);
	dp[0] = 0;
	for (int i = 1; i < h + 1;i++) {
		rep(j, n) {
			auto v = vs[j];
			ll p = max(0LL, i - v.first);
			dp[i] = min(dp[i], dp[p] + v.second);
		}
	}
	cout << dp[h] << endl;		
	return 0;
}


Measured memory_bytes: 384
# include <iostream>
# include <string>
using namespace std;
/* Author: Shirai Kuroko
Bolg URL:www.kuroko.fun
OJ source : ALDS1_8_A&B&C */
struct Tree
{
	int val;
	Tree *left,*right,*dad;
};
bool f = false; // 根节点是否存在 
void Insert(Tree *&root,Tree *x)
{
	if(!f)
	{
		root = x;
		f = true;
		return;
	}
	if(root->val > x->val)
	{
		if(root->left == NULL)
		{
			root->left = x;
			x->dad = root;
		}
		else Insert(root->left,x); 
	}
	else
	{
		if(root->right == NULL)
		{
			root->right = x;
			x->dad = root;
		}
		else Insert(root->right,x);
	}
}

bool Search(Tree *root,int x)
{
	if(!f) return false;
	bool ans;
	if(root == NULL) return false;
	if(root->val == x) return true;
	if(root->val > x) ans = Search(root->left,x);
	else ans = Search(root->right,x);
	return ans;
} 
Tree* Search_Back(Tree* root,int x)
{
	while(root->val != x)
	{
		if(root->val  < x) root = root->right;
		else root = root->left;
	}
	return root;
}
void Delete(Tree *&root,Tree *&x)
{
	if(x->left == NULL && x->right == NULL)
	{
		if(root == x) 
		{
			f = false;
		}
		else
		{
			if(x->dad->left == x) x->dad->left = NULL;
			else x->dad->right = NULL;
		}
	}
	else if(x->left == NULL && x->right != NULL)
	{
		if(root == x) 
		{
			root = root->right;
			root->dad = NULL;
		}
		else
		{
			if(x->dad->left == x) x->dad->left = x->right;
			else x->dad->right = x->right;
			x->right->dad = x->dad;
		}
	}
	else if(x->left != NULL && x->right == NULL)
	{
		if(root == x)
		{
			root = root->left;
			root->dad = NULL;
		}
		else
		{
			if(x->dad->left == x) x->dad->left = x->left;
			else x->dad->right = x->left;
			x->left->dad = x->dad;
		}
	}
	delete x;
}

void Pre_Print(Tree *root)
{
	if(!f) return ;
	if(root != NULL) cout<<" "<<root->val;
	if(root->left != NULL)Pre_Print(root->left);
	if(root->right != NULL)Pre_Print(root->right);
}

void In_Order(Tree *root)
{
	if(!f) return;
	if(root->left != NULL) In_Order(root->left);
	if(root != NULL) cout<<" "<<root->val;
	if(root->right != NULL) In_Order(root->right);
}

void Post_Print(Tree *root)
{
	if(!f) return ;
	if(root->left != NULL) Post_Print(root->left);
	if(root->right != NULL) Post_Print(root->right);
	if(root != NULL) cout<<" "<<root->val; 
}

int main(void)
{
	int n,k; string m;
	Tree *root,*x;
	root = NULL;
	cin>>n;
	while(n--)
	{
		cin>>m;
		if(m == "insert")
		{
			cin>>k;
			x = new Tree; x->val = k; x->dad = NULL;
			x->left = NULL; x->right = NULL;
			Insert(root,x);
		}
		else if(m == "find")
		{
			cin>>k;
			cout<<(Search(root,k)?"yes":"no")<<endl;
		}
		else if(m == "delete")
		{
			cin>>k;
			if(!Search(root,k)) cout<<"The operation is failed, for the tree has not this key"<<endl;
			else
			{
				x = Search_Back(root,k);
				Delete(root,x);
			}
		}
		else
		{
			In_Order(root); cout<<endl;
			Pre_Print(root); cout<<endl;
		}
	}
	return 0;
}


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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    map<int, int> A;
    int a;
    for ( int i=0; i<N; i++ ) {
        cin >> a;
        A[a]++;
    }

    /* 同じ長さが2本以上ずつある棒の中から
     * 長い方から２つ探す */
    int longest1 = 0, longest2 = 0;
    for ( auto itr : A ) {
        if ( itr.second >= 2  && itr.first > longest2 ) {
            if ( itr.first > longest1 ) {
                longest2 = longest1;
                longest1 = itr.first;
            }
            else {
                longest2 = itr.first;
            }
        }
    }

    long long ans;
    if ( A[longest1] >= 4 )
        ans = (long long)longest1 * longest1;
    else
        ans = (long long)longest1 * longest2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int max_n = 1e6;
ll a[2][200];
int main(){
  cin >> n;
  int dp[2][200]={0};
  for(int i=0 ; i<2 ; i++){
    for(int j=0 ; j<n ; j++){
      cin >> a[i][j];
    }
  }
  for(int i=0 ; i<2 ; i++){
    for(int j=0 ; j<n ; j++){
      if(i==0){
        dp[i][j] = dp[0][j-1]+a[0][j];
      }else{
        dp[i][j] = max(dp[0][j]+a[1][j], dp[1][j-1]+a[1][j]);
      }
    }
  }
  cout << dp[1][n-1] << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
alpha = list("abcdefghijklmnopqrstuvwxyz")

if len(S) < 26:
    s = set(list(S))
    for i in range(26):
        if alpha[i] not in s:
            S += alpha[i]
            break
else:
    flag = False
    for i in range(24, -1, -1):
        tmp = ord(S[i])
        for j in range(25, i, -1):
            if tmp < ord(S[j]):
                S = S[:i] + S[j]
                flag = True
                break    
        
        if flag:
            break
    else:
        S = "-1"

print(S)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int n,x,a;
    char k;
    cin >> n;
    int b[100][100];
    
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            b[i][j]=0;
        }
    }
    
    for(int i=0;i<n;i++){
        cin >> k >> x;
        if(k=='S')a=0;
        if(k=='H')a=1;
        if(k=='C')a=2;
        if(k=='D')a=3;
        b[a][x-1]=1;
    }
    
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(b[i][j]==0){
                if(i==0)cout << "S " << j+1 << endl;
                if(i==1)cout << "H " << j+1 << endl;
                if(i==2)cout << "C " << j+1 << endl;
                if(i==3)cout << "D " << j+1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d[256];
  cin>>a>>b>>c;
  d[0]=a;
  d[1]=b;
  d[2]=c;
  sort(d,d+3);
  if(d[0]==5 && d[1]==5 && d[2]==7){
      cout<<"YES"<<'\n';
  }
  else{
    cout<<"NO"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int h = num/(60*60); num = num - (h*60*60);
		int m = num/60; num = num - (m*60);
		int s = num;
		System.out.println(h+":"+m+":"+s);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}



Measured memory_bytes: 26136
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,n,x,k;
    t=1;
    for(i=0;i<t;i++){
        cin>>n>>k;
        lli a[n];
        for(j=0;j<n;j++){
            cin>>a[j];
        }
        x=0;
        sort(a,a+n);
        for(j=0;j<k;j++){
            x=x+a[j];
        }
        cout<<x;
    }
}




Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
using namespace std;
int solve(int* arr,int n){
	int* dp = new int[n];
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	dp[2] = min((dp[1]+abs(arr[1]-arr[2])),abs(arr[0]-arr[2]));
	for(int i=3;i<n;i++){
		dp[i] = min((dp[i-1]+abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
	}
	int ans = dp[n-1];
	delete[] dp;
	return ans;
}
int main(){
	int n;
	cin >> n;
	int* arr =new int[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	cout << solve(arr,n) << "\n";
	delete[] arr;
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter
N,M=map(int, input().split())
A=[]
for i in range(M):
    tmp=list(map(int, input().split()))
    A.append(tmp[0])
    A.append(tmp[1])
Acnt=dict(Counter(A).items())
for i in range(1,N+1):
    if i in Acnt:
        print(Acnt[i])
    else:
        print(0)


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine();
        var length = inputs.Length;
        var front = inputs.Take((length - 1) / 2);
        var back = inputs.Reverse().Take((length - 1) / 2);

        if (IsPalindrome(inputs) && IsPalindrome(front) && IsPalindrome(back)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    public static bool IsPalindrome<T>(IEnumerable<T> str)
        => str.SequenceEqual(str.Reverse());
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(c-a)<=d){
    puts("Yes");
    return 0;
  }

  if(abs(c-b)<=d&&abs(a-b)<=d){
    puts("Yes");
    return 0;
  }
  puts("No");

  return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N)cin>>S.at(i);

    int C0=0;
    int C1=0;
    int C2=0;
    int C3=0;

    rep(i,N){
        if(S.at(i)=="AC"){
            C0++;
        }else if(S.at(i)=="WA"){
            C1++;
        }else if(S.at(i)=="TLE"){
            C2++;
        }else if(S.at(i)=="RE"){
            C3++;
        }
    }
    cout<<"AC x "<<C0<<endl;
    cout<<"WA x "<<C1<<endl;
    cout<<"TLE x "<<C2<<endl;
    cout<<"RE x "<<C3<<endl;


    return 0;
}

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

char* hantei(int seireki, int tsuki, int nichi)
{
	int day = seireki * 10000 + tsuki * 100 + nichi;
	if (day < 18680908) {
		return "pre-meiji";
	}
	else if (day < 19120730) {
		return "meiji";
	}
	else if (day < 19261225) {
		return "taisho";
	}
	else if (day < 19890108) {
		return "showa";
	}
	else {
		return "heisei";
	}
}

int main(void)
{
	int seireki, tsuki, nichi;
	while(scanf("%d %d %d", &seireki, &tsuki, &nichi) != EOF) {
		//scanf("%d %d %d", &seireki, &tsuki, &nichi);
		char gengou[10];
		strcpy(gengou, hantei(seireki, tsuki, nichi));
		if (strcmp(gengou, "pre-meiji") == 0) {
			printf("pre-meiji\n");
		}
		else {
			int kijun;
			if (strcmp(gengou, "meiji") == 0) {
				kijun = 1867;
			}
			else if (strcmp(gengou, "taisho") == 0) {
				kijun = 1911;
			}
			else if (strcmp(gengou, "showa") == 0) {
				kijun = 1925;
			}
			else {
				kijun = 1988;
			}
			printf("%s %d %d %d\n", gengou, seireki - kijun, tsuki, nichi);
		}
	}
	return 0;
}

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

template <typename T>
T BinarySearch(T ok, T ng, std::function<bool(T)> pred) {
  while (abs(ok - ng) > 1) {
    T mid = (ok + ng) / 2;
    (pred(mid) ? ok : ng) = mid;
  }
  return ok;
}

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

ll n, k;
ll a[2 * 100000];
const ll tens = 1e9;

// Returns the number of pairs whose values are equal to or less than x.
ll count(ll x) {
  ll cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] < 0) {
      if (a[i - 1] * a[i] <= x) {
        if (a[0] * a[i] <= x) {
          cnt += i;
          continue;
        }
        int j =
            BinarySearch<int>(0, i, [&](int idx) { return a[i] * a[idx] > x; });
        cnt += i - (j + 1);
      }
    } else {
      if (a[0] * a[i] <= x) {
        int j = BinarySearch<int>(0, i,
                                  [&](int idx) { return a[i] * a[idx] <= x; });
        cnt += j + 1;
      }
    }
  }
  return cnt;
}

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  sort(a, a + n);

  ll x = BinarySearch<ll>(-tens * tens - 1, tens * tens + 1,
                          [&](ll x) { return count(x) < k; });
  dbg(x, count(x - 1), count(x), count(x + 1));
  wt(x + 1);
}


Measured memory_bytes: 5136
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int[] array = new int[150];
		Scanner input = new Scanner(System.in);
		int n;
		int max = 0;
		
		while(input.hasNext()){
			n = input.nextInt();
			
			array[n]++;
			
			if(max < array[n]) max = array[n];
		}
		
		for(int i = 0; i < array.length; i++){
			if (array[i] == max){
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 18148
main=do
  s<-getLine
  putStr $ if eval s then makeAns.solve$s else "-1"

eval s
  | head s == '1' && r == '0' = go s rs
  | otherwise = False
  where
  (r:rs) = reverse s
  go [] _ = True
  go _ [] = True
  go (c:s) (r:rs) = c == r && go s rs

makeAns = unlines.map (unwords.(\(a,b)->[show a,show b]))

solve = go 1 []
  where
  go cur toConnect ['0'] = zip (repeat cur) toConnect
  go cur toConnect ('0':s) = go (cur+1) (cur:toConnect) s
  go cur toConnect ('1':s) = edges ++ go (cur+1) [cur] s
    where edges = zip (repeat cur) toConnect

Measured memory_bytes: 15996
#include <iostream>
#include <vector>

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

int main() {
  int N, W;
  std::cin >> N >> W;
  std::vector<int> w(N);
  std::vector<int> v(N);
  for (int i = 0; i < N; ++i)
    std::cin >> w[i] >> v[i];

  int K = N * 1000;
  long long inf = 1LL << 60;
  std::vector<std::vector<long long>> dp(
      N + 7, std::vector<long long>(2 * K + 7, inf));

  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int k = 0; k < v[i]; ++k)
      chmin(dp[i + 1][k], dp[i][0] + w[i]);
    for (int k = 0; k <= K; ++k) {
      chmin(dp[i + 1][k], dp[i][k]);
      chmin(dp[i + 1][k + v[i]], dp[i][k] + w[i]);
      // for (int l = 0; l <= v[i]; ++l)
      //   chmin(dp[i + 1][k + l], dp[i][k] + w[i]);
    }
  }

  // for (int k = 0; k < 200; ++k)
  //   std::cout << "k: " << k << ": " << dp[N][k] << std::endl;

  long long res = -1;
  for (int k = 0; k <= K; ++k) {
    // if (dp[N][k] <= W)
    //   res = k;
    if (W < dp[N][k + 1]) {
      res = k;
      break;
    }
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 169216
//g++  5.4.0

#include <iostream>
using namespace std;

int main()
{
    int h, w, id=0;
    cin>>h>>w;
    string g[h +3], wh;
    for(int i=0; i<w; i++) wh += ".";
    for(int i = 0; i < h; i++)
    {
        string a;
        cin>>a; cin.ignore();
        if(a!=wh) g[id++] = a;
    }
    for(int i = 0; i < w; i++)
    {
       int ck = 0;
       for(int j = 0; j<id; j++) if(g[j][i]=='.') ck++;
       if(ck == id) for(int j = 0; j < id; j++) g[j][i] = '*';
    }
    for(int i = 0; i < id; i++)
    {
        for(int j = 0; j < w; j++)
           if(g[i][j]!= '*') cout << g[i][j];
        cout<<endl;
    }
    return 0;
}

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

string s;
long a[500001];
int main() {
  cin >> s;
  const int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == '<') a[i + 1] = a[i] + 1;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
  }
  cout << accumulate(a, a + n + 1, 0l) << endl;
}

Measured memory_bytes: 4740
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	
	public static final int PANELS = 16;
	
	public static void bit_print(int bit){
		StringBuilder sb = new StringBuilder();
		sb.append(Integer.toBinaryString(bit));
		if(sb.length() < 16){
			final int diff = 16 - sb.length();
			
			for(int i = 0; i < diff; i++){
				sb.insert(0, "0");
			}
		}
		
		System.out.println(sb.toString());
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int n = sc.nextInt();
			final int c = sc.nextInt();
			
			if(n == 0 && c == 0){
				break;
			}
			
			int[] humen = new int[n];
			int[] hands = new int[c];
			
			/* set humen */
			for(int i = 0; i < n; i++){
				int bit = 0;
				for(int j = 0; j < PANELS; j++){
					final int hand = sc.nextInt();
					
					bit |= (hand << j);
				}
				
				humen[i] = bit;
			}
			
			/* set hands */
			for(int i = 0; i < c; i++){
				int bit = 0;
				for(int j = 0; j < PANELS; j++){
					final int hand = sc.nextInt();
					
					bit |= (hand << j);
				}
				
				hands[i] = bit;
			}
			
			int[][] dp = new int[n + 1][1 << PANELS];
			for(int i = 0; i <= n; i++){
				Arrays.fill(dp[i], -1);
			}
			dp[0][humen[0]] = 0;
			
			for(int time = 0; time < n; time++){
				for(int bit = 0; bit < 1 << PANELS; bit++){
					if(dp[time][bit] >= 0){
						for(int hand = 0; hand < c; hand++){
							final int hand_bit = hands[hand];	
							final int score = Integer.bitCount(hand_bit & bit);
							final int next_bit = (bit & (~hand_bit)) | (time + 1 < n ? humen[time + 1] : 0);
							
							
							//bit_print(bit);
							//bit_print(hand_bit);
							//bit_print(next_bit);
							
							dp[time+1][next_bit] = Math.max(dp[time+1][next_bit], dp[time][bit] + score);
						}
					}
				}
			}
			
			int max = 0;
			for(int i = 0; i < 1 << PANELS; i++){
				max = Math.max(max, dp[n][i]);
			}
			
			System.out.println(max);
		}
		
		
		sc.close();
	}
}

Measured memory_bytes: 65108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<ll> A(N);
    for(auto& e : A){
        cin >> e;
    }

    vector<ll> right = A;
    vector<ll> ans_right(N, 0);
    int right_edge = N - 1;
    for(int i=N - 2;i>=0;i--){
        ans_right[i] = ans_right[i + 1];
        if(right[i] <= right[i + 1]){
            // ok
        }else{
            for(int j=i;j+1<right_edge;j++){
                while(right[j + 1] < right[j]){
                    right[j + 1] *= 4;
                    ans_right[i] += 2;
                }
            }
            while(right[right_edge] < right[right_edge - 1]){
                right[right_edge] *= 4;
                ans_right[i] += 2 * (N - right_edge);
            }
            while(i < right_edge && right[right_edge] < 4 * right[right_edge - 1]){
                assert(right[right_edge - 1] <= right[right_edge]);
                right_edge--;
            }
        }
    }

    vector<ll> left = A;
    for(int i=0;i<N;i++){
        left[i] *= -2;
    }
    vector<ll> ans_left(N, 0);
    ans_left[0] = 1;
    int left_edge = 0;
    for(int i=1;i<N;i++){
        ans_left[i] = ans_left[i - 1] + 1;
        if(left[i - 1] <= left[i]){
            // ok
        }else{
            for(int j=i;j-1>left_edge;j--){
                while(left[j - 1] > left[j]){
                    assert(left[j - 1] < 0);
                    left[j - 1] *= 4;
                    ans_left[i] += 2;
                }
            }
            while(left[left_edge] > left[left_edge + 1]){
                left[left_edge] *= 4;
                ans_left[i] += 2 * (left_edge + 1);
            }
            while(left_edge < i && left[left_edge] > 4 * left[left_edge + 1]){
                assert(left[left_edge] <= left[left_edge + 1]);
                left_edge++;
            }
        }
    }

    // for(int i=0;i<N;i++){
    //     cout << ans_left[i] << " " << ans_right[i] << endl;
    // }

    ll ans = min(ans_left[N - 1], ans_right[0]);
    for(int i=1;i<N;i++){
        ans = min(ans_left[i - 1] + ans_right[i], ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<functional>
typedef long long ll;
#define INF 99999999
int main() {
	int h = 0, w = 0;
	char can[50][50] = {};
	bool flug = true;//true yes false no
	std::cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			std::cin >> can[i][j];
		}
	}
	if (can[0][0] == '#' && can[0][1] == '.' && can[1][0] == '.') {
		flug = false;
	}
	if (can[0][w-1] == '#' && can[0][w-2] == '.' && can[1][w-1] == '.') {
		flug = false;
	}
	if (can[h-1][0] == '#' && can[h-1][1] == '.' && can[h-2][0] == '.') {
		flug = false;
	}
	if (can[h-1][w-1] == '#' && can[h-1][w-2] == '.' && can[h-2][w-1] == '.') {
		flug = false;
	}
	for (int i = 1; i < w; i++) {
		if (can[0][i] == '#' && can[0][i + 1] == '.' && can[0][i - 1] == '.' && can[1][i] == '.') {
			flug = false;
		}
	}
	for (int i = 1; i < w; i++) {
		if (can[h-1][i] == '#' && can[h-1][i + 1] == '.' && can[h-1][i - 1] == '.'&&can[h-2][i]=='.') {
			flug = false;
		}
	}
	for (int i = 1; i < h; i++) {
		if (can[i][0] == '#' && can[i-1][0] == '.' && can[i+1][0] == '.'&&can[i][1] == '.') {
			flug = false;
		}
	}
	for (int i = 1; i < h; i++) {
		if (can[i][w-1] == '#' && can[i - 1][w-1] == '.' && can[i + 1][w-1] == '.'&&can[i][w-2] == '.') {
			flug = false;
		}
	}
	for (int i = 1; i < h-1; i++) {
		for (int j = 1; j < w-1; j++) {
			if (can[i][j] == '#' && can[i - 1][j] == '.' && can[i + 1][j] == '.' && can[i][j + 1] == '.' && can[i][j - 1] == '.') {
				flug = false;
			}
		}
	}
	if (flug == true) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int r, c, i, j, csum, rsum;

  scanf("%d %d", &r, &c);
  int data[r+1][c+1];

  //表の初期化
  for(i=0; i <= r; i++){
    for(j=0; j <= c; j++){
      data[i][j]=0;
    }
   }

  //表に値を代入
  for(i=0; i < r; i++){
    for(j=0; j < c; j++){
      scanf("%d", &data[i][j]);
    }
  }

  //行の合計計算
  for(i=0; i < r; i++){
    csum=0;
    for(j=0; j < c; j++){
      csum += data[i][j];
    }
    data[i][c]=csum;
  }

  //列の合計計算
  for(i=0;i <= c; i++){
    rsum=0;
    for(j=0; j <= r; j++){
      rsum += data[j][i];
    }
    data[r][i]=rsum;
  }

  //表の出力
  for(i=0; i <= r; i++){
    for(j=0; j < c; j++){
      printf("%d ", data[i][j]);
    }
    printf("%d", data[i][c]);
    printf("\n");
  } 

  return 0;
}

Measured memory_bytes: 1072
sub f{my$p=$h[my$c=$c[$_]-1];my$r=$s=$v[++$_]=1;$v[$_--]or$a[$c]-=-$s*(-$s+($s=($r+=f())-$h[$c]+$p))for@$_;$a[$c]+=($p+$r-$h[$c])*(@a-($h[$c]=$p+$r))+1;$r}@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f;print"@a"

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> H(n);
    rep(i, n) cin >> H[i];

    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = abs(H[0] - H[1]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4844
//
//  main.cpp
//  A - Airplane
//
//  Created by Hashizo on 2019/06/09.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	int p,q,r,t;
	cin >> p >> q >> r;

	if (p > q) {
		if (q > r) {
			t = q + r;
		}
		else {
			if (p > r) {
				t = q + r;
			}
			else {
				t = q + p;
			}
		}
	}
	else {
		if (p > r) {
			t = p + r;
		}
		else {
			if (q > r) {
				t = p + r;
			}
			else {
				t = p + q;
			}
		}
	}
	
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,M;
ll s[1010];
ll minPoint[100010]={};
ll maxPoint[100010]={};
P ma[100010]={};
P mi[100010]={};
int main(){
    while(cin>>N>>M,N!=0){
        for(ll i=0;i<N;i++){
            minPoint[i]=0;
            maxPoint[i]=0;
        }
        for(ll i=0;i<M;i++){
            ll s,k,c;
            cin>>s>>k;
            for(ll j=0;j<k;j++){
                cin>>c;
                c--;
                maxPoint[c]+=s;
            }
            if(k==1){
                minPoint[c]+=s;
            }
        }
        for(ll i=0;i<N;i++){
            ma[i]=P(maxPoint[i],i);
            mi[i]=P(minPoint[i],i);
        }
        sort(ma,ma+N);
        sort(mi,mi+N);
        P ma1=ma[N-1],ma2=ma[N-2];
        P mi1=mi[0],mi2=mi[1];
        if(ma1.second!=mi1.second){
            cout<<ma1.first-mi1.first+1<<endl;
        }else{
            cout<<max(ma2.first-mi1.first,ma1.first-mi2.first)+1<<endl;
        }
    }
    return 0;
}



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

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  
  if(K>N){
    cout << N*X << endl;
  }
  else{
    cout << (N-K)*Y+K*X << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#define INF 100000000
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;

int h, w;
vector<string> s;
vector<vector<int> > d;
queue<pair<int, int> > que;

int bfs(){

  pair<int, int> start(0,0);
  que.push(start);

  while(!que.empty()){
    pair<int, int> p = que.front();
    que.pop();
    int cx = p.first;
    int cy = p.second;

    if(cx == h-1 && cy == w-1){
      return d[cx][cy];
    }

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

    rep(i,4){
      int nx = cx + dx[i];
      int ny = cy + dy[i];
      pair<int, int> next(nx,ny);

      if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' && d[nx][ny] == INF){
	que.push(next);
	d[nx][ny] = d[cx][cy] + 1; 
      }
    }
  }
  return -1;
}

int main(){

  cin >> h >> w;
  s = vector<string>(h);
  d = vector<vector<int> >(h, vector<int>(w,INF));
  d[0][0] = 0;
  rep(i,h) cin >> s[i];

  int n = 0;
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#') n++;
    }
  }

  int l = bfs();

  if(l == -1) cout << -1 << endl;
  else cout << h*w - n - l - 1 << endl;
  
  return 0;
}


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

int main() {
  int H,W,N;
  cin>>H>>W>>N;
  int A=N/H;
  int B=N/W;
  
  if(H>=W){
    if(A*H==N){
      cout<<A<< endl;
    }
    else{
      cout<<A+1<< endl;
    }
  }
  if(H<W){
    if(B*W==N){
      cout<<B<< endl;
    }
    else{
      cout<<B+1<< endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int W = in.nextInt(), H = in.nextInt(), x = in.nextInt(), y = in.nextInt(), r = in.nextInt();
        String ans = "Yes";
        if (x - r < 0 || //
                x + r > W || //
                y - r < 0 || //
                y + r > H) {
            ans = "No";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26300
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DLazyFaith {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int A, B, Q;
	    in >> A >> B >> Q;
	    vector<ll> s(A), t(B), x(Q);
	    REP(i,0,A) in >> s[i];
	    REP(i,0,B) in >> t[i];
	    REP(i,0,Q) in >> x[i];

	    sort(all(s));
	    sort(all(t));

	    REP(i,0,Q) {
	        ll prevShrine = -1e11, nextShrine = 1e11, prevTemple = -1e11, nextTemple = 1e11;
	        const auto itrShrine = lower_bound(all(s), x[i]);
	        if (itrShrine != s.end()) nextShrine = *itrShrine;
	        if (itrShrine != s.begin()) prevShrine = *(itrShrine - 1);
            const auto itrTemple = lower_bound(all(t), x[i]);
            if (itrTemple != t.end()) nextTemple = *itrTemple;
            if (itrTemple != t.begin()) prevTemple = *(itrTemple - 1);
            vector<ll> answers = {
                    max(nextShrine, nextTemple) - x[i],
                    x[i] - min(prevShrine, prevTemple),
                    2 * (x[i] - prevShrine) + (nextTemple - x[i]),
                    2 * (x[i] - prevTemple) + (nextShrine - x[i]),
                    2 * (nextShrine - x[i]) + (x[i] - prevTemple),
                    2 * (nextTemple - x[i]) + (x[i] - prevShrine),
            };
            ll answer = *min_element(all(answers));
            out << answer << "\n";
	    }
	}
};


signed main() {
	DLazyFaith solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,h,w,a,b,ans=0;
  cin>>n>>h>>w;
  fr(i,n){
    cin>>a>>b;
    if(a>=h&&b>=w) ans++;
  }
  cout<<ans<<endl;
}

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

const int INF = 1e9;

int main(){
    int n;
    int ans;
    vector<int> a;
    cin >> n;
    for(int i=0;i<n;i++){
        int ai;
        cin >> ai;
        a.push_back(ai);
    }
    sort(a.begin(), a.end());

    if(n%2==0){
        for(int i=0;i<n;i+=2){
            if(a[i]==a[i+1]&&a[i]==i+1)
                continue;
            else{
                ans=0;
                cout << ans << endl;
                return 0;
                break;
            }
        }
    } else {
        for(int i=0;i<n;i+=2){
            if(i==0&&a[i]==0)
                continue;
            else if(a[i]==a[i-1]&&a[i]==i)
                continue;
            else{
                ans=0;
                cout << ans << endl;
                return 0;
                break;
            }
        }
    }

    ans = 1;
    for(int i=0;i<(n/2);i++){
        ans *= 2;
        ans = ans%1000000007;
    }
    cout << ans << endl;
    //ans = int(pow(2, int(n/2)));
    //cout << ans%1000000007 << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
ll modi(ll a,ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b;
    swap(a,b);
    u-=t*v;
    swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
ll fact[100010]={};
ll modf(ll a,ll m){
  if(!a) return fact[0]=1;
  return fact[a]=modf(a-1,m)*a%m;
}
ll modc(ll a,ll b,ll m){
  ll c=modf(a,m);
  c=c*modi(modf(b,m),m)%m;
  c=c*modi(modf(a-b,m),m)%m;
  return c;
}
int main(){
  int N,K;
  cin>>N>>K;
  ll mod=1000000007;
  rep(i,K+1){
    if(i){
      if(i<=N-K+1){
        ll tmp=modc(N-K+1,i,mod)*modc(K-1,i-1,mod)%mod;
        cout<<tmp<<endl;
      }else cout<<0<<endl;
    }
  }
}

Measured memory_bytes: 384
#include <stdio.h>
 
int main(){
    char ch;
    while((ch = getchar()) != EOF){
            if(ch >= 97 && ch <= 122)
                printf("%c",ch-32);
            else if(ch >= 65 && ch <= 90)
                printf("%c",ch+32);
            else
                printf("%c",ch);
    }
}


Measured memory_bytes: 2496
N = int(input())
T = [int(t) for t in input().split()]
A = [int(a) for a in input().split()]
mod = 7 + 10**9

TS, AS = [None for i in range(N)], [None for j in range(N)] #山の高さが一意に決まるならTrue
TS[0], AS[-1] = True, True
for i in range(1, N):
    if T[i] > T[i-1]: TS[i] = True
    else: TS[i] = False
    if A[N-1-i] > A[N-i]: AS[N-1-i] = True
    else: AS[N-1-i] = False

Ans = 1
for i in range(N): 
    if TS[i] and AS[i]:
        if T[i] != A[i]: 
            Ans = 0
            break
    elif TS[i]:
        if A[i] < T[i]:
            Ans = 0
            break
    elif AS[i]:
        if T[i] < A[i]:
            Ans = 0
            break
    else:
        Ans *= min(T[i], A[i])
        Ans %= mod

print(Ans)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    int k;
    cin>>k;
    double p=0;
    for(int i = 1;i < n+1; i++){
        int now=i;
        double tmp=1.0/n;
        while(now<k){
            //cout<<now<<endl;
            now*=2;
            tmp/=2;
        }
        p+=tmp;
    }
    printf("%.12f\n",p);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const double PI = 3.141592653589793238463;
const ll N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    int x,y;
    for (int i=0; i<s.length(); i++)
    {
        if (s[i]=='A')
        {
            x=i;
            break;
        }
    }
    for (int i=s.length()-1; i>=0; i--)
    {
        if (s[i]=='Z')
        {
            y=i;
            break;
        }
    }
    cout<<1+y-x<<endl;
    return 0;
}


Measured memory_bytes: 720
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (3e5),n,m;
	static List<Integer>[] edges;
    static int[] dp,in;
    static List<Integer> list;
    
	public static void main(String[] args) {
		  n = sc.nextInt();
		  m = sc.nextInt();
		  edges = new ArrayList[n+1];
		  for(int i=0;i<edges.length;++i) edges[i] = new ArrayList<>();
		  in = new int[n+1];
		  for(int i=1;i<=m;++i) {
			  int u = sc.nextInt();
			  int v = sc.nextInt();
			  edges[u].add(v);
			  in[v]++;
		  }
		  tsort();
		  dp = new int[n+1];
		  Arrays.fill(dp, -1);
		  int ans = 1;
		  for(int i=list.size()-1;i>=0;--i) {
			  int v = list.get(i);
			  dp[v] = 1;
			  for(int node : edges[v]) {
				  dp[v] = Math.max(dp[v],dp[node] + 1);
			  }
			  ans = Math.max(ans, dp[v]);
		  }
		--ans;
	   out.print(ans);
	  out.close();
	 }
	 private static boolean tsort() {
			int n = in.length-1;
			// at any point it will contain only source vertex
			Queue<Integer> q = new LinkedList<>(); 
			for(int i=1;i<=n;++i)
				if(in[i] == 0) q.add(i); // adding all the source node with indegree 0.
			
			list = new ArrayList<>();
			while(q.size() > 0) {
				int x = q.poll();
				list.add(x);
				for(int node : edges[x]) {
					if(--in[node] == 0)
						q.add(node); // adding only when it becomes source
				}
			}
			if(list.size() == n) return true;
			else return false;
			
		}
}


Measured memory_bytes: 51768
#include<stdio.h>

int main()

{
      int t;//与えられた秒数
      int h;//時間
      int m;//60未満の分
      int s;//60未満の秒
      
     // printf("時間を秒単位で入力してください。:");
      
      scanf("%d",&t);
      
      h=t/(60*60);
      
	  m=(t%(60*60))/60;
      
      s=t%60;
      
      printf("%d:%d:%d\n",h,m,s);
	return 0;
}     





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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int k, s, cnt = 0;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s - i - j <= k && i + j <= s) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s;
	cin>>s;
	for(int i=0;;i++){
		if(s==1||s==2||s==4){
			cout<<i+4<<endl;
			return 0;
		}
		if(s%2==0)
			s/=2;
		else
			s=s*3+1;
	}
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
print(str((ty-sy)*'U' + (tx-sx)*'R' + (ty-sy)*'D' + (tx-sx+1)*'L' + (ty-sy+1)*'U' + (tx-sx+1)*'R' + 'DR' + (ty-sy+1)*'D' + (tx-sx+1)*'L' + 'U'))

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

int main() {
    int n, m;
    int l[100000], r[100000];
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> l[i] >> r[i];

    sort(l, l + m, greater<>());
    sort(r, r + m);
    int ans = r[0] - l[0] + 1;
    if (ans < 0) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 4380