akhauriyash/Code-Regression huggingface dataset:
import math
a, b, x = map(int, input().split())
if x <= a*a*b/2:
    k = ((x*2)/(a*b))
    ans = math.degrees(math.atan(b/k))
    print(ans)
else:
    k = ((a**2*b-x)*2)/(a*a)
    ans = math.degrees(math.atan(k/a))
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    if(a==1&&b==2 || b==1&&a==2) cout<<3<<endl;
    else if(a==1&&b==3||a==3&&b==1) cout<<2<<endl;
    else if(a==2&&b==3||a==3&&b==2) cout<<1<<endl;
    return 0;
}


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

int main(){
    int t, k;
    int check[4];
    for(int i = 0; i < 4; i++){
        check[i] = 0;
    }
    for(int i = 0; i < 3; i++){
        cin >> t >> k;
        check[t - 1]++;
        check[k - 1]++;
    }

    int flag_1 = 0;
    int flag_2 = 0;
    for(int i = 0; i < 4; i++){
        if(check[i] == 1){
            flag_1++;
        }else if(check[i] == 2){
            flag_2++;
        }else{
            break;
        }
    }

    if(flag_1 == 2 && flag_2 == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

int main() {
  int n,k,ans = 0;
  cin >> n >> k;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  for(int i = 0;i < k;i++){
    ans += data[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll a,b; cin>>a>>b;
    b=b*2+1;
    cout<<a/b+!!(a%b)<<endl;
}




Measured memory_bytes: 256
import sys
import math
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()

pct = 0
for i in range(1, N+1):
	if i>= K: pct+=1
	else:
		coin = math.ceil(math.log2(K/i))
		#print(coin)
		#i * 2**n >= K
		#2**n = K/i
		pct+=0.5**coin
print(pct/N)

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const ll mod=1000000007LL;
ll dp[310][310][310];

int main(void){
	int n,m;
	cin >> n >> m;
	
	dp[0][1][0]=1LL;

	rep(i,m){
		rep(j,n+1)rep(k,n+1){
			if(dp[i][j][k]==0) continue;
			dp[i+1][j+k][0]+=1LL*dp[i][j][k]*j%mod;
			dp[i+1][j+k][0]%=mod;

			dp[i+1][j][k]+=1LL*dp[i][j][k]*k%mod;
			dp[i+1][j][k]%=mod;

			int res=n-j-k;
			dp[i+1][j][k+1]+=1LL*dp[i][j][k]*res%mod;
			dp[i+1][j][k+1]%=mod;
		}
	}

	ll ans=dp[m][n][0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 110080
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 0
for keta in range(61):
    now = 0
    for x in a:
        if x & (1 << keta):
            now += 1
    ans += (now*(n-now))*2**keta
    ans %= mod

print(ans)


Measured memory_bytes: 122936
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    if(X >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
h, w = map(int, input().split())
G = [input() for _ in range(h)]
R = [["."]*w for _ in range(h)]
B = [["."]*w for _ in range(h)]
for i in range(1, h-1):
  if i%2:
    R[i] = list("." + "#"*(w-2) + ".")
    B[i] = list(G[i])
  else:
    B[i] = list("." + "#"*(w-2) + ".")
    R[i] = list(G[i])
    
for i in range(h):
  R[i][0] = "#"
  B[i][-1] = "#"
for r in R:
  print("".join(r))
print()
for b in B:
  print("".join(b))

Measured memory_bytes: 8308
#include <stdio.h>

int main(void)
{
	int n,k,i,j,temp,ans=0;
	int l[50];
	scanf("%d %d",&n,&k);
	
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	
	
	for (i = 0;i < n - 1;i++) {
		for (j = 0;j < n - 1;j++) {
			if (l[j + 1] < l[j]) {
				temp = l[j];l[j] = l[j + 1];l[j + 1] = temp;
			}
		}
	}
	
	for(i=n-1;i>=n-k;i--){
		ans+=l[i];
	}
	
	printf("%d\n",ans);
		
       return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<21)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll ar[M],mp[M],s[M];

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

	ll n,k,i,a,b=0,c;

	cin >> n >> k;
	for(i=1;i<=n;++i)
		cin >> ar[i];

	s[0] = 1;
	mp[1] = 1;
	for(i=1;i<=1e6;++i)
	{
		s[i] = ar[s[i-1]];
		if(mp[s[i]] && b == 0)
		{
			a = mp[s[i]]-1;
			b = i;
		}
		mp[s[i]] = i+1;
	}
	
	ll m = 1e6;
	if(k<=m)
		cout << s[k] << endl;
	else
	{
		if(a == b)
			cout << s[a] << endl;
		else
		{
			c = (k-a)%(b-a);
			cout << s[a+c] << endl;
		}
	}
}



	

Measured memory_bytes: 14556
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e18)
#define int long long
#define double long double

signed main(){
	int H, W, i, j, v;
	scanf("%lld%lld", &W, &H);
	vector<string> c(H);
	int sx, sy, floor = 0;
	queue<pair<pair<int, int>, int>> q1, q2;
	for(i = 0; i < H; i++){
		cin >> c[i];
		for(j = 0; j < W; j++){
			if(c[i][j] == 's'){
				sx = i;
				sy = j;
				c[i][j] = '.';
			}
			if(c[i][j] == 'g'){
				q1.push(pair<pair<int, int>, int>(pair<int, int>(i, j), 0));
			}
			if(c[i][j] == '*'){
				q2.push(pair<pair<int, int>, int>(pair<int, int>(i, j), 0));
			}
			if(c[i][j] == '.'){
				floor++;
			}
		}
	}
	int dx[4] = {0, 1, 0, -1};
	int dy[4] = {1, 0, -1, 0};
	int d;
	vector<vector<int>> A1(H, vector<int>(W, inf));
	while(q1.size() > 0){
		i = q1.front().first.first;
		j = q1.front().first.second;
		v = q1.front().second;
		q1.pop();
		if(c[i][j] == '#' || c[i][j] == '*' || A1[i][j] <= v){
			continue;
		}
		A1[i][j] = v;
		for(d = 0; d < 4; d++){
			q1.push(pair<pair<int, int>, int>(pair<int, int>(i + dx[d], j + dy[d]), v + 1));
		}
	}
	vector<vector<int>> A2(H, vector<int>(W, inf));
	while(q2.size() > 0){
		i = q2.front().first.first;
		j = q2.front().first.second;
		v = q2.front().second;
		q2.pop();
		if(c[i][j] == '#' || c[i][j] == 'g' || A2[i][j] <= v){
			continue;
		}
		A2[i][j] = v;
		for(d = 0; d < 4; d++){
			q2.push(pair<pair<int, int>, int>(pair<int, int>(i + dx[d], j + dy[d]), v + 1));
		}
	}
/*	printf("floor = %d\n", floor);
	printf("A1\n");
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			printf("%2d ", A1[i][j]);
		}
		printf("\n");
	}
	printf("A2\n");
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			printf("%2d ", A2[i][j]);
		}
		printf("\n");
	}
*/	double l = 0, h, r = 1e12;
	for(int k = 0; k < 200; k++){
//		printf("(l, r) = (%lf, %lf)\n", l, r);
		h = (l + r) / 2;
		double hf = 0;
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(c[i][j] == '.'){
					hf += min((double)A1[i][j], A2[i][j] + h);
				}
			}
		}
//		printf("(h, hf) = (%lf, %lf)\n", h, hf);
		if(h * floor < hf){
			l = h;
		}
		else{
			r = h;
		}
	}
	printf("%.20Lf\n", min((double)A1[sx][sy], A2[sx][sy] + r));
	return 0;
}


Measured memory_bytes: 9312
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()

for a in range(1, 10):
    for b in range(1, 10):
        if a * b == N:
            print('Yes')
            exit()
print('No')


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

int main()
{
    char field[11][11];
    string r;
    int i,j;
    do {
	for (i=0; i<8; i++)
	{
	    scanf("%s",field[i]);
	}
	for (i=0; i<8; i++)
	{
	    for (j=0; j<8; j++)
	    {
		if (field[i][j] == '1')goto b;
	    }
	}
    b:
	if (field[i][j+1] == '1')
	{
	    if (field[i][j+2] == '1')
		r="C";
	    else if (field[i+1][j] == '1') {
		if (field[i+1][j+1] == '1')
		    r="A";
		else
		    r="G";
	    }
	    else
		r="E";
	} else {
	    if (field[i+2][j] == '1')
		r="B";
	    else if (field[i+1][j+1] == '1')
		r="F";
	    else
		r="D";
	}
	cout << r << endl;
	getchar();
    } while (getchar() != EOF);
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		System.out.println(s.equals("Sunny") ? "Cloudy" : s.equals("Cloudy") ? "Rainy" : "Sunny");
	}
}

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




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

    
    ll m,d;
    cin>>m>>d;
    ll ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=22;j<=d;j++){
            if((j%10)<2) continue;
            ll t = (j%10);
            ll s = j/10;
            t *= s;

            if(t==i){
                ans++;
            }
        }
    }

    cout<<ans<<endl;
    
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map> 
#include<set>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    int ans = a - b -b;
    ans = max(0,ans);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>g[59];
