akhauriyash/Code-Regression huggingface dataset:
n, A, B, C = map(int, input().split())
s = [list(input()) for _ in range(n)]

cur = dict()
cur['A'], cur['B'], cur['C'] = A, B, C

f = True
ans = []
for i, ss in enumerate(s):
    if cur[ss[0]] == 1 and cur[ss[1]] == 1 and sorted(list(cur.values())) == [0, 1, 1] and i < len(s) - 1:
        if ss[0] in s[i + 1]:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])
        elif ss[1] in s[i + 1]:
            cur[ss[1]] += 1
            cur[ss[0]] -= 1
            ans.append(ss[1])

    else:
        if cur[ss[0]] >= cur[ss[1]]:
            cur[ss[0]] -= 1
            cur[ss[1]] += 1
            ans.append(ss[1])
        else:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])

    if -1 in list(cur.values()):
        f = False
        break

if f:
    print('Yes')
    for a in ans:
        print(a)
else:
    print('No')


Measured memory_bytes: 95892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n,h; cin >>n>>h;
    vector<ll> a(n); vector<ll> b(n);
    REP(i,n) cin >> a[i] >> b[i];

    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());

    ll sum = 0;
    ll count = 0;
    for (int i = 0; i < n; i++) {
        if (sum >= h || b[i] < a[0]) {
            break;
        } 
        sum += b[i];
        count++;
    }
    if (sum < h) {
        count += (h - sum) / a[0];
        if ((h - sum) % a[0] != 0) {
            count++;
        } 
    } 
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	int n,w;
	cin >> n >> w;
	vector<vector<ll>> dp(100001, vector<ll>(2));
	dp[0][0] = 1;
	dp[0][1] = 0;
	cu(i,0,n){
		int x,y;
		cin >> x >> y;
		fd(j,100000,0){
			if(dp[j][0] && j + y <= 100000){
				if(dp[j+y][0]){
					dp[j + y][1] = min(dp[j + y][1], dp[j][1] + x);
				}
				else{
					dp[j + y][0] = 1;		
					dp[j + y][1] = dp[j][1] + x;		
				}
			}
		}
	}
	fd(i,100000,0){
		if(dp[i][0] && dp[i][1] <= w){
			cout << i << '\n';
			return 0;
		}
	}
}
	

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

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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

