akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int64_t INF = 1LL << 60;

int main() {
 	int64_t H,N;
   cin>>H>>N;
   vector<int64_t>A(N);
   int64_t sum=0;
   for(int i=0;i<N;i++){
     cin>>A[i];
     sum+=A[i];
   }
   sort(A.begin(),A.end());
   if(sum>=H){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int a, x;
    cin >> x >> a;
    if(x < a)cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
	KAKA
	ll l,r,d;
	cin>>l>>r>>d;
	ll a = l/d;
	ll b = r/d;
	ll c = b - a;
	if((l % d) == 0) c++;
	cout<<c<<"\n";
}

Measured memory_bytes: 3576
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) {
    def printRectangle: Unit = {
      val Array(a, b) = readLine().split(" ").map(_.toInt)
      if(a != 0 || b != 0) {
        for(i <- 0 until a) {
          println(Seq.fill(b)("#").mkString(""))
        }

        println()
        printRectangle
      }
    }

    printRectangle
  }
}

Measured memory_bytes: 48108
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {}
for key, a in zip(range(1, n+1), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)

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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;

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

    ll k;
    cin >> k;
    vector<bool> seen(k+1,false);
    seen[0]=true;
    ll rem=7;
    int cnt=0;
    fr(i,0,k){
        rem%=k;
        if(rem==0){
            cnt=i+1;
            break;
        }else{
            rem=rem*10+7;
        }
    }
    if(rem==0){
        cout << cnt << "\n";    
    }else{
        cout << "-1" << "\n";
    }
}   


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

bool checkA(char* s){
	if(s[0] != '>' || s[1] != '\'' || s[2] != '='){
		return false;
	}
	int slen = 0;
	while(s[slen+2] == '='){
		slen++;
	}
	if(s[slen+2] != '#'){
		return false;
	}
	for(int i = slen+3; i < slen*2+3;i++){
		if(s[i] != '='){
			return false;
		}
	}
	return (s[slen*2+3] == '~' && s[slen*2+4] == '\0');
}

bool checkB(char* s){
	if(s[0] != '>' || s[1] != '^' || s[2] != 'Q' || s[3] != '='){
		return false;
	}
	int slen = 0;
	while(s[slen*2+2] == 'Q' && s[slen*2+3] == '='){
		slen++;
	}
	return (s[slen*2+2] == '~' && s[slen*2+3] == '~' && s[slen*2+4] == '\0');
}

int main(){
	int n;
	char S[1024];

	scanf("%d",&n);
	for(int step = 0; step < n; step++){
		scanf("%s",S);
		if(checkA(S)){
			printf("A\n");
		}
		else if(checkB(S)){
			printf("B\n");
		}
		else{
			printf("NA\n");
		}
	}

	return 0;
}




Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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


  long long* dba = new long long[n];

  int itra = 0;
  int itrb = 0;

  long long result = 0;

  for(int i = 0; i < n; i++) {
    while(a[itra] < b[i] && itra != n) {
      itra++;
    }
    if(i == 0) {
      dba[i] = itra;
    } else {
      dba[i] = dba[i-1] + itra;
    }
  }

  for(int i = 0; i < n; i++) {
    while(b[itrb] < c[i] && itrb != n) {
      itrb++;
    }
    if(itrb == 0) continue;
    result += dba[itrb-1];
  }

  cout << result << endl;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
// g++ -std=c++17 -Wshadow -Wall sol.cpp -o  s -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vvi = vector< vi > ;
using ld = long double;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fll;
template<typename T> T abs (T x) { return x < 0 ? -x : x; }
template<typename T> void max_self(T &a, T b) {  a = max(a, b); }
template<typename T> void min_self(T &a, T b) {  a = min(a, b); }

void solve(int tc) {
  int r;
  cin >> r;
  double pi = atan(1)*4;
  cout << std::fixed << std::setprecision(20) << 1.0 * pi * 2 * r << endl;
 }

int main() {
  int tc = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cin >> tc;
  for(int i = 1; i <= tc; ++i)solve(i);
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0;i<N;i++){
    cin >> h[i];
  }

  vector<int> dp(111111,0);
  dp[1]=abs(h[1]-h[0]);

  for(int i=2;i<N;i++)
    dp[i]=min(abs(h[i-1]-h[i])+dp[i-1],abs(h[i-2]-h[i])+dp[i-2]);