int n,logn,depth[59],parent[9][59],m;
long long state[29],ans;
void dfs(int u,int p,int d) {
	parent[0][u]=p;
	depth[u]=d;
	for(int i=0;i<g[u].size();i++)
		if(g[u][i]!=p)
			dfs(g[u][i],u,d+1);
}
int lca(int u,int v) {
	if(depth[u]>depth[v]) swap(u,v);
	for(int i=0;i<=logn;i++)
		if((depth[v]-depth[u])>>i&1)
			v=parent[i][v];
	if(u==v) return u;
	for(int i=logn;i>=0;i--)
		if(parent[i][u]!=parent[i][v]) {
			u=parent[i][u];
			v=parent[i][v];
		}
	return parent[0][u];
}
int main() {
	scanf("%d",&n);
	logn=log2(n);
	ans=1ll<<(n-1);
	for(int i=0;i<n-1;i++) {
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,0,0);
	for(int i=1;i<=logn;i++)
		for(int j=1;j<=n;j++)
			parent[i][j]=parent[i-1][parent[i-1][j]];
	scanf("%d",&m);
	for(int i=0;i<m;i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		int p=lca(u,v);
		for(;u!=p;u=parent[0][u]) state[i]|=1ll<<u;
		for(;v!=p;v=parent[0][v]) state[i]|=1ll<<v;
	}
	for(int mask=1;mask<(1<<m);mask++) {
		long long path=0;
		for(int i=0;i<m;i++)
			if((1<<i)&mask)
				path|=state[i];
		ans+=(1ll<<(n-1-__builtin_popcountll(path)))*(__builtin_popcount(mask)%2?-1ll:1ll);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var sb=new StringBuilder();
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				sb.AppendLine(String.Format("{0}x{1}={2}",i,j,i*j));
			}
		}
		Console.Write(sb.ToString());
	}

	public Sol(){
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define d2r(deg) deg*(M_PI/180.0)

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll a, b, h, m; cin >> a >> b >> h >> m;

    long double th = abs((m*6)-((60*h + m)/2.0));
    if(th>180) th = 360-th;

    cout << fixed << setprecision(15) << sqrt(pow(a, 2)+pow(b, 2)-2*a*b*cos(d2r(th))) << endl;

    return 0;
}

