akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b;
  cin >> a >> b ;
  
  int max = 0;
  
  if ( (a+b) >= (a-b) )
    max = a+b ;
  else
    max = a-b ;
  
  if ( max >= a*b )
    cout << max ;
  else 
    cout << a*b ;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long n = 0, h = 0, w = 0;
        for (int i = 1; i < 3501; i++) {
            for (int j = 1; j < 3501; j++) {
                long a = N * i * j;
                long b = 4*i*j - N*i - N*j;
                if(0 < b && b < a && a % b == 0){
                    h = i; w = j; n = a/b; break;
                }
            }
        }
        System.out.println(n + " " + h + " " + w);
        sc.close();

    }

}


Measured memory_bytes: 22740
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	long long a, b, n;
	scanf("%lld%lld%lld", &a, &b, &n);
	
	long long r;
	if (n >= b) {
		r = b - 1;
	} else {
		r = n;
	}
	
	long long ans = r * a / b;
	printf("%lld\n", ans);
	
	
	

	return 0;
}

//A*B*M+r*A => r*A/B，r要尽可能大 
//A*B*M


Measured memory_bytes: 1736
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>
#include <math.h>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
#define PI (acos(-1))  // 円周率pi

/* typedef */
// long long
typedef long long ll;

// pair
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<double, double> d_d;


/* main関数 */
int main(void) {
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n / 2 - 1;
	else cout << n / 2;

	return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (isupper(c)) {
    cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }
}

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

int main() {
  vector<int> V(5);
  for (int i=0; i<5; i++) {
    cin >> V[i];
  }
  int k;
  cin >> k;
  if (V[4]-V[0]>k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 3548
#include <iostream>

void call(int n);

int main(int argc, char** argv)
{
	int n;
	std::cin >> n;
	call(n);
}

void call(int n)
{
	int i = 1;
	while (true)
	{
		int x = i;
		if (x % 3 == 0)
		{
			std::cout << " " << i;
		}
		else
		{
			while (true)
			{
				if (x % 10 == 3)
				{
					std::cout << " " << i;
					break;
				}

				x /= 10;

				if (!x)
				{
					break;
				}
			}
		}

		if (++i > n)
		{
			break;
		}
	}

	std::cout << std::endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
        cin >> a[i];

    ll res = 0;
    for (ll d = 60; d >= -1; d--) // XとKのbitが初めて一致しなかった桁 =: d
    {
        if (d != -1 && !(k & (1LL << d))) // 一致しない桁を探す、d == -1 => X == K
            continue;

        ll tmp = 0;
        for (ll e = 60; e >= 0; e--)
        {
            ll mask = 1LL << e;
            ll num = 0; // e桁目に立っているbitの数

            for (ll i = 0; i < n; i++)
            {
                if (a[i] & mask)
                    num++;
            } 

            if (e > d) // dより上位の桁はKに合わせる
            {
                if (k & mask)
                    tmp += mask * (n - num);
                else
                    tmp += mask * num;
            }
            else if (e == d) // d桁目は1
            {
                tmp += mask * num;
            }
            else // dより下位の桁は貪欲に決めて良い
            {
                tmp += mask * max(num, n - num);
            }

            res = max(res, tmp);
        }
    }
    cout << res << endl; 
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc144/tasks/abc144_d

from math import pi, tan, atan, degrees

a, b, x = [int(i) for i in input().split()]

theta = (pi * 0.5) - atan(2 * x / (a * b**2))

if b * tan(pi * 0.5 - theta) <= a:
    print(degrees(theta))

else:
    theta = atan(((2 * b) / a) - (2 * x / a**3))
    print(degrees(theta))


Measured memory_bytes: 62700
#include <cstdio>
#include <vector>
using namespace std;

long long c;

void merge(int left, int mid, int right, vector<int>& A) {
	vector<int> L, R;
	int n1=mid-left;
	int n2=right-mid;
	int i,j,k;

	L.resize(n1+1);
	R.resize(n2+1);

	for(i=0; i<n1; ++i) {
		L[i]=A[left+i];
	}
	for(i=0; i<n2; ++i) {
		R[i]=A[mid+i];
	}
	i=j=0;
	L[n1]=1000000001;
	R[n2]=1000000001;
	for(k=left; k<right; ++k) {
		if(L[i]>R[j]) {
			c+=(long long)n1-(long long)i;
			A[k]=R[j];
			++j;
		} else {
			A[k]=L[i];
			++i;
		}
	}
	return;
}

void mergeSort(int left, int right, vector<int>& A) {
	if(left+1<right) {
		int mid=left+(right-left)/2;
		mergeSort(left,mid,A);
		mergeSort(mid,right,A);
		merge(left,mid,right,A);
	}
	return;
}

int main() {
	int n;
	vector<int> A;
	scanf("%d",&n);
	c=0;
	A.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&A[i]);
	}
	mergeSort(0,n,A);
	printf("%lld\n",c);
	return 0;
}

Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n,m;
    cin>>n>>m;
    int ans=n*(n-1)/2+m*(m-1)/2;
    cout<<ans<<endl;
  }
  //time("");
  return 0;
}