void WF(ll N,  vector<vector<ll>> &g) {
	repn(k, N) {
		repn(i, N) {
			repn(j, N) {
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}
}


int main() {

   ll x,a,b;
   cin >>x>>a>>b;
   if(abs(x-a)<abs(x-b)){cout <<"A";}
   else{cout <<"B";}

 
	

}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;


int main(){
  int N;cin >> N;
  vector<int> X(N);
  vector<int> Y(N);
  for(int i = 0; i < N; i++){
    cin >> X[i];
    Y[i] = X[i];
  }
  sort(Y.begin(),Y.end());
  int m1 = Y[N/2-1];
  int m2 = Y[N/2];
  
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(X[i] <= m1) ans = m2;
    else if(X[i] >= m2) ans = m1;
    cout << ans << endl;
  }
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll n, m;
    cin >> n >> m;
    set<ll> st;
    vector<ll> h(n), a(m), b(m);
    rep(i, n) cin >> h.at(i);
    rep(i, m) {
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    
    rep(i, m) {
        if(h.at(a.at(i)) == h.at(b.at(i))) {
            st.insert(a.at(i));
            st.insert(b.at(i));
        }
        else if(h.at(a.at(i)) > h.at(b.at(i))) {
            st.insert(b.at(i));
        }
        else{
            st.insert(a.at(i));
        }
    }
    
    cout << n - st.size() << endl;
}

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

const int MOD = 1000000007;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

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

    vector<int> S(N);
    S[0] = W[0].second;
    for (int i = 1; i < N; i++) S[i] = S[i-1] + W[i].second;

    bool flag = true;

    for (int i = 0; i < N; i++) {
        if (S[i] > W[i].first) flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main()
{
  long long int a,b,c,d,e;
  long long int n1,n2,n3;
  long long int m1,m2,m3;
  long long int r;
  long long int ans;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

  if(b<a)
  {
    e=b;
    b=a;
    a=e;
  }
  if(c<d)
  {
    e=c;
    c=d;
    d=e;
  }

  /*cの倍数の数*/
  m1=a/c;

  if(a%c==0)
  {
    m1=m1-1;
  }

  n1=b/c;

  /*dの倍数の数*/
  m2=a/d;

  if(a%d==0)
  {
    m2=m2-1;
  }

  n2=b/d;
  /*cとdの最大公約数*/
  long long int gcd=d;
  long long int t=c;
  while((r=t%gcd)!=0)
  {
    t=gcd;
    gcd=r;
  }

  long long int lcm;

  lcm=c * d / gcd;

  /*d(cとdの最小公倍数)の倍数の数*/
  m3=a/lcm;

  if(a%lcm==0)
  {
    m3=m3-1;
  }

  n3=b/lcm;

  /*求める答え*/
  ans=b-a+1-(n1-m1)-(n2-m2)+(n3-m3);

  printf("%lld",ans);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> n >> a;
	while (n >= 0) {
		n -= 500;
	}
	if (500 + n <= a) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
res = 0
if k == 0:
    print(n**2)
    quit()
for b in range(k+1,n+1):
    cnt = 0
    cnt += (b-1)-(k-1)
    cnt += (n-(b-1))//b * (b-k)
    cnt += max(0, (n-(b-1))%b-k)
    res += cnt
print(res)

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

int main() {
  char C;
  cin >> C;
  C++;
  cout << C << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 


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

i64 N, W; cin >> N >> W;
VP wv(N); rep(i, 0, N) cin >> wv[i].first >> wv[i].second;
sort(ALL(wv), greater<PII>());
vector<VP> wvm(4);
for(PII p: wv) wvm[p.first - wv[N-1].first].push_back(p);

i64 maxi = 0;
rep(i0, 0, wvm[0].size()+1) rep(i1, 0, wvm[1].size()+1) 
rep(i2, 0, wvm[2].size()+1) rep(i3, 0, wvm[3].size()+1){
    i64 v = 0, w = 0;
    rep(i, 0, i0) { w += wvm[0][i].first; v += wvm[0][i].second;}
    rep(i, 0, i1) { w += wvm[1][i].first; v += wvm[1][i].second;}
    rep(i, 0, i2) { w += wvm[2][i].first; v += wvm[2][i].second;}
    rep(i, 0, i3) { w += wvm[3][i].first; v += wvm[3][i].second;}
    if (w <= W) maxi = max(maxi, v);
}

cout << maxi << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n, k;
llint a[505];
set<llint> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint sum = 0;
	for(int i =1; i<= n; i++) sum += a[i];
	
	for(llint i = 1; i*i <= sum; i++){
		if(sum % i == 0) S.insert(i), S.insert(sum/i);
	}
	
	llint ans = 1;
	for(auto it = S.begin(); it != S.end(); it++){
		llint cnt = 0;
		for(int i = 1; i <= n; i++) cnt += a[i] % (*it);
		vector<llint> vec;
		for(int i = 1; i <= n; i++) vec.push_back(a[i] % (*it));
		sort(vec.rbegin(), vec.rend());
		llint tmp = 0;
		for(int i = cnt/(*it); i < vec.size(); i++) tmp += vec[i];
		if(tmp <= k) ans = max(ans, *it);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll ans = 0;
    rep(i, N) {
        ll sum = 0;
        rep(j, i + 1) sum += A[0][j];
        foreps(j, i, N) sum += A[1][j];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<sstream>
using namespace std;
stringstream ans;
main()
{
	int n;cin>>n;
	ans<<"!";
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			cout<<"? ";
			for(int k=0;k<n;k++)cout<<(k==i||k==j);
			cout<<endl;
			int d;cin>>d;
			if(d)ans<<" ("<<i<<","<<j<<")";
		}
	}
	cout<<ans.str()<<endl;
}

Measured memory_bytes: 852
#include<cstdio>
#include<cstring>
#define N 200010
#define ll long long
#define mod 1000000007
using namespace std;
struct bb{int x, y;}b[N];
int n, f[4010][4010], map[4010][4010], jc[8010], inv[8010], ans, INV, m;
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d%d", &b[i].x, &b[i].y);
	m=4001; memset(map, 0, sizeof(map));
	for(int i=1; i<=n; i++)map[2001+b[i].x][2001+b[i].y]++;
	memset(f, 0, sizeof(f));
	for(int i=m; i; i--)
		for(int j=m; j; j--)f[i][j]=((map[i][j]+f[i+1][j])%mod+f[i][j+1])%mod;
	ans=0;
	for(int i=1; i<=n; i++)ans=(ans+f[2001-b[i].x][2001-b[i].y])%mod;
	jc[0]=1; for(int i=1; i<=8000; i++)jc[i]=(ll)jc[i-1]*i%mod;
	inv[0]=inv[1]=1; for(int i=2; i<=8000; i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1; i<=8000; i++)inv[i]=(ll)inv[i]*inv[i-1]%mod;
	for(int i=1; i<=n; i++)ans=(ans-(ll)jc[b[i].x*2+b[i].y*2]*inv[b[i].x*2]%mod*inv[b[i].y*2]%mod+mod)%mod;
	INV=(mod+1)>>1; ans=(ll)ans*INV%mod; printf("%d", ans);
	return 0;
}

Measured memory_bytes: 127360
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A)+1
lst.sort()
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(lst[i][1]-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)


Measured memory_bytes: 72784
#include<bits/stdc++.h>
#define maxn 10005
using namespace std;
typedef long long LL;
int read()
{
	char c;int sum=0,f=1;c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
int n;
struct node{
	int x,id,rev;
	friend bool operator <(node a,node b){return a.x<b.x;}
}d[maxn*2];
int a[maxn],b[maxn],c[maxn*2];
int leaf[maxn*2],lson[maxn*10],rson[maxn*10],tot;
int head[maxn*10],to[maxn*100],nex[maxn*100],cnt,num;
int root,top,sum,cur,s[maxn*10],dfn[maxn*10],low[maxn*10],bel[maxn*10];
bool vis[maxn*10];
void add(int u,int v)
{
	to[++cnt]=v;
	nex[cnt]=head[u];
	head[u]=cnt;
}
void build(int &x,int l,int r)
{
	if(!x) x=++tot;
	if(l==r)
	{
		leaf[l]=x;
		return;
	}
	int mid=(l+r)>>1;
	build(lson[x],l,mid);build(rson[x],mid+1,r);
}
void connect(int x,int l,int r)
{
	if(l==r) return;
	add(x,lson[x]);add(x,rson[x]);
	int mid=(l+r)>>1;
	connect(lson[x],l,mid);connect(rson[x],mid+1,r);
}
void insert(int x,int l,int r,int ql,int qr,int id)
{
	if(ql>qr) return;
	if(l==ql && qr==r)
	{
		add(id,x);
		return;
	}
	int mid=(l+r)>>1;
	if(qr<=mid) insert(lson[x],l,mid,ql,qr,id);
	else if(ql>mid) insert(rson[x],mid+1,r,ql,qr,id);
	else insert(lson[x],l,mid,ql,mid,id),insert(rson[x],mid+1,r,mid+1,qr,id);
}
void ins(int id,int x,int dis)
{
    int L,R,l,r,mid;
    l=x;r=2*n;
    while(l<r)
	{
        mid=(l+r+1)/2;
        if(c[mid]-c[x]<dis) l=mid;
		else r=mid-1;
    }
    R=l;
    l=1;r=x;
    while(l<r)
	{
        mid=(l+r)/2;
        if(c[x]-c[mid]<dis) r=mid;
		else l=mid+1;
    }
    L=l;
    insert(root,1,2*n,L,x-1,id);
    insert(root,1,2*n,x+1,R,id);
}
void tarjan(int x)
{
	s[++top]=x;
	dfn[x]=low[x]=++cur;
	vis[x]=1;
	for(int i=head[x];i;i=nex[i])
	{
		if(!dfn[to[i]])
		{
			tarjan(to[i]);
			low[x]=min(low[x],low[to[i]]);
		}
		else if(vis[to[i]])
		low[x]=min(low[x],dfn[to[i]]);
	}
	if(dfn[x]==low[x])
	{
		sum++;
		do
		{
			vis[s[top]]=0;bel[s[top]]=sum;
			top--;
		}
		while(s[top+1]!=x);
	}
}
bool check(int x)
{
	cnt=0;
	memset(head,0,sizeof(head));
	connect(root,1,2*n);
	for(int i=1;i<=n;i++)
	{
		add(leaf[b[i]],i*2-1);
        add(leaf[a[i]],i*2);
        ins(i*2-1,a[i],x);
        ins(i*2,b[i],x);
	}
	top=cur=sum=0;
	memset(vis,0,sizeof(vis));
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	for(int i=1;i<=num;i++)
	if(!dfn[i]) tarjan(i);
	for(int i=1;i<=n;i++)
    if(bel[i*2-1]==bel[i*2]) return false;
    return true;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read(),b[i]=read();
		d[i*2-1].x=a[i];d[i*2-1].rev=0;
		d[i*2].x=b[i];d[i*2].rev=1;
		d[i*2-1].id=d[i*2].id=i;
	}
	sort(d+1,d+2*n+1);
	for(int i=1;i<=2*n;i++)
	{
		if(!d[i].rev) a[d[i].id]=i;
		else b[d[i].id]=i;
		c[i]=d[i].x;
	}
	tot=2*n;
    build(root,1,2*n);
    num=tot;
    int l=0,r=1000000000,mid;
    while(l<r)
	{
        mid=(l+r+1)/2;
        if (check(mid)) l=mid;else r=mid-1;
    }
    printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 12288
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n,m;
    cin>>n>>m;
    if(2*n>=m) cout<<min(n,m/2)<<endl;
    else cout<<n+(m-2*n)/4<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

cnt = {}
for n in a:
    cnt[n] = cnt.get(n, 0) + 1

ans = 0
for n in a:
    g = 2 ** n.bit_length()
    s = g - n
    if n == s:
        pair = cnt.get(s, 0) // 2
        ans += pair
        cnt[s] = cnt.get(s, 0) % 2
    else:
        pair = min(cnt.get(n, 0), cnt.get(s, 0))
        ans += pair
        cnt[n] = cnt.get(n, 0) - pair
        cnt[s] = cnt.get(s, 0) - pair
print(ans)


Measured memory_bytes: 56664
/*#include<iostream>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<cmath>
    #include<map>
    #include<cstdio>
    #include<stack>
    #include<queue>
    #include<fstream>
    #include<cstdio>
    #include<deque>
    #include<iomanip>
    #include <numeric>*/
    #include<bits/stdc++.h>

    using namespace std;
    #define ok1 printf("ok1\n");
    #define ok2 printf("ok2\n");
    #define M 1000000000000000000LL
    #define rep(i,n) for(int i=0;i<n;i++)
    #define REP(i,s,n) for(int i=(s);i<(n);i++)
    #define repr(i,n) for(int i=n-1;i>=0;i--)
    #define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
    #define all(a) (a).begin(),(a).end()
    #define reall(a) (a).rbegin(),(a).rend()
    #define pb push_back
    #define pf push_front
    #define MIN(a,b) a=min((a),(b))
    #define MAX(a,b) a=max((a),(b))
    #define SIZE(v) (int)v.size()
    const double pi = acos(-1.0);

    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef long long ll;
    typedef vector<ll> vll;
    typedef vector<vi> vvi;
    typedef vector<vll> vvll;
    typedef deque<ll> dll;
    typedef pair<ll, ll> P;
    typedef vector<P> vP;
    const ll mod = 1e9 + 7;
    ll dx[4] = {1,0,-1,0};
    ll dy[4] = {0,1,0,-1};

ll n,ans=0,k;
ll dp[100][100][5000];
int main(){
    cin >> n >> k;
    vll v(n);
    rep(i,n) {
        cin >> v[i];
    }
    dp[0][0][0] = 1;
    rep(i,n){
        rep(j,n){
            rep(k,5000){
                if(dp[i][j][k] == 0) continue;
                dp[i + 1][j + 1][k + v[i]] += dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }
    REP(i,1,n+1){
        ans += dp[n][i][i*k];
    }
    cout << ans << endl;
    return 0;
}
    


Measured memory_bytes: 151808
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))


//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a;}atai;
atai xx(atai x,atai y){
	atai r;
//	r.a=x.a+y.a;//sum
	r.a=min(x.a,y.a);//min
	return r;
}
atai aid={0};
//↑ここを変える

int segNUM;
atai *segN,*seg;
void seguse(int n){
	segN=(atai*)calloc(2*n,sizeof(atai));
	segNUM=n;
	seg=segN+segNUM;
	rep(i,1,2*segNUM)segN[i]=aid;
}
//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで
//*/



int main(){
	int n,l;
	scanf("%d%d",&n,&l);
	seguse(1<<20);
	for(int i=0;i<n;i++)scanf("%lld",&(seg[i].a));
	seginit();
	for(int i=0;i+l<=n;i++)printf("%lld%c",segcalc(i,i+l).a,i+l==n?10:32);
}


Measured memory_bytes: 18244
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();

        int match[] = {-100, 2, 5, 5, 4, 5, 6, 3, 7, 6};

        int[] use = new int[10];
        Arrays.fill(use, 1<<29);
        for (int i=0; i<M; i++) {
            int cu = in.nextInt();
            use[cu] = match[cu];
        }

        int[] dp = new int[N+100];
        Arrays.fill(dp, -1<<29);
        dp[0] = 0;

        for (int i = 0; i < N; i++) {
            for (int k = 1; k <= 9; k++) {
                if(use[k] != 1<<29) dp[i + use[k]] = Math.max(dp[i + use[k]], dp[i] + 1);
            }
        }

        StringBuilder ans = new StringBuilder();
        while(N > 0){
            for (int i=9; i>0; i--) {
                if(N - use[i] >= 0){
                    if(dp[N] == dp[N - use[i]] + 1){
                        ans.append(i);
                        N -= use[i];
                        break;
                    }
                }
            }
        }
        out.println(ans);
    }

}
}



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

int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) 
		if (2 * i < m + 2) printf("%d %d\n", i, m + 2 - i);
	for (int i = 1; i <= m; ++i) 
		if (2 * i < m + 1) printf("%d %d\n", m + 1 + i, 2 * m + 2 - i);
	return 0;
}


