akhauriyash/Code-Regression huggingface dataset:
def PAndB(n):
    return (2 ** (n + 2)) - 3


def allPatty(n):
    return (2 ** (n + 1)) - 1


def count(N, X):
    if N == 0:
        return 1
    elif X <= N:
        return 0
    elif X >= PAndB(N) - (N - 1):
        return allPatty(N)
    elif X == PAndB(N - 1) + 2:
        return allPatty(N - 1) + 1
    elif X <= PAndB(N - 1) + 1:
        return count(N - 1, X - 1)
    else:
        return allPatty(N - 1) + 1 + count(N - 1, X - (PAndB(N - 1) + 2))


def main():
    N, X = map(int, input().split())
    print(count(N, X))


if __name__ == '__main__':
    main()

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

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;
  //iはtとsの重複した長さ
  for (int i = N; i >= 1; i--) {
    bool check = true;
    for (int j = 0; j < i; j++) {
      if (s[N-i+j] != t[j]) {
        check = false;
      }
    }
    if (check) {
      cout << 2*N-i << endl;
      return 0;
    }
  }
  cout << 2*N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b;
  string s;
  cin >> a >> b >> s;
  bool ans = true;
  rep(i, s.size()) {
    if(i == a && s[i] != '-') ans = false;
    if(i != a && (s[i] < '0' || '9' < s[i])) ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

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

const int N = 2e5 + 100;

ll h[N], dp[N];
int Q[N];
int L, R;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll c;
    cin >> n >> c;
    for (int i=0; i<n; i++) {
        cin >> h[i];
    }
    auto cost = [&](int i, int j) -> ll {
        ll d = h[j] - h[i];
        return dp[j] + d*d + c;
    };
    auto better_at = [&](int i, int j) -> int {
        int lo = 0, hi = i;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (cost(mid, i) < cost(mid, j)) {
                lo = mid + 1;
            }
            else {
                hi = mid;
            }
        }
        return lo - 1;
    };
    Q[R++] = n-1;
    for (int i=n-2; i>=0; i--) {
        while (R-L >= 2 && better_at(Q[L+1], Q[L]) >= i) {
            L++;
        }
        dp[i] = cost(i, Q[L]);
        while (R-L >= 2) {
            int old = better_at(Q[R-1], Q[R-2]);
            int cur = better_at(i, Q[R-1]);
            if (cur < old) {
                Q[R++] = i;
                break;
            }
            R--;
        }
        if (R-L == 1) {
            int cur = better_at(i, Q[L]);
            if (cur >= i-1) {
                L++;
            }
            if (cur >= 0) {
                Q[R++] = i;
            }
        }
    }
    cout << dp[0] << '\n';
}


Measured memory_bytes: 4224
@n = gets.split(' ').map(&:to_i)
m = gets.split(' ').map(&:to_i)

def throw(a, b)
    temp = @n[0]
    @n[0] = @n[a]
    @n[a] = @n[5]
    @n[5] = @n[b]
    @n[b] = temp
end

while (m[1] != @n[0])
    throw(4, 1)
    break if m[1] == @n[0]
    throw(2, 3)
end
throw(4, 1)
while (m[0] != @n[0])
    throw(2, 3)
end
puts @n == m ? 'Yes' : 'No'

Measured memory_bytes: 8640
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long Int;

Int top(Int x){
  if(x == 0)return 0;
  Int res = 1;
  while(x >= res*2)res *= 2;
  return res;
}

Int solve(Int a, Int b){
  if (a == b)return 1;
  Int ta = top(a), tb = top(b);
  if(ta == tb)return solve(a - ta, b- tb);
  Int lower = a;
  Int upper = b - tb;
  Int hoge = top(upper) * 2;
  if(upper == 0)hoge = 1;
  return (tb - lower) + min(tb, tb - lower + hoge);
}

int main(){
  Int a, b;
  cin >> a >> b;
  cout << solve(a, b) << endl;
  
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#define MN 500000
char s[MN+5];
int a[MN+5];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),l,r,mid,ans,i,x,L,R;
	for(l=1,r=1e6;l<=r;)
	{
		mid=l+r>>1;L=0;R=mid*9;
		for(i=1;i<=n;++i)a[i]=s[i]-'0';
		for(i=n;i;--i)
		{
			R-=((R-a[i])%10+10)%10;
			if(R<L)break;
			x=R/10;R=(R-L)+x;L=x;
		}
		if(i)l=mid+1;else ans=mid,r=mid-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 2560
def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1]))