Measured memory_bytes: 256
def inputInts
    gets.chomp.split(" ").map(&:to_i)
end

def getTemp(h)
    @T - h * 0.006
end

def getDiff(index)
    (getTemp(@Hn[index-1]) - @A).abs
end

N = gets.to_i
@T, @A = inputInts
@Hn = inputInts

ans = 1
min_d = getDiff(1)
(1..N).each do |i|
    target_d = getDiff(i)
    if min_d > target_d
        min_d = target_d
        ans = i
    end
end

puts ans



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

void generator() {
    srand(time(NULL));

    ofstream out("a.in");
    int n = rand() % 10 + 2;
    int m = rand() % (n * n) + 1;
    out << n << " " << m << endl;
    for(int i = 1; i <= n; i ++) {
        int x = rand() % 20 + 1;
        out << x << " ";
    }

    out.close();
}

int brut() {
   ifstream in("a.in");
   int n, m;
   in >> n >> m;
   vector<int> v(n + 1, 0);
   for(int i = 1; i <= n; i ++)
        in >> v[i];

   map<pair<int, int>, bool> check;
   int ans = 0;
   while(m) {
        int mx = 0, a = 0, b = 0;
        for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= n; j ++)
                if(!check[{i, j}] && mx < v[i] + v[j]) {
                    a = i, b = j;
                    mx = v[i] + v[j];
                }
        check[{a, b}] = 1;
        ans += mx;

        m --;
   }
   in.close();

   return ans;
}

ll howmany(int lim, int n, const vector<ll> &v) {
    int j = 1;
    ll ans = 0;
    for(int i = n; i >= 1; i --) {
        while(j <= n && v[i] + v[j] < lim)
            j ++;
        ans += 1LL * (n - j + 1);
    }

    return ans;
}

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    ll m;
    cin >> n >> m;
    vector<ll> v(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];
    sort(v.begin() + 1, v.end());

    int x = 0;
    for(int step = (1 << 18); step; step >>= 1)
        if(m < howmany(x + step, n, v))
            x += step;
    x ++;

    vector<ll> sum(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        sum[i] = sum[i - 1] + v[i];

    int j = 1;
    ll ans = 0;
    for(int i = n; i >= 1; i --) {
        while(j <= n && v[i] + v[j] < x)
            j ++;
        ans += (v[i] * (n - j + 1) + sum[n] - sum[j - 1]);
    }

    m -= howmany(x, n, v);
    ans += ( (x - 1) * m);

    cout << ans;

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    ll h, ans = 1;
    cin >> h;
    while (h) {
        ans *= 2;
        h /= 2;
    }
    cout << ans-1;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int A, B, C;
    cin >> A >> B >> C;

    if(A == B && A != C) {
        printf("Yes\n");
    }
    else if(A == C && A != B) {
        printf("Yes\n");
    }
    else if(B == C && A != B) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;
class Program
{
    static void Main()
    {
        int[] beta = new int[2];
        while (true)
        {

            string[] alpha = Console.ReadLine().Split(' ');
            for (int i = 0; i < 2; i++) beta[i] = int.Parse(alpha[i]);
            if (beta[0] == 0 && beta[1] == 0) break;                        /*//if 0 0, break*/
            int unt = beta[0];
            int sumd = beta[1];
            int[] num = new int[150];
            for (int i = 0; i < unt; i++) num[i] = i;
            int count = 0;
            /*//unt までの数字を抽出*/
            for (int i = 1; ; i++)
            {
                if (i == unt+1) break;                                      /*//unt まで確認したら計算終了*/
                {
                    for (int j = 1; ; j++)
                    {
                        if (j == unt+1) break;
                        for (int k = 1; ; k++)
                        {
                            if (k == unt+1) break;
                            if (i == j || i == k || j == k||i ==0||j==0||k==0) break;
                            { if (i + j + k == sumd) count++; }
                        }
                    }
                }
            }
            Console.WriteLine(count/2);
        }
    }
}


Measured memory_bytes: 17976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a,p;cin>>a>>p;
	a=a*3+p;
	a/=2;
	cout<<a<<"\n";
}
/*
1 3
#.#


2 3
#.#
..#

3 3
##.
#.#
..#

3
2 5
6 1
3 7
Ans:6

4
3 7
2 9
8 16
10 8
Ans:9
*/


