akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

ll n,m;
vector<ll> a;
ll count1[200002];

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

bool happy(ll x){
  ll k = 0;
  for(int i=0;i<a.size();i++){
    k += n - count1[max(0ll,(x - a[i]-1))];
  }
  if(k >= m) return true;
  else return false;
}

int main(){
  cin >> n >> m;
  ll temp;
  for(int i=0;i<n;i++){
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(),a.end());

  count1[0] = 0;
  for(int i=0;i<n;i++){
    count1[a[i]]++;
  }

  for(int i=1;i<200002;i++){
    count1[i] += count1[i-1];
  }

  ll l = 0,r = 200001;
  ll mid;
  while(true){
    mid = (l+r)/2;
    //cout << l << " " << r << endl;
    if(happy(mid) && !happy(mid+1)){
      break;
    }
    if(happy(mid)) l = mid;
    else r = mid;
  }

  ll b[n+1];
  b[0] = 0;
  for(int i=0;i<n;i++){
    b[i+1] = b[i]+a[i];
  }
  ll ans = 0;
  ll cnt = 0;
  ll k;
  for(int i=0;i<n;i++){
    k = n - count1[max(0ll,(mid - a[i]-1))];
    cnt += k;
    ans += b[n]-b[n-k]+k*a[i];
  }
  ans -= (cnt-m)*mid;
  cout << ans << endl;
  return 0;
}


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

int main() {

  string s1, s2;
  cin >> s1 >> s2;
  reverse(s1.begin(), s1.end());
  if(s1 == s2) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll x=0,y=0;
    rep(i,n){
      cin>>a[i];
      if(a[i]%2==0)x++;
      else y++;
    }
    x+=y/2;
    if(y%2==0){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
//#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    t=1;
    //cin>>t;
    while(t--){
    	int w,s;
    	cin>>s>>w;
    	if(w>=s)
    	{
    		cout<<"unsafe";
		}
		else
		cout<<"safe";
		

    }

}

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

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

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

    int q;
    cin >> q;


    vector< pair<int,bool> > t(q);
    for(int i=0;i<q;i++){
        int c;
        cin >> c;

        t[i] = make_pair(c,true);
    }

    int ans = 0;


    for(int i=0;i<n;i++){
        int x = s[i];
        for(int j=0;j<q;j++){
            if(x==t[j].first&&t[j].second){
                t[j].second = false;
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;

    sort(s.begin(), s.end());

    int c = 0;

    for (int i = 0; i < s.size() / 2; i++)
        if (s[i] == s[i + 1])
            c++;

    for (int i = s.size() / 2; i < s.size(); i++)
        if (s[i] == s[i + 1])
            c++;

    cout << (c == 2 ? "Yes" : "No") << '\n';
    return 0;
}


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


int main(){
	
	int n,m,t,sum=0;
	cin>>n>>m;
 
	for(int i=0;i<m;i++){
		cin>>t;
		sum+=t;
	}
	if(n-sum<0) cout<<-1<<"\n";
	else cout<<n-sum<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;

    int min,P,c=1;
    cin >> min;
    for (int i = 0; i < N-1; i++)
    {
        cin >> P;
        if(P<min){
            min = P;
            c++;
        }
    }

    cout << c << endl;
    
}

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var s = Console.ReadLine();
        Console.WriteLine(s.Substring(0, ab[1] - 1) + s.Substring(ab[1] - 1, 1).ToLower() + s.Substring(ab[1]));
    }
}

Measured memory_bytes: 13140
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	a, b, n := float64(nextInt()), float64(nextInt()), nextInt()

	m := float64(min(int(b)-1, n))

	fmt.Println(int(math.Floor(a*m/b) - a*math.Floor(m/b)))
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}

func min(n, m int) int {
	if n < m {
		return n
	}
	return m
}


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