Measured memory_bytes: 3796
l = int(input())
if l%3 == 0:
    print((l//3)**3)
else:
    t = l//3
    if l%3 == 1:
        print(t**3+t**2+t/3+1/27)
    else:
        print(t**3+2*t**2+4*t/3+8/27)


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

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B ;
  
  if (op=='+'){
    cout << A+B << endl;
  }
  else if (op=='-'){
    cout << A-B << endl;
  }
  
}




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

int tolls[7][7] = {
    {  -1,  300,  500,  600,  700, 1350, 1650},
    { 300,   -1,  350,  450,  600, 1150, 1500},
    { 500,  350,   -1,  250,  400, 1000, 1350},
    { 600,  450,  250,   -1,  250,  850, 1300},
    { 700,  600,  400,  250,   -1,  600, 1150},
    {1350, 1150, 1000,  850,  600,   -1,  500},
    {1650, 1500, 1350, 1300, 1150,  500,   -1}
};
int dist[7][7] = {
    {-1,  6, 13, 18, 23, 43, 58},
    { 6, -1,  7, 12, 17, 37, 52},
    {13,  7, -1,  5, 10, 30, 45},
    {18, 12,  5, -1,  5, 25, 40},
    {23, 17, 10,  5, -1, 20, 35},
    {43, 37, 30, 25, 20, -1, 15},
    {58, 52, 45, 40, 35, 15, -1}
};

int main() {
    int ic1, h1, m1, ic2, h2, m2;
    while (cin >> ic1, ic1) {
        cin >> h1 >> m1 >> ic2 >> h2 >> m2;
        --ic1; --ic2;
        bool half = false;
        int start = 17 * 60 + 30;
        int end = 19 * 60 + 30;
        int t1 = h1 * 60 + m1;
        int t2 = h2 * 60 + m2;
        if (dist[ic1][ic2] <= 40) {
            if ((start <= t1 && t1 <= end) || (start <= t2 && t2 <= end)) {
                half = true;
            }
        }
        int res = tolls[ic1][ic2];
        if (half) {
            if (tolls[ic1][ic2] % 100 == 50) res += 50;
            res /= 2;
        }
        cout << res << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i);
  }
  sort(X.begin(),X.end());
  int cost = 1919810; 
  for(int j=X.at(0);j<X.at(N-1)+1;j++){
    int sum = 0;
    for(int k=0;k<N;k++){
      sum+=(j-X.at(k))*(j-X.at(k));
    }
    if(sum<=cost){
      cost=sum;
    }
  }
   
  cout << cost <<endl;
}

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++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