Measured memory_bytes: 256
using System;
using System.Linq;

namespace arc074_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (x[0] % 3 == 0 || x[1] % 3 == 0) Console.WriteLine(0);
            else
            {
                long ret = x.Min();
                for (int i = 1; i < x[0]; i++)
                {
                    long[] a = new long[] { i * x[1],(x[0] - i) * (x[1] / 2),(x[0] - i) * (x[1] - x[1] / 2) };
                    ret = Math.Min(ret,a.Max() - a.Min());
                }
                for (int i = 1; i < x[1]; i++)
                {
                    long[] a = new long[] { x[0] * i,(x[0] / 2) * (x[1] - i),(x[0] - x[0] / 2) * (x[1] - i) };
                    ret = Math.Min(ret,a.Max() - a.Min());
                }
                Console.WriteLine(ret);
            }
        }
    }
}

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

typedef long long ll;

ll N, K;
vector<ll> A;
typedef bitset<5000> bset;
vector<bset> S, T;
ll R;

int main() {
  cin >> N >> K;
  A.resize(N);
  for (ll i = 0; i < N; ++i) cin >> A[i];
  S.resize(N + 1);
  S[0][0] = 1;
  for (ll i = 0; i < N; ++i) {
    S[i + 1] = S[i] | (S[i] << A[i]);
  }
  T.resize(N + 1);
  T[N][0] = 1;
  for (ll i = N - 1; i >= 0; --i) {
    T[i] = T[i + 1] | (T[i + 1] << A[i]);
  }
  for (ll i = 0; i < N; ++i) {
    if (A[i] >= K) continue;
    vector<ll> c;
    c.resize(K + 1);
    for (ll x = 0; x < K; ++x) c[x + 1] = c[x] + T[i + 1][x];
    bool no_need = true;
    for (ll x = 0; x < K; ++x) {
      if (!S[i][x]) continue;
      if (c[K - x] > c[max(0ll, K - A[i] - x)]) {
        no_need = false;
      }
    }
    if (no_need) ++R;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 6528
import math
from functools import lru_cache
from itertools import combinations


@lru_cache(maxsize=None)
def gcd2(a: int, b: int) -> int:
    return math.gcd(a, b)


def gcd3(a: int, b: int, c: int) -> int:
    return gcd2(gcd2(a, b), c)


def main() -> None:
    k = int(input())

    one_to_k = range(1, k + 1)
    s1 = sum(one_to_k)
    s2 = sum(gcd2(a, b) for a, b in combinations(one_to_k, 2))
    s3 = sum(gcd3(a, b, c) for a, b, c in combinations(one_to_k, 3))
    print(s1 + 6 * s2 + 6 * s3)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11356
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) { cin >> A[i] >> B[i]; }

    sort(all(A));
    sort(all(B));
    double Amid, Bmid;
    ll ans;
    if (N % 2 == 0) {
        Amid = (double)(A[N / 2 - 1] + A[N / 2]) / 2;
        Bmid = (double)(B[N / 2 - 1] + B[N / 2]) / 2;
        ans = (Bmid - Amid) * 2 + 1;
    } else {
        Amid = A[(N + 1) / 2 - 1];
        Bmid = B[(N + 1) / 2 - 1];
        ans = (Bmid - Amid) + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6412
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    lint x,k,d,ans;cin>>x>>k>>d;
    if(x<0)x=-x;
    lint kaisuu=x/d;
    if(kaisuu>k){
        ans=x-k*d;
    }
    else{
        k-=kaisuu;
        x-=kaisuu*d;
        lint another=abs(x-d);
        k%=2;
        if(k==0)ans=x;
        else ans=another;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
 char A[10],B[10],C[10];
  int la,lb,lc;
  cin>>A>>B>>C;
  la=strlen(A);
  lb=strlen(B);
  
  if(A[la-1]==B[0]&&B[lb-1]==C[0])
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
x, k, d = map(int, input().split())

if x < 0:
    if x + k * d < 0:
        print(-x - k * d)
    else:
        a = -x // d
        x += a * d
        if (k - a) % 2 == 0:
            print(-x)
        else:
            print(x + d)
            
else:
    if x - k * d > 0:
        print(x - k * d)
    else:
        a = x // d
        x -= a * d
        if (k - a) % 2 == 0:
            print(x)
        else:
            print(d - x)


Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£???
		Scanner sc = new Scanner(System.in);
		// n????????°????????????
		int n = sc.nextInt();


		//???????????£?¨?
		int [] num = new int[n];

		//?????????????´?
		for(int i =0; i<n; i++){
			num[i] = sc.nextInt();
		}

		//??£?¨?
		int min = num[0];//????°????
		int max = num[0];//?????§???
		long sum = 0;//????¨????

		//
		for(int i = 0; i< n; i++){
			//?????¶???
			if(min > num[i]){
				min = num[i];
			}
			//?????¶??? ?????§???
			if(max < num[i]){
				max = num[i];
			}
			sum += num[i];
		}

		//????????¨???
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 41336
from bisect import bisect_left,bisect_right

def cntneg(X):
    cnt,r=0,posst
    for l in range(negend):
        while r<N and A[l]*A[r]>X:
            r+=1
        cnt+=poscnt-(r-posst)
    return cnt
def cntpos(X):
    cnt,r=0,N-1
    #正のペアの数
    for l in range(posst,N):
        while l<r and A[l]*A[r]>X:
            r-=1
        cnt+=max(0,r-l)
    l=0
    for r in range(negend-1,-1,-1):
        while l<r and A[l]*A[r]>X:
            l+=1
        cnt+=max(0,r-l)
    return cnt

N,K=map(int,input().split())
A=sorted(map(int,input().split()))
negend=bisect_left(A,0);posst=bisect_right(A,0)
poscnt=N-posst;negcnt=negend;zerocnt=N-poscnt-negcnt
zeroans=zerocnt*(poscnt+negcnt)+zerocnt*(zerocnt-1)//2
posans=poscnt*(poscnt-1)//2+negcnt*(negcnt-1)//2
negans=negcnt*poscnt

if(K<=negans):
    ng,ok=-10**18,0
    while abs(ok-ng)>1:
        X=(ng+ok)//2
        if cntneg(X)>=K:
            ok=X
        else:
            ng=X
elif(K<=negans+zeroans):
    print(0)
    exit()
else:
    K-=negans+zeroans
    ng,ok=0,10**18
    while abs(ok-ng)>1:
        X=(ng+ok)//2
        if cntpos(X)>=K:
            ok=X
        else:
            ng=X
            
print(ok)

Measured memory_bytes: 92608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double a,b,h,m,pi=3.1415926535897932384626;

int main(){
	cin>>a>>b>>h>>m;
	double ang,rageh=h/12.0+m/60.0/12.0,ragem=m/60.0;
	ang=fabs(rageh-ragem);
	if(ang>0.5)
		ang=1.0-ang;
	//cout<<ang*360<<endl;
	printf("%.16lf",double(sqrt(a*a+b*b-cos(ang*2.0*pi)*2.0*a*b)));
	
	
	
	return 0;
}

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

int main(){
    string S,T; cin >> S >> T;
        
    bool OK = false;
    for(int i = S.size() - T.size(); i >= 0; i--){
        string S_substr = S.substr(i,T.size());
        //cout << S_substr << endl;
        for(int j = 0; j < T.size(); j++){
           if( S_substr.at(j) != T.at(j) && S_substr.at(j) != '?'){
                break;
            }
            if(j == T.size() - 1){
                OK = true;
                for(int k = 0; k < T.size(); k++){
                    S.at(i+k) =T.at(k); 
                }
            }
        }if(OK) break;
    }
    
    for(int i = 0; i < S.size(); i++){
        if(S.at(i) == '?') S.at(i) = 'a';
    }

    if(OK) cout << S << endl;
    else cout << "UNRESTORABLE" << endl;
}



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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  bool ok = true;
  
  int i = 0;
  while(i < A + B + 1) {
    if(i == A && S[i] != '-') {
      cout<< "No" << endl;
      ok = false;
      break;
    }
    else if(i != A && S[i] == '-') {
      cout << "No" << endl;
      ok = false;
      break;
    }
    i++;
  }
  
  if(ok == true) cout << "Yes" << endl;
}

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

int main(){
	string s="CODEFESTIVAL2016";
	string s2;
	cin>>s2;
	
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=s2[i])ans++;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  double ans=0;
  rep(i,n) {
    double x;
    R x;
    ans+=1.0/x;
  }
  pd(1.0/ans);
}

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


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,n) for(int i=a;i<n;i++)
#define ps(x) cout<<x<<" "
#define pn(x) cout<<x<<"\n"
#define sz(a) int((a).size())
#define pb push_back
typedef vector< int > vi;
typedef pair< int,int > pairs;