main()

Measured memory_bytes: 224560
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

vector<int> sw[11];
int p[11];
int ck[11];

int main()
{
    int n, m;

    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int tmp;
            cin >> tmp;
            sw[i].push_back(tmp - 1);
        }
    }

    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }

    int res = 0;

    for (int bit = 0; bit < (1 << n); bit++)
    {
        //cout << "loop" << bit << endl;

        //ビットごとの処理
        for (int i = 0; i < n; i++)
        {
            if (bit & (1 << i))
            { // i が bit に入るかどうか
                //スイッチがon
                ck[i] = 1;
            }
            else
            {
                ck[i] = 0;
            }
        }

        /*
        for (int i = 0; i < n; i++)
        {
            cout << ck[i];
        }
        cout << endl;
       */
        bool flag = true;

        //電球の点灯チェック
        for (int i = 0; i < m; i++)
        {

            //cout << "subloop" << i << endl;

            int ct = 0;

            for (auto e : sw[i])
            {
                //cout << "check sw" << e << endl;
                if (ck[e] == 1)
                {
                    ct++;
                }
            }

            if (ct % 2 == p[i])
            {
                //cout << ct % 2 << "yay" << endl;
            }
            else
            {
                flag = false;
            }
        }

        //全部ついてる
        if (flag == true)
        {
            res++;
        }
    }

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

void cut(vector<int> &V,int k) {
	vector<int> NV;
	for(int i=k;i<V.size();i++) {
		NV.push_back(V[i]);
	}
	for(int i=0;i<k;i++) {
		NV.push_back(V[i]);
	}
	V=NV;
}

void shuffle(vector<int> &V) {
	vector<int> NV;
	for(int i=0;i<V.size()/2;i++) {
		NV.push_back(V[i]);
		NV.push_back(V[i+V.size()/2]);
	}
	V=NV;
}