int n;
set<pair<string,int>> s;

void dfs(string s,int m,int d){
	if(d==0){
		cout<<s<<endl;
		return;
	}
	rep(i,m)dfs(s+(char)('a'+i),m,d-1);
	dfs(s+(char)('a'+m),m+1,d-1);
}

int main(void){
	cin>>n;
	dfs("",0,n);
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n1 = sc.nextInt();

		int d1[] = new int[n1];

		for(int i = 0; i < n1; i++){
			d1[i] = sc.nextInt();	
		}

		Arrays.sort(d1);

		int r1 = 0;
		for(int i1 = 0; i1 < n1 - 2; i1++){
			for(int i2 = 0; i2 < n1 - i1 - 1; i2++){
				for(int i3 = 0; i3 < n1 - i1 - i2 - 2; i3++){
					if (d1[i1] < d1[i2 + i1 + 1] + d1[i1 + i2 + i3 + 2]){
                		if (d1[i2 + i1 + 1] < d1[i1] + d1[i1 + i2 + i3 + 2]){
                    		if (d1[i1 + i2 + i3 + 2] < d1[i1] + d1[i2 + i1 + 1]){
                        		r1++;
							} else{
								break;
							}
						}
					}
				}
			}
		}
		System.out.println(r1);			
	}
}

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