int main()
{
    string a, b; int n,m;
    cin>>a>>b;
    n=a.length();m=b.length();
    loop(i,0,n) 
    {
        if(a[i]!=b[i])
        {pn("No");return 0;}
    }
    if(m-n == 1)    pn("Yes");
}

Measured memory_bytes: 3628
process.stdin.on("data",function(c){
	(c+"").trim().split("\n").some(function(n){
		var i=9999,c=0,s;
		while(s=(i+""),+s[0]+(+s[1]||0)+(+s[2]||0)+(+s[3]||0)===+n&&(c++),--i);
		console.log(c);
	});
}).resume();

Measured memory_bytes: 10256
#include <bits/stdc++.h>
using namespace std;
int sum0 = 0;
int sum1 = 0;
int main(){
  //char s[100000];
  string s;
  //scanf("%s", s);
  cin >> s;
  for(int i=0 ; i<s.size() ; i++){
    if(s[i]=='0') sum0++;
    else sum1++;
  }
  cout << min(sum0, sum1)*2 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int N,n;
    cin>>N;
    REP(i,1,450){
        if(N==(i*i+i)/2){
            n=i+1;
            break;
        }else if(N<(i*i+i)/2){
            cout<<"No"<<ENT;
            return 0;
        }
    }
    vector< vector<int> > v= vector< vector<int> > (n,vector<int>());
    int j=0,k=1;
    REP(i,1,N+1){
        v[j].push_back(i);
        v[k].push_back(i);
        if(k<n-1)k++;
        else{j++;k=j+1;}
    }
    cout<<"Yes"<<ENT<<n<<ENT;
    REP(i,0,n){
        cout<<n-1;
        REP(j,0,n-1) cout<<" "<<v[i][j];
        cout<<ENT;
    }
    return 0;
}


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