int main() {
	int n;
	scanf("%d",&n);
	vector<int> V;
	for(int i=1;i<=2*n;i++) {
		V.push_back(i);
	}
	int m;
	scanf("%d",&m);
	for(int i=0;i<m;i++) {
		int k;
		scanf("%d",&k);
		if(k==0) shuffle(V);
		else cut(V,k);
	}
	for(int i=0;i<V.size();i++) {
		printf("%d\n",V[i]);
	}
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    const ll inf = 1e12;
    ll n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n, 0));
    rep(i, n) rep(ii, n) cin >> a[i][ii];
    vector<vector<ll>> d(n, vector<ll>(n, 0));
    ll ans = 0;
    rep(i, n) rep(ii, n) d[i][ii] = a[i][ii];
    rep(i, n) {
        rep(ii, n) {
            rep(iii, n) {
                d[ii][iii] = min(d[ii][iii], d[ii][i] + d[i][iii]);
            }
        }
    }
    rep(i, n) {
        rep(ii, n) {
            if (d[i][ii] != a[i][ii]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    rep(i, n) {
        rep(ii, n) {
            rep(iii, n) {
                if ((i == ii) || (i == iii)) continue;
                if (d[ii][iii] == (d[ii][i] + d[i][iii])) {
                    // printf("%d->%d = %d->%d->%d\n", ii, iii, ii, i, iii);
                    d[ii][iii] = inf;
                    d[iii][ii] = inf;
                }
            }
        }
    }
    rep(i, n) {
        rep(ii, n) {
            if (d[i][ii] != inf) ans = ans + d[i][ii];
            // printf("%d%s", d[i][ii], (ii == (n - 1)) ? "\n" : " ");
        }
    }
    cout << (ans / 2) << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const ll INFL = 9e18;

int main() {
  int N, mx = 0, sum = 0; cin >> N;
  vi L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
    sum += L[i];
    mx = max(mx, L[i]);
  }
  cout << ((sum-mx > mx) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;

int H,W,K; char map[808][808]; int dist[808][808];

int main()
{
	scanf ("%d %d %d",&H,&W,&K);
	queue<pair<int, int> > Q;
	for (int i=0;i<H;i++){
		scanf ("%s",map[i]);
		for (int j=0;j<W;j++){
			dist[i][j] = -1;
			if (map[i][j] == 'S'){
				Q.push({i,j}); dist[i][j] = 0;
			}
		}
	}

	while (!Q.empty()){
		int x = Q.front().first, y = Q.front().second; Q.pop();
		int dx[4] = {0,1,0,-1};
		int dy[4] = {1,0,-1,0};
		for (int k=0;k<4;k++){
			int px = x + dx[k], py = y + dy[k];
			if (px < 0 || px >= H || py < 0 || py >= W) continue;
			if (dist[px][py] == -1 && map[px][py] != '#'){
				Q.push({px,py}); dist[px][py] = dist[x][y] + 1;
			}
		}
	}

	int ans = 0x7fffffff;
	for (int i=0;i<H;i++) for (int j=0;j<W;j++) if (dist[i][j] != -1 && dist[i][j] <= K){
		int r = (min(min(i,H-i-1),min(j,W-j-1)) + K - 1) / K + 1;
		ans = min(r,ans);
	}
	printf ("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;

int atcoder(){
    //入力
    ll n,m;
    ll ans=0;
    cin >> n >> m;
    vector<pair<ll,ll>> v(n);
    REP(i,0,n){
        ll tmpa,tmpb;
        cin >> tmpa >> tmpb;
        v[i] = make_pair(tmpa,tmpb);
    }
    SRTV(v);
    for(ll i=0; m>0; ++i){
        if(m>v[i].second){
            ans += v[i].first*v[i].second;
            m -= v[i].second;
        }else{
            ans += v[i].first * m;
            break;
        }
    }
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
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()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

ll gcd(ll a, ll b) {
  return b?gcd(b,a%b):a;
}

ll llmax = 2*1e18;
ll mul(ll a, ll b) {
  if (a>llmax/b) return llmax;
  return a*b;
}

ll a[20];
double p[20];
ll dp[1<<20];

int main() {
  int n;
  ll m;
  while(cin>>n>>m) {
    REP(i,n) cin >> a[i];
    REP(i,n) {
      cin >> p[i];
      p[i] /= 100;
    }
    REP(S,1<<n) {
      ll lcm = 1;
      REP(i,n) {
        if (S>>i&1) {
          lcm = mul(lcm/gcd(lcm,a[i]), a[i]);
          if (lcm > m) break;
        }
      }
      if (S == 0) dp[S] = 0;
      else {
        if (__builtin_popcount(S) & 1) dp[S] = m / lcm;
        else dp[S] = - m / lcm;
      }
      // cout << bitset<3>(S) << " " << dp[S] << endl;
    }
    REP(i,n) {
      // cout << i << endl;
      REP(S,1<<n) {
        if (S>>i&1) {
          dp[S] += dp[S^(1<<i)];
        }
        // cout << bitset<3>(S) << " " << dp[S] << endl;
      }
    }
    double ans = 0;
    REP(S,1<<n) {
      double P = 1;
      REP(i,n) {
        if (S>>i&1) P *= p[i];
        else P *= 1-p[i];
      }
      ans += dp[S] * P;
    }
    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 9448
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN2(s,t);
  swap(t[0],t[2]);
  YES(s==t);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n[1000],i=0,j,k,m;
    double a,b,c,d;
    while(1){
        if(scanf("%d",&m)==EOF){
            break;
        }
        scanf(",%lf,%lf",&a,&b);
        if((a/b/b)>=25)n[i++]=m;
        
    }
    for(j=0;j<i;j++){
        printf("%d\n",n[j]);
    }

    return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	int n;
	cin >> n;
	int pt, px, py;
	int ct, cx, cy;
	ct = 0;
	cx = 0;
	cy = 0;
	ff(i, 0, n) {
		pt = ct;
		px = cx;
		py = cy;
		int it, ix, iy;
		cin >> it >> ix >> iy;
		ct = it;
		cx = ix;
		cy = iy;
		int t, x, y;
		t = max(-(ct - pt), ct - pt);
		x = max(-(cx - px), cx - px);
		y = max(-(cy - py), cy - py);
		if (t < x + y || (t - (x + y)) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double a = arr[0], b = arr[1], perc = arr[2];
            double rad = perc * Math.PI / 180;

            Console.WriteLine($"{0.5 * a * b * Math.Sin(rad):0.000000000}");
            Console.WriteLine($"{a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(rad)):0.000000000}");
            Console.WriteLine($"{b * Math.Sin(rad):0.000000000}");
        }
    }
}


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

using ll = long long;
using ld = double;
using pii = pair<int, int>;

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

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

	vector<int> a(n);

	for (int &x : a) {
		cin >> x;
	}

	for (int i = k; i < n; i++) {
		int i1 = i - k;
		int i2 = i;

		if (a[i2] > a[i1]) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}

	return 0;
}

Measured memory_bytes: 3984
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
ll a,b,n;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>a>>b>>n;
	ll ans=0;
	if(n>b-1) n=b-1;
	ans=a*n/b-a*(n/b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  int h,w;
  cin >> h >> w;
  vector<string>vec(h);
  rep(i,h) cin >> vec[i];
  rep(i,w+2)cout << '#';
  cout << endl;
  rep(i,h){
    cout << "#" << vec[i] << "#" << endl;
  }
  rep(i,w+2)cout << '#';
  cout << endl;
}


Measured memory_bytes: 12288
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Dice {
public:
    int label1;
    int label2;
    int label3;
    int label4;
    int label5;
    int label6;

    Dice() {
        label1 = 0;
        label2 = 0;
        label3 = 0;
        label4 = 0;
        label5 = 0;
        label6 = 0;
    }

    void setValue(int n, int l) {
        switch (l) {
        case 1: label1 = n; break;
        case 2: label2 = n; break;
        case 3: label3 = n; break;
        case 4: label4 = n; break;
        case 5: label5 = n; break;
        case 6: label6 = n; break;
        default: break;
        }
    }

    void roll(char c) {
        int a = label1;
        switch (c) {
        case 'N':            
            label1 = label2;
            label2 = label6;
            label6 = label5;
            label5 = a;                
            break;
        case 'S':
            label1 = label5;
            label5 = label6;
            label6 = label2;
            label2 = a;
            break;
        case 'W':
            label1 = label3;
            label3 = label6;
            label6 = label4;
            label4 = a;
            break;
        case 'E':
            label1 = label4;
            label4 = label6;
            label6 = label3;
            label3 = a;
            break;
        default: 
            break;
        }
    }
};

int main()
{
    Dice DiceA;

    for (int i = 0; i < 6; i++) {
        int n = 0;
        cin >> n;
        DiceA.setValue(n, i + 1);
    }

    string str;
    cin >> str;
    if (str.empty()) return 1;
    int nSize = (int)str.size();
    for (int i = 0; i < nSize; i++) {
        char c = str[i];
        DiceA.roll(c);
    }

    cout << DiceA.label1 << endl;
}


Measured memory_bytes: 3224
import scala.io._

object Main extends App {
  val n = StdIn.readLine.toInt

  val a = (n / 4)
  val b = (n / 7)

  val combos = for {
    i <- 0 to a
    j <- 0 to b
  } yield i*4 + j*7

  if (combos.toList.contains(n))
    println("Yes")
  else
    println("No")
}


Measured memory_bytes: 27316
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;


int call1000(double time) {
	int res = 7;
	if (time < 71.00) {
		res = 0;
	} else if (time < 77.00) {
		res = 1;
	} else if (time < 83.00) {
		res = 2;
	} else if (time < 89.00) {
		res = 3;
	} else if (time < 105.00) {
		res = 4;
	} else if (time < 116.00) {
		res = 5;
	} else if (time < 148.00) {
		res = 6;
	}

	return res; 
} 


void main()
{
	auto rank = ["AAA", "AA", "A", "B", "C", "D", "E", "NA"];
	foreach (line; stdin.byLine) {
		auto x = line.chomp.split.map!(to!double);
		int res = 7;
		
		if (x[0] < 35.50) {
			res = max(0, call1000(x[1]));
		} else if (x[0] < 37.50) {
			res = max(1, call1000(x[1]));
		} else if (x[0] < 40.00) {
			res = max(2, call1000(x[1]));
		} else if (x[0] < 43.00) {
			res = max(3, call1000(x[1]));
		} else if (x[0] < 50.00) {
			res = max(4, call1000(x[1]));
		} else if (x[0] < 55.00) {
			res = max(5, call1000(x[1]));
		} else if (x[0] < 70.00) {
			res = max(6, call1000(x[1]));
		} 
		
		writeln(rank[res]);
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) x.begin(),x.end()
#define len(x) (int)(x).size()
//#define endl "\n"
#define m_p make_pair
#define int long long


using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pari;

ld PI = 3.14159265358979323846;


struct Edge{
    int x,coast;
};

typedef tree<int, null_type, less<int >,
    rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void volodya22(){
    #ifdef THERE
        freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
    cout << fixed;
}


int n,k;
const int N = 1e6+7;
const int alphabet = 256;
const int INF = 1e18;
const ll MOD = 1e9+7;
const ld eps = 1e-19;
const int L = 30;

int m1 = 137*137*137*137*13;
int m2 = 1e9+9;
//int p = 347;

vector<Edge> path[N];

void input(){
    cin >> n;
    for(int i = 0;i < n-1;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        path[a].push_back({b,c});
        path[b].push_back({a,c});
    }
}

int ans[N];

int DFS(int x,int p){
    for(Edge i : path[x]){
        if(i.x == p) continue;
        if(i.coast%2){
            ans[i.x] = !ans[x];
            DFS(i.x,x);
        }else{
            ans[i.x] = ans[x];
            DFS(i.x,x);
        }
    }
}

void solve(){
    DFS(0,0);
    for(int i = 0;i < n;i++) cout << ans[i] << endl;
}

signed main(){
    volodya22();
    input();
    solve();
}


Measured memory_bytes: 33024
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

fn main() {
    let a: usize = input();
    let b: usize = input();
    let q: usize = input();
    let mut s: Vec<i64> = (0..a).map(|_| input()).collect();
    let mut t: Vec<i64> = (0..b).map(|_| input()).collect();
    let x: Vec<i64> = (0..q).map(|_| input()).collect();
    const INF: i64 = 1001001001001001;

    s.insert(0, -INF);
    s.push(INF);
    t.insert(0, -INF);
    t.push(INF);

    let mut ans = vec![i64::max_value(); q];
    for i in 0..q {
        for j in 0..2 {
            let sx = s.lower_bound(&x[i]);
            for k in 0..2 {
                let tx = t.lower_bound(&s[sx - j]);
                if tx == 0 {
                    break;
                }
                let temp = i64::abs(x[i] - s[sx - j]) + i64::abs(s[sx - j] - t[tx - k]);
                ans[i] = std::cmp::min(ans[i], temp);
            }
        }
        for j in 0..2 {
            let tx = t.lower_bound(&x[i]);
            for k in 0..2 {
                let sx = s.lower_bound(&t[tx - j]);
                if sx == 0 {
                    break;
                }
                let temp = i64::abs(x[i] - t[tx - j]) + i64::abs(t[tx - j] - s[sx - k]);
                ans[i] = std::cmp::min(ans[i], temp);
            }
        }
    }

    with_stdout_lock(|mut w| {
        for a in ans {
            writeln!(w, "{}", a).unwrap();
        }
    });
}

trait LowerBound<T: Ord> {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, f: F) -> usize;
    fn lower_bound(&self, x: &T) -> usize {
        self.lower_bound_by(|e| e.cmp(x))
    }
    fn lower_bound_by_key<U: Ord, F: FnMut(&T) -> U>(&self, x: &U, mut f: F) -> usize {
        self.lower_bound_by(|e| f(e).cmp(x))
    }
}
impl<T: Ord> LowerBound<T> for [T] {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, mut f: F) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if f(&self[m]) == std::cmp::Ordering::Less {
                l = m as i64;
            } else {
                r = m as i64;
            }
        }
        r as usize
    }
}


Measured memory_bytes: 13564
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
 ll N;
 cin>>N;
 vector<ll> a(N);
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
ll tar =1;
  for(ll i=0;i<N;i++){
    if(a[i]==tar){
      tar++;
    }
  }

 
  if(tar==1){
    cout<<-1<<endl;
    return 0;
  }

  cout<<N-(tar-1)<<endl;

}








Measured memory_bytes: 1792
def nankai_waretano(n):
    kaisuu = 0
    while n % 2 == 0:
        n /= 2
        kaisuu += 1        
    return kaisuu
    
n = int(input()) 
a = map(int, input().split())
kaisuu = min(map(nankai_waretano, a))
print(kaisuu)

Measured memory_bytes: 2940
A = []
for i in range(3):
    A.append(list(map(int, input().split())))

N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

bingo = []
for t in range(N):
    for i in range(3):
        if b[t] in A[i]:
            j = A[i].index(b[t])
            #bingo.append((i, j))
            A[i][j] = True

answer = "No"
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        answer = "Yes"

for j in range(3):
    if A[0][j] == A[1][j] == A[2][j]:
        answer = "Yes"
if A[0][0] == A[1][1] == A[2][2]:
    answer = "Yes"

if A[2][0] == A[1][1] == A[0][2]:
    answer = "Yes"
    

print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
//#include<math.h>
#include <unordered_map>
using namespace std;

int main()
{
    int n;
    int keta=0;
    int temp=1;
    int m;
    cin>>n;

    while(1)
    {
        keta++;
        temp*=10;
        if(n<temp)
        {
            break;
        }
    }
    int a=1;
    for(int i=0;i<keta-1;i++)
    {
        a*=10;
    }

    int ans=0;
    temp=9;
    for(int i=0;2*i+1<keta;i++)
    {
        ans+=temp;
        temp*=100;
    }
    if(keta%2==1)
    {
        ans+=n-a+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 888
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; i32);
  let mut a = scan!(sc => n; usize);
  counting_sort(&mut a);
  println!("{}", a.write(" "));
}

fn counting_sort(vec: &mut Vec<usize>) {
  let mut b = vec![0_usize; vec.len()];
  let mut c = vec![0_usize; 10001];
  for &e in vec.iter() {
    c[e] += 1;
  }
  for i in 0..c.len() - 1 {
    c[i + 1] += c[i];
  }
  for &e in vec.clone().iter().rev() {
    let idx = c[e] - 1;
    b[idx] = e;
    c[e] -= 1;
  }
  for (i, &e) in b.iter().enumerate() {
    vec[i] = e;
  }
}



Measured memory_bytes: 93100
from collections import Counter, defaultdict
N, W = map(int, input().split())
wv_dict = defaultdict(list)
for i in range(N):
    w, v = map(int, input().split())
    wv_dict[w] += [v]
sorted_w = sorted(wv_dict.keys())
w0 = sorted_w[0]
w_list = [w0 + i for i in range(4)]
for key in w_list:
    sorted_v = sorted(wv_dict[key], reverse=True)
    for i in range(len(sorted_v)-1):
        sorted_v[i+1] += sorted_v[i]
    wv_dict[key] = [0] + sorted_v
w0, w1, w2, w3 = [w0 + i for i in range(4)]
ans = 0
for c0 in range(len(wv_dict[w0])):
    for c1 in range(len(wv_dict[w0+1])):
        for c2 in range(len(wv_dict[w0+2])):
            for c3 in range(len(wv_dict[w0+3])):
                if w0 * c0 + w1 * c1 + \
                    w2 * c2 + w3 * c3 <= W:
                    v = wv_dict[w0][c0] + wv_dict[w1][c1] + \
                        wv_dict[w2][c2] + wv_dict[w3][c3]
                    ans = max(ans, v)

print(ans)

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

using namespace std;

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

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		205

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	int H,W;cin>>H>>W;
	vector<vector<int>> c(10,vector<int>(10));
	vector<vector<int>> A(H,vector<int>(W));

	REP(i,10)REP(j,10)cin>>c[i][j];
	REP(i,H)REP(j,W)cin>>A[i][j];

	vector<int> is_cnt(10,0);
	REP(i,H)REP(j,W){
		if(A[i][j]>=0)is_cnt[A[i][j]]++;
	}

	REP(k,10)REP(i,10)REP(j,10)
		c[i][j] = min(c[i][j],c[i][k]+c[k][j]);

	ll ans = 0;
	REP(i,10){
		if(is_cnt[i]==0)continue;
		ans += (ll)is_cnt[i] * c[i][1];
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 384
# include "deque"
# include "iostream"
# include "cstdio"

using namespace std;

deque<int> LH;
int N;

int main(){
	register int i,Num;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%d",&Num);
		if(i&1) LH.push_front(Num);
		else LH.push_back(Num);
	}
	if(N&1) for(i=0;i<N;i++) printf("%d ",LH[i]);
	else for(i=N-1;i>=0;i--) printf("%d ",LH[i]);
	return 0;
}

Measured memory_bytes: 2944
def main(input = STDIN)
  while (a, b, c = input.gets.split(" ").map(&:to_i)) != [0, 0, 0]
    array = Array.new(a + b + c + 1)
    test = []
    input.gets.to_i.times do
      test << input.gets.split(" ").map(&:to_i)
    end
    test.sort_by!{|i|-i[3]}
    #p test
    test.each do |arg|
      if arg[3] == 1
        array[arg[0]], array[arg[1]], array[arg[2]] = true, true, true
      #p [arg, array]
      elsif [array[arg[0]], array[arg[1]], array[arg[2]]].select{|i|i}.size == 2
        array[arg.find{|i|array[i].nil?}] = false
        #p [arg, [array[arg[0]], array[arg[1]], array[arg[2]]]]
      end
    end
    puts array[1..-1].map{|i|
      if i
        1
      elsif i.nil?
        2
      else
        0
      end
    }
  end
end
main

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],vis[5000001];
vector<ll>v[500001];
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
    ll ans=1;
    for(int i=1; i<=n; i++)
        ans*=a;
    return ans;
}

ll cnt=0;
void go(ll start)
{
    cnt++;
    vis[start]=1;
    for(int i=0; i<v[start].size(); i++)
    {
        ll u=v[start][i];
        if(vis[u]==0)
        {
            go(u);
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,m,a,b,ans=0;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==0)
        {
            go(i);
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

string s;
set <char> st;

int main () {
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		st.insert(s[i]);
	}
	if(st.size() == s.size()) {
		cout << "yes";
	}
	else {
		cout << "no";
	}
	return 0;
}

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

int main(){
		int n;
		int a[100];
		int v;
		int min_index;
		int c=0;

		scanf("%d",&n);
		for(int i=0 ; i<n ; i++) scanf("%d",&a[i]);

		for(int i=0 ; i<n ; i++){
				min_index = i;
				for(int j=i ; j<n ; j++){
						if(a[j] < a[min_index]) min_index = j;
				}
				if(min_index != i){
						v = a[i];
						a[i] = a[min_index];
						a[min_index] = v;
						c++;
				}
		}
		for(int i=0 ; i<n-1 ; i++) printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
		printf("%d\n",c);
}




Measured memory_bytes: 2756
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  cin >>n>>m;
  int x[m],y[m],num[n],r[n];
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    }
  for(int i=1;i<n+1;i++){ 
    num[i]=1;
    r[i]=0;
    }
  r[1]=1;
  for(int i=0;i<m;i++){
    num[x[i]]--;
    num[y[i]]++;
    if(r[x[i]]==1){
      r[y[i]]=1;
      if(num[x[i]]==0){
        r[x[i]]=0;
        }
      }
      }
  int ans=0;
  for(int i=1;i<n+1;i++){
    ans+=r[i];
    }
  cout<<ans<<endl;
  return 0;
  }
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int b[n];
    for (int i=0;i<n;i++)
    scanf("%d",&a[i]);
    for (int j=0;j<n;j++)
    scanf("%d",&b[j]);
    int fac[9];
    fac[0]=1;
    for (int i=1;i<=8;i++)
    fac[i]=fac[i-1]*i;
    int attend1[9]={};
    int attend2[9]={};
    int val1=0,val2=0;
    for (int i=n-1;i>=0;i--)
    {
        int c1=0,c2=0;
        for (int j=1;j<a[(n-1)-i];j++)
        {
            if (attend1[j]==0)
            c1++;
        }
        for (int j=1;j<b[(n-1)-i];j++)
        {
            if (attend2[j]==0)
            c2++;
        }
        attend1[a[(n-1)-i]]=1;
        attend2[b[(n-1)-i]]=1;
        val1=val1+c1*fac[i];
        val2=val2+c2*fac[i];
    }
    printf("%d\n",abs(val1-val2));
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

// a >= b ?
bool comp(string a, string b){
    if(b == "-") return true;
    if(a == "-") return false;
    if(a.size() > b.size()) return true;
    if(a.size() < b.size()) return false;
    rep(i, 0, a.size()){
        if(a[i] > b[i]) return true;
        if(a[i] < b[i]) return false;
    }
    return true;
}

ll r[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<string> dp(n+1000, "-");
    rep(i, 0, m) cin >> a[i];
    dp[0] = "";
    rep(i, 0, n+1){
        if(dp[i] == "-") continue;
        for(auto e : a){
            if(!comp(dp[i+r[e]], dp[i] + (char)('0' + e))) dp[i+r[e]] = dp[i] + (char)('0' + e);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 61716
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
int w[50];
struct Node{
	int x,y;
}node[1010];
ll myabs(ll x)
{return x<0?-x:x;}
ll dis(ll x,ll y,ll xx,ll yy)
{return myabs(x-xx)+myabs(y-yy);}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		node[i]=(Node){x,y};
		if (i>1&&myabs(node[i].x+node[i].y)%2!=myabs(node[1].x+node[1].y)%2)
			return puts("-1"),0;
	}
	if (myabs(node[1].x+node[1].y)%2==1)
	{
		w[(*w)=31]=1;
		for (int i=30;i;i--) w[i]=w[i+1]*2;
		printf("%d\n",(*w));
		for (int i=1;i<=(*w);i++) printf("%d",w[i]),putchar(i==(*w)?'\n':' ');
		for (int i=1;i<=n;i++)
		{
			ll x=0,y=0;
			for (int j=1;j<=(*w);j++)
			{
				ll a=dis(x+w[j],y,node[i].x,node[i].y),b=dis(x-w[j],y,node[i].x,node[i].y),
					c=dis(x,y+w[j],node[i].x,node[i].y),d=dis(x,y-w[j],node[i].x,node[i].y);
				ll minn=min(a,min(b,min(c,d)));
				if (minn==a)
				{
					x+=w[j];
					putchar('R');
					continue;
				}
				if (minn==b)
				{
					x-=w[j];
					putchar('L');
					continue;
				}
				if (minn==c)
				{
					y+=w[j];
					putchar('U');
					continue;
				}
				y-=w[j];
				putchar('D');
			}
			putchar('\n');
		}
		return 0;
	}
	w[(*w)=32]=1; 
	for (int i=31;i>1;i--) w[i]=w[i+1]*2;
	w[1]=1;
	printf("%d\n",(*w));
	for (int i=1;i<=(*w);i++) printf("%d",w[i]),putchar(i==(*w)?'\n':' ');
	for (int i=1;i<=n;i++)
	{
		ll x=0,y=0;
		x++;putchar('R');
		for (int j=2;j<=(*w);j++)
		{
			ll a=dis(x+w[j],y,node[i].x,node[i].y),b=dis(x-w[j],y,node[i].x,node[i].y),
				c=dis(x,y+w[j],node[i].x,node[i].y),d=dis(x,y-w[j],node[i].x,node[i].y);
			ll minn=min(a,min(b,min(c,d)));
			if (minn==a)
			{
				x+=w[j];
				putchar('R');
				continue;
			}
			if (minn==b)
			{
				x-=w[j];
				putchar('L');
				continue;
			}
			if (minn==c)
			{
				y+=w[j];
				putchar('U');
				continue;
			}
			y-=w[j];
			putchar('D');
		}
		putchar('\n');
	}
	return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    int count = 0;
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
	for (int k = 0; k <= 9; k++) {
	  for (int l = 0; l <= 9; l++) {
	    if (i+j+k+l == n) {
	      count++;
	    }
	  }
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3056
s=input()
ans=10**30
for i in range(len(s)):
	p=[-1]
	for j in range(len(s)):
		if s[j]==s[i]:
			p.append(j)
	p.append(len(s))
	m=-1
	for j in range(len(p)-1):
		m=max(m,p[j+1]-p[j]-1)
	ans=min(m,ans)
print(ans)



Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(long long val):value((int)(val<0?MOD+val%MOD:val%MOD)){ }

    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const{
        if(value == 0)return 0;
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

mint dp[41][1<<18];

int main(){
    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;
    int x = X, y = x + Y, z = y + Z;
    int ma = (1 << (z + 1)) - 1, mask = 1 | (1 << Z) | (1 << (Z + Y)) | (1 << (Z + Y + X));
    dp[0][1] = 1;
    rep(i, N)rep(S, ma + 1) {
        for(int j = 1; j <= 10; ++j) {
            int T = ma & (S << j | 1);
            if((mask&T)!=mask) {
                dp[i + 1][T] += dp[i][S];
            }
        }
    }
    mint ans = mint(10).pow(N);
    rep(S, ma + 1)ans -= dp[N][S];
    cout << ans << endl;
}

Measured memory_bytes: 42240