namespace _029_EnglishSentence
{
	class Program
	{
		static void Main ( string[] args )
		{
			string[] inputStr = Console.ReadLine ().Split (' ');

			Array.Sort (inputStr);

			int[] countArray = new int[inputStr.Length];
			countArray[0] = 1;

			string maxLengthStr = inputStr[0];

			for (int lp = 1; lp < inputStr.Length; lp++)
			{
				//count
				if (inputStr[lp] == inputStr[lp - 1])
				{
					countArray[lp] = countArray[lp - 1] + 1;
				}
				else
				{
					countArray[lp] = 1;
				}

				//length
				if (maxLengthStr.Length < inputStr[lp].Length)
				{
					maxLengthStr = inputStr[lp];
				}
			}

			int maxCount = countArray.Max ();
			int index = Array.IndexOf (countArray, maxCount);
			string maxCountStr = inputStr[index];

			Console.WriteLine (maxCountStr + " " + maxLengthStr);
		}
	}
}

Measured memory_bytes: 10248
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int n = getInput().get(0);
        ArrayList<Integer> p = getInput();

        int count = 1;
        int tmin = Integer.MAX_VALUE;
        for (int i = 1; i < n; i++) {
            tmin = Math.min(p.get(i - 1), tmin);
            if (p.get(i) <= tmin) ++count;
        }

        Print(count);
    }

    private static Scanner scanner = new Scanner(System.in);

    private static ArrayList<Integer> getInput() {
        String in = scanner.nextLine();

        ArrayList<Integer> result = new ArrayList<>();
        for (String t : in.split(" ")) {
            result.add(Integer.parseInt(t));
        }

        return result;
    }

    private static void Print(Object o) {
        System.out.println(o);
    }

    private static void Print(Object... o) {
        for (Object i : o) System.out.print(i);
        System.out.println();
    }
}


Measured memory_bytes: 60432
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

class T{
public:
  int id,school,ac,p;
  T(){}
  T(int _id,int _school,int _ac,int _p){
    id = _id;
    school = _school;
    ac = _ac;
    p = _p;
  }

  bool operator<(const T &t)const{
    if(ac == t.ac){
      if(p == t.p){
        return id < t.id;
      }
      return p < t.p;
    }
    return ac > t.ac;
  }
};

int n;
T t[302];

void solve(){
  int pass = 0;
  int scCnt[1002];
  vector<int> ans;
  memset(scCnt,0,sizeof(scCnt));
  sort(t,t+n);

  rep(i,n){
    bool flg = false;

    if(pass < 10){
      if(scCnt[t[i].school] < 3){
        flg = true;
      }
    }
    else if(pass < 20){
      if(scCnt[t[i].school] < 2){
        flg = true;
      }
    }
    else if(pass < 26){
      if(scCnt[t[i].school] == 0){
        flg = true;
      }
    }

    if(flg){
      ans.push_back(t[i].id);
      scCnt[t[i].school]++;
      pass++;
    }
  }

  rep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
}

