akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(string &a){reverse(a.begin(),a.end()) ;}

bool prime(ll a){
	if(a==1) return true ;
	for(ll i=2;i*i<=a;i++){
		if(a%i==0) return false ;
	}
	return true ;
}

int main(){
	ll a,b ;
	cin >> a >> b ;
	if(a==1||b==1){
		cout << 1 << endl ;
		return 0 ;
	}
	ll ans = 0 ;
	for(ll i=1;i*i<=a;i++){
		if(a%i==0){
			if(b%i==0){
				if(prime(i)) ans++ ;
			}
			if(b%(a/i)==0){
				if(prime(a/i)) ans++ ;
			}
		}
	}
	cout << ans << endl ;
}


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

int main() {
  ll n;
  cin >> n;
  vector<set<ll>> v(n);
  for(ll i=0;i<n;i++) {
    ll f,k;
    cin >> f >> k;
    for(ll j=0;j<k;j++) {
      ll temp;
      cin >> temp;
      temp--;
      v[i].insert(temp);
    }
  }
  vector<ll> ans(n,-1);
  ans[0]=0;
  queue<ll> q;
  q.push(0);
  while(q.size()) {
    ll p=q.front();
    q.pop();
    for(ll t:v[p]) {
      if(ans[t]<0) {
        ans[t]=ans[p]+1;
        q.push(t);
      }
    }
  }
  for(ll i=0;i<n;i++) {
    cout << i+1 << " " << ans[i] << endl;
  }
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  int n; cin >> n;
  int ans = 0;
  rep(i, n) {
    ll a; cin >> a;
    while(true) {
      if(a%2 != 0) break;
      ++ans;
      a /= 2;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var h = long.Parse(Console.ReadLine());
        long l = 1;
        while (l <= h) l <<= 1;
        Console.WriteLine(l - 1);
    }
    
}



Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
ll a[100005];

int main()
{
    int n;
    cin>>n;
    ll ans;
    for(int i=0;i<n;++i){
        scanf("%lld",&a[i]);
        if(i==0) ans=a[i];
        else ans=ans^a[i];
    }
    if(ans==0) cout<<"Yes";
    else cout<<"No";

    return 0;
}


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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] += par[y]; par[y] = x;
        }
    }

    int distinct() {
        int res = 0;
        for(int i = 0; i < (int)par.size(); i++) res += (par[i] < 0);
        return res;
    }
};

const int MOD = 1001;

int main() {
    vector<int> fib(1001);
    fib[0] = 1, fib[1] = 2;
    for(int i = 2; i <= 1000; i++) {
        fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
    }
    for(int V, D; cin >> V >> D; ) {
        UnionFind uf(V);
        for(int i = 1; i <= V; i++) {
            for(int j = 1; j <= V; j++) {
                if(abs(fib[i] - fib[j]) < D) uf.merge(i - 1, j - 1);
            }
        }
        int res = uf.distinct();
        cout << res << endl;
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<int> a(5);
	int sum=0;
	rep(i,5) cin>>a[i],sum+=a[i];
	int ans=INF;
	sort(begin(a),end(a));
	do{
		int now=0;
		rep(i,5){
			while(now%10){
				now++;
			}
			now+=a[i];
		}
		chmin(ans,now);
	}while(next_permutation(begin(a),end(a)));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
x,n = list(map(int,input().split()))
if n==0:
	print(x)
	exit()
arr = list(map(int,input().split()))
d = {}
for i in arr:
	d[i] = 1
p = 0
while(True):
	if (x-p not in d):
		print(x-p)
		break
	if x+p not in d:
		print(x+p)
		break
	p+=1

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
 
int main(){
int n;
cin >> n;
int ara[n];
for(int i=0;i<n;i++) cin >> ara[i];
for(int i=n-1;i>=1;i--) cout << ara[i] << " ";
cout << ara[0] << endl;
return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define int long long
using namespace std;
int n,k,x,y,cev=1;
vector<int> v[li];
inline int mul(int x,int y){
	return (x%md)*(y%md)%md;
}
void dfs(int node,int ata){
	int say=0;
	if(node==1) say=k;
	else say=k-1;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata) continue;
		say--;
		cev=mul(cev,say);
		dfs(go,node);
		//say--;
	}
}
main(){
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<n;i++){
		scanf("%lld %lld",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,0);
	printf("%lld\n",mul(cev,k));
	return 0;
}




Measured memory_bytes: 11520
#include <iostream>
using namespace std;
 
int n, a[10009], sum;
 
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		while (a[i] % 2 == 0) { a[i] /= 2; sum++; }
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    char s[3];
    int count = 0;
    for(int i = 0; i < 3; i++){
        scanf("%c",&s[i]);
        if(s[i] == '1'){
            count++;
        }
    }
    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, string S){
  ll ans=0;
  for (int i = 0; i < 1000; i++) {
    string x = to_string(i);
    ll a=0;
    while(x.length() < 3){
      x = '0'+x;
    }
    for (int i = 0; i < N; i++) {
      if(S[i] == x[a])a++;
    }
    if(a == 3)ans++;
  }
  cout << ans << endl;
}