Measured memory_bytes: 4160
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a,b,c,d,area1,area2;
	cin>>a>>b>>c>>d;
	area1=a*b;
	area2=c*d;
	
	if(area1>area2)
	{
		cout<<area1;
	}
	else if(area1<area2)
	{
		cout<<area2;
	}
	else if(area1==area2)
	{
		cout<<area1;
	}
}

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

using namespace std;

int main()
{
    int n,arr[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>n;
    cout<<arr[n]<<endl;
}

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

int main() {
  int N,num,ans;
  cin >> N ;
  if(N%1000 == 0){
  	cout << "0" << endl;
  }else{
  	num = N/1000 + 1;
  	ans = 1000*num -N;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    int n; cin >> n;
    n -= 400;
    cout << 8 - n / 200;
    return 0;
}

Measured memory_bytes: 3632
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
are(a::Array{Int,1},x::Int)=Int[i%x for i in a]

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	r = 29
	ans = 0
	for i in 1:r
		t = 2^(i-1)
		c = are(a,2t)
		c = sort(c,rev=true)
		d = are(b,2t)
		d = sort(d)
		s = 0
		p,q,u,v=1,1,1,1
		for j in 1:n
			while p<=n && d[p]<t-c[j]
				p+=1
			end
			while q<=n && d[q]<2t-c[j]
				q+=1
			end
			while u<=n && d[u]<3t-c[j]
				u+=1
			end
			while v<=n && d[v]<4t-c[j]
				v+=1
			end
			s+=v-u+q-p
		end
		ans += (s%2)*t
	end
	println(ans)
end

main()

Measured memory_bytes: 178560
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 30*30;
using BS = bitset<MAX*2>;
void det(vector<BS> &v){
  int n=v.size();
  for(Int i=0;i<n;i++){
    for(Int k=i;k<n;k++){
      if(v[k][i]){
	swap(v[i],v[k]);
	break;
      }
    }
    for(Int k=0;k<n;k++)
      if(i!=k&&v[k][i]) v[k]^=v[i];
  }
}

signed main(){
  int m,n,d;
  while(cin>>m>>n>>d,m){
    vector<vector<int> > s(n,vector<int>(m));
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
	cin>>s[i][j];

    vector<BS> v(n*m,BS(0));
    auto idx=[&](int y,int x){return y*m+x;};
    auto in=[&](int y,int x){return 0<=y&&y<n&&0<=x&&x<m;};
    auto bfs=[&](int y,int x){
      int z=idx(y,x);
      v[z][z]=1;
      v[z][n*m]=s[y][x];
      
      vector<vector<int> > dp(n,vector<int>(m,-1));
      using P = pair<int, int>;
      queue<P> q;
      dp[y][x]=0;
      q.emplace(y,x);
      int dy[]={0,0,1,-1};
      int dx[]={1,-1,0,0};
      while(!q.empty()){
	tie(y,x)=q.front();q.pop();
	if(dp[y][x]==d) v[z][idx(y,x)]=1;
	for(int k=0;k<4;k++){
	  int ny=y+dy[k],nx=x+dx[k];
	  if(!in(ny,nx)||~dp[ny][nx]) continue;
	  dp[ny][nx]=dp[y][x]+1;
	  q.emplace(ny,nx);
	}
      }
    };
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
	bfs(i,j);
    
    auto u=v;
    det(v);
    int ans=1;
    for(int i=0;i<n*m;i++){
      int tmp=s[i/m][i%m];
      for(int j=0;j<n*m;j++) tmp+=u[i][j]&v[j][n*m];
      ans&=!(tmp&1);
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    sort(ar.rbegin(),ar.rend());
    //printvec(ar);
    priority_queue<ll> pq;
    pq.push(ar[0]);
    ll ans = 0;
    rep(i,n-1){
        ans += pq.top(); pq.pop();
        pq.push(ar[1+i]);
        pq.push(ar[1+i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
vector<int> fr[100000], bl[100000];

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unionSet(a, b);
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    for(int i = 0; i < K; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        bl[a].push_back(b);
        bl[b].push_back(a);
    }
    for(int i = 0; i < N; i++){
        int s = uf.size(i)-1;
        for(int j = 0; j < fr[i].size(); j++){
            s--;
        }
        for(int j = 0; j < bl[i].size(); j++){
            int c = bl[i][j];
            if(uf.findSet(i, c)) s--;
        }
        cout << s;
        if(i == N-1) cout << endl;
        else cout << ' ';
    }
}

Measured memory_bytes: 12280
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll kai(ll x){
  if(x == 1) return 1;
  return x * kai(x-1) % MOD;
}

int main(){
  ll N, M; cin >> N >> M;
  if(abs(N-M) >= 2){
    cout << 0 << endl;
    return 0;
  }

  if(N == M){
    cout << kai(N) * kai(M) * 2 % MOD << endl;
  }else{
    cout << kai(M) * kai(N) % MOD << endl;
  }

}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
string s;
/******* define variable end *******/
ll solve()
{
    cin >> s;
    REP(i, s.size())
    {
        if (i % 2 == 0)
        {
            if (s.substr(i, 2) != "hi")
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  P m[10];
  m[0] = P(1, 2);
  m[1] = P(-1, 3);
  m[2] = P(1, -1);
  m[3] = P(4, 5);
  m[4] = P(5, 2);
  m[5] = P(2, 1);

  string s;

  while(cin >> s && s != "#") {
    int idx = 0;
    rep(i, 0, s.size()) {
      if(s[i] == '0') {
        idx = m[idx].first;
      }else {
        idx = m[idx].second;
      }
      if(idx == -1) break;
    }
    if(idx == 5) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
  }
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	cin>>n;
    vector<int> data(n);
	for(int i=0;i<n;i++){
		cin>>data[i];
    }
	sort(data.begin(), data.end());
	cout<<(data[n/2]-data[n/2-1]);
}


Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <cassert>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int ans;
int k,t,a[100],m;
int main() {
  cin >> k >> t;
  m = 0;
  rep(i,t){
    cin >> a[i];
    if(m < a[i]) m = a[i];
  }
  if(m>(k-m)+1){
    ans = m-(k-m)-1;
    cout << ans << endl;
  }else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1,N):
    dp[i][0] = max(dp[i - 1][1],dp[i-1][2]) + abc[i][0]
    dp[i][1] = max(dp[i - 1][0],dp[i-1][2]) + abc[i][1]
    dp[i][2] = max(dp[i - 1][0],dp[i-1][1]) + abc[i][2]
print(max(dp[-1]))

Measured memory_bytes: 47384
import datetime
S = str(input())
S_formatted = datetime.datetime.strptime(S, "%Y/%m/%d")
start_of_tbd = datetime.datetime(2019,5,1,0,0,0)
if S_formatted.date() < start_of_tbd.date():
    print("Heisei")
else:
    print("TBD")


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << ((s == "AAA" || s == "BBB") ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1)
				break;
			if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65) {
				System.out.println("B");
			} else if (m + f >= 50) {
				System.out.println("C");
			} else if (m + f >= 30) {
				if (r >= 50)
					System.out.println("C");
				else
					System.out.println("D");
			} else {
				System.out.println("F");
			}
		}
	}

}



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

int main(){
    int x;
    cin >> x;
    if(x==3 || x==5 || x==7){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define MAX 100010
using namespace std;

int arr[MAX];

int main(void)
{
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int t;
		cin >> t;
		arr[t] = i;
	}
	for (int i = 1; i <= N; i++) cout << arr[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 1152
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
#import numpy as np
n = int(input())
#n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(1, n):
    a = (n-1) // i
    #print(i, a)
    ans += a

print(ans)
        
    



        


Measured memory_bytes: 10144
def input_from_console():
    a, b = map(int, input().split())
    return a, b


def solve(a, b):
    if a >= 13:
        return b
    elif a >= 6:
        return int(b / 2)
    return 0


def main():
    a, b = input_from_console()
    print(solve(a, b))


if __name__ == "__main__":
    DEBUG = False
    if not DEBUG:
        main()

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

const int INF = 1e9;
const ll LINF = 1e18;


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

    if (n == 1 && m == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> s(m);
    vector<int> c(m);

    rep(i, m) cin >> s[i] >> c[i];

    vector<int> r(n, -1);

    rep(i, m) {
        if (r[s[i] - 1] == c[i]) {
            ;
        } else if (r[s[i] - 1] != -1) {
            cout << -1 << endl;
            return 0;
        } else {
            r[s[i] - 1] = c[i];
        }
    }

    if (n == 1 && r[0] == 0) {
        cout << 0 << endl;
        return 0;
    }

    if (r[0] == 0) {
        cout << -1 << endl;
        return 0;
    }

    if (r[0] == -1) {
        r[0] = 1;
    }

    rep(i, 1, n) {
        if (r[i] == -1) {
            r[i] = 0;
        }
    }

    rep(i, n) {
        cout << r[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Blackjack
public class Main{

	char[] s;
	int res;
	boolean bj;
	
	int f(char c){
		if(Character.isDigit(c))return c-'0';
		return c=='A'?1:10;
	}
	
	boolean dfs(int k, int sum, boolean ace){
		if(21<sum)return false;
		if(sum<=16||sum==17&&ace){
			int x = f(s[k]);
			if(x==1){
				if(sum+11<=21)
					if(dfs(k+1, sum+11, true))return true;
				return dfs(k+1, sum+1, ace); 
			}
			else return dfs(k+1, sum+x, ace);
		}
		else{
			if(k==2&&sum==21)bj = true;
			if(sum<=21){
				res = Math.max(res, sum);
				return true;
			}
			return false;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			res = 0;
			bj = false;
			s = new char[10];
			for(int i=0;i<10;i++)s[i]=sc.next().charAt(0);
			boolean f = dfs(0, 0, false);
			System.out.println(bj?"blackjack":!f?"bust":res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split();
            int x = int.Parse(line[0]), y = int.Parse(line[1]);

            Console.WriteLine(x + (y / 2));
        }
    }
}

Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
public class Main {
    public static void main (String [] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        long number = Long.parseLong(in.readLine());
        ArrayList<Long> factors = new ArrayList<Long>();

        for(long i = 1; i <= Math.sqrt(number); i++)
        {
            if(number % i == 0)
            {
                factors.add(i);
                if(i != number/i)
                    factors.add(number/i);
            }
        }

        int times = 0;
        Collections.sort(factors);
        if(factors.size() > 0)
        {
            factors.remove(0);
        }
        for(long i : factors)
        {

            if(i > number)
                break;
            boolean isPrime = true;
            for(long j = 2; j <= Math.sqrt(i); j++)
            {
                if(i % j == 0)
                    isPrime = false;
            }
            if(isPrime)
            {
                boolean primeLoop = true;
                long primeExp = i;
                while(primeLoop)
                {
                    if(number % primeExp == 0)
                    {
                        times++;
                        
                        number /= primeExp;
                        primeExp *= i;
                    }
                    else
                    {
                        primeLoop = false;
                    }
                }
            }
        }
        
        
        
        /*
        int times = 0;
        for(long i = 2; i <= number; i++)
        {
            boolean runLoop = number % i == 0;
            boolean isPrime = runLoop;
            for(long j = 2; j < Math.sqrt(i) && runLoop; j++)
            {
                if(i % j == 0)
                    isPrime = false;
            }
            if(isPrime)
            {
                boolean primeLoop = true;
                long primeExp = i;
                while(primeLoop)
                {
                    if(number % primeExp == 0)
                    {
                        times++;
                        
                        number /= primeExp;
                        primeExp *= i;
                    }
                    else
                    {
                        primeLoop = false;
                    }
                }
            }
        }
        */
        System.out.println(times);
        


    }
}

Measured memory_bytes: 26660
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>

using namespace std;

int main() {
	long long N, M;
	cin >> N >> M;
	if (N == 1 && M == 1) cout << 1 << endl;
	else if (N == 1) {
		cout << M - 2 << endl;
	}
	else if (M == 1) {
		cout << N - 2 << endl;
	}
	else {
		cout << (M - 2) * (N - 2) << endl;
	}
	system("pause");
	return 0;
}

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

using namespace std;

template<class INT>
std::vector<INT> get_min_prime_fact_table(INT n){
    std::vector<INT> lp(n + 1), P;
    for (INT i = 2; i <= n; i++){
        if (lp[i] == 0){
            lp[i] = i;
            P.push_back(i);
        }
        for (INT j = 0; j <= P.size() and P[j] <= lp[i] and i * P[j] <= n; j++)
            lp[i * P[j]] = P[j];
    }

    return lp;
}

template<class INT>
std::map<INT, int> prime_factorize(INT n, std::vector<INT>& lp){
    std::map<INT, int> res;
    while (n != 1){
        res[lp[n]]++;
        n /= lp[n];
    }

    return res;
}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    int g = 0;
    for (const auto &a: A)
        g = gcd(g, a);
    
    if (g != 1){
        puts("not coprime");
        return 0;
    }

    auto lp = get_min_prime_fact_table(int(1e6));
    map<int, int> P;
    for (const auto &a: A){
        auto pf = prime_factorize(a, lp);
        for (const auto &[p, f]: pf)
            P[p]++;
    }

    for (const auto &[p, c]: P){
        if (c > 1){
            puts("setwise coprime");
            return 0;
        }
    }

    puts("pairwise coprime");
}

Measured memory_bytes: 14520
#include <bits/stdc++.h>
using namespace std;
int a[100500];
int N;
long long int ans;
int main()
{
        scanf("%d",&N);
        int n;
        ans=1;
        memset(a,0,sizeof(a));
        for(int i=1;i<=N;i++)
        {
            scanf("%d",&n);
            a[n]++;
            if(n==0&&a[n]==1)
            {
                ans*=1;
            }
            else if(n==0&&a[n]>1)
            {
                ans=0;
                break;
            }
            else if(a[n]==1)
            {
                ans*=2;
            }
            else if(a[n]>2)
            {
                ans=0;
                break;
            }
            ans%=1000000007;
        }
        printf("%lld\n",ans);
        return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>


//페르마의 소정리.

using namespace std;

long long int MOD = 1000000007;
long long int f[200005];
long long int invf[200005];	
void proc(void)
{
	f[0]=1,f[1] = 1;
	invf[0] = 1,invf[1] = 1;

	//어떤 수에 대한 역원 구하기.
	for (int i = 2; i <= 200004; i++)
	{
		invf[i] = (invf[MOD%i] * (-MOD / i)) % MOD;
		if (invf[i] < 0)
		{
			invf[i] += MOD;
		}
	}


	//팩토리얼과 팩토리얼의 역 구하기
	for (int i = 2; i <= 200004; i++)
	{
		f[i] = (i*f[i - 1]) % MOD;
		invf[i] = (invf[i] * invf[i - 1]) % MOD;
	}
}

long long int combination(long long int a, long long int b)
{
	//nCr=(n+r)!/(n!r!)
	long long int res;
	res = f[a] % MOD;
	res = (res*invf[b]) % MOD;
	res = (res*invf[a - b]) % MOD;

	return res;
}
int main(void)
{
	long long int res=0;
	int H, W, a, b;

	proc();
	cin >> H >> W >> a >> b;

	for (int i = b + 1; i <= W; i++)
	{
		res = (res + (combination((H - a -1) + (i-1), i - 1)*combination((a - 1) + (W-i), W - i))) % MOD;
		res %= MOD;
	}

	cout << res << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back


void modcomb(vec &c, ll n, ll k, ll m)
{
    vec inv(k+1, 0);
    inv[1] = 1;
    c[0] = 1; c[1] = n;
    REP(i,2,k+1) {
        inv[i] = m - inv[m%i] * (m / i) % m;
        c[i] = (((c[i-1] * (n - i + 1)) % m) * inv[i]) % m;
    }
}


int main()
{
    ll X, Y;
    cin >> X >> Y;

    ll k = 2 * Y - X;
    ll l = 2 * X - Y;
    ll cnt = 0;
    if(k >= 0 && k % 3 == 0 && l >= 0 && l % 3 == 0) {
        k /= 3; l /= 3;
        ll n = k + l;
        k = MIN(k,l);
        vec C(k+1);
        modcomb(C, n, k, MOD);
        cnt = C[k];
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 5504
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;

ll a[MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%lld",&a[i]);
	
	for(int i=1; i<=n; ++i)
		if(!a[i])
		{
			printf("0");
			return 0;
		}
	
	ll ans = 1;
	ll mx = 1e18;
	for(int i=1; i<=n; ++i)
	{
		if(mx/ans < a[i])
		{
			printf("-1");
			return 0;
		}
		ans *= a[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4540
def d_friends():
    class UnionFind(object):
        def __init__(self, n):
            """要素番号は 0 スタートを前提とする"""
            self.num_element = n
            self.parents = [-1] * n  # 要素が根の場合は、-(グループの要素数) を格納

        def find(self, x):
            """要素 x が属するグループの根を返す"""
            if self.parents[x] < 0:
                return x
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

        def union(self, x, y):
            """要素 x が属するグループと要素 y が属するグループとを併合する"""
            u, v = self.find(x), self.find(y)

            if u == v:
                return

            # u のグループの方が要素数が少なかった (parents の 定義より)
            if self.parents[u] > self.parents[v]:
                u, v = v, u

            self.parents[u] += self.parents[v]  # u と同グループの要素数を増やす
            self.parents[v] = u  # v は u に繋げる

        def get_size(self, x):
            """要素 x が属するグループの要素数を返す"""
            return -self.parents[self.find(x)]

    N, M = [int(i) for i in input().split()]
    uf = UnionFind(N)
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        uf.union(a, b)
    return max([uf.get_size(r) for r in range(N)])

print(d_friends())

Measured memory_bytes: 22472
import java.math.BigInteger

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toLong() }.sorted()

    var ans = BigInteger.valueOf(1L)
    for (i in 0 until n) {
        ans *= BigInteger.valueOf(a[i])
        if (ans > BigInteger.valueOf(1e18.toLong())) {
            ans = BigInteger.valueOf(-1)
            break
        }
    }
    println(ans)
}


Measured memory_bytes: 66168
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
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))

s = input()
n = len(s)
res = 0
bc = 0
i = n-1
while i >= 0:
    if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1
print(res)

Measured memory_bytes: 5592
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():
    n,m = LI()
    f = [1]*n
    l = [0]*n
    l[0] = 1
    for i in range(m):
        x,y = LI()
        x -= 1
        y -= 1
        if l[x]:
            l[y] = 1
        f[x] -= 1
        f[y] += 1
        if f[x] == 0:
            l[x] = 0
    ans = 0
    for i in range(n):
        if l[i]:
            ans += 1
    print(ans)
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()


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

int main() {
    int n; cin >> n;
    string c; cin >> c;
    int l,r;
    l = 0;
    r = n-1;
    int ans = 0;
    while (l < r) {
        while (l < n && c[l] != 'W') l++;
        while (r >= 0 && c[r] != 'R') r--;
        //cout << l << ' ' << r << endl;
        if (l < n && r >= 0 && l < r) ans ++;
        l ++;
        r --;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
////#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//
//long long n,ans;
//int main() {
//    while(cin >> n) {
////          cout << __gcd(n,(long long)2) << endl;
//        if(__gcd((long long)2,n) == 1)
//            cout << (long long)2 * n << endl;
//        else {
//            cout << n << endl;
//
//        }
//    }
//    return 0;
//}
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;

//long long n,ans;
int n,x;
int main() {
    while(cin >> n) {
            int Max = -99;
            int Min = 2e9;
            for(int i = 0;i < n;i++){
                    cin >> x;
                 Max = max(x,Max);
                 Min = min(x,Min);
            }
            cout << Max - Min << endl;
    }
    return 0;
}


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

int n;
char c[10010];
int nextNum;

int check(int f) {
  if (c[f + 1] >= '0' && c[f + 1] <= '9') {
    int i = f + 1, counter = 0;
    while (c[i] != ']') counter *= 10, counter += (int)c[i++] - '0';
    nextNum = i + 1;
    return counter;
  }
  vector<int> vec;
  int i = f + 1;
  bool flag = c[f + 2] >= '0' && c[f + 2] <= '9';
  while (1) {
    if (c[i] == '[') {
      vec.push_back(check(i));
      if (c[i + 1] >= '0' && c[i + 1] <= '9') flag = true;
      i = nextNum;
      if(c[i] == ']') {
        break;
      }
    }
  }
  sort(vec.begin(), vec.end());
  int sum = 0, size = (vec.size() + 1) / 2;
  for (int i = 0; i < size; i++) {
    if (flag) sum += (vec[i] + 1) / 2;
    else sum += vec[i];
  }
  nextNum = i + 1;
  return sum;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", c);
    printf("%d\n", check(0));
  }
}



Measured memory_bytes: 2788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;

int main(int argc, char **argv) {
    int x;
    cin >> x;

    int t = x / 500;
    int x2 = x % 500;
    int t2 = x2 / 5;

    cout << (t*1000 + t2*5) << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N,K;
    cin >>N>>K;
    vector<ll> H(N);

    rep(i,N){
        cin>>H[i];
    }
    sort(all(H));
    reverse(all(H));
    ll ans = 0;
    rep3(i,K,N){
        ans += H[i];
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4832