akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>

using namespace std;

int h, w;

char s[110], a[110][110];

int Sum(int x, int y) {
	int res = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (a[x + i][y + j] == '#') {
				res++;
			}
		}
	}
	return res;
}

int main() {
	scanf("%d %d", &h, &w);
	for (int i = 1; i <= h; i++) {
		scanf("%s", s);
		for (int j = 0; s[j]; j++) {
			a[i][j + 1] = s[j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (a[i][j] == '#') {
				printf("#");
			}
			else {
				printf("%d", Sum(i, j));
			}
		}
		printf("\n");
	}
	return 0;
} 

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

int main()
{
	int d, k, ans;
	while( cin >> d )
	{
		k = 0;
		ans = 0;
		while(k < 600) 
		{
			ans += d * k * k;
			k += d;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long r1, c1, r2, c2, fac[2000009], inv[1000009];

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

long long gun(int r, int c)
{
	long long ret;
	ret = fac[r + c];
	ret *= quickpow((fac[r] * fac[c]) % MOD, MOD - 2);
	ret %= MOD;
	return ret;
}

long long fun(int r, int c)
{
	long long ret = 0;
	for (int i = 0; i <= r; i++) {
		ret += gun(i + 1, c);
		ret %= MOD;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> r1 >> c1 >> r2 >> c2;
	fac[0] = 1;
	for (int i = 1; i <= 2000002; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= MOD;
	}
	for (int i = 0; i <= 1000000; i++) {
		inv[i] = quickpow(fac[i], MOD - 2);
	}
	long long ans = fun(r2, c2);
	ans += fun(r1 - 1, c1 - 1);
	ans %= MOD;
	ans -= fun(r2, c1 - 1);
	ans += MOD;
	ans -= fun(r1 - 1, c2);
	ans += MOD;
	ans %= MOD;
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    //dp[i] denotes the minimum cost to reach ith stone
    // 0 < i < n - 1 are the stones
    //We are asked to dind the cost to reach last stone i.e dp[n - 1]
    //Initially there is infinite cost to reach ith stones
    vector<int> dp(n, INT_MAX);
  
    //To reach first stone there is no cost. SO dp[0] = 0
    dp[0] = 0;
   //To reach second stone the frog can jump from 0th stone costing dp[1] = abs(h[1] - h[0])
    dp[1] = abs(h[1] - h[0]);
    
    //For every other stones 2 <= i < n, the frog can jump from the (i - 1), (i - 2)...(i - k)th stones 
    for(int i = 2; i < n; i++){
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
    //Print minm cost to reach (n - 1)th stone
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 3976
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
int f[1<<21][22];
char X[1<<20];
int n,K;
int main() {
	rd(n),rd(K);
	for(int i=0;i<=n;++i) {
		scanf("%s",X);
		for(int j=0;j<(1<<i);++j)
			f[(1<<i)|j][i]=X[j]=='1';
	}
	for(int i=n;i>=0;--i)
		for(int s=0;s<(1<<i);++s)
			for(int j=i;j>=0;--j)
			 if(f[(1<<i)|s][j]) 
			 {
				int cur=f[(1<<i)|s][j];
				int s1=s>>j;
				int s2=s&((1<<j)-1);
				if(j) f[(1<<i-j)|s1][0]+=cur;
				if(s2) {
					int p=j-1; while(!((s2>>p)&1)) p--;
					f[(1<<(i-(j-1-p)))|(s1<<p+1)|(1<<p)|(s2&((1<<p)-1))][p]+=cur;
				}
				if(((1<<j)-1)&(~s2)) {
					int p=j-1; while((s2>>p)&1) p--;
					f[(1<<(i-(j-1-p)))|(s1<<p+1)|(s2&((1<<p)-1))][p]+=cur;
				}
			}
	for(int i=n;i>=0;--i)
		for(int j=0;j<(1<<i);++j)
			if(f[(1<<i)|j][0]>=K) {
				for(int k=i-1;k>=0;--k) printf("%d",(j>>k)&1);
				return 0;
			}
	return 0;
}


Measured memory_bytes: 181632
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int a[5];
  while(cin >> a[0], a[0]) {
    REP(i,4)
      cin >> a[i+1];
    int te[3] = {};
    REP(i,5)
      te[a[i]-1]++;
    int hoge=0;
    REP(i,3)
      if (te[i])
        hoge++;
    if (hoge != 2) {
      REP(i,5)
        cout << 3 << endl;
      continue;
    }
    int win = 0;
    if (!te[0])
      win = 1;
    else if (!te[1])
      win = 2;
    REP(i,5) {
      if (a[i]-1 == win)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    }
  }
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

char S[202020], T[202020];
ll i, j, k;

int main(){
    scanf("%s%s", S, T);
    ll N = strlen(S);
    rep(i,0,N){
        if(S[i]!=T[i])
            ++j;
    }
    printf("%lld\n", j);
    return 0;
}

Measured memory_bytes: 4204
def main():
    a, b, c, d, e, f = map(int, input().split())
    sugar = 0
    water = 0
    con = 0
    for i in range(f//100+1):
        if i%b == 0 or i%a == 0:
            w = i*100
            x = min(f-w, i*e)
            s = 0
        for j in range(x//c+1):
            ss = j*c
            s = max(s,ss+((x-ss)//d)*d)
        if w != 0:
            if con <= (100*s)/(w+s):
                water = w
                sugar = s
                con = (100*s)/(w+s)
    print(sugar+water, sugar)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
 
}

const int MAXN = 2e5 + 100;
ll fat[MAXN],inv[MAXN];
const int M = 1e9 + 7;
int32_t main(){
  fastio;
  ll n,a,b;
  cin>>n>>a>>b;
  ll Lol = exp(2LL,n,M);
  fat[0] = inv[0] = 1;
  for(int i=1;i<MAXN;i++){
    fat[i] = (fat[i-1]*i)%M;
    inv[i] = exp(fat[i],M-2,M);
  }
  auto C = [&](ll nn,ll k){
    ll res = 1;
    for(ll i=nn;i>=nn-k+1;i--){
      res = mod(res*i,M);
    }
    return mod(res*inv[k],M);
  };
  Lol = (Lol - 1 - C(n,a) - C(n,b))%M;
  if(Lol<0)Lol+=M;
  cout<<Lol<<endl;

  
  // Math -> gcd it all // check MAXN // check ll
  //did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(void){
   int a,b,c,d,e,f;
   cin >> a >> b >> c >> d >> e >> f;
   if(a*1+b*5+c*10+d*50+e*100+f*500>=1000){
       cout<<"1"<<endl;
   }
   else cout << "0" << endl;
    
}



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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

template<typename T> using V = vector<T>;

// borrowed from neal's code
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const double PI = acos(-1);

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n - 1), cnt(n + 2);

    for (int &i : a) {
        cin >> i;
        ++cnt[i];
    }

    for (int i = 1; i <= n; ++i) cout << cnt[i] << "\n";

}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
#define int long long
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;


ll mod_pow(ll a, ll b, ll r) {
  return b <= 0? 1: (b % 2? a: 1) * mod_pow(a * a % r, b / 2, r) % r;
}

int a[51];
int cntG;
signed main(){
  int n,p;
  cin>>n>>p;
  rep(i,n){
    cin>>a[i];
    if(a[i]%2==0)cntG++;
  }
  int cntK=n-cntG;
  if(cntK==0){
    if(p==0){
      cout<<mod_pow(2,n,INF)<<endl;
    }else{
      cout<<'0'<<endl;
    }
  }else{
    cout<<mod_pow(2,n-1,INF)<<endl;
  }
}


Measured memory_bytes: 256
h,w=map(int,input().split())
g=[input() for _ in range(h)]
d=[[-1]*w for _ in range(h)]
d[0][0]=0
q=[(0,0)]
while q:
  tx,ty=q.pop(0)
  for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
    nx,ny=tx+dx,ty+dy
    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
      d[nx][ny]=d[tx][ty]+1
      q+=[(nx,ny)]
print((sum(s.count('.') for s in g)-d[-1][-1])*(d[-1][-1]>0)-1)

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

using namespace std;

const int N = 100000 + 10;
const int MOD = 1000000007;

int F[N];
vector<int> V[N];
int res, n, k;

int exp(int x, int n)
{
	int tmp;
	if (n == 0) return 1;
	tmp = exp(x, n / 2);
	tmp = 1LL * tmp * tmp % MOD;
	if (n % 2) tmp = 1LL * tmp * x % MOD;
	return tmp; 
}

int P(int m, int n)
{
	if (m < n) return 0; else return 1LL * F[m] * exp(F[m-n], MOD - 2) % MOD;
}

void dfs(int u, int p)
{
	int v, i;
	if (res == 0) return;
	res = 1LL * res * P(k - 2, V[u].size() - 1) % MOD;
	for (i=0; i<V[u].size(); i++)
	{
		v = V[u][i];
		if (v != p) dfs(v, u);
		if (!res) break;
	}
}

int main()
{
	int a, b, i;
	cin>>n>>k;
	F[0] = 1;
	for (i=1; i<=k; i++) F[i] = 1LL * F[i-1] * i % MOD;
	for (i=0; i<n-1; i++)
	{
		cin>>a>>b;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	res = P(k, V[1].size() + 1);
	if (res)
	{
		for (i=0; i<V[1].size(); i++) 
		{
			dfs(V[1][i], 1);
			if (!res) break;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
main() {
	map<string,int> mp;
	int n; cin >> n;
	for (int i = 0;i < n; i++) {
		string s; cin >> s;mp[s]++;
	}
	cout << "AC x " << mp["AC"] <<'\n';
	cout << "WA x " << mp["WA"] <<'\n';
	cout << "TLE x " << mp["TLE"] <<'\n';
	cout << "RE x " << mp["RE"] <<'\n';

}

Measured memory_bytes: 3636
# https://atcoder.jp/contests/abc065/tasks/arc076_b

import itertools
from collections import Counter
from collections import defaultdict
import collections
from functools import reduce
import bisect
import math
import heapq
import copy

# Union find
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]  # 負の値の場合根を表す。正の値は次の要素を返す、根まで続く
        self.size = [1 for _  in range(size)]

    #集合の代表を求める
    def find(self,x):
        while self.table[x] >= 0:
            #根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    #併合
    def union(self,x,y):
        s1 = self.find(x)#根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:#根が異なる場合
            if self.table[s1] != self.table[s2]:#グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                    self.size[s1] += self.size[s2]
                else:
                    self.table[s1] = s2
                    self.size[s2] += self.size[s1]
            else:
                #グラフの長さが同じ場合,どちらを根にしても変わらない
                #その際,グラフが1長くなることを考慮する
                self.table[s1] += -1
                self.table[s2] = s1
                self.size[s1] += self.size[s2]
        return

    def group_size(self, x):
        return self.size[self.find(x)]

Edge = collections.namedtuple("Edge", "start end weight")


def solve_by_kraskal(n, edges):
    """
        最小全域木を計算してそのルートを返す
        Parameters
        ----------
        n : int
            頂点の数
        edges: [Edge]
            辺のリスト

        Returns
        -------
        route : [Edge]
            最小全域木を構築する辺
    """

    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(n)
    route = []

    for edge in edges:
        if not uf.is_same(edge.start, edge.end):
            uf.union(edge.start, edge.end)
            route.append(edge)

    return route


def main():
    N = int(input())
    x_dots = []
    for i in range(N):
        x, y = map(int, input().split())
        x_dots.append((i, x, y))

    x_dots.sort(key=lambda x: x[1])
    y_dots = copy.copy(x_dots)
    y_dots.sort(key=lambda x: x[2])
    # print(x_dots)
    # print(y_dots)

    x_edges = []
    for i in range(N - 1):
        dot = x_dots[i]
        next_dot = x_dots[i + 1]
        x_edges.append(Edge(dot[0], next_dot[0], min(abs(dot[1] - next_dot[1]), abs(dot[2] - next_dot[2]))))
        x_edges.append(Edge(next_dot[0], dot[0], min(abs(dot[1] - next_dot[1]), abs(dot[2] - next_dot[2]))))

    y_edges = []
    for i in range(N - 1):
        dot = y_dots[i]
        next_dot = y_dots[i + 1]
        y_edges.append(Edge(dot[0], next_dot[0], min(abs(dot[1] - next_dot[1]), abs(dot[2] - next_dot[2]))))
        y_edges.append(Edge(next_dot[0], dot[0], min(abs(dot[1] - next_dot[1]), abs(dot[2] - next_dot[2]))))

    route = solve_by_kraskal(N, x_edges + y_edges)
    ans = 0
    for r in route:
        ans += r[2]

    print(ans)


if __name__ == '__main__':
    main()


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

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    while (y) {
        x %= y;
        swap(x, y);
    }
    return x;
}

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

    vector<int> L(N + 1);
    L[0] = 0;
    vector<int> R(N + 1);
    R[N] = 0;
    for (int i = 0; i < N; i++)
        L[i + 1] = gcd(L[i], A[i]);
    for (int i = N - 1; i >= 0; i--)
        R[i] = gcd(R[i + 1], A[i]);

    int m = 0;
    for (int i = 0; i < N; i++) {
        int l = L[i];
        int r = R[i + 1];

        m = max(m, gcd(l, r));
    }
    cout << m << endl;
    return 0;
}




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

struct vertex {
	int estart;
	int ecur;
	int dist;
} v[300003];
struct edge {
	int enext,to;
	int cap;
} e[1000003];int en;
void addedge(int a,int b,int cap)
{
	e[en].enext = v[a].estart;e[en].to = b;e[en].cap = cap;v[a].estart = en++;
	e[en].enext = v[b].estart;e[en].to = a;e[en].cap = 0;v[b].estart = en++;
}
int start, end;
int dfs(int i,int cap)
{
	if(i == end) return cap;
	int flow = 0;
	for(int &j = v[i].ecur;j != -1;j = e[j].enext) {
		int to = e[j].to;
		if(e[j].cap == 0 || v[to].dist != v[i].dist + 1) continue;
		int val = dfs(to,std::min(cap,e[j].cap));
		flow += val;cap -= val;e[j].cap -= val;e[j^1].cap += val;
		if(cap == 0) break;
	}
	return flow;
}
int n,m;
struct vertex2 {
	std::vector<int> inset;
	bool vis;
} v2[100003];
std::pair<int,int> ans[100003];
int match[100003];
int main()
{
	scanf("%d",&n);
	for(int i = 0;i < 2*n+1;++i) {
		v[i].estart = -1;
	}
	start = 2*n-1, end = 2*n;
	// root = 0
	for(int i = 1;i < n;++i) {
		addedge(start,i,1);
	}
	for(int i = 0;i < n - 1;++i) {
		int c;
		scanf("%d",&c);
		for(int j = 0;j < c;++j) {
			int k;
			scanf("%d",&k);--k;
			v2[k].inset.push_back(i);
			if(k != 0) addedge(k,n+i,1);
		}
		addedge(n+i,end,1);
	}
	int flow = 0;
	for(;;) {
		for(int i = 0;i < 2*n+1;++i) {
			v[i].dist = -1;
			v[i].ecur = v[i].estart;
		}
		v[start].dist = 0;
		std::queue<int> q;
		q.push(start);
		while(!q.empty()) {
			int cur = q.front();q.pop();
			for(int j = v[cur].estart;j != -1;j = e[j].enext) {
				if(e[j].cap == 0) continue;
				int to = e[j].to;
				if(v[to].dist == -1) {
					v[to].dist = v[cur].dist + 1;
					q.push(to);
				}
			}
		}
		if(v[end].dist == -1) break;
		flow += dfs(start,999999);
	}
	if(flow != n-1) {
		printf("-1\n");
		return 0;
	}
	for(int i = 0;i < n - 1;++i) {
		int x = n+i;
		match[i] = -1;
		for(int j = v[x].estart;j != -1;j = e[j].enext) {
			if(e[j].to >= 1 && e[j].to < n && e[j].cap == 1) {
				match[i] = e[j].to;
				break;
			}
		}
		assert(match[i] != -1);
	}
	
	{
		std::queue<int> q;
		q.push(0);v2[0].vis = true;
		int cnt = 0;
		while(!q.empty()) {
			int cur = q.front();q.pop();
			for(int j = 0;j < v2[cur].inset.size();++j) {
				int to = v2[cur].inset[j];
				if(!v2[match[to]].vis) {
					ans[to] = std::make_pair(cur,match[to]);
					v2[match[to]].vis = true;
					q.push(match[to]);
				}
			}
			++cnt;
		}
		if(cnt == n) {
			for(int i = 0;i < n-1;++i) printf("%d %d\n", ans[i].first+1, ans[i].second+1);
		} else {
			printf("-1\n");
		}
	}
}


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

int main(){
    string s,rev,no_x,pali;
    int i,j,k,left_x = 0,right_x = 0,ans = 0;
    cin >> s;
    rev = s;
    for(int i = 0;i < s.size();i++){
        if(s[i] != 'x'){
            no_x.push_back(s[i]);
            pali.push_back(s[i]);
        }
    }
    reverse(pali.begin(),pali.end());

    if(no_x != pali){
        cout << -1 << endl;
        return 0;
    }
    reverse(rev.begin(),rev.end());

    for(i = 0,j = 0,k = 0;i < s.size() && j < rev.size();i++,j++){
        if(s[i] == 'x' && rev[j] != 'x')while(s[i] == 'x')i++,ans++;
        else if(s[i] != 'x' && rev[j] == 'x')while(rev[j] == 'x')j++,ans++;
        if(s[i] == 'x' && rev[j] == 'x')continue;
        k++;
        if(k > (no_x.size() / 2))break;
    }
    cout << ans << endl;
}


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

int main(){
    int A, B;
    cin >> A >> B;

    if(A>B){
        cout << A*2-1 << endl;
    }else if(A==B){
        cout << A*2 << endl;
    }else{
        cout << B*2-1 << endl;
    }
    return 0;
}

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

void Main()
{
  ll W,H,x,y;
  cin >> W >> H >> x >> y;
  double area = (W*H) / 2.0;
  cout << area << " ";
  if (abs(W/2.0-(double)x) < 1e-9 && abs(H/2.0-(double)y) < 1e-9) cout << 1 << endl;
  else cout << 0 << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  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 h = sc.nextInt();
            int w = sc.nextInt();
            if((h == 0)&&(w == 0)){
                break;
            }
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if((i == 0)||(i == h-1)||(j == 0)||(j == w-1)){
                        System.out.print("#");
                    }
                    else{
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34364
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

void mymain(){
    int n;
    cin >> n;
    vector<vector<int>> arr(3,vector<int>(n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> arr[j][i];
        }
    }
    vector<vector<int>> dp(3,vector<int>(n,0));
    dp[0][0]=arr[0][0];
    dp[1][0]=arr[1][0];
    dp[2][0]=arr[2][0];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int change = INT_MIN;
            for(int k=0;k<3;k++){
                if(j==k)
                    continue;
                change = max(change,dp[k][i-1]);
            }
            dp[j][i] = change + arr[j][i];
        }
    }

    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> a(5);
  int x=0;
  
  for(int j=0; A<=B; j++) {
    int y=A;
    for(int i=0; i<5; i++) {
      a[i] = y%10;
      y/=10;
    }
    if(a[0]==a[4] && a[1]==a[3])
      x++;
    A++;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
const int MAXL = 1e5 + 10;
int Tree[MAXL];
int findRoot(int x) {
	if (Tree[x] == x) return x;
	else return Tree[x] = findRoot(Tree[x]);
}

int list[MAXL];

int main() {
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF) {
		for (int i = 1; i <= n; i++) {
			scanf("%d", &list[i]);
			Tree[i] = i;
		}
		while (m--) {
			int a, b;
			scanf("%d%d", &a, &b);
			a = findRoot(a);
			b = findRoot(b);
			if (a != b) {
				Tree[a] = b;
			}
		}

		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (findRoot(list[i]) == findRoot(i))
				ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 896
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


const int L=2e5+9;
int cnt[L];
void solve(long long N, std::vector<long long> A){
	for(auto a:A){
		cnt[a]++;
	}
	for(int i=1;i<=N;i++){
		cout << cnt[i] << endl;
	}

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5260
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

ll func(ll A){
	ll res = 0;

	A++; // 周期的に考えてると0からスタートしてしまうので，インクリメント
	for(int i=0; i<50; i++){
		//Aを2進数の0~50桁目の各桁について
		//1の個数を数える
		ll loop = (ll)1 << (i+1);//00001111000011...という感じで01の周期
		ll cnt = A/loop * loop/2;//周期の半分が1なので Aの中の周期数×周期の半分，半分が1

		//周期のはみ出たところの1を足す
		//(loop個のうちの半分は0なので，Aが0で終わってたらマイナスになるので0とmaxをとる
		cnt += max((ll)0,  A%loop - loop/2);
		// cout << " i: " << i << " cnt: " << cnt << " cnt%2: " << cnt%2 << endl;
		if(cnt % 2 == 1){
			res += (ll)1 << i;
		}

	}
	return res;
}

int main(){
	ll A, B;
	cin >> A >> B;

	// A~BのXOR   =  (0~BのXOR)  XOR  (0~A-1のXOR)
	//なぜなら a^a = 0 である．
	// 例: (4^5^6^7) = (1^2^3^4^5^6^7) ^ (1^2^3)
	ll ans = func(B)^func(A-1);
	// cout << " func(A-1): " << func(A-1) << "  func(B): " << func(B) << endl;
	cout << ans << endl;
}



Measured memory_bytes: 3576
# -*- coding utf-8 -*-

S = input()

if S[0]==S[1]:
    if S[2] == S[3]:
        ans = 'Yes'
    else:
        ans = 'No'
elif S[0]==S[2]:
    if S[1] == S[3]:
        ans = 'Yes'
    else:
        ans = 'No'
elif S[0]==S[3]:
    if S[1] == S[2]:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    ans = 'No'

if S[0]==S[1] and S[0]==S[2] and S[0]==S[3]:
    ans = 'No'
print(ans)

Measured memory_bytes: 3064
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    x,y,z = mi()
    y,x = x,y
    z,x = x,z
    print(x,y,z)


main()





Measured memory_bytes: 5884
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;
    cout << x2 - dy << " " << y2 + dx << " " << x1 - dy << " " << y1 + dx << endl;
}


Measured memory_bytes: 256
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MOD=998244353;
LL quick(LL A,LL B){
	if(B==0) return 1;
	LL  tmp=quick(A,B>>1);
	tmp*=tmp;
	tmp%=MOD;
	if(B&1)
		tmp*=A,tmp%=MOD;
 	return tmp;
}
void add(int & A,int B){
	A+=B;
	if(A>=MOD) A-=MOD;
}
int inv(int A){return quick(A,MOD-2);}
int x[200000+20];
int n,k;
const int MAXN=200000;
struct BIT{
	void add(int & A,int B){
		A+=B;
		if(A>=MOD) A-=MOD;
	}
	int bit[MAXN+10]={0};
	int sum(int i){
		int s=0;
		while(i>0){
			add(s,bit[i]);
			i-=i&(-i);
		}
		return s;
	}
	void modi(int i,int x=1){
		while(i<=n){
			add(bit[i],x);
			i+=i&(-i);	
		}
	}
}sum,cnt;
int main(){
	fastio;
	int rest=0;
	cin>>n>>k;
	rb(i,1,n) R(x[i]);
	int p=1ll*(k-1)*inv(k)%MOD;
	rl(i,n,1){
		int fi=max(0,i-k);
		int tmp;
		tmp=sum.sum(n)-sum.sum(x[i]);
		if(tmp<0) tmp+=MOD;
		tmp=1ll*tmp*inv(quick(p,fi))%MOD;
		add(rest,tmp);
		
		
		
		tmp=sum.sum(x[i]-1);
		int cn=cnt.sum(x[i]-1);
		tmp=1ll*tmp*inv(quick(p,fi))%MOD;
		cn-=tmp;
		if(cn<0) cn+=MOD;
		add(rest,cn);
		
		
		cnt.modi(x[i]);
		sum.modi(x[i],1ll*inv(2)*quick(p,fi)%MOD);
		
//		cout<<rest<<" "<<p<<endl;
	}
	cout<<rest<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


Measured memory_bytes: 5912
//             بسم الثالوث الاقدس

#include<iostream>	
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<fstream>
using namespace std;
//********************************************************************************************
//******************************************************************************************** 
/*
jesus help me.......
*/
typedef long long lld;
typedef char c;


bool prime(int x)
{
	if (x == 1)
		return false;
	else if (x == 2)
		return true;
	for (int i = 2; i*i <= x; i++)
	{
		if (x%i == 0)
			return false;

	}
	return true;
}
bool AreDoubleSame(double dFirstVal, double dSecondVal)
{
	return fabs(dFirstVal - dSecondVal) < numeric_limits<double>::epsilon();
}


/*
jesus help me.......
jesus help me.......
jesus help me.......
*/




int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);


	//freopen("keys.in", "r", stdin);
	
	long long x, y;
	cin >> x >> y;
	long long a = 0;
	while (x <= y)
	{
		x = x * 2;
		a++;
	}
	cout << a << endl;


	//system("pause");
	return 0;
}
/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int num = Integer.parseInt(str[0] + str[1]);
    boolean sqrRootFlg = false;
    for(int i=1; i<=1000; i++) {
      if(Math.sqrt(num)==i) {
        sqrRootFlg = true;
        break;
      }
    }
    System.out.println(sqrRootFlg==true?"Yes":"No");
  }
}

Measured memory_bytes: 37240
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
  int n,a,b,m,p,cnt=0;
  vector<vector<int>> v(100010);
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    if(a<b)
      v[a].push_back(b);
    else
      v[b].push_back(a);
  }
  for(int i=1;i<=n;i++)
    sort(v[i].begin(),v[i].end());
  p=n+1;
  for(int i=1;i<=n;i++){
    if(i==p){
      //printf("%d\n",i);
      cnt++;
      p=n+1;
    }
    if(!v[i].empty()&&v[i][0]<p){
      p=v[i][0];
      //printf("%d %d\n",i,v[i][0]);
    }
  }
  printf("%d\n",cnt);
}


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

int main() {
     string A;
	cin >> A;
  
  int ans;
  
  if (A[0] == '1') 
        ans++;
  if (A[1] == '1') 
        ans++;
  if (A[2] == '1')
        ans++;

  cout << ans << endl;
  
}

Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

jihun = 60*h + m


kakua= 2* math.pi * jihun/720
kakub =2* math.pi * m/60



ax = a * math.cos(kakua)
ay = a * math.sin(kakua)



bx = b * math.cos(kakub)
by = b * math.sin(kakub)


ans = math.sqrt((ax-bx)**2 + (ay-by)**2)

print(ans)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#define p(s) cout<<(s)<<endl
using namespace std;

int main() {
	int k[3];
	cin>>k[0]>>k[1]>>k[2];
	sort(k,k+3);
	if(k[0]+k[1]==k[2]) p("Yes");
	else p("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<vector> 
#include<string> 
#include<algorithm> 
using namespace std; 
int main()
{
	string s; 
	cin >> s; 
	for (int i = s.size()-2; i >1; i-=2)
	{
		string a, b;
		for (int j = 0; j < i/2; j++)
		{
			a += s.at(j); 
			b += s.at(j + i / 2);
		}
		if (a==b)
		{
			cout << i << endl; 
			break;
		}
	}
}

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


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int a, b;
    cin >> a >> b;
    int k = keta(b);
    int num = a * pow(10, k) + b;
    int test = sqrt(num);
    if(test * test == num)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
int a[maxn],b[maxn];

int main(){
 int n,m;
 cin >> n >> m;
 memset(a,0,sizeof(a));
 memset(b,0,sizeof(b));
 for(int i = 1;i <= m;i++){
  int t;
  string s;
  cin >> t >> s;
  if(s == "AC"){
   a[t] = 1;
  }
  else if(s == "WA"){
   if(!a[t])
    b[t]++;
  }
 }
 int cnt1 = 0,cnt2 = 0;
 for(int i = 1;i <= n;i++){
  if(a[i]){
   cnt1++;
   cnt2 += b[i];
  }
 }
 printf("%d %d\n",cnt1,cnt2); 
 return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2*b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
 
 
    int n,m, sum=0, cnt=0;
    float b=0;
    cin >> n >> m;
    int a[n];
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }

    b = (float)sum/(4*m);

    REP(i,n){
        if ((float)a[i] >= b){
            cnt ++;
        }
    }

    if (cnt >= m){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
   
}


Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream cin("input.txt")
//#define of1 ofstream cout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

bool cmp(pair<ll,ll> &a,pair<ll,ll> &b)
{
    return (a.se<b.se);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    vector< pair<ll,ll> >vv(n+1);
    for(ll i=1;i<=n;i++)
    {
        ll a,b;
        cin>>a>>b;
        vv[i]=mp(a,b);
    }
    sort(vv.begin()+1,vv.begin()+1+n,cmp);
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        sum+=vv[i].fi;
        if(sum>vv[i].se)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
 return 0;   
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<double> p(n+1);
    for (int i=0; i<n; ++i) {
        int num; cin >> num;
        p[i+1] = p[i] + (num+1)/2.0;
    }
    double M = 0;
    for (int i=n; i-k+1 >= 0; --i) {
        M = max(M, p[i] - p[i-k]);
    }
    printf("%.10lf\n", M);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int vec[N]={0};
    int ves[N]={0};
    for(int i=1; i<N; i++){
     cin>>vec[i];
     ves[vec[i]]++;}
    for(int j=1; j<N; j++){
     cout<<ves[j]<<endl;}
     cout<<0<<endl;
  return 0;
    }


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

using Graph = vector<vint>;

struct SCC {
  vint cmp;
  SCC(){}
  void dfs(const Graph& graph, int u, vint& vis, vint& ord) {
    vis[u] = 1;
    for(int v : graph[u]) {
      if(!vis[v]) dfs(graph, v, vis, ord);
    }
    ord.push_back(u);
  }
  void rdfs(const Graph& rgraph, int u, int k) {
    cmp[u] = k;
    for(int v : rgraph[u]) {
      if(cmp[v] == -1) rdfs(rgraph, v, k);
    }
  }
  Graph build(const Graph& graph) {
    int n = graph.size();
    resz(cmp, n, -1);
    Graph rgraph(n);
    rep(u, n) {
      for(int v : graph[u]) {
	rgraph[v].push_back(u);
      }
    }
    vint vis(n, 0), ord;
    rep(u, n) {
      if(!vis[u]) dfs(graph, u, vis, ord);
    }
    reverse(all(ord));
    int sz = 0;
    for(int u : ord) {
      if(cmp[u] == -1) rdfs(rgraph, u, sz++);
    }
    Graph dag(sz);
    set<Pi> exist;
    rep(u, n) {
      for(int v : graph[u]) {
	int x = cmp[u], y = cmp[v];
	if(x != y && !exist.count(Pi(x, y))) {
	  dag[x].push_back(y);
	  exist.emplace(x, y);
	}
      }
    }
    return dag;
  }
};

int N, M;
Graph graph;
Graph dag;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M;
  resz(graph, N);
  rep(i, M) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
  }
  SCC scc;
  dag = scc.build(graph);
  int n = dag.size();
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vint in(n, 0), out(n, 0);
  rep(u, n) {
    for(int v : dag[u]) {
      ++in[v];
      ++out[u];
    }
  }
  int source = count(all(in), 0);
  int sink = count(all(out), 0);
  cout << max(source, sink) << endl;

  return 0;
}



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

using namespace std;

using ll = long long;
using ull = unsigned long long;

ll ans = 0;

void p(int N,ll X){
   //cout<<N<<" "<<X<<" "<<ans<<endl;
   //全部
   if(X == pow(2,N+2)-3){
      ans += pow(2,N+1)-1;
      return ;
   }
   //何も食べない
   if(X == 0){
      return;
   }
   //真ん中のパティを食べる
   if(X > pow(2,N+1)-2){
      ans += pow(2,N);
      p(N-1,X-(pow(2,N+1)-1));
   }
   else{
      p(N-1,X-1);
   }
   return ;
}

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

   int N;
   ll X;
   cin>>N>>X;
   p(N,X);
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;

inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
const int N=200010;
int d[N<<2],s[N<<2],a[N],n,wz[N];
void build(int l,int r,int w){
	if(l==r){
		if(l&1)d[w]=a[l],s[w]=1<<30;
		else d[w]=1<<30,s[w]=a[l];
		return;
	}
	int mid=l+r>>1;
	build(l,mid,w<<1),build(mid+1,r,w<<1|1);
	d[w]=min(d[w<<1],d[w<<1|1]);
	s[w]=min(s[w<<1],s[w<<1|1]);
}
int query(int l,int r,int w,int L,int R,int op){
	if(L<=l && r<=R){
		if(op)return d[w];
		else return s[w];
	}
	int mid=l+r>>1,ans=1<<30;
	if(L<=mid)ans=min(ans,query(l,mid,w<<1,L,R,op));
	if(R>=mid+1)ans=min(ans,query(mid+1,r,w<<1|1,L,R,op));
	return ans;
}
//op==0 ou
//op==1 ji
struct Q{
	int l,r,v;
	bool operator<(const Q&a)const{
		return v>a.v;
	}
};
priority_queue<Q>p;
map<int,int>mp;
map<int,int>::iterator it;
int main(){
	splay(n);
	for(int i=1;i<=n;i++){
		splay(a[i]);
		wz[a[i]]=i;
	}
	build(1,n,1);
	mp[0]=mp[n+1]=1;
	//cerr<<query(1,n,1,1,n-1,1)<<endl;
	p.push((Q){1,n,query(1,n,1,1,n-1,1)});
	for(int i=1;i<=(n>>1);i++){
		Q x=p.top();p.pop();
		//cerr<<x.l<<" "<<x.r<<endl;
		while(1){
			//cerr<<mp.lower_bound(x.l)->first<<" "<<x.r<<endl;
			if(mp.lower_bound(x.l)->first>x.r)break;
			x=p.top();p.pop();
		}
		int v=x.v;
		printf("%d ",v);
		v=wz[v];mp[v]=1;
		it=mp.lower_bound(v);--it;
		if(v-it->first>=2){
			p.push((Q){it->first+1,v-1,query(1,n,1,it->first+1,v-1,(it->first+1)&1)});
		}
		it=mp.lower_bound(v);++it;
		int w=query(1,n,1,v+1,it->first-1,(v+1)&1);
		printf("%d ",w);w=wz[w];mp[w]=1;
		if(w-v>=2){
			p.push((Q){v+1,w-1,query(1,n,1,v+1,w-1,(v+1)&1)});
		}
		if(it->first-w>=2){
			p.push((Q){w+1,it->first-1,query(1,n,1,w+1,it->first-1,(w+1)&1)});
		}
	}
}

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

using namespace std;

const int MOD = 1000000007;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

int main(){
    const int maxSize = 200001;
	vector<long long> inv(maxSize);
	vector<long long> fact(maxSize);
	vector<long long> factInv(maxSize);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<maxSize;i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    auto perm = [&](int n, int r){
        if(n < r || r < 0) return 0LL;
        return fact[n] * factInv[n-r] % MOD;
    };
    int n, a, b;
    while(cin >> n >> a >> b){
        long long res = (modPow(2, n) + MOD - 1) % MOD;
        auto calc = [&](int t){
            long long r = 1;
            for(int i=0;i<t;i++){
                r *= (n-i);
                r %= MOD;
                r *= inv[i+1];
                r %= MOD;
            }
            return r;
        };
        res = (res + MOD - calc(a)) % MOD;
        res = (res + MOD - calc(b)) % MOD;
        cout << res << endl;
    }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
long long a[100005];
long long dfs(int x, int p) {
  int cnt = 0;
  long long sum = 0, maxx = 0;
  for (auto y : edges[x]) {
    if (y == p) continue;
    cnt++;
    long long ret = dfs(y, x);
    sum += ret;
    maxx = max(maxx, ret);
  }
  if (cnt == 0) {
    return a[x];
  }
  if (a[x] > sum || a[x] < maxx) {
    printf("NO\n");
    exit(0);
  }
  long long send = a[x] * 2 - sum;
  if (p == 0 && send != 0 || send < 0) {
    printf("NO\n");
    exit(0);
  }
  return send;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  if (n == 2) {
    if (a[1] != a[2]) {
      printf("NO\n");
    } else {
      printf("YES\n");
    }
    return 0;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (edges[i].size() >= 2) {
      dfs(i, 0);
      printf("YES\n");
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s, t;
    cin >> s >> t;

    sort(all(s));
    sort(rall(t));

    if(s < t) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=600+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,k;
int sum[N];
int x[N],y[N];
void input()
{
	n=read<int>()<<1;k=read<int>();
	For(i,1,n)sum[i]=1;
	For(i,1,k)
	{
		x[i]=read<int>(),y[i]=read<int>();
		sum[x[i]]=0,sum[y[i]]=0;
	}
}
const int mo=1e9+7;
int mc[N];
bool in(int pos,int l,int r)
{
	return l<=pos&&pos<=r;
}
bool check(int l,int r)
{
	For(i,1,k)if(in(x[i],l,r)^in(y[i],l,r))return false;
	return true;
}
int dp[N][N],ans;
void work()
{
	For(i,1,n)sum[i]+=sum[i-1];
	mc[0]=1;
	for(int i=2;i<=n;i+=2)mc[i]=1ll*mc[i-2]*(i-1)%mo;
	int j;
	For(len,1,n)For(i,1,n-len+1)
	{
		j=i+len-1;
		int tot=sum[j]-sum[i-1];
		if((tot&1)||!check(i,j))continue;
		int cur=mc[tot];
		For(k,i,j-1)cur=(cur-1ll*dp[i][k]*mc[sum[j]-sum[k]]%mo+mo)%mo;
		dp[i][j]=cur;
		ans=(ans+1ll*cur*mc[sum[n]-tot]%mo)%mo;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 1664
X, N = map(int, input().split())
p = list(map(int, input().split()))

if len(p) == 0:
    print(X)
    exit()

if not X in p:
    print(X)
    exit()

small = [i for i in range(-101, X)]
big = [i for i in range(X+1, 102)]
small.reverse()
for i in range(max(len(big),len(small))):
    if not small[i] in p:
        print(small[i])
        exit()
    elif not big[i] in p:
        print(big[i])
        exit()

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

typedef long long ll;

ll N;
map<ll, ll> ACnt;
multiset<ll> Pairs;

ll solve() {
  if (Pairs.size() < 2) return 0;
  return *prev(Pairs.end(), 1) * *prev(Pairs.end(), 2);
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    ++ACnt[a];
  }
  for (auto acnt : ACnt) {
    ll a, cnt;
    tie(a, cnt) = acnt;
    if (cnt >= 2) Pairs.insert(a);
    if (cnt >= 4) Pairs.insert(a);
  }
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 6528