int main() {
  int N;
  cin >> N;
  int A[200];
  for(int i = 0; i < N; i++) cin >> A[i];
  int res = 0;
  while (true) {
    bool exist_odd = false;
    for(int i = 0; i < N; ++i) {
      if (A[i] % 2 != 0)
        exist_odd = true;
    }
    if (exist_odd == true) break;
    for(int i = 0; i < N; ++i) {
      A[i] /= 2;
    }
    ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#define ll long long
using namespace std;
struct value
{
	ll x;
	ll y;
};
bool compare(value a, value b)
{
	//for descending order replace with a.roll >b.roll
	if (a.y < b.y)
		return 1;
	else
		return 0;
}
void pk()
{
	ll n;
	cin>>n;
	string s;
	map<string,ll> mp;
	while(n--)
	{
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
		pk();
	
	
}

Measured memory_bytes: 3660
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define INF (int)1e5
#define nax (ll)2e5+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
 
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
// look for  all edge cases
//search for a pattern




int main(){
	fast;
	double n;
	cin>>n;
	cout<<fixed<<setprecision(6);
	double pi = 3.1415;
	cout<<2*(pi)*n;
	return 0;
}

	


Measured memory_bytes: 3800
/*
 * VJUDGE A - Foods Loved by Everyone
 * author: roy4801
 * (C++)
 */
#include <bits/stdc++.h>

using namespace std;

#define PROB "A"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define N 30
int arr[N+5];
int n, m, k, tmp, ans;
bool flag;
int main()
{
	#ifdef DBG
	freopen("./testdata/" PROB TESTC ".in", "r", stdin);
	freopen("./testdata/" PROB ".out", "w", stdout);
	#endif
	while(cin >> n >> m)
	{
		memset(arr, 0, sizeof(arr));
		ans = 0;
		//
		for(int i = 0; i < n && cin >> k; i++)
			for(int j = 0; j < k && cin >> tmp; j++)
				arr[tmp]++;
		for(int i = 1; i <= m; i++)
			if(arr[i] == n)
				ans++;
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll n;
    while(cin>>n && n){
        ll count=n/2;
        ll i;
        for(i=1;i*i<n/2;i++){
            count+=(n/2+i-1)/i;
        }
        cout<<((((count*=2)-=i*i)*=8)+=2*4*n)<<endl;
    }
    
    return 0;
}



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


int main() {

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

	vector<int> a = { A,B,C };
	sort(a.begin(), a.end());

	int ans;
	if ((a.at(0) - a.at(1)) % 2 == 0) {
		ans = (2 * a.at(2) - a.at(1)-a.at(0)) / 2;
	}

	else {
		ans = (2 * a.at(2) - a.at(1) - a.at(0) + 3) / 2;
	}
	cout << ans;
}

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;


    cin >> r;

    cout << r * 2 * 3.14159 << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


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

int main(){
 long long N,u,c,ans;
  cin>>N;
  ans=100000000000;
  c=0;
  vector<int>s(N);
    for(int i=0;i<N;i++){
      cin>>s[i];
c+=s[i];
    }
  if(c%10!=0){
    cout<<c<<endl;
    return 0;
  }
  else{
    sort(s.begin(),s.end());
     for(int i=0;i<N;i++){
      if(s[i]%10==0){
        continue;
      }
       else{
         cout<<c-s[i]<<endl;
         return 0;
       }
     }
  }
      cout<<0<<endl;
}

Measured memory_bytes: 256
input()
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
pts = 0
prev = 0
for i in range(len(A)):
    try:
        pts += B[A[i] - 1]
    except:
        pass
    try:
        if prev+1 == A[i]:
            pts += C[A[i-1]-1]
    except:
        pass
    prev = A[i]
print(pts)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
long long a,b,c[100],ans;
int main()
{
	cin>>a>>b;
	for(int s=0;s<a;s++)cin>>c[s];
	sort(c,c+a);
	for(int s=a-1;s>=a-b;s--)ans+=c[s];
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[100100], b[100100];

int solve() {
    ll sum_a = 0, sum_b = 0;
    for (int i = 0; i < n; i++) {
        sum_a += a[i];
        sum_b += b[i];
    }
    if (sum_a < sum_b) return -1;

    vector<int> vec(n);
    for (int i = 0; i < n; i++) vec[i] = i;
    sort(ALL(vec), [](int i, int j){ return a[i]-b[i] < a[j]-b[j]; });

    int idx = 0;
    ll lack = 0;
    while (a[vec[idx]] - b[vec[idx]] < 0) {
        lack += b[vec[idx]] - a[vec[idx]];
        idx++;
    }

    int res = idx;
    for (int i = n-1; i >= 0 && lack > 0; i--) {
        lack -= a[vec[i]] - b[vec[i]];
        res++;
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 2176
myList=[]
myList_int=[]
myList=input().split() #split()でリストに入力をstrで入れる
myList_int=[int(s) for s in myList] #intに変換

#print(myList)

if myList_int== [7,5,5]:
    print("YES")
elif myList_int== [5,7,5] :
    print("YES")
elif myList_int== [5,5,7] :
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
N = int(input())
L = 10**9+7
# -0が存在しない-9が存在しない+0,9の両方が存在しない
# (0が存在する+9が存在する)-(0,9野どちらかが存在する)
# 0、9のどちらかがある場合 = 全体(10**N)-8**N
# ０が存在する場合=全体-0が存在しない場合(9**N)
# 9が存在する場合=全体-9が存在しない場合
# 0は存在するけど9は存在しない
# 0or9のどちらかがある場合は?
# 100-81
if N==1:
    print(0)
    exit()
All = pow(10,N,L)
C09 = All - pow(8,N,L)
C9 = All - pow(9,N,L)
C0 = All - pow(9,N,L)
print((-C09+C9+C0)%L)



Measured memory_bytes: 9188
N = int(input())
A = list(map(int, input().split()))

sums =sum(A)

l = 0
mlen = sums
for i in A:
    l += i
    r = sums - l
    #print("l="+str(l) + "r="+str(r))

    lr =l-r
    if lr <0:lr*=-1

    #print("mlen="+str(mlen)+"rl=" + str(lr))
    if mlen < lr:
        break
    else:
        mlen = r-l
        if mlen <0:mlen*=-1



print(mlen)

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

using namespace std;

long long inf=1000000007;

long long solve(vector<long long> num,long long mid){
	long long ret=0;

	for(int i=0;i<(int)num.size();i++){
		ret+=abs(num.at(i)-mid);
	}

	return ret;
}

int main(){
	int n;
	cin>>n;
	vector<long long> num(n);

	for(int i=0;i<n;i++){
		cin>>num.at(i);
		num.at(i)-=i+1;
	}

	sort(num.begin(),num.end());

	cout<<min(solve(num,num.at(n/2)),solve(num,num.at(max(n/2-1,0))))<<endl;

	return 0;
}


Measured memory_bytes: 4992
# 1
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_a
if False:
    N,K=map(int,input().split())
    print('YES' if N-K-(K-1)>=0 else 'NO')

# 2
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b
if False:
    N=int(input())
    S=input()
    print('Yes' if S.count('R')>S.count('B') else 'No')

# 3
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_a
if False:
    print('Yes' if len(set(input().split()))==1 else 'No')

# 4
# https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_b
if False:
    N=int(input())
    S=input()
    K=int(input())
    r=S[K-1]
    ans=''
    for s in S:
        if s==r: ans+=s
        else: ans+='*'
    print(ans)

# 5
# https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_a
if True:
    A,B,C=map(int,input().split())
    if A>B: A,B=B,A
    print('Yes' if A<=C<=B else 'No')

Measured memory_bytes: 3064
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

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

struct seg{
	int L, R;
};
const int MAXN = 2e5+5;

int n, m;
seg s[MAXN];
vi Rs[MAXN];

ii solve(int p){
	priority_queue<int> pq;
	FOR(i,p+1,m+1) for(auto r : Rs[i]) pq.push(r);
	int lr=0, rr=0;
	FORR(i,p,0){
		for(auto r : Rs[i]) pq.push(r);
		if(pq.empty()) continue;
		int r = pq.top();
		pq.pop();
		lr++;
	}
	for(auto r : Rs[0]) pq.push(r);
	FORR(i,m,p){
		while(!pq.empty() && pq.top()>i) pq.pop();
		if(pq.empty()) continue;
		int r = pq.top();
		pq.pop();
		rr++;
	}
	return {lr,rr};
}

int main(){
	scan(n,m);
	FOR(i,0,n) scan(s[i].L, s[i].R);
	FOR(i,0,n) Rs[s[i].L].pb(s[i].R);
	int lo=0, hi=m;
	while(lo<hi){
		int mi = (lo+hi+1)>>1;
		debug(lo,mi,hi);
		ii ret = solve(mi);
		if(ret.fst + ret.snd == n) lo=hi=mi;
		else{
			if(ret.fst == mi) lo = mi;
			else hi=mi-1;
		}
	}
	ii ret = solve(lo);
	int ans = ret.fst + ret.snd;
	printf("%d\n",n-ans);
}

Measured memory_bytes: 11120
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

fn main() {
    let (a, b, c, x): (usize, usize, usize, usize);
    input!(a);
    input!(b);
    input!(c);
    input!(x);
    let mut ans: usize = 0;

    for i in 0..a + 1 {
        for j in 0..b + 1 {
            for k in 0..c + 1 {
                if 500 * i + 100 * j + 50 * k == x {
                    ans += 1;
                }
            }
        }
    }
    p(ans);
}

Measured memory_bytes: 4352
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))

tar=1000*(t-a)/6
best=10**5
best_i=-1
for i in range(len(H)):
  dif=abs(tar-H[i])
  if dif<best:
    best=dif
    best_i=i
print(best_i+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
string mode[2] = {"LR", "DU"};
vi m;
char move(int& a, int b, int c) {
	int op = a < 0 ? -1 : 1;
	char s = mode[c][a >= 0];
	a = (abs(a) - b) * op;
	return s;
}
void solve() {
	var(int, n);
	int yx[n][2];
	rep(i, 0, n) cin >> yx[i][0] >> yx[i][1];
	bool odd = (abs(yx[0][0]) + abs(yx[0][1])) % 2;
	rep(i, 1, n) {
		if (((abs(yx[i][0]) + abs(yx[i][1])) % 2) != odd) {
			print(-1);
			return;
		}
	}
	rrep(i, 30, -1) {
		m.eb(1 << i);
	}
	if (!odd) m.eb(1);
	print(len(m));
	rep(i, 0, len(m) - 1)
		cout << m[i] << " ";
	print(m.back());
	each(a, yx) {
		string s = "";
		each(b, m) {
			if (abs(a[0]) > abs(a[1])) {
				s += move(a[0], b, 0);
			} else {
				s += move(a[1], b, 1);
			}
		}
		print(s);
	}
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int test(string s,char t,int f)
{
    for(int i=f;i<s.size();i++)
    if(s[i]==t) return i+1;
    return 0;
}
int main()
{
    string s;
    cin>>s;
    if(test(s,'C',0) && test(s,'F',test(s,'C',0)-1))
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<n*(n-1)/2-n/2<<endl;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i+j==n+(n%2==0?1:0)){
				continue;
			}else{
				cout<<i<<" "<<j<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
    

while Q:top = Q.pop(0);func(top)

for i in range(N):print(i + 1 ,int(L[i]))



Measured memory_bytes: 5624
#include <iostream>
#include <cmath>

using namespace std;

#define MAX(x, y) (x > y ? x : y)

int main()
{

	long long int n, y;
	cin >> n >> y;
	
	long long int yu = -1, hi = -1, no = -1;
	for (int i = 0; i <= n; i++) 
	{
		for (int j = 0; j <= n; j++)
		{
			if (i + j > n) break;
			for (int k = 0; k <= n; k++)
			{
				if (i + j + k > n) break;
				if (i + j + k != n) continue;

				if (i * 10000 + j * 5000 + k * 1000 == y)
				{
					yu = i;
					hi = j;
					no = k;
					goto loop;
				}
			}
		}
	}
	loop:
	cout << yu << " " << hi << " " << no << endl;

	return 0;
}


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

int main() {
  int N, diff=0;
  cin >> N;
  
  vector<int> a_i(N);
  
  for (int i=0;i<N;i++)
    cin >> a_i.at(i);
  
  sort(a_i.begin(), a_i.end());
  reverse(a_i.begin(), a_i.end());
  
  if (N%2 == 0){
    for (int i=0;i<N/2;i++)
      diff += a_i.at(i*2) - a_i.at(i*2+1);
  }
  else{
    for (int i=0;i<N/2;i++)
      diff += a_i.at(i*2) - a_i.at(i*2+1);
    diff += a_i.at(N-1);
  }
  
  cout << diff << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    double x[57],y[57];
    int xs[57],ys[57];
    cin >> N;
    REP(i,N){
        cin >> xs[i] >> ys[i];
        x[i]=xs[i];y[i]=ys[i];
    }
    double L=0,R=2000.0,r;
    
    while(abs(R-L)>1e-8){
        r=(L+R)/2;
        vector<pair<double,double>> P;
        REP(i,N){
            REP(j,N){
                if(i>=j)continue;
                pair<double,double> C={(x[i]+x[j])/2.0,(y[i]+y[j])/2.0};
                pair<double,double> v={(y[i]-y[j]),(x[j]-x[i])};
                double d = hypot(v.first,v.second);
                v.first/=d;v.second/=d;
                double l = hypot((x[i]-x[j]),(y[i]-y[j]))/2.0;
                if(r<l)continue;
                double h = sqrt(r*r-l*l);
                P.push_back({C.first+h*v.first,C.second+h*v.second});
                P.push_back({C.first-h*v.first,C.second-h*v.second});
                
                /*printf("{%.10f,%.10f}\n",x[i],y[i]);
                printf("{%.10f,%.10f}\n",x[j],y[j]);
                printf("{%.10f,%.10f}\n",P[0].first,P[0].second);
                printf("{%.10f,%.10f}\n",P[1].first,P[1].second);*/
                //cout << c[0] MM c[1] << endl;
                
            }
        }
        bool c = false;
        REP(j,P.size()){
            double mx = 0;
            REP(i,N){
                mx=max(mx,hypot(x[i]-P[j].first,y[i]-P[j].second));
            }
            if(mx<=r+1e-10){
                c=true;
            }
        }
        
        //printf("%.10f\n",r);
        //cout << (c?"true":"false") << endl;
        
        if(c){
            R=r;
        }else{
            L=r;
        }
    }
    
    printf("%.10f\n",L);
    return 0;
}



Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
num = []
def dfs(n, curnum):
    if n == 0:
        num.append(curnum)
        return
    last = int(curnum[-1])
    next_digits = []
    for k in [-1, 0, 1]:
        if 9 >= last + k >= 0:
            next_digits.append(str(last + k))
    for dig in next_digits:
        dfs(n-1, curnum + dig)

def main():
    K = I()
    for i in range(0, 100):
        for j in range(1, 10):
            dfs(i, str(j))
            if len(num) > K:
                print(num[K-1])
                return


main()



Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

//エデュフォバチャやる
int main() {
    map<int, int> mp;
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++;mp[b]++;mp[c]++;
    for(auto x : mp){
        if(x.second == 1)cout << x.first << endl;
    }
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int sunuke[N] = {0};
	
	for(int i = 0; i < K; i++){
		int d;
		cin >> d;
		for(int j = 0; j < d; j++){
			int tmp;
			cin >> tmp;
			sunuke[tmp-1]++;
		}
	}

	int count = 0;
	for(int i = 0; i < N; i++){
		if(sunuke[i] == 0) count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3636
<?php
list($a,$b) = explode(" ",trim(fgets(STDIN)));

// Zero 判定
if ( ($a < 0 && $b > 0) || ($a == 0) || ($b == 0) ) {
	echo 'Zero'.PHP_EOL;
	return 0;
}

// Negative 判定
if ( !($a == $b) && ($a < 0) && !(($a - $b) % 2) ) {
	echo 'Negative'.PHP_EOL;
	return 0;
}

// その他はすべて Positive
echo 'Positive'.PHP_EOL;
return 0;


Measured memory_bytes: 2812
# ABC131C - Anti-Division
from fractions import gcd

A, B, C, D = map(int, input().split())
X = B // C - (A - 1) // C
Y = B // D - (A - 1) // D
lcm = int(C / gcd(C, D) * D)
Z = B // lcm - (A - 1) // lcm
print(B - A + 1 - X - Y + Z)


Measured memory_bytes: 5432
import java.util.Scanner;
import java.math.BigInteger;
 
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
BigInteger a=sc.nextBigInteger();
BigInteger b=sc.nextBigInteger();
a=a.add(b);
if(String.valueOf(a).length()>80){
System.out.println("overflow");
}
else{
System.out.println(a);
}
}
}
}

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

int main() {
  int R;
  cin >> R;
  
  if(R < 1200) {
    cout << "ABC" << endl;
  }
  else if(R >= 1200 && R<2800) {
    cout << "ARC" << endl;
  }
  else if(R >= 2800) {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse2")

#include <cstdio>
using namespace std;

int main() {
    const int m_max = 200000;
    const int q_max = 100000;

    int N, M, Q;
    scanf("%d%d%d", &N, &M, &Q);

    alignas(32) short L[m_max], R[m_max];

    for (int i = 0; i < M; i++) {
        scanf("%hd%hd", &L[i], &R[i]);
    }

    int ans[q_max];
    alignas(32) short p[q_max], q[q_max];

    for (int i = 0; i < Q; i++) {
        ans[i] = 0;
    }

    for (int i = 0; i < Q; i++) {
        scanf("%hd%hd", &p[i], &q[i]);
    }

    const int Q1 = Q / 6 * 6;
  
    for (int i = 0; i < Q1; i += 6) {
        for (int j = 0; j < M; j++) {
            ans[i] += (p[i] <= L[j] & R[j] <= q[i]);
            ans[i + 1] += (p[i + 1] <= L[j] & R[j] <= q[i + 1]);
            ans[i + 2] += (p[i + 2] <= L[j] & R[j] <= q[i + 2]);
            ans[i + 3] += (p[i + 3] <= L[j] & R[j] <= q[i + 3]);
            ans[i + 4] += (p[i + 4] <= L[j] & R[j] <= q[i + 4]);
            ans[i + 5] += (p[i + 5] <= L[j] & R[j] <= q[i + 5]);
        }
    }
  
    for (int i = Q1; i < Q; i++) {
        for (int j = 0; j < M; j++) {
            ans[i] += (p[i] <= L[j] & R[j] <= q[i]); 
        }
    }

    for (int i = 0; i < Q; i++) {
        printf("%d\n", ans[i]);
    }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
double distance(int x1, int y1) 
{ 
    // Calculating distance 
    return sqrt(pow(x1, 2) +  
                pow(y1, 2) * 1.0); 
} 
int main() {
	// your code goes here
    int n,d;
    cin>>n>>d;
    int cnt=0;
    while(n--){
        int x,y;
        cin>>x>>y;
        double dist=distance(x,y);
        if(dist<=d*1.0)
            cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3676
#include <stdio.h>

int main(void) {
	
	int x,i=1;
	
	while(1){
		
		scanf("%d",&x);
		
		if (x==0){
			break;
		}
		
		printf("Case %d: %d\n",i,x);
		i=i+1;
		
		
	}
	
	return 0;
}

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

int main() {
    //
    int num;

    cin >> num;

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == num) { cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";
    //
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

    if(b>=a*c) cout << c << endl;
    else cout << b/a << endl;


    return 0;
}


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

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

struct mintcomb{
    vector<mint> fact;
    vector<mint> ifact;
    mintcomb(ll n) : fact(n + 1, 1), ifact(n + 1, 1) {
        for(ll i = 2; i <= n; ++i){
            fact.at(i) = fact.at(i - 1) * i;
            ifact.at(i) = fact.at(i).inv();
        }
    }

    mint factorial(ll k) const { return fact.at(k); }
    mint combination(ll k, ll l) const {
        return fact.at(k) * ifact.at(l) * ifact.at(k - l);
    }
};

vector<mint> pow2;

mint calc(ll r, ll c){
    mint ans = 0;
    ans += pow2.at(r + c + 1) - 1;
    mintcomb mc(r + c + 1);
    REP(i, c){
        const mint v = mc.combination(r + i, i);
        ans -= v * (pow2.at(c - i) - 1);
    }
    REP(i, r){
        const mint v = mc.combination(c + i, i);
        ans -= v * (pow2.at(r - i) - 1);
    }
    return ans;
}

int main(){
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    pow2.resize(r2 + c2 + 2);
    pow2.at(0) = 1;
    for(ll i = 1; i < pow2.size(); ++i){
        pow2.at(i) = pow2.at(i - 1) * 2;
    }

    const mint v1 = calc(r2, c2);
    const mint v2 = calc(r2, c1 - 1);
    const mint v3 = calc(r1 - 1, c2);
    const mint v4 = calc(r1 - 1, c1 - 1);
    const mint ans = v1 - v2 - v3 + v4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 47168
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>
 
 
using namespace std;
 
#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
const ll MOD = 1e9 + 7;
vi alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };
 
 
 
int main() {
    ll N;
    cin >> N;
    vll A(N);
    vll B(N);
    vll C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A);
    sort(B);
    sort(C);
    ll ans = 0;
    rep(i, N) {
        ll b = B[i];
        ll counta = 0;
        ll countc = 0;
        auto a = lower_bound(all(A),b);
        auto c = upper_bound(all(C), b);
        counta = a - A.begin();
        countc = C.end() - c;
        ans += counta * countc;
    }
    cout << ans << endl;
}

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

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(){
  int n,upp_w;
  cin >> n >> upp_w;
  
  ll w[n],v[n];
  for(int i = 0;i<n;++i){
    cin >> w[i] >> v[i];
  }
  
  int sum_vmax = 0;
  ll sum_wmax = 0;
  for(int i = 0;i<n;++i){
    sum_vmax += v[i];
    sum_wmax += w[i];
  }
  
  //初期化 初期条件
  ll dp[n+5][sum_vmax+5];
  for(int i = 0;i<n+5;++i){
    for(int sum_v = 0;sum_v < sum_vmax+5;++sum_v){
      dp[i][sum_v] = sum_wmax;
    }
  }
  
  //ループ
  for(int i = 0;i<n;++i){
    for(int sum_v = 0;sum_v <= sum_vmax;++sum_v){
      chmin(dp[i+1][sum_v],dp[i][sum_v]);
    }
    for(int sum_v = 0;sum_v <= sum_vmax - v[i];++sum_v){
      chmin(dp[i+1][sum_v],dp[i][sum_v+v[i]]-w[i]);
    }
  }
  
  //解の出力
  int ans = 0;
  for(int sum_v = sum_vmax;sum_v>=0;--sum_v){
    for(int i = 0;i<n+1;++i){
      if(dp[i][sum_v] <= upp_w){
        ans = sum_v;
        break;
      }
    }
    if(ans) break;
  }  
  cout << ans;
}

Measured memory_bytes: 82304
#include<queue>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h&&(w||h)){
    int a[10][10],x,y;
    memset(a,0,sizeof(a));
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	cin>>a[j][i];
	if(a[j][i]==2){
	  a[j][i]=1;
	  x=j;
	  y=i;
	}
      }
    }
    unsigned b[10][10][7];
    memset(b,-1,sizeof(b));
    queue<pair<pair<int,int>,pair<int,int> > > c;
    c.push(make_pair(make_pair(x,y),make_pair(0,6)));
    while(c.empty()==0){
      int x,y,z,h;
      x=c.front().first.first;
      y=c.front().first.second;
      z=c.front().second.first;
      h=c.front().second.second;
      if(h&&a[x][y]==3)
	break;
      c.pop();
      if(a[x][y]==4&&h)
	h=6;
      if(a[x][y]!=0&&b[x][y][h]>(unsigned)z&&h){
	b[x][y][h]=z;
	c.push(make_pair(make_pair(x-1,y),make_pair(z+1,h-1)));
	c.push(make_pair(make_pair(x+1,y),make_pair(z+1,h-1)));
	c.push(make_pair(make_pair(x,y-1),make_pair(z+1,h-1)));
	c.push(make_pair(make_pair(x,y+1),make_pair(z+1,h-1)));
      }
    }
    cout<<(c.empty()?-1:c.front().second.first)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 102
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(int);
void visit(int,int);
void print(int);

int A[MAX][MAX],d[MAX],f[MAX],color[MAX],time;
int main(){
  int n,m,i,j,flag=0,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&A[i][0],&m);
    for(j=1;j<=m;j++){
      flag = scanf("%d",&k);
      if(flag==1) A[i][k]=1;
      flag=0;
    }
  }
  dfs(n);
  print(n);
  return 0;
}
void dfs(int n){
  int i;
  for(i=1;i<=n;i++){
    if(color[i]==WHITE) visit(i,n);
  }
}
void visit(int u,int n){
  int i;
  color[u]=GRAY;
  d[u]=++time;
  for(i=1;i<=n;i++){
    if(A[u][i]==0) continue;
    if(color[i]==WHITE) visit(i,n);
    }
  color[u]=BLACK;
  f[u]=++time;
}
void print(int n){
  int i;
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
}




Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

// a=a'c,b=b'cなので、LCM(a,b)=a*b/GCD(a,b)
ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

ll count(ll a) {
  if (a % 2 == 1)
    return 0;
  return 1 + count(a / 2);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll now = A[0] / 2;
  FOR(i, 1, N) now = now * A[i] / (2 * GCD(now, A[i] / 2));
  bool ok = true;
  ll yo = count(A[0]);
  FOR(i, 1, N) if (yo != count(A[i])) ok = false;
  if (ok)
    cout << (M / (2 * now)) + ((M / now) % 2) << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int H,W,cnt=0;
	vector<string> S;
	bool flag;

	cin>>H>>W;
	string tmp;
	for(int i=0;i<W;i++){
		tmp.pb('.');
	}
	for(int i=0;i<H;i++){
		string s;
		cin>>s;
		if(s!=tmp){
			S.pb(s);
			cnt++;
		}
	}
	for(int i=0;i<W;i++){
		flag=true;
		for(int j=0;j<cnt;j++){
			if(S[j][i]=='#')flag=false;
		}
		if(flag){
			for(int j=0;j<cnt;j++){
				S[j][i]='a';
			}
		}
	}
	for(int i=0;i<cnt;i++){
		for(int j=0;j<W;j++){
			if(S[i][j]!='a')cout<<S[i][j];
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = input().split()
num = [0 for _ in range(len(n))]
for i in range(len(n)):
    num[i] = int(n[i])
for i in (reversed(range(len(n)))):
    for j in range(i):
        if num[j] > num[j + 1]:
            tmp = num [j + 1]
            num[j + 1] = num[j]
            num[j] = tmp
print(str(num[0])+" "+str(num[1])+" "+str(num[2]))




Measured memory_bytes: 5604
/*
      THINK  TWICE  CODE  ONCE
        KEEP   GOING   BI*CH
           NEVER GIVE UP
               3 R B
                . .
                 .
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-14;
const ll MOD = 1e9+7;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int s,w;
    cin>>s>>w;
    if(w>=s)
       cout<<"unsafe";
    else
        cout<<"safe";
}


Measured memory_bytes: 3520
#include <iostream>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    if(n%2 == 1){
        if(k>(n/2)+1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }
    }else{
        if(k>n/2){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }
    }
    return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	
 
const ll mod=1e9+7;
const int INF=INT_MAX/2;

int main(){
	int n, k;
	cin>>n>>k;
	int d[k];
	bool have[n];
	REP(i,n)have[i]=false;
	REP(i,k){
		cin>>d[i];
		REP(j,d[i]){
			int ai;
			cin>>ai;
			ai--;
			have[ai]=true;
		}
	}
	int cnt=0;
	REP(i,n)if(!have[i])cnt++;
	cout<<cnt<<endl;
	return 0;
}
 

Measured memory_bytes: 3652