cout<< dp[N-1];
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] p = new int[3];
		p[0] = Integer.parseInt(sc.next());
		p[1] = Integer.parseInt(sc.next());
		p[2] = Integer.parseInt(sc.next());


		Arrays.sort(p);

		int ans = p[0] +p[1];
		System.out.println(ans);
	}

}

Measured memory_bytes: 21844
#include<iostream>

using namespace std;
int main()
{
	int n;
	cin >> n;
	for(int i=0; i<30; i++){
		for(int j=0; j<20; j++){
			if((n- 4*i - 7*j) == 0){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	
	return 0;
}

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

int main(){
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int x=max(a*c,a*d);
    long long int y=max(b*c,b*d);
    long long int ans=max(x,y);
    cout<<ans<<endl;
  }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){return powm(a,m-2,m);}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,o,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>s;
n=s.size();
if(s[n-1]=='s')
{
  s+="es";
}
else
{
  s+='s';
}
cout<<s;
}


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

int main() {
	int n, m;
	while (scanf("%d", &n), n) {
		scanf("%d", &m);
		vector<P>E[100];
		bool used[100]{};
		rep(i, m) {
			int a, b, d; scanf("%d,%d,%d", &a, &b, &d);
			E[a].push_back(P(d, b)); E[b].push_back(P(d, a));
		}
		priority_queue<P, vector<P>, greater<P>>que;
		int ans = 0;
		que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (used[p.second])continue;
			used[p.second] = true;
			ans += max(0, p.first / 100 - 1);
			for (P v : E[p.second])que.push(P(v.first, v.second));
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3376
n, x = map(int, input().split())
a_list = list(map(int, input().split()))

a_list.sort()
ans = 0
for a in a_list:
  if x < a:
    break
  x = x - a
  ans += 1

if ans == n and x > 0:
  ans -= 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int b1,b2;
  cin >> b1;
  int sum = b1;
  for(int i = 0;i < n - 2;i++) {
    cin >> b2;
    sum += min(b1,b2);
    b1 = b2;
  }
  sum += b1;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,m,a[N],f[N],x,y;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;++i)
	{
		cin>>x>>y;
		if (x>y)
			swap(x,y);
		if (x==1)
			a[y]=1;
		if (y==n)
			f[x]=1;
	}
	for (int i=2;i<n;++i)
		if (a[i]&&f[i])
		{
			puts("POSSIBLE");
			return 0;
		}
	puts("IMPOSSIBLE");
}

Measured memory_bytes: 1792
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<set>
using namespace std;

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

	set<int> table;
	for(int i=0; i<N; i++)
	{
		int a;
		cin >> a;

		table.insert(a);
	}

	int ret = table.size();
	if(table.size()%2 == 0)
		ret--;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 4992
a,b=[int(s) for s in input().split()]
n=b-a+1
def odd(x):
    return x&1 == 1
def even(x):
    return not odd(x)
if odd(a) and odd(b) and odd((n-1)//2):
    print(a^1)
if odd(a) and odd(b) and even((n-1)//2):
    print(a)
if odd(a) and even(b) and odd((n-1)//2):
    print((a^b)^1)
if odd(a) and even(b) and even((n-1)//2):
    print(a^b)
if even(a) and odd(b) and odd((n-1)//2):
    print(0)
if even(a) and odd(b) and even((n-1)//2):
    print(1)
if even(a) and even(b) and odd((n-1)//2):
    print(b^1)
if even(a) and even(b) and even((n-1)//2):
    print(b)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<string> S(N);
    for(ll i=0;i<N;++i)cin>>S[i];
    vector<P> vec1(0);
    vector<P> vec2(0);
    ll sum=0;
    for(ll i=0;i<N;++i){
        ll n=S[i].size();
        ll L=0,R=0;
        ll h=0;
        for(ll j=0;j<n;++j){
            if(S[i][j]=='(')L++;
            else R++;
            chmin(h,L-R);
        }
        sum+=R-L;
        if(L>=R)vec1.emplace_back(P(h,L-R));
        else vec2.emplace_back(P(h-L+R,L-R));
    }
    if(sum!=0){prt("No")return 0;}
    sort(vec1.rbegin(), vec1.rend());
    sort(vec2.begin(), vec2.end());
    ll afford=0;
    for(auto p: vec1){
        if(afford+p.first<0){
            prt("No")return 0;
        }
        afford+=p.second;
    }
    for(auto p: vec2){
        if(afford+p.first+p.second<0){
            prt("No")return 0;
        }
        afford+=p.second;
    }
    prt("Yes")


    return 0;
}


Measured memory_bytes: 50212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	const int r = count(s.begin(), s.end(), 'R');
	cout << (r > n - r ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
ll ans2 = 0;
    ll mypow(ll a,ll b){
        ll res=1;
        a%=mo;
        while(b){
            if(b&1)
                res=res*a%mo;
            a=a*a%mo;
            b>>=1;
        }
        return res;
    }
        const int MAX = 510000;
    const int MOD = 1000000007;
    long long fac[MAX], finv[MAX], inv[MAX];

    // テーブルを作る前処理
    void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    long long COM(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
int main()
{
ll n,k;
cin >> n>>k;
    vector<ll> kaij;
    kaij.push_back(1);
    for(ll i = 1; i < k+5; i++){
        kaij.push_back((kaij[i-1]*i)%mo);
    }
COMinit();
rep(i,k){
    ans=COM(n-k+1,i+1);
    ans2=COM(n-k+1,i+1);

    ll an=kaij[k-1]*mypow((kaij[k-i-1]*kaij[i])%mo,mo-2);
    an%=mo;
    ans*=an;
    ans2*=COM(k-1,i);
    
    ans%=mo;
    ans2%=mo;
    //cout << ans <<" "<<ans2<< endl;
    cout << ans <<endl;
}
return 0;
}


Measured memory_bytes: 12288
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
B = [abs(A[i] - A[i-1]) for i in range(N+2)]
allPath = sum(B)

def diffWithoutNum( num):
    return B[num + 1] + B[num] - abs(A[i + 1] -A[i - 1])

for i in range( 1, N + 1):
    print( allPath - diffWithoutNum(i))

Measured memory_bytes: 14048
#include <stdio.h>

int main(void)
{
	int a,b;
	
	while(1)
	{
		scanf("%d%d",&a,&b);
		
		if(a==0&&b==0)
			break;
		
		else if(a>=b)
		printf("%d %d\n",b,a);

		else if(a<=b)
		printf("%d %d\n",a,b);
	}
	
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);

    vector<int> a(N);
    vector<int> b(N);
    Rep(i,N){
        Scd(a[i]);
    }
    Rep(i,N){
        Scd(b[i]);
    }

    sort( a.begin(), a.end() );
    sort( b.begin(), b.end() );

    int ans = 0;
    ll dig = 0x40000000;
    for (int i = 28; dig ; i--){
        Rep(ii,N){
            a[ii] &= (dig<<1)-1;
            b[ii] &= (dig<<1)-1;
        }
        sort( a.begin(), a.end() );
        sort( b.begin(), b.end() );
        // printf ("!%d\n", dig);
        int t1,t2,t3,t4;
        int t = 0;
        Rep(ai,N){
            int l = 0; //OK
            int r = N; //NG -> [l,r)
            l = -1; r = N;
            while( r - l > 1 ){
                int m = r+l>>1;
                // printf ("%d+%d >= %lld\n", a[ai], b[m], dig );
                if( a[ai] + b[m] >= dig ){
                    r = m;
                }else{
                    l = m;
                }
            }
            t1 = l;
            l = -1; r = N;
            while( r - l > 1 ){
                int m = r+l>>1;
                // printf ("%d+%d >= %lld\n", a[ai], b[m], dig );
                if( a[ai] + b[m] >= dig*2 ){
                    r = m;
                }else{
                    l = m;
                }
            }
            t2 = l;
            l = -1; r = N;
            while( r - l > 1 ){
                int m = r+l>>1;
                // printf ("%d+%d >= %lld\n", a[ai], b[m], dig );
                if( a[ai] + b[m] >= dig*3 ){
                    r = m;
                }else{
                    l = m;
                }
            }
            t3 = l;
            l = -1; r = N;
            while( r - l > 1 ){
                int m = r+l>>1;
                // printf ("%d+%d >= %lld\n", a[ai], b[m], dig );
                if( a[ai] + b[m] >= dig*4 ){
                    r = m;
                }else{
                    l = m;
                }
            }
            t4 = l;
            t += t2-t1+t4-t3;
            // printf ("%d %d %d %d\n", t1,t2,t3,t4);
        }
        // printf ("%d\n", t);
        ans += dig * ( t&1 );
        dig >>= 1;
    }
    printf ("%d\n", ans );


    return 0;
}



Measured memory_bytes: 1792
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

ll wa(ll a) {
    if(a%2==0) {
        return (a+1)*(a/2);
    }else {
        return (a+1)*(a/2)+(a+1)/2;
    }
}
int main() {
    string s; cin >> s;
    vector<int> v;
    ll cnt = 1;
    REP(i,1,s.size()) {
        if(s[i]!=s[i-1]) {
            v.push_back(cnt);
            cnt = 1;
        }else cnt++;
    }
    if(cnt) v.push_back(cnt);
    
    ll ans = 0;
    if((int)v.size()==1) {
        ans = wa(v[0]);
        cout << ans << endl;
        return 0;
    }
    if(s[0]=='>') {
        ans += wa(v[0]);
        v.erase(v.begin());
    }
    if((int)v.size()==1) {
        ans += wa(v[0]);
        cout << ans << endl;
        return 0;
    }
    int l = (int)v.size();
    v.push_back(0);
    for(int i = 0; i < l; i+=2) {
            ans += wa(max(v[i],v[i+1]));
            ans += wa(min(v[i],v[i+1])-1);
        }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
const unsigned int M = 1000000007;
using namespace std;
 
int main()
{
string a,b,c,v; cin>>a>>b;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
if(a<b) cout<<"Yes";
else cout<<"No";
return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=262244,M=22,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,a[N],v[20],l[20][N],r[20][N],f[N],g[N];


void solve(int x){
	for(int i=1;i<=n;i++){
		int t=i;
		while(t<n&&a[t+1]-a[t]<=v[x]) t++;
		for(int j=i;j<=t;j++)
			l[x][j]=t+1,r[x][j]=i-1;
		i=t;
	}
	l[x][n+1]=n+1;
	r[x][0]=0;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);read(v[0]);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int j=1;v[j-1];j++,m=j) v[j]=v[j-1]>>1;
	for(int i=0;i<m;i++) solve(i);
	int cnt=0;
	for(int i=1;i<n;i++)
		if(a[i+1]-a[i]>v[0]) cnt++;
	if(cnt>m){
		for(int i=1;i<=n;i++)
			puts("Impossible");
		return 0;
	}
	debug(m);
	f[0]=1;g[0]=n;
	for(int i=1;i<(1<<m-1);i++){
		f[i]=1,g[i]=n;
		for(int j=1;j<m;j++)
			if(i&(1<<j-1)) gmax(f[i],l[j][f[i^(1<<j-1)]]),gmin(g[i],r[j][g[i^(1<<j-1)]]);
		}
	int u=(1<<m-1)-1;
	for(int i=1;i<=n;i++){
		int r=i,isok=0;
		while(r<n&&a[r+1]-a[r]<=v[0]) r++;
		for(int j=0;j<(1<<m-1);j++)
			if(f[j]>=i&&g[u^j]<=r) isok=1;
		for(int j=i;j<=r;j++)
			if(isok) puts("Possible"); else puts("Impossible");
		i=r;
	}
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


Measured memory_bytes: 46208
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int aa[N+2],bb[N+2],dp[10000+2][1000+2];
int dfs(int h,int n)
{
  if(h<=0)return 0;if(n<1)return inf;
  if(dp[h][n]!=-1)return dp[h][n];
  return dp[h][n]=min(bb[n]+dfs(h-aa[n],n),dfs(h,n-1));
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int h,n;cin>>h>>n;
  for(int i=1;i<=n;i++)cin>>aa[i]>>bb[i];
  memset(dp,-1,sizeof(dp));cout<<dfs(h,n)<<endl;
  return 0;
}

Measured memory_bytes: 43776
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 500010;
int f[maxn],g[maxn],d[maxn];
int main(){
    int n,D;read(n);read(D);
    f[0] = D;
    rep(i,1,n){
	read(d[i]);
	f[i] = min(f[i-1],abs(f[i-1] - d[i]));
    }
    g[n+1] = 1;
    per(i,n,1){
	g[i] = g[i+1] + d[i];
	if(d[i] >= 2*g[i+1]) g[i] = g[i+1];
    }
    int Q;read(Q);
    int x;
    while(Q--){
	read(x);
	if(g[x+1] <= f[x-1]) puts("YES");
	else puts("NO");
    }
    return 0;
}


Measured memory_bytes: 7680
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

int main() {
    ll a, b;
    cin >> a >> b;

    ll large = (a > b) ? a : b;
    ll small = (a < b) ? a : b;
    if(large - small <= 1) cout << "Brown";
    else cout << "Alice";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n; cin>>n;
    vector<ll> a(4,1),b(4,1),dp(n+1,0);
    rep(i,3) cin>>a[i];
    rep(i,3) cin>>b[i];
    rep(i,n+1){
        rep(j,4){
            if(i+a[j]<=n){
                if(dp[i+a[j]]<dp[i]+b[j])
                dp[i+a[j]]=dp[i]+b[j];
            }
        }
    }
    vector<ll> dp2(dp[n]+1,0);
    rep(i,dp[n]+1){
        rep(j,4){
            if(i+b[j]<=dp[n]){
                if(dp2[i+b[j]]<dp2[i]+a[j])
                dp2[i+b[j]]=dp2[i]+a[j];
            }
        }
    }
    cout<<dp2[dp[n]]<<endl;
}

Measured memory_bytes: 195584
fun main(arg: Array<String>) {
    val (H, W, N) = listOfInt()
    val M = java.util.HashMap<Pair<Int, Int>, Int>()
    repeat(N) {
        val (a, b) = listOfInt(-1)
        for (h in -1 .. 1) {
            for (w in -1 .. 1) {
                val key = a + h to b + w
                M.set(a + h to b + w, M.getOrElse(a + h to b + w, {0}) + 1)
            }
        }
    }
    val ans = LongArray(10)
    for ((key, cnt) in M) {
        if (1 <= key.first && key.first < H - 1 && 1 <= key.second && key.second < W - 1) {
            ans[cnt] = ans[cnt] + 1
        }
    }
    ans[0] = (1L * (H - 2) * (W - 2)) - ans.sum()
    ans.forEach { println(it) }
}
fun tripleLongLongInt() = listOfLong().let { Triple(it[0], it[1], it[2].toInt()) }

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }




Measured memory_bytes: 200228
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long z[2000][2000];

int main(int argc, char* argv[])
{
    long n, x;
    scanf("%ld%ld", &n, &x);

    vector<long> a(n);
    long i, j;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }

    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if(j==0) z[i][j]=a[i];
            else     z[i][j]=MIN(z[i][j-1], a[(i-j+n)%n]);
        }
    }

    ll ans = LINF;
    long k;
    for(k=0; k<n; k++) {
        ll sum=0;
        for(i=0; i<n; i++) {
            sum += z[i][k];
        }
        ans = MIN(ans, sum+k*x);
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;


int h[100010],dp[100010],n,k;

int call(int i)
{
	if(i == n-1)return 0;
	if(dp[i] != -1)return dp[i];

	int ret = 1 << 30;

	for(int j = 1;j <= k;j++){

		if(i+j <= n-1)ret = min(ret,call(i+j) + abs(h[i] - h[i+j]));
	}

	return dp[i] = ret;
}

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

	for(int i = 0;i < n;++i){

		cin >>  h[i];
	}
	for(int i = 0;i <= 100000;i++)dp[i]=-1;

	cout << call(0) << endl;

	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int n,k;
char s[200005];
int a[200005];
deque<int>q;
void print(int x)
{
    if(x==1)putchar('A');
    else putchar('B');
}
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)a[i]=1-(s[i]-'A'),q.push_back(a[i]);int now=0;
    for(int i=1;i<=2*n;i++)
    {
        if((q.front()^now)==1)
        {
            q.pop_front();q.push_front(0^now);
        }
        else
        {
            now^=1;q.pop_front();q.push_back(now^1);
        }
        if(i==k)
        {
            for(int j=1;j<=n;j++)print(now^q.front()),q.pop_front();
            return 0;
        }
    }k-=2*n;
    if(n%2==0||((q.front()^now)==1&&k%2==0)||((q.front()^now)==0&&k%2==1))
    {
        for(int i=1;i<=n;i++)if((n-i)&1)print(0);else print(1);
    }
    else
    {
        for(int i=1;i<=n;i++)if(((n-i)&1)||i==1)print(0);else print(1);
    }
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;


int main() {
    string s, t, s1,judge = "Yes";
    int n = -1 + (s.length()+3)/2;
    int h = (s.length()-1)/2;
    cin>>s;

    
    t = s;
    Reverse(t);
    if(s != t) judge = "No";
    
    s = s.substr(0, (s.size()-1)/2);
    t = s;
    Reverse(t);
    
    if(s != t) judge = "No";
    
    s = s.substr(n, h);
    //cout<<s<<endl;
    
    if(s != t) judge = "No";
    
    cout<<judge<<endl;
    
    return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N)
    {
        cin >> A[i];
        B[i] = A[i] - (i + 1);
    }
    sort(ALL(B));

    ll ans = 0;
    if (N % 2 == 0)
    {
        REP(i, N)
        {
            if (i < N / 2)
            {
                ans += -B[i];
            }
            else
            {
                ans += B[i];
            }
        }
    }
    else
    {
        REP(i, N)
        {
            if (i == N / 2)
            {
                continue;
            }
            else if (i < N / 2)
            {
                ans += -B[i];
            }
            else
            {
                ans += B[i];
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    
    int N =sc.nextInt();
    int[] array= new int[N];
    
    int sum=0;
    for(int i=0;i<N;i++){
    	array[i]=sc.nextInt();
    	sum+=array[i];
    }
    int sum2=0;
    int dif=0;
    int min=10000;
    for(int i=0;i<N;i++){
    	sum-=array[i];
    	sum2+=array[i];
    	dif=Math.abs(sum-sum2);
    	if(min>dif){
    		min=dif;
    	}
    }
    System.out.println(min);
    
    
    
    
    
  }
}

Measured memory_bytes: 23764
// BubbleSort
#include<iostream>
using namespace std;

template<class T>
int bubbleSort(T* array, int size)
{
        int nSwap=0;
        for(int i=size; i>0; i--){
                for(int j=0; j<i-1; j++){
                        if( array[j] > array[j+1] ){
                                int tmp = array[j+1];
                                array[j+1] = array[j];
                                array[j] = tmp;
                                nSwap++;
                        }
                }
        }
        return nSwap;
}

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

        cout << array[0];
        for(int i=1; i<n; i++){
                cout << " " << array[i];
        }
        cout << endl << s << endl;
        return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
int main()
{
    char m[200];
    int n,i,a=-1,b=-1;
    gets(m);
    n=strlen(m);
    for(i=0;i<n;i++)
    {
        if(m[i]=='C')
        {
            a=i;
            break;}}
     for(i=0;i<n;i++)
     {
        if(m[i]=='F')
        b=i;}
     if(a<b&&a!=-1&&b!=-1)
         printf("Yes");
        else
        printf("No");}

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

int main(){
    long long int N, happy;
    cin >> N;
    happy = 0;
    while(N >= 500){
        N -= 500;
        happy += 1000;
    }

    while(N >= 5){
        N -= 5;
        happy += 5;
    }


    cout << happy << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

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

  vector<int64_t> H(N);
  rep(i, N) cin >> H.at(i);

  vector<int> ten(N, 1);

  rep(i, M){
    int A, B;
    cin >> A >> B;

    if(H.at(A-1)>=H.at(B-1)) ten.at(B-1) = 0;
    if(H.at(B-1)>=H.at(A-1)) ten.at(A-1) = 0;
  }

  int ans = 0;
  rep(i, N){
    if(ten.at(i) == 1) ans++;
  }

  cout << ans;
}

Measured memory_bytes: 4580
#--import&define---------------------
import math
import sys
input = sys.stdin.readline
def yes():
    print("Yes")
def no():
    print("No")

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
#--以下解答---------------------------------
x = int(input())
prime_list = primes(10**6)

i = x
flag = True
while True:
    if prime_list[i] == True:
        print(i)
        sys.exit()
    i += 1



Measured memory_bytes: 10996
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner num = new Scanner(System.in);
    double r = num.nextDouble();
    double pi = Math.PI;
    double area = r * r * pi;
    double length = 2 * r * pi;
    System.out.printf("%f %f\n",area,length);
  }
}

Measured memory_bytes: 28072
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;

using namespace std;

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

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n;
int ans;

int main()
{
    //~ freopen("file.in", "r", stdin);
    scanf("%d%d",&n,&ans);
	ans=n-ans+1;

	printf("%d\n",ans);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

int INF = 1e9;

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

  bool ok = false;
  for(int j = 1; j <= 9; j++){
    if((n % j == 0) && (n / j <= 9)){
      ok = true;
      break;
    }
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;  
}


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

const int S = 48600;
int bit[S], A[S], B[S], C[S], e[S];
pair<long double, int> d[S];

int main(){
	int N; scanf("%d", &N);
	T(N, i) scanf("%d%d%d", &A[i], &B[i], &C[i]);

	T(2, o){
		T(N, i) d[i] = {(C[i] - A[i] * -1e9L) / B[i], i};
		sort(d, d + N);
		T(N, i) e[d[i].second] = i;

		auto l = -1e9L, r = 1e9L;
		T(80, p){
			auto m = (l + r) / 2;
			T(N, i) d[i] = {(C[i] - A[i] * m) / B[i], i};
			sort(d, d + N);

			T(S, i) bit[i] = 0;
			long a = 0;
			T(N, i){
				int aj = e[d[i].second], j = aj+1;
				a += aj;
				for(; j; j -= j&-j) a -= bit[j-1];
				for(j = aj+1; j <= S; j += j&-j) ++bit[j-1];
			}
			if(a < (N*(N-1) + 2) / 4) l = m;
			else r = m;
		}

		printf("%.9Lf%s", l, o ? "\n" : " ");
		swap(A, B);
	}

	return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int X, N;
int p[100];
int main(void){
    cin >> X >> N;
    REP(i,N) cin >> p[i];
    int X_t = 222;
    int i = -100;
    for(int i=-101;i<=101;i++){
        bool f = true;
        for (int j=0;j<N;j++){
            if(p[j] == i){
                f = false;
                break;
            }
        }
        if(f and abs(X-i) < abs(X_t-X)){
            X_t = i;
        }
    }
    cout << X_t << endl;
    return 0;
}



Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var h = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        void ChMin<T>(ref T min, T value)
            where T : IComparable
        {
            if (value.CompareTo(min) < 0)
                min = value;
        }
        
        int GetCost(int a, int b) => Math.Abs(a - b);

        var dp = Enumerable.Repeat(int.MaxValue, N).ToArray();
        dp[0] = 0;

        for (int i = 1; i < N; i++)
        {
            ChMin(ref dp[i], dp[i - 1] + GetCost(h[i], h[i - 1]));
            if (1 < i)
                ChMin(ref dp[i], dp[i - 2] + GetCost(h[i], h[i - 2]));
        }

        WriteLine(dp[N - 1]);
    }
}


Measured memory_bytes: 40396
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
using namespace std;
#define M 1000000007
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
ll mod = 998244353;


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t; t = 1;
	// cin >> t;
	while(t--)
	{
		int a, b, c, k;ll sum = 0;
		cin >> a >> b >> c >> k;
		while(k && a)
		{
			sum++;
			a--;
			k--;
		}
		while(k && b)
		{
			k--;
			b--;
		}
		while(k && c)
		{
			sum--;
			c--;
			k--;
		}
		cout << sum << endl;

	}
		
}  

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        while (true) {
            String s = sc.next();
            if (s.equals("0")) break;
            calc(s);
        }
    }
    
    private static void calc(String s) {
        int ret = 0;
        for (int i = 0;i < s.length();i++) {
            ret += Integer.parseInt(s.substring(i, i+1));
        }
        System.out.println(ret);
    }
}



Measured memory_bytes: 26672
#include <iostream>
#include <string>

using namespace std;

bool is753(int64_t n) {
    string S = to_string(n);
    return (S.find("3") != string::npos && S.find("5") != string::npos && S.find("7") != string::npos);
}

int ans;
void dfs(int64_t s, int64_t n) {
    if(s > n) {
        return;
    } else {
        ans += is753(s);
        dfs(10*s + 3, n);
        dfs(10*s + 5, n);
        dfs(10*s + 7, n);
    }
}

int main(void) {
    int64_t N;
    cin >> N;
    dfs(0, N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    a = input_number_list()
    a.sort(reverse=True)
    alice = sum(a[::2])
    bob = sum(a[1::2])
    print(alice - bob)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  string s; cin >> s;
  if (s[0]==s[2]){cout << "Yes";}
  else {cout << "No";}

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  string s;
  cin >> s;
  ll x,y;
  for (ll i=0;i<s.size();i++) {
    if (s.at(i)=='A') {
      x=i;
      break;
    }
  }
  for (ll i=0;i<s.size();i++) {
    if (s.at(s.size()-i-1)=='Z') {
      y=s.size()-i-1;
      break;
    }
  }
  cout << y-x+1;
}

Measured memory_bytes: 640
r,c=map(int, input().split())

a=[]
for i in range(r):
    a.append(list( map (int, input().split())))
    
b=[]

for j in range(c):
    b.append(int(input()))
    
    
for j in range(r):
    q=0
    for i in range(c):
        q=q+a[j][i]*b[i]
    print("%d"%q)
        


Measured memory_bytes: 6008
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI d(n+1, -1);
    queue<int> que;

    VI next;
    next.push_back(1);
    int x = 6;
    while (x <= n){
        next.push_back(x);
        x *= 6;
    }
    x = 9;
    while (x <= n){
        next.push_back(x);
        x *= 9;
    }

    d[0] = 0;
    que.push(0);
    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (int y : next){
            if (x + y > n) continue;
            if (d[x + y] != -1) continue;
            d[x + y] = d[x] + 1;
            que.push(x + y);
        }
    }
    cout << d[n] << endl;

    return 0;
}


Measured memory_bytes: 768
/*
 * ALDS1_10_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

int dp[1001][1001];
bool dpR[1001][1001];

int lcm(char* X, char* Y, int nx, int ny) {
	dp[1][1] = (X[0] == Y[0]);
	for(int i=1; i<=nx; i++) {
		for(int j=1; j<=ny; j++) {
			dp[i][j] = (X[i-1]==Y[j-1]) + dp[i-1][j-1];
			dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
			dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
		}
	}
	return dp[nx][ny];
}

int lcmRec(char* X, char* Y, int nx, int ny) {
	if(nx <=0 || ny <= 0) return 0;
	if(!dpR[nx][ny]) {
		dpR[nx][ny] = 1;
		dp[nx][ny] = lcmRec(X, Y, nx-1, ny-1) + (X[nx-1]==Y[ny-1]);
		dp[nx][ny] = std::max(lcmRec(X, Y, nx-1, ny), dp[nx][ny]);
		dp[nx][ny] = std::max(lcmRec(X, Y, nx, ny-1), dp[nx][ny]);
	}
	return dp[nx][ny];
}

int main() {
	int q;
	scanf("%d", &q);
	char X[1001];
	char Y[1001];
	while(q--) {
		for(int i=0; i<1001; i++) {
			for(int j=0; j<1001; j++) {
				dpR[i][j] = dp[i][j] = 0;
			}
		}
		scanf("%s", X);
		scanf("%s", Y);
		int nx = (int)strlen(X);
		int ny = (int)strlen(Y);
		//printf("%d\n", lcm(X, Y, nx, ny));
		printf("%d\n", lcmRec(X, Y, nx, ny));
	}
}





Measured memory_bytes: 7656