akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,k,x[55],y[55];
vector<int> vecx,vecy;
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>x[i]>>y[i];
		vecx.push_back(x[i]);
		vecy.push_back(y[i]);
	}
	sort(vecx.begin(),vecx.end());
	sort(vecy.begin(),vecy.end());
	int ans=INF;
	for(int i:vecx){
		for(int j:vecx){
			if(i==j)continue;
			for(int l:vecy){
				for(int m:vecy){
					if(l==m)continue;
					int cnt=0;
					rep(o,n){
						if(i<=x[o]&&x[o]<=j&&l<=y[o]&&y[o]<=m)cnt++;
					}
					if(cnt>=k)ans=min(ans,(j-i)*(m-l));
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 1e5 + 10, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

vector <lli> v[N], tp;
bool mark[N];
lli dp[N];

void dfs (lli x) {
	mark[x] = true;
	for (lli u: v[x])
		if (!mark[u])
			dfs (u);
	tp.pb(x);
}

int32_t main() {
	fast;
	lli n, m, ans = 0;
	cin >> n >> m;
	for (lli i = 0; i < m; i++) {
		lli x, y;
		cin >> x >> y;
		x--, y--;
		v[x].pb(y);
	}
	for (lli i = 0; i < n; i++)
		if (!mark[i])
			dfs (i);
	reverse (all(tp));
	for (lli x: tp) {
		for (lli u: v[x])
			dp[u] = max (dp[u], dp[x] + 1);
		ans = max (ans, dp[x]);
	}
	cout << ans << '\n';
	return 0;
}


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

int A[1000000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid]) return 1;
        if(key > A[mid]) left = mid + 1;
        else if(key < A[mid]) right = mid;
    }
    return 0;
}

int main(){
    int q, k, sum = 0;
    
    cin >> n;
    rep(i, n) cin >> A[i];
    
    cin >> q;
    rep(i, q){
        cin >> k;
        if(binarySearch(k)) sum++;
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll d, c[26], s[365][26], t[365],sc[365], last[26];

void input() {
  cin >> d;
  rep(i, 26) { cin >> c[i]; }
  rep(i, d) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  rep(i, d) {
    ll T;
    cin >> T;
    t[i] = T - 1;
  }
}

// satisfactory decrease
ll satDec(ll date, ll con) {
  ll ans = 0;
  rep(i, 26) {
    if (i != con) { ans += c[i] * (date - last[i]); }
  }
  return ans;
}

// コンテストconを選んだときの満足度の変化を計算する
// 26回ループで求まる
ll satChange(ll date, ll con) { return s[date][con] - satDec(date, con); }

// 満足度を1日ごとに計算する
ll calcSat() {
  ll s = 0;
  rep(i, d) {
    last[t[i]] = i;
    s += satChange(i,t[i]);
  }
  return s;
}

void solve() {
  rep(i,26){last[i]=-1;}
  ll sat = calcSat();
  //cout << sat << endl;
  /*
  // コンテストとその日付をcontest:{日付,日付,...}で保持する
  unordered_map<ll,vll> contests;
  rep(i,d){
    contests[t[i]].push_back(i);
  }
  */
  // クエリを処理する
  ll m;
  cin >> m;
  rep(i,m){
    ll cq,q2;
    cin >> cq >> q2;
    cq--;
    q2--;
    ll q1=t[cq];
    ll befq1=-1,nextq1=d,befq2=-1,nextq2=d;
    for (ll j=cq-1; j>=0; j--){
      if (t[j]==q1){
        befq1=j;
        break;
      }
    }
    for (ll j=cq+1; j<d; j++){
      if (t[j]==q1){
        nextq1=j;
        break;
      }
    }
    for (ll j = cq - 1; j >= 0; j--) {
      if (t[j] == q2) {
        befq2 = j;
        break;
      }
    }
    for (ll j = cq + 1; j < d; j++) {
      if (t[j] == q2) {
        nextq2 = j;
        break;
      }
    }
    /*
    cout << cq << endl;
    cout << q1 << endl;
    cout << q2 << endl;
    cout << befq1 << endl;
    cout << nextq1 << endl;
    cout << befq2 << endl;
    cout << nextq2 << endl;
    */
    /*
    auto cq1Iter = lower_bound(contests[q1].begin(),contests[q1].end(),cq);
    ll befq1,nextq1;
    if (cq1Iter-contests[q1].begin()==0){
      befq1=-1;
    } else {
      befq1=contests[q1][*cq1Iter-1];
    }
    if (contests[q1].end()-cq1Iter==1){
      nextq1=d;
    } else {
      nextq1=contests[q1][*cq1Iter+1];
    }
    auto cq2Iter = lower_bound(contests[q2].begin(), contests[q2].end(), cq);
    ll befq2, nextq2;
    if (cq2Iter - contests[q2].begin() == 0) {
      befq2 = -1;
    } else {
      befq2 = contests[q2][*cq2Iter - 1];
    }
    if (contests[q2].end() - cq2Iter == 1) {
      nextq2 = d;
    } else {
      nextq2 = contests[q2][*cq2Iter + 1];
    }
    contests[q1].erase(cq1Iter);
    contests[q2]
    */

    sat = sat - s[cq][q1] - c[q1] * (cq - befq1) * (nextq1 - cq) + s[cq][q2] + 
        c[q2] * (cq - befq2) * (nextq2 - cq);
    cout << sat << endl;
    t[cq]=q2;
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
string s[6] = {"Sunny", "Cloudy", "Rainy", "Sunny", "Cloudy", "Rainy"};
int A[123456];
int main(void)
{

	int N, M;
	priority_queue<int> Q;
	cin >> N >> M;
	for (int i = 1; i <= N; ++i) {
		int  t ; scanf("%d", &t);
		Q.push(t);
	}
	while (M > 0 && !Q.empty()) {
		int x = Q.top(); Q.pop();
		Q.push(x / 2);
		M--;
	}
	LL s = 0;
	while (!Q.empty())
		s += Q.top(), Q.pop();
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 892
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S[3];
	rep(i, 0, 3)cin >> S[i];
	int t = 0;
	while (true)
	{
		if (S[t].empty())break;
		int nt = S[t].front() - 'a';
		S[t].erase(S[t].begin());
		t = nt;
	}

	cout << (char)('A' + t) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,i;
  cin>>n; 
    for( i=1;i<=9;i++)
    {
      if(n%i==0&&n/i<=9)
         break; 
    }
    if(i>9)
      cout<<"No";
    else
      cout<<"Yes";
}

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

int k, n;

void decrement(std::vector<int>&);

int main()
{
	scanf("%d%d", &k, &n);
	if (~k & 1)
	{
		printf("%d", k / 2);
		for (int i{}; i < n - 1; i++)
			printf(" %d", k);
		putchar('\n');
		return 0;
	}
	std::vector<int> ans(n, k / 2 + 1);
	int delta{n - 1};
	while (delta > 0)
	{
		decrement(ans);
		delta -= 2;
	}
	for (unsigned int i{}; i < ans.size(); i++)
		printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');

	return 0;
}

void decrement(std::vector<int>& ans)
{
	ans.back()--;
	if (!ans.back())
		ans.pop_back();
	else
		ans.resize(n, k);	
}

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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 3000 + 10;
int T;

int dp[N][N];
pair<int, int> pre[N][N];
char s[N], t[N];

string func(int x, int y)
{
    string ret = "";
    while (x > 0 && y > 0)
    {
        int prex = pre[x][y].first;
        int prey = pre[x][y].second;
        // debug(x, y, prex, prey);
        if (prex != x && prey != y)
        {
            assert(s[x] == t[y]);
            ret += s[x];
        }
        x = prex;
        y = prey;
    }
    reverse(ret.begin(), ret.end());
    // debug(ret.size());
    return ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (~scanf("%s%s", s + 1, t + 1))
    {
        int lens = strlen(s + 1);
        int lent = strlen(t + 1);

        for (int i = 0; i < lens; i++)
        {
            dp[i][0] = 0;
            pre[i][0] = {-1, -1};
        }

        for (int j = 0; j < lent; j++)
        {
            dp[0][j] = 0;
            pre[0][j] = {-1, -1};
        }

        for (int i = 1; i <= lens; i++)
        {
            for (int j = 1; j <= lent; j++)
            {
                dp[i][j] = dp[i - 1][j];
                pre[i][j] = {i - 1, j};

                if (dp[i][j - 1] > dp[i][j])
                {
                    dp[i][j] = dp[i][j - 1];
                    pre[i][j] = {i, j - 1};
                }

                if (s[i] == t[j])
                {
                    if (dp[i - 1][j - 1] + 1 > dp[i][j])
                    {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                        pre[i][j] = {i - 1, j - 1};
                    }
                }
            }
        }

        string ans = func(lens, lent);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 109512
A,B,C,X,Y = input().split(' ')

#print(A,B,C,X,Y)

ans = 10 ** 12
for i in range(0,100001):
  tmp = int(C) * 2 * i + int(A) * max(int(X)-i,0) + int(B) * max(int(Y)-i,0)
  ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 41196
count = range(1000001) 
for i in range(2, 500001):
    n = i * 2
    while n <= 1000000:
        count[n] -= (count[i] - 1) 
        n += i

ret = [0] * 1000001
ret[1] = 2
for i in range(2,1000001):
    ret[i] += count[i] + ret[i-1] - 1

t = int(raw_input())
for i in range(t):
    print ret[int(raw_input())] 

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

// DAG - directed acyclic graph

const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) {
    assert(!visited[a]);
    visited[a] = true;
    for(int b : edges[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if(in_degree[b] == 0) {
            dfs(b);
        }
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while(m--) {
        int a, b;
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int answer = 0;
    for(int i = 1; i <= n; ++i) {
        answer = max(answer, dist[i]);
    }
    printf("%d\n", answer);
}

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

int main(){
    int N; cin>>N;
    map<string,int> mp;
    for(int i=0;i<N;i++){
        string s; cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    long long ans=0;
    for(auto& p:mp){
        int n=p.second;
        ans+=(long long)n*(n-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
const int MAX = static_cast<int>(1e9);

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<bool>> board(H, vector<bool>(W));
	pair<int, int> S;
	for (int i = 0; i < H; i++) {
		string A;
		cin >> A;
		for (int j = 0; j < W; j++) {
			if (A[j] == 'S') {
				S = make_pair(i, j);
			} else if (A[j] == '#') {
				board[i][j] = true;
			}
		}
	}
	auto calc_score = [H, W](const pair<int, int>& p) {
		return min({ p.first, (H - 1) - p.first, p.second, (W - 1) - p.second });
	};
	auto calc_ans = [K](int score) {
		return ((score + K - 1) / K) + 1;
	};
	vector<vector<int>> step(H, vector<int>(W, MAX));
	typedef pair<int, int> t;
	queue<t> q;
	q.push(S);
	step[S.first][S.second] = 0;
	int ans = MAX;
	while (!q.empty()) {
		pair<int, int> pos;
		pos = q.front(); q.pop();
		int score = calc_score(pos);
		ans = min(ans, calc_ans(score));
		if (score == 0) {
			break;
		}
		if (step[pos.first][pos.second] >= K)
			continue;
		static const int dx[4] = { 1, 0, -1, 0 };
		static const int dy[4] = { 0, 1, 0, -1 };
		for (int d = 0; d < 4; d++) {
			auto p2 = pos;
			p2.first += dy[d];
			p2.second += dx[d];
			if (!board[p2.first][p2.second] && step[p2.first][p2.second] == MAX) {
				q.push(p2);
				step[p2.first][p2.second] = step[pos.first][pos.second] + 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2944
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N,A,B=LI()

print(min(N*A,B))


Measured memory_bytes: 38384
//
// Created by mamurai on 16/09/11.
//

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

char s[11];

long long int mstoi(int l, int r, char *s) {
    char t[11];
    for (int i = 0; i <= r - l; i++) {
        t[i] = s[l + i];
    }
    t[r-l+1] = '\0';
    return atoll(t);
}

void printar(int a[], int len) {
    for (int i = 0; i < len; ++i) {
        printf("a[%d] = %d\n", i, a[i]);
    }
}
long long int solve(char *s, int len, int i, int depth, int plus[]) {
    if (i == 0) {
        return atoll(s);
    } else if (depth < i) {
        long long int tmp = 0;
        for (int j = plus[depth - 1] + 1; j <= len - i + depth - 2; j++) {
            plus[depth] = j;
            tmp += solve(s, len, i, depth + 1, plus);
        }
//        printf("in depth %d %lld\n", depth, tmp);
        return tmp;
    } else if (depth == i) {
        long long int tmp = 0;
        for (int j = plus[i - 1] + 1; j <= len - 2; j++) {
            plus[i] = j;
//            printar(plus, i + 1);
            tmp += mstoi(0, plus[1], s);
//            printf("start %lld\n", mstoi(0, plus[1], s));
            for (int k = 1; k < i; ++k) {
                tmp += mstoi(plus[k] + 1, plus[k + 1], s);
//                printf("mid %lld\n", mstoi(plus[k] + 1, plus[k + 1], s));
            }
            tmp += mstoi(plus[i] + 1, len - 1, s);
//            printf("mstoi(2,2)=%lld\n", mstoi(2,2,s));
//            printf("s=%s\n", s);
//            printf("end %lld\n", mstoi(plus[i] + 1, len - 1, s));
        }
//        printf("in final %lld\n", tmp);
        return tmp;
    }
}
int main() {
    scanf("%s", s);
    int len = strlen(s);
    long long int ans = 0;
    int plus[10];
    plus[0] = -1;

    for (int i = 0; i < len; ++i) {
        ans += solve(s, len, i, 1, plus);
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0||(a+b)%3==0)
    {
        cout<<"Possible"<<endl;
    }
    else 
    {
        cout<<"Impossible"<<endl;
    }
}


Measured memory_bytes: 256
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       N: usize,
       kuji:[String;N],
    }

    let mut h = HashSet::new();
    for item in &kuji {
        h.insert(item);
    }

    echo!(h.len());
}


Measured memory_bytes: 18564
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=300005,mod=998244353;
char s[N]; int n,ans,r,b,g,rb,rg,bg;
int main()
{
	RI i; for (scanf("%d%s",&n,s+1),ans=i=1;i<=n;++i)
	ans=1LL*ans*i%mod; for (i=3*n;i;--i)
	switch (s[i])
	{
		case 'R':
			if (bg) ans=1LL*ans*(bg--)%mod; else
			if (b) ans=1LL*ans*(b--)%mod,++rb; else
			if (g) ans=1LL*ans*(g--)%mod,++rg; else ++r;
			break;
		case 'G':
			if (rb) ans=1LL*ans*(rb--)%mod; else
			if (r) ans=1LL*ans*(r--)%mod,++rg; else
			if (b) ans=1LL*ans*(b--)%mod,++bg; else ++g;
			break;
		case 'B':
			if (rg) ans=1LL*ans*(rg--)%mod; else
			if (r) ans=1LL*ans*(r--)%mod,++rb; else
			if (g) ans=1LL*ans*(g--)%mod,++bg; else ++b;
			break;
	}
	return printf("%d",ans),0;
}

Measured memory_bytes: 512
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Sep  7 21:12:24 2019
//
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scan(&n)

	bs := make([]int, n-1)
	for i := range bs {
		fmt.Scan(&bs[i])
	}
	ans := 0

	for i := range bs {
		if i == 0 {
			ans += bs[i]
		} else {
			ans += min(bs[i], bs[i-1])
		}
	}
	ans += bs[len(bs)-1]

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int a[100010];
vector<pair<int,int>> v;
int main(){
	int i,m,n;
	cin >> m >> n;
	if(m==2){
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		int cnt = n,cnt1 = 0;
		for(i=0;i<n;i++){
			if(i&1 && a[i]==1) cnt1++;
			if(!(i&1) && a[i]==2) cnt1++;
		}
		cnt = min(cnt,cnt1);
		cnt1 = 0;
		for(i=0;i<n;i++){
			if(i&1 && a[i]==2) cnt1++;
			if(!(i&1) && a[i]==1) cnt1++;
		}
		cnt = min(cnt,cnt1);
		cout << cnt << endl;
		return 0;
	}
	for(i=0;i<n;i++){
		int a; cin >> a;
		if(i==0 || v.back().first!=a){
			v.push_back({a,1});
		}else{
			v.back().second++;
		}
	}
	int cnt = 0;
	for(i=0;i<v.size();i++){
		cnt += v[i].second/2;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3808
# ABC129C - Typical Stairs
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().rstrip().split()))
    A = set(map(int, [input().rstrip() for _ in range(M)]))
    MOD = 10 ** 9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(1, N + 1):
        if i in A:
            continue
        else:
            for j in range(1, 3):
                if i - j >= 0:
                    dp[i] = (dp[i] + dp[i - j]) % MOD
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 58076
"""
Writer: SPD_9X2
https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_f
Xが偶数か奇数かは重要な気がする
長さL(<=N)の1,2で構成された文字列の問題、に変換できる
O(L)で求められばおｋ
dpか？

X == 1なら、0,2のみで構成されてればおｋ
X == 2なら、1が2つ以上入っていたら不可能 0 & 1が1つまで
X == 3なら、2を入れる場合→1は入れられないが、2を好きなだけ入れていい
            入れない場合→1を2個まで入れられる
X == 4なら、

→やはり偶奇が重要か？

とどく場合は X-1　→ X+1の移動は強制
すなわち 座標1に行ってはいけない
初手は2に行くしかない
同様にX+2には行けない
X+3に行くしかない
3には行けないから4に行くしかない
つまり2以外不可？？ 

無限に移動を続ける場合は少なくともX=奇数 2のみ以外無理
偶数の場合はX以前に奇数回1をはさむ必要あり
a→a+1と移動すると、X+a-1から先は移動できなくなる

よって2Xは絶対超えられない
あとは数え上げにどうやって落とすか
Lは固定でいいと思うんだよな
O(L)で解ければ勝ち

dp ?
総和で場合分け or Lで場合分け
総和で場合分けする場合、当然Lは異なるのでまとめる必要がある
Lの長さの移動の寄与にはNCLを掛ける必要がある
移動するときにLは1増えるんだよな…
nC(l+1) = nCl * (n-l)/(l+1)
移動処理を一気に行えばlは統一できるからおｋ？

総和SはX以上の場合 X+1+2kしかありえない
S-X以前は2のみ進軍可能、以降は自由

対称性？
1と2の数を全探索？ ならばO(N**2)でいける
1がA個,2がB個の時、最初と最後に2をいくつか置く必要がある
→後は残りの位置から1を置く場所を選べばよい

→解けたっぽい？

場合分け頑張ろう

合計がX以下の場合→完全に自由
合計が2X以上の場合→Xが奇数の場合のみ all2が可能。それ以外は死
X以上2X以下の場合
→
    S-Xが奇数である必要あり
    まず2を(S-X+1)こ消費する（前後に置く分）
    あとは自由に順列を作ってどうぞ
    
"""

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod


N,X = map(int,input().split())

mod = 998244353
fac,inv = modfac(N+10,mod)
ans = 0

for two in range(N+1):

    for one in range(N+1):

        if one + two > N:
            break
        
        dist = one + two*2
        zero = modnCr(N,one+two,mod,fac,inv)
        now = 0

        if dist < X:
            now = modnCr(one+two,one,mod,fac,inv) * zero
        elif dist == X:
            continue
        elif dist < 2*X:
            if (dist-X) % 2 == 0:
                continue
            dtwo = two - (dist-X+1)
            if dtwo >= 0:
                now = modnCr(one+dtwo,one,mod,fac,inv) * zero
        elif X % 2 == 1 and one == 0:
            now = zero

        #print (one,two,now)
        
        ans += now
        ans %= mod

print (ans)
            


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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e13;
int main() {
    int Q;
    cin >> Q;
    const int MAX = 100001;
    vector<ll> table(MAX, 1), done(MAX), acc(MAX);
    for(int i = 2; i < MAX; ++i) {
        for(int j = i * 2; j <= MAX; j += i) {
            if(!done[j]) {
                table[j] *= i;
                if(table[j] >= j * 2) done[j] = 1;
            }
        }
    }
    for(int i = 1; i <= MAX; ++i)
        acc[i] = acc[i - 1] + done[i];
    while(Q--) {
        ll N;
        cin >> N;
        cout << acc[N] << endl;
    }
    return 0;
}


Measured memory_bytes: 5196
// ACM-ICPCà\I2010 E. Å­Ìô¶

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef vector< vector< pair<int, string> > > Graph;

class Node{
public:
	int pos; string str; int prev;
	Node(int pos, string str, int prev) : pos(pos), str(str), prev(prev) {}
	bool operator < (const Node &nd) const { return str > nd.str; }
};

int main(){
	int n, a, s, g;
	int prev[480][40];
	string str[480][40];
	while(cin >> n >> a >> s >> g, n){
		Graph graph(n);
		for(int i=0;i<a;i++){
			int x, y; string lab; cin >> x >> y >> lab;
			graph[x].push_back(make_pair(y,lab));
		}
		memset(prev, -1, sizeof(prev));
		for(int i=0;i<12*n;i++)
			for(int j=0;j<n;j++) str[i][j] = "";
		priority_queue<Node> qu; qu.push(Node(s, "", -2));
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			int pos = nd.pos, size = nd.str.size();
			if(prev[size][pos]!=-1) continue;
			prev[size][pos] = nd.prev;
			str[size][pos] = nd.str;
			for(int i=0;i<graph[pos].size();i++){
				int npos = graph[pos][i].first;
				if(size + graph[pos][i].second.size() >= 12*n) continue;
				string nstr = nd.str + graph[pos][i].second;
				if(str[nstr.size()][npos]==""||nstr<str[nstr.size()][npos]){
					str[nstr.size()][npos] = nstr;
					qu.push(Node(npos, nstr, size*n+pos));
				}
			}
		}
		int minpos = -1;
		string ans = "";
		for(int i=0;i<12*n;i++){
			if(str[i][g]=="") continue;
			if(ans == ""||ans > str[i][g]){
				ans = str[i][g];
				minpos = i;
			}
		}
		bool flag = (minpos != -1);
		bool visit[40];
		memset(visit, false, sizeof(visit));
		int cur = minpos*n+g;
		while(flag&&cur!=-2){
			if(visit[cur%n]) flag = false;
			visit[cur%n] = true;
			cur = prev[cur/n][cur%n];
		}
		cout << (flag ? ans : "NO") << endl;
	}
}

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

int main()
{
        int n;
        cin >> n;
        vector<int> L(n);
        for (int i = 0; i < n; ++i)
                cin >> L[i];
        int dp[2005] = {};
        // dp[x] : 0からxまでx+1の中から選ぶ
        dp[0] = dp[1] = 0;
        sort(L.begin(), L.end());
        for (int i = 2; i < n; ++i)
        {
                // i番目を選ぶ
                // 0からiまでの中から選ぶ
                // L[t] <= L[s] <= L[i]
                int ans = 0;
                for (int s = i - 1; s >= 0; --s)
                        for (int t = s - 1; t >= 0; --t)
                        {
                                if (L[i] >= L[s] + L[t])
                                        break;
                                ++ans;
                        }
                dp[i] = dp[i - 1] + ans;
        }
        cout << dp[n - 1] << endl;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int count = 1;
    string a = "";
    char l = s[0];
    for(int i=0; i<n; i++){
        if(s[i] != l){
            count ++;
            l = s[i];
        }
    }
    cout << count << endl;
}

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

int main() {
    int d;
    cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve"<< endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;

}

Measured memory_bytes: 256
S = input()
bin_S = int(S, 2)
N = len(S)

b = 0
w = 1
#
bw = []
for i in range(int(N / 2)):
    bw.append(b)
    bw.append(w)
if len(bw) < N:
    bw.append(b)
bw = ''.join(map(str, bw))

bin_bw = int(bw, 2)

#
wb = []
for i in range(int(N / 2)):
    wb.append(w)
    wb.append(b)
if len(wb) < N:
    wb.append(w)
wb = ''.join(map(str, wb))

bin_wb = int(wb, 2)
#
bw_xor_S = format(bin_bw ^ bin_S, 'b')
wb_xor_S = format(bin_wb ^ bin_S, 'b')
bwcout = 0
wbcout = 0
for i in range(len(bw_xor_S)):
    if bw_xor_S[i] == '1':
        bwcout += 1

for i in range(len(wb_xor_S)):
    if wb_xor_S[i] == '1':
        wbcout += 1

print(min(bwcout,wbcout))



Measured memory_bytes: 10376
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 7;
char lst[Max][Max];
int ls[Max][Max];

int main()
{
	ll n, k;
	cin >> n >> k;
	ll sum = 1;
	for (int i = 1; i <= n; i++)
	{
		sum += min(sum, k);
	}
	cout << sum;
}

Measured memory_bytes: 3156
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


void Main(int argc, char** argv) {
    int h, w, k;
    cin>>h>>w>>k;
    string s[h];
    int cake[h][w];
    rep(i,h) rep(j,w) cake[i][j] = 0;
    rep(i,h) {
        cin>>s[i];
    }
    int now = 0;

    bool empty[h];
    rep(i,h)  {
        bool e = true;
        rep(j,w) {
            if (s[i][j] == '#') {
                e = false;
            }
        } 
        empty[i] = e;
    }

    int row = 0;
    rep(i,h) {
        if(empty[i]) {
            row++;
        } else {
            break;
        }
    }

    rep(i,h) {
        if (i < row) continue;
        if (empty[i]) {
            rep(j,w) cake[i][j] = cake[i-1][j];
            continue;
        }
        bool flag = false;
        rep(j,w) {
            if (s[i][j] == '#' && j == 0) {
                if (flag) {
                    now++;
                }
                flag = true;
                now++;
            } else if (j == 0) {
                now++;
            } else if (s[i][j] == '#') {
                if (flag) {
                    now++;
                }
                flag = true;
            }
            cake[i][j] = now;
        }
    }

    if(row != 0) {
        for(int i = row - 1; i >= 0; i--) {
            rep(j, w) {
                cake[i][j] = cake[i+1][j];
            }
        }
    }

    rep(i,h) {
        rep(j,w) {
            cout << cake[i][j] << " ";
        }
        cout << endl;
    }

}

signed main(int argc, char** argv) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main(argc, argv);
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    int k, x;
    cin >> k >> x;
    
    if(500*k >= x) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	string s;
	cin >> s;
	int n = s.size() + 1;
	int k[2][500001] = {};
	// hidarikara
	// cout << s << " " << n << endl;
	// rep (i, n - 1) cout << (s[i] == '<' ? 0 : 1); cout << endl;
	for (int i = 0; i < n - 1; i++) {
		// cout << i + 1 << " ";
		if (s[i] == '<') k[0][i + 1] = k[0][i] + 1;
		else k[0][i + 1] = 0;
	}

	for (int i = n - 1; i > 0; i--) {
		if (s[i - 1] == '>') k[1][i - 1] = k[1][i] + 1;
		else k[1][i - 1] = 0;
	}
	ll ans = 0;
	rep (i, n) {
		ans += (ll)max(k[0][i], k[1][i]);
	}
	cout << ans << endl;
	// rep(i, n) cout << k[0][i] << " "; cout << endl;
	// rep(i, n) cout << k[1][i] << " "; cout << endl;

	return 0;
}

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

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if(a%2 == b%2){
        cout << abs(a- (a+b)/2) << endl;
    }else{
        cout << min(a-1,n-b) + 1 + (b-a-1)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sf(a) scanf("%d",&a)
#define MX 1100010
#define inf 1e9
#define m_p make_pair
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))
#define MOD 100000

int main() {
    int n;
    sf(n);

    vector<string> vs(n);

    map<string,int> mps;
    for(int i=0;i<n;i++){
        cin >> vs[i];
        string s = vs[i];
        mps[s] = i+1;
    }
    vector<string> vs1(n);
    vs1 = vs;

    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            string s1 = vs[j];
            string s2 = vs[j+1];
            int a = s1[1];
            int b = s2[1];
            if(a>b){
                swap(vs[j],vs[j+1]);
            }
        }
    }

    for(int i=0;i<n;i++){
        if(i+1==n) cout << vs[i] << endl;
        else cout << vs[i] << " ";
    }


    bool flag1 = false;
    for(int i=1;i<n;i++){
        string s1 = vs[i];
        string s2 = vs[i-1];
        if(s1[1]==s2[1]){
            int val1 = mps[vs[i]];
            int val2 = mps[vs[i-1]];
            if(val1 < val2){
                flag1 = true;
                break;
            }
        }
    }

    if(flag1) cout << "Not stable" << endl;
    else cout << "Stable" << endl;


    for(int i=0;i<n;i++){
        int mn = i;
        string s2 = vs1[mn];
        int b = s2[1]-'0';
        for(int j=i+1;j<n;j++){
            string s1 = vs1[j];
            int a = s1[1]-'0';
            if(a < b){
                mn = j;
                b = a;
            }
        }
        swap(vs1[i],vs1[mn]);
    }

    for(int i=0;i<n;i++){
        if(i+1==n) cout << vs1[i] << endl;
        else cout << vs1[i] << " ";
    }

    bool flag2 = false;
    for(int i=1;i<n;i++){
        string s1 = vs1[i];
        string s2 = vs1[i-1];
        if(s1[1]==s2[1]){
            int val1 = mps[vs1[i]];
            int val2 = mps[vs1[i-1]];
            if(val1 < val2){
                flag2 = true;
                break;
            }
        }
    }


    if(flag2) cout << "Not stable" << endl;
    else cout << "Stable" << endl;

    return 0;
}



Measured memory_bytes: 3244
//====== begin of bisma c++ template===========
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))

//=======binarysearch===========
int bs(vector<int>&a,int que){
 auto it=lower_bound(a.begin(),a.end(),que);
 if(*it==que){
    return it-a.begin();
 }
 return -1;
}
//========binarysearch=========



//=======SUBSET WITH BRUTEFORCE=============
void subsets(int S[], int n) {
     int nSub = 1<<n; 
     for(int i=0; i<nSub; i++){
          cout<<"{ ";//optional
          for(int k=0; k<n; k++){
               //if the k-th bit is set
               if( (1<<k) & i){
                    cout<<S[k]<<" ";
               } 
          }
          cout<<"}\n"; //optional
     }
}
//======SUBSET WITH BRUTE FORCE================


//======permuatate all ==================
void permutate(){
int n,x;
cin>>n;

vector<int> permutation;
for (int i = 0; i < n; i++) {
    cin>>x;
permutation.push_back(x);
}
do {
 rep(i,0,n-1) cout<<permutation[i];
 cout<<endl;
} while (next_permutation(permutation.begin(),permutation.end()));

}
//====permuatate all======================





//=====check prime========================
bool isprime(int x)
{
  if ( x == 2 ) return true;
  if ( x  < 2 ) return false;
  for ( int i = 2; i * i <= x; i++ )
    if ( x % i == 0 ) return false;
  return true;
}
//======check prime=====================



//======= the end of bisma c++ template ============



int main(){


int N, M, sz[100009];
bool ap[100009];
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M), ap[1] = 1;
for (int i=1; i<=N; i++)
    sz[i] = 1;
while (M --)
{
    int x, y;
    scanf ("%d %d", &x, &y), sz[x] --, sz[y] ++;
    if (ap[x])
    {
        ap[y] = 1;
        if (sz[x] == 0) ap[x] = 0;
    }
}
int sol = 0;
for (int i=1; i<=N; i++)
    sol += (ap[i] == 1);
printf ("%d\n", sol);

return 0;
}














Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1e+8;
int ans;


void solve( const string& s, int k, int l, int r, int t, int cnt){
	if( k == s.size() ){
		ans = min( ans, cnt );
		return;
	}
	
	if( t == 0 ){	//テ・ツ渉ウティツカツウテ・ツ仰陛」ツ?凝」ツ??
		int ly = (( l - 1) % 3) + 1;	//テ・ツキツヲy
		int next = s[k] - '0';
		int ry = (( next - 1) % 3) + 1;	//テヲツャツ。テ」ツ?ョテ・ツ渉ウy	
		
		if(ly <= ry){	//テ・ツ仰陛」ツ?湘」ツ?ィテ」ツ??
			solve( s, k + 1, l, next, (t + 1) % 2, cnt);
		}else{	//テ・ツ仰陛」ツ?凝」ツ?崚」ツ?ェテ」ツ??」ツ?ィテ」ツ??
			solve(s, k + 1, next, r, t, cnt + 1);
		}
	}else{	//テ・ツキツヲティツカツウテ・ツ仰陛」ツ?凝」ツ??
		int ry = ((r - 1) % 3) + 1;
		int next = s[k] - '0';
		int ly = (( next - 1) % 3) + 1; 
		
		if(ly <= ry){	//テ・ツ仰陛」ツ?湘」ツ?ィテ」ツ??
			solve(s, k + 1, next, r, ( t + 1 ) % 2, cnt );
		}else{	//テ・ツ仰陛」ツ?凝」ツ?崚」ツ?ェテ」ツ??」ツ?ィテ」ツ??
			solve( s, k + 1, l, next, t, cnt + 1);
		}
			
	}
}

int main(){
	string s;
	while( cin >> s, s != "#"){
		ans = INF;
		for(int i = 1; i <= 9; i++){
			if(i == 5) continue;
			solve(s, 0, i, 0, 0, 0);
			solve(s, 0, 0, i, 1, 0);
		}
		cout << ans << endl;
	}
	
}

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N, M = readInts()
  A = readInts()
  BC = [readInts() for _ in range(M)]

  A.sort()
  BC.sort(key=lambda bc: -1 * bc[1])

  cur = 0
  for B, C in BC:
    count = 0
    while count < B and cur < len(A) and A[cur] < C:
      A[cur] = C
      count += 1
      cur += 1

  print(sum(A))

if __name__ == "__main__":
  main()


Measured memory_bytes: 30144
#include <iostream>
using namespace std;
int main() {
  int x, f = 0; cin >> x;
  int len, tmp = x;
  while(tmp != 0) {
    f += tmp % 10;
    tmp /= 10;
  }
  cout << ((x % f == 0) ? "Yes" : "No") << endl; 
}

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

int main(){
    string s;
    deque<char> sq;
    cin >> s;
    int n;
    cin >> n;
    rep(i,s.size()){
        sq.push_back(s.at(i));
    }
    bool rev_fl = false;
    rep(i,n){
        int a;
        cin >> a;
        if(a == 1){
            rev_fl = !rev_fl;
        } else {
            int b;
            char c;
            cin >> b >> c;
            if(b == 1){
                if(rev_fl){
                    // back
                    sq.push_back(c);
                }else {
                    // front
                    sq.push_front(c);
                }
            }else {
                if(rev_fl){
                    // front
                    sq.push_front(c);
                }else{
                    // back
                    sq.push_back(c);
                }
            }
        }
    }
    if(rev_fl){
        while(!sq.empty()){
            cout << sq.back();
            sq.pop_back();
        }
        cout << endl;
    }else {
        while(!sq.empty()){
            cout << sq.front();
            sq.pop_front();
        }
        cout << endl;
    }
    return 0;
} 

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

using namespace std;


bool test(vector<vector<int > >v,int h,int w,int n){
	bool flag[31][31]={};
	bool clear_flag=1;
	int count=1;
	int down=0;
	while(clear_flag==1){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				flag[i][j]=0;
			}
		}
		clear_flag=0;
		for(int i=0;i<h;i++){
			count =1;
			for(int j=0;j<w-1;j++){
				if(v[i][j]==v[i][j+1]&&v[i][j]!=0){
					count +=1;
				}else{
					if(count>=n){
						clear_flag=1;
						for(int k=0;k<count;k++){
							flag[i][j-k]=1;
						}
					}
					count =1;
				}
			}
			if(count>=n){
				clear_flag=1;
				for(int k=0;k<count;k++){
					flag[i][w-1-k]=1;
				}
			}
			count =1;
		}
		for(int j=0;j<w;j++){
			count =1;
			for(int i=0;i<h-1;i++){
				if(v[i][j]==v[i+1][j]&&v[i][j]!=0){
					count +=1;
				}else{
					if(count>=n){
						clear_flag=1;
						for(int k=0;k<count;k++){
							flag[i-k][j]=1;
						}
					}
					count =1;
				}
			}
			if(count>=n){
				clear_flag=1;
				for(int k=0;k<count;k++){
					flag[h-1-k][j]=1;
				}
			}
			count =1;
		}
		for(int j=0;j<w;j++){
			down=0;
			for(int i=h-1;i>=0;i--){
				if(flag[i][j]==1){
					down+=1;
					v[i][j]=0;
				}else{
					if(down!=0){
						v[i+down][j]=v[i][j];
						v[i][j]=0;
					}
				}
			}
		}
	}

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(v[i][j]!=0){
				return 0;
			}
		}
	}
	return 1;
}

int main(){
	int h,w,n,tmp_v1,down;
	bool flag;
	cin >> h >> w >> n;
	string s;
	vector<vector<int> > v,v1;
	for(int i=0;i<h;i++){
		cin >> s;
		vector<int>tmp;
		for(int j=0;j<w;j++){
			if(s[j]=='.'){
				tmp.push_back(0);
			}else{
				tmp.push_back(s[j]-'@');
			}
		}
		v.push_back(tmp);
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			v1 = v;
			tmp_v1=v1[i][j];
			v1[i][j]=v1[i][j+1];
			v1[i][j+1]=tmp_v1;
			for(int j=0;j<w;j++){
				down=0;
				for(int i=h-1;i>=0;i--){
					if(v1[i][j]==0){
						down+=1;
					}else{
						if(down!=0){
							v1[i+down][j]=v1[i][j];
							v1[i][j]=0;
						}
					}
				}
			}	
			flag = test(v1,h,w,n);
			if(flag==1){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3184
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=[input() for i in range(n)]
lst=[0]*n

def chenge(m):
    nn,mm=m.split(".")
    mm+=(9-len(mm))*"0"
    return int(nn+mm)

for i in range(n):
    if "." in a[i]:
        lst[i]=chenge(a[i])
    else:
        lst[i]=int(a[i]+9*"0")

# print(lst)

tf=[0]*n
for i in range(n):
    mm=lst[i]
    t,f=0,0
    while mm%2==0:
        t+=1
        mm//=2
    while mm%5==0:
        f+=1
        mm//=5
    tf[i]=(t,f)
# print(tf)

rui=[[0]*50 for i in range(50)]
for i in range(n):
    t,f=tf[i]
    rui[t][f]+=1

for i in range(49):
    for j in range(49):
        rui[48-i][48-j]+=rui[49-i][48-j]+rui[48-i][49-j]-rui[49-i][49-j]
# print(rui)

ans=0
for i in range(n):
    t,f=tf[i]
    ans+=rui[max(0,18-t)][max(0,18-f)]
    if t>=9 and f>=9:
        ans-=1
    # print(rui[max(0,18-t)][max(0,18-f)])
print(ans//2)

Measured memory_bytes: 98512
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

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

  vector<long long> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  sort(h.begin(), h.end());

  long long ttl = 0;
  for(int i = 0; i < (n-k); i++){
    ttl += h[i];
  }

  cout << ttl << endl;
}


Measured memory_bytes: 1792
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
k=0;
a=[]
for i in range(N):
    a.append(list(map(int, input().split())))


for i in range(N):
    s=0
    for j in range(M):
        s+=a[i][j]*B[j]

    if s+C>0:
        k+=1

print(k)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>

using namespace std;
int a,b;
int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.inp","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> a >> b;
	if (a<=0 and b>=0) cout << "Zero";
	else
	if (a>0 and b>0) cout << "Positive";
	else
	if (a<0 and b<0)
	{
		if ((abs(a)-abs(b)+1)%2==0) cout << "Positive";
		else cout << "Negative";
	}
	return 0;
}

Measured memory_bytes: 256
import math
n, d = map(int, input().split())

point = []
for i in range(n):
    tmp = list(map(int, input().split()))
    point.append(tmp)

count = 0
for i in range(n):
    for j in range(i+1, n):
        cal = 0
        for y, z in zip(point[i], point[j]):
            cal += (y - z) ** 2
        # print(math.sqrt(cal))
        if math.sqrt(cal).is_integer():
            count += 1


print(count)


Measured memory_bytes: 3064