Measured memory_bytes: 2304
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 1e5 + 100;
char s[N];
bool vis[N];
int main() {
    scanf("%s", s);
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
        if(s[i] == '1') vis[i+1] = true;
    }
    if(vis[1] == 0 || vis[n-1] == 0 || vis[n] == 1) {
        printf("-1\n");
        return 0;
    }
    for (int i = 2; i < n-1; i++) {
        if(vis[i] != vis[n-i]) {
            printf("-1\n");
            return 0;
        }
    }
    stack<int> st;
    for (int i = 1; i <= n; i++) {
        if(vis[i]) {
            while(!st.empty()) printf("%d %d\n", st.top(), i), st.pop();
        }
        if(i != n)st.push(i);
    }
    while(!st.empty()) printf("%d %d\n", st.top(), n), st.pop();
    return 0;
}


Measured memory_bytes: 1868
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string s;cin>>s;
    vector<string> vec{"KIHBR","KIHBAR","AKIHBR","KIHABR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"};
    for(string x:vec){
        if(s==x){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}



Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string s1, s2;
  cin >> s1 >> s2;
  if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int wa(int x){
  int ret=0;
  for(int i=0;i<10;i++){
    ret+=x%10;
    x/=10;
  }
  return ret;
}

int main(){
  int N; cin >> N;
  int ans=100000;
  for(int i=1;i<=N/2;i++){
    ans=min(ans,wa(i)+wa(N-i));
  }
  cout << ans << endl;
}

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

int main() {
    int D,G;
    scanf("%d%d", &D, &G);
    int p[D], c[D];
    for (int i=0; i<D;i++) scanf("%d%d", &p[i],&c[i]);
    
    int ans=100000;
    for (int i=0; i < 1<<D;i++){
        int d=0, sum=0;
        for (int j=0; j<D;j++){
            if (i & 1<<j) {
                d+=100*(j+1)*p[j]+c[j];
                sum+=p[j];
                }
        }
        if (d<G){
            for (int j=D-1; j>=0;j--){
                if (!(i & 1<<j) && (100*(j+1)*p[j]+d>=G)){
                    sum+=(G-d+100*j)/(100*(j+1));
                    break;
                }
                else if (j==0){
                    sum=1000000;
                }
            }
        }
        ans=min(ans,sum);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp> 
#define int long long int
#define all(v) v.begin(),v.end() 
#define rev(v) v.rbegin(),v.rend()
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define inp 100005
#define en "\n"
using namespace std;
using namespace __gnu_pbds;

signed main() 
{
    ssd
    int n,i,j,k;
    cin>>n;
    vector<int> v(n+5), dp(n+5);
    for(i=1; i<=n; i++) cin>>v[i];
    
    dp[1] = 0;
    dp[2] = abs(v[2]-v[1]);
    for(i=3;i<=n;i++)
    {
        dp[i] = dp[i-1] + abs(v[i]-v[i-1]);
        dp[i] = min(dp[i], dp[i-2] + abs(v[i]-v[i-2]));
    }
    cout<<dp[n];
    return 0;           
}

Measured memory_bytes: 4784
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<functional>
#include<stack>
#include<deque>
#include<queue>
using namespace std;

signed main() {
	int a, b; string c; cin >> a >> b >> c;
	if (c.length() != a + b + 1)puts("No");
	else {
		for (int i = 0; i < c.length(); i++) {
			if (i == a) {
				if (c[i]!='-') {
					puts("No");
					return 0;
				}
			}
			else {
				if (c[i]<'0' || c[i]>'9') {
					puts("No");
					return 0;
				}
			}
		}
		puts("Yes");
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  cin>>n;
  vector<int> v;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    v.push_back(x);
  }
  cin>>q;
  vector<int>::iterator it,it2;
  for(int i=0;i<q;i++){
    int a;
    cin>>a;
    int ans,ans2;
    it=lower_bound(v.begin(),v.end(),a);
    it2=upper_bound(v.begin(),v.end(),a);
    cout<<it-v.begin()<<" "<<it2-v.begin()<<endl;
  }
  return 0;
}



Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    char c; cin>>c;
    if(isupper(c)) cout<<'A'<<endl;
    else cout<<'a'<<endl;
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    if (K==1) {
        cout << 0 << "\n";
        return 0;
    }else{
        cout << N - K << "\n";
        return 0;
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define BLK 555
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
const int mod = 1000000007;
const int N = 2e5+5, M = N;
//=========================================

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    int n, m;
    cin >> n >> m;

    cout << (n * (n-1) / 2) + (m * (m-1) / 2);


    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
const int MaxN = 1e5;

int vis[1005],ans[1005];

int main()
{
	int a,b,c,d;
	memset(vis,0,sizeof(vis));
	vis[1] = 1;
	for(int i = 2;i <= 100;i++)
	{
		a = i;
		for(int j = 1;j <= 100;j++)
		{
			a *= i;
			if(a > 1000) break;
			else vis[a] = 1;
		}
	}
	ans[0] = 0;
	for(int i = 1;i <= 1000;i++)
	{
		if(vis[i]) ans[i] = i;
		else ans[i] = ans[i - 1];
	}
	while(~scanf("%d",&a))
	{
		printf("%d\n",ans[a]);
	}
	return 0;
}

Measured memory_bytes: 128
#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

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

const int MAX = 1e5 + 41;

int n, m;
int deg[MAX];
int u[MAX];
vi e[MAX];

bool dfs(int x, int p, int want, int ban) {
	u[x] = 1;
	for (int y : e[x]) {
		if (y == ban) continue;		
		if (y == p) continue;
		if (y == want) return true;
		if (u[y]) continue;
		if (dfs(y, x, want, ban)) return true;
	}
	return false;
}

void solve () {
	int cnt4 = 0;
	int cnt6 = 0;
	fi(0, n - 1) {
		if (deg[i] % 2 == 1) {
			printf("No\n");
			return;
		}
		if (deg[i] >= 4) cnt4++;
		if (deg[i] >= 6) cnt6++;
	}
	if (cnt4 >= 3 || cnt6 >= 1) {
		printf("Yes\n");
		return;
	}
	if (cnt4 == 2) {
		int x = -1;
		int y = -1;
		fi(0, n - 1) {
			if (deg[i] == 4) {
				x = i;
			}
			if (x > y) swap(x, y);
		}		
		memset(u, 0, sizeof(u));
		if (dfs(x, -1, x, y)) {
			printf("Yes\n");
			return;
		} 
		memset(u, 0, sizeof(u));
		if (dfs(y, -1, y, x)) {
			printf("Yes\n");
			return;
		} 
	}
	printf("No\n");
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif

	scanf("%d %d", &n, &m);
	fi(1, m) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--, y--;
		e[x].pb(y);
		e[y].pb(x);
		deg[x]++;
		deg[y]++;
	}	
	solve();

	exit();
	return 0;
}





Measured memory_bytes: 8064
/* -----KAUN_MEET--------*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
int mod = 1000000007;
#define P get<0>
#define D get<1>
#define T get<2>
#define C get<3>
#define PB push_back
#define MP make_pair
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define F first
#define S second
#define gcd __gcd
#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void __print(int x)
{
    cerr << x;
}
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename Th, typename V>
void __print(const pair<Th, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename Th>
void __print(const Th &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
int ans[105][100000 + 3];
vector<pair<int, int>> p;
int n;
int answer(int i, int w)
{
    if(w<=0)
    return 0;

    if (i >= n)
        return 0;

    if (ans[i][w] != -1)
        return ans[i][w];

    int cost=p[i].S;
    int val=p[i].F;

    if(w<val){
        ans[i][w]=0;
        return 0;
    }
    ans[i][w]=max(answer(i+1,w),answer(i+1,w-val)+cost);
    return ans[i][w];
    
}
void binary_rock()
{
    int w;
    cin >> n >> w;

    int i, j, k, l;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= w; j++)
            ans[i][j] = -1;
    }

    for (i = 0; i < n; i++)
    {
        cin >> j >> k;
        p.PB({j,k});
        // cin>>p[i].F>>p[i].S;
    }
  sort(p.begin(),p.end());

    cout << answer(0, w) << endl;
}

signed main()
{
    fastio
        clock_t t1 = clock();

    int t = 1;
    // cin >> t;
    while (t--)
    {
        binary_rock();
    }

    clock_t t2 = clock();
    // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;
    // cout << CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 80128
import sys
from collections import defaultdict
sys.setrecursionlimit(1000000)

def dfs(d,s,l,v,dic):
    s_ = tuple(s)
    if dic[(d,s_)] != None:
        return dic[(d,s_)]
    if d == l:
        dic[(d,s_)] = 1
        for x in s:
            if x > (n>>1):
                dic[(d,s_)] = 0
                return 0
        return 1
    else:
        res = 0
        i,j = v[d]
        if s[i] < (n>>1):
            s[i] += 1
            res += dfs(d+1,s,l,v,dic)
            s[i] -= 1
        if s[j] < (n>>1):
            s[j] += 1
            res += dfs(d+1,s,l,v,dic)
            s[j] -= 1
        dic[(d,s_)] = res
        return res

def solve(n):
    dic = defaultdict(lambda : None)
    m = int(sys.stdin.readline())
    s = [0]*n
    f = [[1]*n for i in range(n)]
    for i in range(n):
        f[i][i] = 0
    for i in range(m):
        x,y = [int(x) for x in sys.stdin.readline().split()]
        x -= 1
        y -= 1
        s[x] += 1
        f[x][y] = 0
        f[y][x] = 0
    v = []
    for i in range(n):
        for j in range(i+1,n):
            if f[i][j]:
                v.append((i,j))
    l = len(v)
    print(dfs(0,s,l,v,dic))

while 1:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    solve(n)



Measured memory_bytes: 60040
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int a[] = new int[m+1];
    int b[] = new int[m+1];
    int answer = 0;
    int maxb = -1;
    int maxidx = -1;
    int work = 1;
    boolean flag = true;
	boolean hflag = true;
    for(int i = 1; i <= m; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    if(n == 1){
      for(int i = 1; i <= m; i++){
        if(a[i] == 1 && b[i] == 1){
          flag = false;
          break;
        }
      }
      if(!flag){
        System.out.println(1);
      }else{
        System.out.println("Impossible");
      }
    }else{
      while(work < n){
        maxb = -1;
        for(int i = 1; i <= m; i++){
		  if(hflag){
		  	if(a[i] <= 1){
			  if(b[i] > maxb){
                maxb = b[i];
                maxidx = i;
              }
		  	}
		  }else{
            if(a[i] <= work+1){
              if(b[i] > maxb){
                maxb = b[i];
                maxidx = i;
              }
          	}
		  }
        }
        if(maxb == -1){
          flag = false;
          break;
        }else{
          answer++;
          work = maxb;
          a[maxidx] = 101;
          b[maxidx] = 101;
		  hflag = false;
        }
      }
      if(flag){
        System.out.println(answer);
      }else{
        System.out.println("Impossible");
      }
    }
  }
}



Measured memory_bytes: 26492
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int s = n * (n + 1) / 2;
    int m3 = n / 3;
    int m5 = n / 5;
    int m15 = n / 15;
    cout << s - (m3*(m3+1)/2*3 + m5*(m5+1)/2*5 - m15*(m15+1)/2*15);
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a,count=0,count2=0;
    cin>>a;
    int b=a;
    while(b!=0){
        int rem=b%10;
        count++;
        b=b/10;
    }
    if(count==1){
        for(int i=1;i<=a;i++){
            count2++;
        }
        cout<<count2<<endl;
    }
    else if(count==2){
        cout<<9<<endl;
    }
    else if(count==3){
        for(int i=100;i<=a;i++){
            count2++;
        }
        cout<<count2+9<<endl;
    }
    else if(count==4){
        for(int i=1000;i<=a;i++){
            count2++;
        }
        cout<<909<<endl;
    }
    else if(count==5){
        for(int i=10000;i<=a;i++){
            count2++;
        }
        cout<<count2+909<<endl;
    }
    else if(count==6){
        cout<<90909<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=18e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int m;
    cin>>m;
    ll sum=0,sumb=0;
    for(int i=1;i<=m;i++)
    {
        ll a,b;
        cin>>a>>b;
        sum+=a*b;
        sumb+=b;
    }
    cout<<(sum-1)/9+sumb-1<<endl;
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

template<typename T>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
};

template<typename T> using wgraph = vector<vector<Edge<T>>>;

int N;
wgraph<int> G;
vint plen;

void dfs1(int u, int p) {
	plen[u] = 0;
	for (auto &e : G[u]) {
		if (e.to != p) {
			dfs1(e.to, u);
			chmax(plen[u], plen[e.to] + e.cost);
		}
	}
}

int dfs2(int u, int par_d, int p) {
	vint child = {0};
	for (auto &e : G[u]) {
		if (e.to == p) child.push_back(par_d);
		else child.push_back(plen[e.to] + e.cost);
	}
	sort(rbegin(child), rend(child));
	int ret = child[0] + child[1];
	
	for (auto &e : G[u]) {
		if (e.to != p) chmax(ret, dfs2(e.to, par_d + e.cost, u));
	}
	return (ret);
}

void Main() {
	cin >> N;
	G = wgraph<int>(N);
	plen = vint(N);
	for (int i = 0; i < N-1; i++) {
		int s, t, w; cin >> s >> t >> w;
		G[s].emplace_back(t, w);
		G[t].emplace_back(s, w);
	}
	dfs1(0, -1);
	cout << dfs2(0, 0, -1) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}



Measured memory_bytes: 25708