int main(){
  while(cin>>n,n){
    rep(i,n){
      cin>>t[i].id>>t[i].school>>t[i].ac>>t[i].p;
    }
    solve();
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();

		for (int i = 1; i <= x; i++) {
			if (i * (i + 1) / 2 >= x) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 23636
#include <stdio.h>
#include <stdlib.h>

#define N   6
#define MAX (1000 * 6 + 1)

int n[N];
int coin[N] = { 1, 5, 10, 50, 100, 500 };

// m????????????????????¬??¨??§??´??£?????????????????´?????????????????¬??¨????????°????????????
// ??????????????´??????-1????????????
int pay(int m) {
    int i;
    int rep = 0;

    for( i = N - 1; i >= 0; i-- ) {
        int cnt = m / coin[i];

        if( cnt > n[i] ) {
            cnt = n[i];
        }
        m -= coin[i] * cnt;
        rep += cnt;
    }

    return m == 0 ? rep : -1;
}

// m???????????£????????¬??¨??§??????????????????????????°???????°???????
int change(int m) {
    int i;
    int rep = 0;

    for( i = N - 1; i >= 0; i-- ) {
        int cnt = m / coin[i];
        rep += cnt;
        m -= cnt * coin[i];
    }

    return rep;
}

int main(void) {
    int p;
    int i;

    scanf("%d", &p);
    if( p == 0 ) return 0;
    do {
        int sum = 0;    // ??????????????¬??¨???????¨???????
        int min = MAX;
        for( i = 0; i < N; i++ ) {
            scanf("%d", n + i);
            sum += n[i] * coin[i];
        }

        for( i = p; i <= sum; i++ ) {
            int tarocnt = pay(i);
            if( tarocnt != -1 ) {
                int tmp = tarocnt + change(i - p);
                min = min < tmp ? min : tmp;
            }
        }

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

        scanf("%d", &p);
    } while( p != 0 );

    return 0;
}

Measured memory_bytes: 596
<?php

[$N, $K] = fscanf(STDIN, "%d%d");
$list = fscanf(STDIN, str_repeat("%d", $N));
const MAX = 1000000000000;
$keta = 0;
$keta = (int)log($K*2+1, 2);
$v=1;
for($i=0;$i<$keta;$i++){
    $ans[$i]= 0;
    $ni[$i] = $v;
    $v<<=1;
}


foreach($list as $value){
    for($i=0;$i<$keta;$i++){
        if(($value & $ni[$i]) > 0){
            $ans[$i]++;
        }
    }
}

$half = intdiv($N+1,2);
$ech = 0;
for($i=$keta-1;$i>=0;$i--){
    if($ans[$i] < $half){
        if($ech + $ni[$i] <= $K){
            $ech+=$ni[$i];
        }

    }
}
$ans = 0;
foreach($list as $value){
    $ans += $value ^ $ech;
}
echo $ans;


Measured memory_bytes: 22716
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric> // next_parmutation
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];
    if(n == 0) cout << x<< endl;
    else{
    ll mini = 100000000000;
    int ans;
    ll cal;

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


    rep(i, n){
        cal = (x - p[i]);
        if(mini > abs(cal)) ans = i;
        mini = min(mini, abs(cal));
    }
    
   

    int j=1;

    while(1){
        if(p[ans]-j != p[ans-j]){
             cout << p[ans]-j << endl;
             break;
        }
        if(p[ans] + j != p[ans+j]){
            cout << p[ans]+j << endl;
             break;
        }
        j++;
    }
    }
}

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

void input(int& rnLimit, vector<llong>& rvnCostA, vector<llong>& rvnCostB)
{
  int nCostASiz, nCostBSiz;
  cin >> nCostASiz >> nCostBSiz >> rnLimit;
  rvnCostA.resize(nCostASiz + 1);
  rvnCostB.resize(nCostBSiz + 1);

  for (int i = 1; i < rvnCostA.size(); i++)
  {
    int nOneCost;
    cin >> nOneCost;
    rvnCostA[i] = rvnCostA[i - 1] + nOneCost;
  }

  for (int i = 1; i < rvnCostB.size(); i++)
  {
    int nOneCost;
    cin >> nOneCost;
    rvnCostB[i] = rvnCostB[i - 1] + nOneCost;
  }
}

int calcMaxSelect(int nLimit, const vector<llong>& cnrvnCostA, 
                              const vector<llong>& cnrvnCostB)
{
  int nCntA = cnrvnCostA.size() - 1;
  
  while ( cnrvnCostA[nCntA] > nLimit )
    --nCntA;

  int nMaxSelect = nCntA;
  int nBgnB = 0;
  int nCntB;

  while ( nCntA >= 0 ) 
  {
    while ( nBgnB < cnrvnCostB.size()  &&
            cnrvnCostA[nCntA] + cnrvnCostB[nBgnB] <= nLimit )
    {
      nCntB = nBgnB;
      ++nBgnB;
    }

    nMaxSelect = max(nMaxSelect, nCntA + nCntB);

    nBgnB = nCntB;
    --nCntA;
  }
  return nMaxSelect;
}
 
int main()
{
  int nLimit;
  vector<llong> vnCostA, vnCostB;

  input(nLimit, vnCostA, vnCostB);
  cout << calcMaxSelect(nLimit, vnCostA, vnCostB) << endl;

  return 0;
}

Measured memory_bytes: 6408
import sys


input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
tree = [[] for i in range(n)]
start_point = [True] * n
for i in range(m):
    tree[info[i][0] - 1].append(info[i][1] - 1)
    start_point[info[i][1] - 1] = False
     
dp = [-1]*n

def dfs(pos):
    if dp[pos] !=-1:
        return dp[pos]
    if not tree[pos]:
        dp[pos] = 0
        return 0
    ans = 0
    for i in tree[pos]:
        ans = max(ans, dfs(i) + 1)
    dp[pos] = ans
    return ans

for i in range(n):
    dfs(i)
print(max(dp))
          

Measured memory_bytes: 141832
#include <iostream>
using namespace std;
int n, m, k, a, meal[35], ans;

int main(void)
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> a;
			meal[a]++;
		}
	}
	for (int i = 1; i <= m; i++)
	{
		if (meal[i] == n) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
ans = 0
while len(L) :
    if not L[0] :
        L.pop(0)
    else :
        ans += 1
        for i in range(len(L)) :
            if L[i] :
                L[i] -= 1
            else :
                break
print(ans)


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

int main(){
    int n;
    int count = 0;
    cin >> n;
    for(int i = 1; i <= n;i++){
        if(i % 2 == 0){
            count++;
        }
    }
    cout << float(n - count) / float(n);
    return 0;
}

Measured memory_bytes: 256
import math
N,D = map(int,input().split())
X  = [None]*N
Y = [None]*N
for i in range(N):
    X[i],Y[i] = map(int,input().split())

ans=0
for i in range(N):
    if(math.sqrt(X[i]**2+Y[i]**2) <=D):
        ans+=1

print(ans)


Measured memory_bytes: 24612
/**********
*	????????¢????????????
*	????????¢?????????????????????????????????????????????????????°??????
*********/

#include <iostream>

int main(void)
{
	int W,H,x,y,r;

	std::cin >> W >> H >> x >> y >> r;
	
	if( 0 < x && x <= (W-r) ){
		if(0 < y && y <= (H-r) ){
			std::cout << "Yes" << std::endl;
		} else{
			std::cout << "No" << std::endl;
		}
	} else{
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    v1 p(n+1);
    vl c(n+1);
    for(int i = 1; i<=n; i++){
        cin >> p[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> c[i];
    }
    ll ans = -1e18;
    for(int si = 1; si <= n; si++){
        v1 link(1, c[si]);
        int next = p[si];
        ll sum = c[si];
        while(next != si){
            link.push_back(c[next]);
            sum += c[next];
            next = p[next];
        }
        int l = link.size();
        ll t = 0;
        rep(i, l){
            t += link[i];
            if(i + 1 > k) break;
            ll now = t;
            if(sum > 0){
                ll e = (k-i-1)/l;
                now += sum*e;
            }
            ans = max(ans, now);
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF = 987654321;
const int MOD = 1000000007;

int main(){
  int N,H,W;
  scanf("%d %d %d",&N,&H,&W);
  printf("%d\n",(N-H+1)*(N-W+1));
}

Measured memory_bytes: 256
a=input()
l=[]
count=0
for i in range(len(a)):
    l.append(a[i])
l.sort()
for i in range(len(a)):
    
    if(l.count(l[i])%2!=0):
        count=1
        print("No")
        break

if count==0:
    print("Yes")

Measured memory_bytes: 3064
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n)]
    for i in range(len(s)):
        pt[s[i]-1].append(t[i]-1)
        if not directed:
            pt[t[i]-1].append(s[i]-1)
    return pt

N = I()
u,v = LIR(N-1,2)

pt = edges_to_pt(u,v,N)
ans = 0
d = 0
for i in range(N):
    s = 0
    for v in pt[i]:
        if v < i:
            s += v+1
    d = d-s+i+1
    ans += d

print(ans)

Measured memory_bytes: 147300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int LIMIT = 1e9 + 7;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int x;cin>>x;
  cout<<(x>=30?"Yes":"No")<<endl;
}

Measured memory_bytes: 3620
//╔╗───────────╔╗────────────────────╔╗─
//║║──────────╔╝╚╗──────────────────╔╝╚╗
//║╚═╗╔══╗╔══╗╚╗╔╝╔══╗╔═╗╔╗╔╗╔══╗ ╔╗╚╗╔╝
//║╔╗║║╔╗║║╔╗║─║║─║║═╣║╔╝║╚╝║║╔╗║─╣║─║║─
//║╚╝║║╔╗║║║║║─║╚╗║║═╣║║─║║║║║╚╝║─║║─║╚╗
//╚══╝╚╝╚╝╚╝╚╝─╚═╝╚══╝╚╝─╚╩╩╝╚══╝─╚╝─╚═╝ 

#include <bits/stdc++.h>

#define ll int64
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
    IO;
    int a,b;
    cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a == b){
        return cout << "Draw",0;
    }else if(a > b){
        return cout << "Alice",0;
    }else{
        return cout << "Bob",0;
    }

}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc066

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (b <= a) cout << "delicious" << endl;
    else if (b - a <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

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

class Main{
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String A[] = scanner.next().split("");
        String B[] = scanner.next().split("");
        String C[] = scanner.next().split("");
        
        int l = 0;
        int m = 0;
        for(int i = 0;i<N;i++){
            if(A[i].equals(B[i]) && A[i].equals(C[i]) && C[i].equals(B[i])){
                
            }
            else if((A[i].equals(B[i])!= true) && (B[i].equals(C[i])!= true)&& (C[i].equals(A[i])!= true)){
                l = l+2;
            }
            else{
                l++;
            }
        }

        System.out.println(l);
        
        
        scanner.close();

    }
    public static int POWER(int a,int b){
        int p = 1;
        for(int i = 1;i<=b;i++){
            p = a*p;
        }
        return p;
    }
    public static int min(int a,int b){
        if(a>=b) return b;
        else return a;
      }
}

Measured memory_bytes: 21844
import java.util.*;


public class Main {
	
	
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		char[] st = s.next().toCharArray();
		int[] a = new int[26];
		for(int i = 0;i<4;i++)
			a[st[i]-'A']++;
		
		int c=  0;
		for(int i=0;i<26;i++)
		{
			if(a[i]>0 && a[i]==2)
				c++;
		}
		if(c==2)System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll int
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
const ll MAX=1e5+3;
const ll mod=1e9+7;
int main()
{
   FASTIO
   int t=1;
  // cin>>t;
   while(t--)
  {
        ll n;
        cin>>n;
        vi v(n);
        rep(i,0,n)
        cin>>v[i];
        vi cost(n);
        cost[0]=0;
        rep(i,1,n)
        {
            if(i-2>=0)
            {
                cost[i]=min(cost[i-1]+abs(v[i]-v[i-1]),cost[i-2]+abs(v[i]-v[i-2]));
            }
            else
                cost[i]=cost[i-1]+abs(v[i]-v[i-1]);
        }
      /*  rep(i,0,n)
        cout<<cost[i]<<" ";
        cout<<endl;*/
        cout<<cost[n-1];
   }
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b;
  cin >> a >> b;

  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define inf 0x7fffffff
using namespace std;
int a[100010],b[100010];
int n,k,cnta=0,cntb=0,be,en,ans=inf;
bool cmp(int aa,int bb){return aa<bb;}
int main(){
	scanf("%d%d",&n,&k);
	int i,j,x;
	for(i=1;i<=n;++i){
		scanf("%d",&x);
		if(x<0)  a[++cnta]=-x;
		else  b[++cntb]=x;
	}
	a[0]=b[0]=0;
	sort(a,a+1+cnta,cmp);sort(b,b+1+cntb,cmp);
	be=max(0,k-cntb);en=min(cnta,k);
	for(i=be;i<=en;++i){
		int nx=a[i],ny=b[k-i];
		ans=min(ans,min(nx*2+ny,ny*2+nx));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, O = 0;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {cin >> p.at(i);}
  for (int i = 0; i < N; i++) {
    if (i + 1 != p.at(i)) {O++;}
  }
  if (O == 2 || O == 0) {cout << "YES" << endl;}
  else {cout << "NO" << endl;}
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long int ll;



using namespace std;

int main()
{

  int N;

  cin >> N;

  vector<ll> A(N);
  vector<ll> B(N);

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

    ll a, b;
    cin >> a >> b;

    A[i]=a;
    B[i]=b;
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());


  ll kasu =0;

  if (N % 2 == 0)
  {
    kasu = 1+2*((double)(B[N / 2 - 1] + B[N / 2])/2. - (double)(A[N / 2 - 1] + A[N / 2])/2.);
  }
  else
  {
    kasu = B[(N + 1) / 2 - 1] - A[(N + 1) / 2 - 1] + 1;
  }

  cout << kasu << endl;
  return 0;
}


Measured memory_bytes: 6420
import scala.io.{StdIn => in}

object Main extends App {
  val mod = 1000000007L

  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  val isUsable = Array.fill(n+1)(true)
  Iterator.continually(in.readInt)
    .take(m)
    .foreach(isUsable(_) = false)

  val dp = Array.ofDim[Long](n+1)
  dp(0) = 1

  for {
    i <- 0 until n
    j <- i + 1 to (n min (i + 2))
    if isUsable(j)
  } {
    dp(j) += dp(i)
    dp(j) %= mod
  }

  val ans = dp(n)
  println(ans)
}

Measured memory_bytes: 37676