int main(){
  long long N;
	scanf("%lld",&N);
	string S;
  cin >> S;
  solve(N, S);
}


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

int kona, minm;

void search(int k, int a, int b, int c){
  if(k <= 0){
    int am = (a / 5) * 5 * 380 * 0.8 + (a % 5) * 380;
    int bm = (b / 4) * 4 * 550 * 0.85 + (b % 4) * 550;
    int cm = (c / 3) * 3 * 850 * 0.88 + (c % 3) * 850;
    int all = am + bm + cm;
    if(all < minm) minm = all;
    return;
  }

  if(k >= 200) search(k - 200, a + 1, b, c);
  if(k >= 300) search(k - 300, a, b + 1, c);
  if(k >= 500) search(k - 500, a, b, c + 1);
}

int main(void){
  while(cin >> kona && kona != 0){
    minm = 100000000;
    search(kona, 0, 0, 0);
    cout << minm << endl;
  }
  return 0;
}

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

using namespace std;

#define int long long
#define fi  first
#define se  second
#define pb  push_back

const int   N   = 2e5 + 1;

typedef pair<int,int>   ii;

int s[N], ft[N];

void upd(int p) {
    for(; p < N ; p += p & -p)
        ft[p]++;
}
int _get(int p) {
    int ans = 0;
    for(; p > 0 ; p -= p & -p)
        ans += ft[p];
    return ans;
}

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

    int n, k;   cin >> n >> k;

    for(int i = 1 ; i <= n ; ++i)   {
        int x;  cin >> x;
        s[i] = s[i - 1] + x - k;
    }

    vector<ii>  v;

    for(int i = 0 ; i <= n ; ++i)
        v.pb({s[i],i});

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

    int cnt = 0;

    for(int i = 0 ; i <= n ; ++i)   {
        if(!i || v[i].fi > v[i - 1].fi)
            ++cnt;
        s[v[i].se] = cnt;
    }

    int ans = 0;

    for(int i = 0 ; i <= n ; ++i)   {
        ans += _get(s[i]);
        upd(s[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 7792
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#define FOR(fornum) for(int i = 0; i < fornum; i++)
using namespace std;

int main(){
    //variable
    int N; scanf("%d", &N);
    vector<int> a(N);
    int Alicetotal = 0;

    //scan
    FOR(N) scanf("%d", &a[i]);

    //solver
    sort(a.begin(), a.end(), greater<int>());
    FOR(N) Alicetotal += ((i + 1) % 2) ? a[i] : (a[i] * -1);

    //print
    printf("%d", Alicetotal);

    //end
    return 0;
}

Measured memory_bytes: 256
import numpy as np

class Calculator:
    def __init__(self):
        self.num = 0

    def set_num(self, N, i):
        self.N = N
        self.i = i

    def calc(self):
        self.num = self.N - self.i + 1;

    def get_num(self):
        return self.num

def main():
    N, i, = map(int, input().split())
    c = Calculator()
    c.set_num(N, i)
    c.calc()
    ans = c.get_num()
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 13000
/**
 *    author:  FromDihPout
 *    created: 2020-09-01
**/

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

vector<vector<int>> adj;
vector<bool> seen;

int dfs(int u) {
    seen[u] = true;
    int len = 1;
    for (int v : adj[u]) {
        if (!seen[v]) {
            len += dfs(v);
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    adj.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    seen.resize(n);
    int max_len = 0;
    for (int i = 0; i < n; i++) {
        if (!seen[i]) {
            max_len = max(max_len, dfs(i));
        }
    }
    cout << max_len << '\n';
    
    return 0;
}

Measured memory_bytes: 23500
program main
implicit none
integer :: i, j, k
integer :: n
character :: s*100

read(*,*) n
read(*,*) s(1:n)
j = 0
k = 0
do i = 1, n
   if( s(i:i) == 'I' ) then
      j = j + 1
   else
      j = j - 1
   end if
   if( j .ge. k ) then
      k = j
   end if
end do
write(*,'(i0)') k



end program main


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 200010;
int parent[N_MAX];
int parent2[N_MAX];

int find(int a){
    if(parent[a] == a){
        return a;
    }
    return parent[a] = find(parent[a]);
}

int find2(int a){
    if(parent2[a] == a){
        return a;
    }
    return parent2[a] = find2(parent2[a]);
}

void _union(int p, int q){
    int p0 = find(p);
    int p1 = find(q);
    if(p0==p1) return;
    parent[p0] = p1;
}

void _union2(int p, int q){
    int p0 = find2(p);
    int p1 = find2(q);
    if(p0==p1) return;
    parent2[p0] = p1;
}

bool is_same_group(int p, int q){
    return find(p) == find(q);
}

bool is_same_group2(int p, int q){
    return find2(p) == find2(q);
}

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

    // input
    ll N, K, L;
    cin >> N >> K >> L;

    FOR(i, 0, N_MAX){
        parent[i] = i;
        parent2[i] = i;
    }

    // K本の道路
    FOR(i, 0, K){
        ll p, q;
        cin >> p >> q;
        _union(p, q);
    }
    
    // L本の鉄道
    FOR(i, 0, L){
        ll p, q;
        cin >> p >> q;
        _union2(p, q);
    }

    // 同ペアをカウント
    map<pair<int, int>, int> mp;

    FOR(i, 1, N+1){
        int a = find(i);
        int b = find2(i);
        auto p = make_pair(a, b);
        mp[p]++;
    }

    FOR(i, 1, N+1){
        int a = find(i);
        int b = find2(i);
        auto p = make_pair(a, b);
        cout << mp[p] << " ";
    }

    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
const int MAX = 510000;

ll color[MAX];

struct edge{
    ll to, cost;
};

vector<edge> G[MAX];

//0はfalse

void dfs(ll v, ll before, ll c){
    color[v] = c;
    for(edge e : G[v]) if(e.to != before){
        if(e.cost % 2) dfs(e.to, v, !c);
        else dfs(e.to, v, c);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    rep(i, n - 1){
        ll u, v, w;
        cin >> u >> v >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    dfs(1, -1, 0);
    Rep(i, 1, n + 1) cout << color[i] << endl;

}

Measured memory_bytes: 21504
import itertools

result = 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
list_in = [a,b,c,d,e]
list_in = sorted(list_in)

for i in itertools.permutations([a,b,c,d,e], r=2):
    i = sorted(i)
    if i[1]-i[0] > k:
      result = 1

if result == 1:
  print(":(")
else:
  print("Yay!")

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

ll vis[200005] ;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n , m , x , y;
    cin >> n >> m ;
    vector< pair<ll,ll> >v ;
    for( ll i = 0 ; i<m ; i++ )
    {
        cin >> x >> y ;
        v.push_back( make_pair(x,y) );
        if( x==1 )
        {
            vis[y] = 1;
        }

    }
    for( ll i = 0 ; i<m ; i++ )
    {
        if( vis[ v[i].first]==1 &&  v[i].second ==n )
        {
            cout << "POSSIBLE" << endl ; return 0 ;
        }
    }

    cout << "IMPOSSIBLE" << endl;
}




Measured memory_bytes: 7536
def main():
  N = int(input())
  val = N % 10
  if val == 2 or val == 4 or val == 5 or val == 7 or val == 9:
    print('hon')
  elif val == 0 or val == 1 or val == 6 or val == 8:
    print('pon')
  elif val == 3:
    print('bon')


if __name__ == '__main__':
  main()


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

int main() {
	// your code goes here
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b){
		cout << c << endl;
	}
	else if(b==c){
		cout << a << endl;
	}
	else cout << b << endl;
	return 0;
}

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

int main(void) {
    int n,a;
    std::deque<int> deq;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end(),greater<int>());
    for (int j=0;j<n-1;j++) {
        int a=deq[0];
        int b=deq[1];
        while (a%b!=0) {
            int tmp=b;
            b=a%b;
            a=tmp;
        }
        deq[0]=(deq[0]*deq[1]/b);
        deq.erase(deq.begin()+1,deq.begin()+2);
    }
    cout<<deq[0]<<endl;
}


Measured memory_bytes: 3156
H,W,K=map(int,input().split());m=10**9+7;c=1;H+=W
for i in range(H-1,H-K,-1):c=c*i %m;
v=pow(H-1,m-2,m);d=K*(K+1)//2;a=c*H*(d+K);d=(K-1)*d//3;a=(a+d*c*v*2*(H-W)*W)%m;print(a)

Measured memory_bytes: 62956
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <limits>
#include <cmath>
#include <vector>
using namespace std;
#define ll long long

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	cout << A << " " << B << " " << 3*C - A - B << endl;
	cout << 4*C - 2*A - B << " " << C << " " << 2*A + B - 2*C << endl;;
	cout << A + B - C << " " << 2*C - B << " " << 2*C - A << endl;;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;
const int mod = 1000000007;

int fpow(int x, int y) {
	if (y == 0) return 1;
	long long res = fpow(x, y / 2);
	(res *= res) %= mod;
	return int(y % 2 == 1 ? (res * x) % mod : res);
}

int rev(int x) {
	return fpow(x, mod - 2);
}

int h, w, a, b, upper[100005], lower[100005];

int main() {
	scanf("%d %d %d %d", &h, &w, &a, &b);
	upper[0] = 1;
	for (int i = 1; i < w; i++) upper[i] = (static_cast<long long>(upper[i - 1]) * (h - a - 1 + i) % mod) * rev(i) % mod;
	lower[0] = 1;
	for (int i = 1; i < w - b; i++) lower[i] = (static_cast<long long>(lower[i - 1]) * (a - 1 + i) % mod) * rev(i) % mod;
	int res = 0;
	for (int i = b; i < w; i++)(res += static_cast<long long>(upper[i]) * lower[w - i - 1] % mod) %= mod;
	printf("%d\n", res);
#ifdef LOCAL_MSVC_DEBUG
	system("pause");
#endif
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N,M = map(int,input().split())
ad = [[] for i in range(N)]
for _ in range(M):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    ad[x].append(y)

dp = [-1]*N

def rec(nodes):
    if dp[nodes] != -1:
        return dp[nodes]
    res = 0
    for ne in ad[nodes]:
        option = rec(ne)+1
        if res < option:
            res = option
    dp[nodes] = res
    return dp[nodes]

ans = 0
for i in range(N):
    res = rec(i)
    if ans < res:
        ans = res
print(ans)

Measured memory_bytes: 59016
#include <iostream>
using namespace std;
int main()
{
    int D, G, p[11], c[11];
    cin >> D >> G;
    for (int i = 0; i < D; ++i)
    {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < (1 << D); ++mask)
    {
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < D; ++i)
        {
            if (mask >> i & 1)
            {
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            }
            else
            {
                rest_max = i;
            }
        }
        if (s < G)
        {
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if (need >= p[rest_max])
            {
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
cnt=[0]*n
for i in range(1,n):
  if s[i]=='E':
    cnt[0]+=1
for i in range(1,n):
  cnt[i]=cnt[i-1]
  if s[i]=='E':
    cnt[i]-=1
  if s[i-1]=='W':
    cnt[i]+=1
print(min(cnt))


Measured memory_bytes: 15260
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int a = sc.nextInt();
        int b = sc.nextInt();
        pw.println(a <= 8 && b <= 8 ? "Yay!" : ":(");
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

#define fi first
#define se second

const int N = 200200;
const long long mod = 998244353;

using namespace std;

int n;
int m;
int a[N];
bool used[N];
vector < int > v[N];
set < pair < int, int > > s;
vector < pair < int, int > > res;

void dfs(int x, int p)
{
        used[x] = true;
        for(int y: v[x]){
                if(y == p){
                        continue;
                }
                if(used[y]){
                        if(s.find({y, x}) == s.end()){
                                s.insert({x, y});
                                a[x] ^= 1;
                        }
                        continue;
                }
                dfs(y, x);
        }
        if(a[x]){
                s.insert({x, p});
                a[x] = 0;
        } else if(p != -1){
                s.insert({p, x});
                a[p] ^= 1;
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> m;
        for(int i = 1; i <= m; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        if(m & 1){
                cout << -1 << "\n";
                return 0;
        }
        dfs(1, -1);
        for(auto p: s){
                cout << p.fi << ' ' << p.se << "\n";
        }
}


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


int main() 
{
    int n;
    cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];

    int maxv = 0;
    int jump = 0;
    rep(i,n-1) {
        if (h[i] < h[i+1]) {
            jump = 0;
        }
        if (h[i] >= h[i+1]) {
            jump++;
            maxv = max(maxv, jump);
        }
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int c;
  c = getc(stdin);
    switch(c){
      case 'a':
            case 'i':
                  case 'u':
                        case 'e':
                              case 'o':
                              printf("vowel");
                              break;
      default:
        printf("consonant");
  }
}


Measured memory_bytes: 128
#starting from X is equivalent to go to x1-X,x2-X,... starting from 0.
#donc x1-X est multiple de D, x2-X l'est aussi...donc gcd des xi-X.
import fractions
from functools import reduce
N,X = map(int,input().split())
L = [abs(i-X) for i in map(int,input().split())]
def gcd_list(numbers):
  return reduce(fractions.gcd,numbers)
print(gcd_list(L))

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

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

  if (a % 2 ==1 && b % 2 == 1 ) {
  cout << "Odd" << endl;
  }
  else{
  cout << "Even" << endl;
  }
}


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

using ll = long long;

int get(string s, string t){
  int ret = 0;
  for(int i = 0; i < (int)s.size(); ++i){
    if(s[i] != t[i])++ret;
  }
  return ret;
}

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

  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int ans = m;
  for(int i = 0; i + m - 1 < n; ++i){
    ans = min(ans, get(s.substr(i, m), t));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
const int MAX = 510000;

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;
}

LL mpow(LL x, LL t){
    if(t == 0) return 1;
    LL ret = mpow(x,t/2);
    ret = ret * ret % MOD;
    if(t%2==1) ret = ret*x%MOD;
    return ret;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();

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

    LL ans = 0;
    FOR(i,N,2*N){
        LL tmp1 = COM(i-1,N-1);
        LL tmp2 = mpow(A,N) * mpow(B,i-N) % MOD;
        LL tmp3 = mpow(A,i-N) * mpow(B,N) % MOD;
        LL tmp4 = i * 100 % MOD;

        // divide
        LL tmp5 = mpow(100-C,i);
        tmp5 = modinv(tmp5,MOD);
        LL tmp6 = modinv(100-C,MOD);

        LL tmpsum = tmp1 * ((tmp2+tmp3) % MOD) % MOD * tmp4 % MOD;
        tmpsum = tmpsum * tmp5 % MOD * tmp6 % MOD;
        ans = (ans + tmpsum) % MOD;

    }

    cout << ans << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long digitsum(long long n){
    long long result = 0;
    while(n > 0) {
        result += n % 10;
        n /= 10;
    }
    return result;
}
int main(){
ll n;
cin >> n;
cout << (!(n%digitsum(n)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int q, w, z,a,d;
    cin>>q>>w;
    z=q+w;
    a=q-w;
    d=q*w;
    if((q<=100&&q>=-100)&&(w<=100&&w>=-100)){
    if(z>=a&&z>d){cout<<z;}
    else if(a>z&&a>d){cout<<a;}
    else{cout<<d;}
    }else{cout<<"not valid";}
return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b<10){
        cout << a+b << endl;
    } else {
        cout << "error" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

//nCk 繰り返し高速
ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll n,k;
  cin >> n >> k;
  fact(n);
  ll r=n-k;
  for(ll i=1;i<=k;i++) {
    if(i>r+1) {
      cout << 0 << endl;
      continue;
    }
    ll ans=comb(r+1,i);
    ans=ans*comb(k-i+(i-1),i-1)%mod;
    cout << ans << endl;
  }
}

Measured memory_bytes: 81224
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_SM(n):
	return [tuple(INSTR_S()) for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

A, B, C = INNUM_S()
print("YNEOS"[(B-A)!=(C-B)::2])

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

int n,t,l,b;

int add(int a,int b)
{
	if(a+b<=n)
		return a+b;
	else
		return n-(a+b-n);
}

int main() {
	while(1) {
		cin >> n >> t >> l >> b;
		if(n==0) break;
		vector<bool> L(n+1,false);
		vector<bool> B(n+1,false);
		for(int i=0;i<l;i++)
		{
			int tmp;
			cin >> tmp;
			L[tmp]=true;
		}
		for(int i=0;i<b;i++)
		{
			int tmp;
			cin >> tmp;
			B[tmp]=true;
		}

		double dp[105][105]={};

		dp[0][0]=1;

		for(int i=0;i<t;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(B[j]==true)
				{

				}
				else if(L[j]==true)
				{
					for(int k=1;k<=6;k++)
					{
						dp[add(j,k)][i+2]+=dp[j][i]/6;
					}
				}
				else
				{
					for(int k=1;k<=6;k++)
					{
						dp[add(j,k)][i+1]+=dp[j][i]/6;
					}
				}
			}
			for(int j=0;j<n;j++)
				if(B[j]==true)
				{
					dp[0][i+1]+=dp[j][i+1];
					dp[j][i]=0;
				}
			dp[n][i+1]+=dp[n][i];
		}

		/*
		for(int i=0;i<=n;i++)
			for(int j=0;j<=t;j++)
				cout << fixed <<setprecision(10) << dp[i][j] << (j==t ? "\n":"\t");
		*/

		cout << fixed << setprecision(10) << dp[n][t] << endl;
	}
}


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

int main(){
  int N,T,A;
  cin>>N>>T>>A;
  vector<int> H(N);
  vector<double> dif(N);
  double min;
  int n,i;
  
  for(i=0;i<N;i++){
    cin>>H[i];
  }
  
  for(i=0;i<N;i++){
    dif[i]=A-T+H[i]*0.006;
    if(dif[i]<0){
      dif[i]=-dif[i];
    }
  }
  
  min=dif[0];
  for(i=1;i<N;i++){
    if(min>dif[i]){
      min=dif[i];
      n=i;
    }
  }
  
  cout<<n+1<<endl;
}
  
  
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int N;
    cin >> N;

    int tmp=(N+1)/2;
    float ans = float(tmp)/N;

    
    cout << ans << endl;



   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
    return 0;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int a[5];
  rep(i,0,5){
    cin>>a[i];
    if(a[i]==0) co(i+1);
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int s[100005];

int main(){
    int N; cin>>N;
    while(N--){
        int n; cin>>n;
        s[n-1]++;
        s[n]++;
        s[n+1]++;
    }
    int max_num = 0;
    for(int i=0;i<=100005;i++){
        max_num = max(max_num, s[i]);
    }
    cout<<max_num<<endl;
    
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int c=a*b;
  if(c%2==1){
    cout<<"Odd"<<endl;
  }
  else if(c%2==0){
    cout<<"Even"<<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
S = input()

al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
step = []
for i in al:
    step.append(i)
    

string = []
for i in S:
    for j in range(26):
        if (i == step[j]): 
            if ((j+N)<26) : string.append(step[j+N])
            else : string.append(step[j+N-26])
            
Ans = ''.join(string)
print(Ans)
    

Measured memory_bytes: 40944
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    sc.close();
    if ((X+Y)%3 != 0) {
      System.out.println(0);
      return;
    }
    int a = X - (X+Y)/3, b = Y - (X+Y)/3;
    if (a < 0 || b < 0) {
      System.out.println(0);
      return;
    }
    long out = 1;
    long modv = (long)Math.pow(10, 9) + 7;
    for (int i = a+1; i <= a+b; i++) {
      out *= i;
      out = out % modv;
    }

    long div = 1;
    for (long i = 1; i <= b; i++) {
      div *= i;
      div %= modv;
    }

    long invDiv = inv(div, modv);
    System.out.println(out*invDiv % modv);
  }

  private static long inv(long a, long p) {
    if (a == 1) return 1;
    return (p - p/a) * inv(p % a, p) % p;
  }
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<25;i++){
		for(int j=0;j<14;j++){
			if(i*4+j*7==n){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 110
#define INFTY 1000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2


int N;
int G[MAX][MAX];

int prime()
{
    int i, j;
    int u, minv;
    int d[MAX]; // ?????????????°???????
    int p[MAX]; // ????°???¨?????¨????????????????????????
    int color[MAX]; // ?¨??????¶???
    
    for (i = 0; i < N; i++) {
        color[i] = WHITE;
        p[i] = -1;
        d[i] = INFTY;
    }
    d[0] = 0;
    p[0] = -1;
    
    while (1) {
        minv = INFTY;
        for (i = 0; i < N; i++) {
            if (color[i] != BLACK && d[i] < minv) {
                minv = d[i];
                u = i;
            }
        }
        
        if (minv == INFTY) {
            break;
        }
        
        color[u] = BLACK;
        
        for (i = 0; i < N; i++) {
            if (color[i] != BLACK && G[u][i] != INFTY) {
                if (G[u][i] < d[i]) {
                    d[i] = G[u][i];
                    p[i] = u;
                    color[i] = GRAY;
                }
            }
        }
    }
    
    int sum = 0;
    for (i = 0; i < N; i++) {
        if (p[i] != -1) {
            sum += G[i][p[i]];
        }
    }
    return sum;
}

int main()
{
    int i, j;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            int e;
            scanf("%d", &e);
            G[i][j] = e == -1 ? INFTY : e;
        }
    }
    
    printf("%d\n", prime());
    
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-6;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

double x[200000],y[200000];
double r;

bool Same(int a,int b){
	return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=r*r+EPS;
}

void Solve(){
	int n;
	scanf("%d%lf",&n,&r);

	vector<pair<double,int>> es;
	rep(i,0,n){
		scanf("%lf%lf",x+i,y+i);
		es.push_back(mp(x[i],i));
		es.push_back(mp(x[i]+r+EPS,i+n));
	}
	sort(es.begin(),es.end());

	set<pair<double,int>> s;
	vector<int> res;
	rep(i,0,es.size()){
		int id=es[i].second%n;
		if(es[i].second<n){
			auto it=s.lower_bound(mp(y[id],id));
			if(it!=s.end()&&Same(id,it->second)) continue;
			if(it!=s.begin()&&Same(id,(--it)->second)) continue;
			res.push_back(id);
			s.insert(mp(y[id],id));
		}else s.erase(mp(y[id],id));
	}

	printf("%d\n",res.size());
}

int main(){
	Solve();
	return 0;
}

Measured memory_bytes: 19736
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

W, A, B = ISI()
if abs(A-B) > W:
    print(abs(A-B)-W)
else:
    print(0)

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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
struct ST {
    int x, y, d;
    ST(int _x, int _y, int _d) : x(_x), y(_y), d(_d) {}
};
int main() {
    int H, W;
    string mp[1000];
    int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    cin >> H >> W;
    REP(y, H) { cin >> mp[y]; }
    queue<ST> q;
    REP(y, H) {
        REP(x, W) {
            if(mp[y][x] == '#') {
                q.push(ST(x, y, 0));
            }
        }
    }
    int ma = 0;
    while(!q.empty()) {
        ST f = q.front();
        q.pop();
        ma = f.d;
        REP(i, 4) {
            int nx = f.x + dir[i][0];
            int ny = f.y + dir[i][1];
            if(0 <= nx && nx < W && 0 <= ny && ny < H) {
                if(mp[ny][nx] == '.') {
                    mp[ny][nx] = '#';
                    q.push(ST(nx, ny, f.d + 1));
                }
            }
        }
    }
    cout << ma;
    return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Pll complex<int>
#define X real()
#define Y imag()
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f


int32_t main()
{
	int x;
	cin >> x;
	int q = (x / 500);
	int ans = 1000 * q; 
	x = x - 500 * q;
	q = x / 5;
	ans += q * 5;
	cout << ans << endl;	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int, int> P;
char G[1005][1005];
int vis[1005][1005];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int h, w, n;
int main()
{
    for(int i = 0; i < 1005; i++)
        for(int j = 0; j < 1005; j++)
            G[i][j] = 'X';
    int sx, sy;
    cin >> h >> w >> n;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
        {
            cin >> G[i][j];
            if(G[i][j] == 'S') {sx = i; sy = j;}
        }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= h; j++)
            for(int k = 1; k <= w; k++)
                vis[j][k] = 0;
        queue<pair<P, int> > que;
        que.push(pair<P, int>(P(sx, sy), 0));
        vis[sx][sy] = 1;
        while(!que.empty())
        {
            P node = que.front().first; int steps = que.front().second; que.pop();
            int x = node.first, y = node.second;
            if(G[x][y] == i + '0')
            {
                sx = x;
                sy = y;
                ans += steps;
                break;
            }
            for(int j = 0; j < 4; j++)
                if(!vis[x + dx[j]][y + dy[j]] && G[x + dx[j]][y + dy[j]] != 'X')
                {
                    que.push(pair<P, int>(P(x + dx[j], y + dy[j]), steps + 1));
                    vis[x + dx[j]][y + dy[j]] = 1;
                }
        }
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 8104
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    int h,w;
    string s;
    cin>>h>>w;
    
    if(w == 1) pr(0);
    else pr( h - w );
    return 0;
}


Measured memory_bytes: 888