akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([0])
    color = [0]*N
    color[0] = 1
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if color[nv]==0:
                color[nv] = -color[v]
                q.append(nv)
            else:
                if color[nv]==color[v]:
                    return [0]*N
        
    return color

N, M = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

color = bfs()

if color==[0]*N:
    print(N*(N-1)//2-M)
else:
    b = color.count(1)
    w = N-b
    print(b*w-M)

Measured memory_bytes: 88416
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
const int MAXN = 200500;

int n;
ll A[MAXN], S[MAXN], X[MAXN];

int main(){
//	freopen("input.txt", "r", stdin);
	while(scanf("%d", &n) == 1){
        forn(i, n)scanf("%lld", &A[i]);
        S[0] = X[0] = A[0];
        forr(i, 1, n){
            S[i] = S[i-1] + A[i];
            X[i] = X[i-1]^A[i];
        }
        ll ans = 0;
        forn(i, n){
            int l = i, r = n;
            while(r - l > 1){
                int m = (l+r)/2;
                if((S[m] - (i ? S[i-1] : 0)) == (X[m] ^ (i ? X[i-1] : 0)))l = m;
                else r = m;
            }
            int t = l - i + 1;
//            printf("Para %d: t = %d\n", i, t);
            ans += (ll)t;// * (t+1)/2;
        }
        printf("%lld\n", ans);
    }
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    int n, t, a[112345], m[112345], d[112345];
    cin >> n >> t;
    REP(i, n)
    {
        cin >> a[i];
    }

    m[n] = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        m[i] = max(a[i], m[i + 1]);
        d[i] = m[i] - a[i];
    }

    //t = (t / 2) * 2;

    sort(d, d + n);

    int ans = 0;
    int i = n - 1;
    d[n] = d[n - 1];
    while (d[i] == d[i + 1] && i >= 0)
    {
        ans++;
        i--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  if(A<=8 && B<=8)  cout << "Yay!" << endl;
  else  cout << ":(" << endl;

  return 0;
}


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

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

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

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

int main()
{
    string S;
    ll K;
    cin >> S >> K;

    if(SZ(S) == 1) PR(S[0]);
    else {
        ll c = 0;
        while(c < MIN(SZ(S),K) && S[c] == '1') ++c;
        PR(S[MIN(c,K-1)]);
    }

    return 0;
}

/*

1113



*/

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <memory>
struct Cell {
	static int i;
	const int id;
	Cell() :id(++i) {};
	virtual Cell *find() {
		return nullptr;
	}
	virtual void join(Cell &other) {}
	virtual bool is_blasted() const { return true; }
	virtual char name() const { return 'C'; }
	virtual char p_name() { return name(); }
	virtual int p_id() { return id; }
}; 
int Cell::i = 0;
struct Bomb :public Cell {
	Cell *u;
	Cell *find() override {
		if (u) {
			return u = u->find();
		}
		else {
			return this;
		}
	}
	void join(Cell &other) override {
		if (u) {
			u->join(other);
		}
		else {
			u = (other.find() == this) ? nullptr : other.find();
		}
	}
	bool is_blasted() const override {
		if (u) {
			return u->is_blasted();
		}
		else {
			return false;
		}
	}
	char name() const override { return 'B'; }
	char p_name() override {
		if (u) {
			return u->find()->p_name();
		}
		else {
			return name();
		}
	}
	int p_id() override { return find()->id; }
};
struct Fuse :public Cell {
	Cell *find() override {
		return this;
	}
	void join(Cell &other) override {
		if (&other != this) {
			other.join(*this);
		}
	}
	bool is_blasted() const override {
		return true;
	}
	char name() const override { return 'F'; }
};
int to_bin(const int &n) {
	if (n == 0)
		return 0;
	else
		return (to_bin(n / 10) << 1) + (n & 1);
}
void show(std::vector<std::shared_ptr<Cell>> &vec) {
	for (auto &v : vec) {
		std::cout << v->p_id();
	}
	std::cout << std::endl;
}
int main() {
	int n;
	std::cin >> n;
	for (auto i = 1; i <= n; ++i) {
		std::vector<std::vector<std::shared_ptr<Cell>>> vector(8, std::vector<std::shared_ptr<Cell>>(8));
		for (auto a = 0; a < 8; ++a) {
			int idx = 1 << 7;
			int in;
			std::cin >> in;
			in = to_bin(in);
			for (auto b = 0; b < 8; ++b) {
				if ((in & idx) != 0) {
					vector.at(a).at(b) = std::make_shared<Bomb>(Bomb());
				}
				else {
					vector.at(a).at(b) = std::make_shared<Cell>(Cell());
				}
				idx >>= 1;
			}
		}
		for (auto a = 0; a < 8; ++a) {
			for (auto b = 0; b < 7; ++b) {
				for (auto d = 1; d < ((8 - b < 4) ? (8 - b) : 4); ++d) {
					vector.at(a).at(b)->join(*vector.at(a).at(b + d));
					vector.at(b).at(a)->join(*vector.at(b + d).at(a));
				}
			}
		}
		Fuse fuse = Fuse();
		{
			int x, y;
			std::cin >> x >> y;
			vector.at(y - 1).at(x - 1)->join(fuse);
		}
		std::cout << "Data " << i << ":\n";
		for (const auto &vec : vector) {
			for (const auto &v : vec) {
				if (v->is_blasted()) {
					std::cout << 0;
				}
				else {
					std::cout << 1;
				}
				//std::cout << v->p_id() << "-";
			}
			std::cout << '\n';
		}
	}
}

Measured memory_bytes: 2976
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
string a,b;

int main(){
  string ans = "No";
  cin >> a >> b;
  int t = stoi(a+b);
  REP(i,1000){
    if(t==i*i) ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0; j = M
for i in range(N+1):
    if da[i] > K:
        break
    while db[j] > K - da[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 48592
n = gets.to_i
as = gets.split.map(&:to_i)

sum_all = as.inject(:+)

sum = 0
near_half = 0
as.each do |a|
  sum += a
  if (near_half - (sum_all-near_half)).abs > (sum - (sum_all-sum)).abs
      near_half = sum
  end
end
puts (near_half - (sum_all-near_half)).abs


Measured memory_bytes: 16132
#include<iostream>
using ll = long long;
using namespace std;
ll X;
ll Y;
void func(ll i, ll num){
    if(num > Y){
        cout << i;
    }
    else {
        num *= 2;
        i++;
        func(i, num);
    }
}
int main(){
    cin >> X >> Y;
    func(0, X);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static long exp(int n){
        if(n == 0)
            return 1;
        if(n == 1)
            return 2;
        if(n % 2 == 1){
            long result = exp(n / 2);
            return 2 * result * result;
        }else{
            long result = exp(n / 2);
            return result * result;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int[] ar = new int[n];
        for(int i =0; i < n; i++)
            ar[i] = sc.nextInt();
        /*long count = 0;
        int total, numElm;
        long limit = exp(n);
        for(long i = 1; i < limit; i++){
            total = 0;
            numElm = 0;
            for(int j = 0; j < n; j++){
                if((i & (1 << j)) >> j == 1) {
                    total += ar[j];
                    numElm += 1;
                }
            }
            if(numElm > 0 && (numElm * a == total))
                count += 1;
        }
        System.out.println(count);*/
        long[][][] dp = new long[n + 1][n + 1][50*50 + 1];
        dp[0][0][0] = 1;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= n; j++){
                for(int k = 0; k <= n * a; k++){
                    if(j > 0 && (k - ar[i - 1] >= 0))
                        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - ar[i - 1]];
                    else
                        dp[i][j][k] = dp[i-1][j][k];
                }
            }
        }
        long count = 0;
        for(int k = 1; k <= n; k++){
            count += dp[n][k][k * a];
        }
        System.out.println(count);
    }
}


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

int main(){
    int n;
    cin >> n;
    pair<int,int> ba[100000];
    set<int> sa, sb;

    bool f = false;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        ba[i].second = a;
    }
    for(int i=0;i<n;++i){
        int b;
        cin >> b;
        ba[i].first = b;
    }
    
    for(int i=0;i<n;++i){
        int a, b;
        tie(b, a) = ba[i];
        if(sa.count(a) || sb.count(b) || a==b) f = true;
        sa.insert(a);
        sb.insert(b);
    }

    sort(ba, ba+n);
    if(f){
        int a[100000], b[100000];
        for(int i=0;i<n;++i) tie(b[i], a[i]) = ba[i];
        sort(a, a+n);
        sort(b, b+n);
        for(int i=0;i<n;++i){
            if(a[i] > b[i]){
                cout << "No" << endl;
               return 0;
            }
        }
        cout << "Yes" << endl;
    }else{
        int a[100000], b[100000], c[100000];
        map<int,int> ai;
        for(int i=0;i<n;++i) tie(b[i], a[i]) = ba[i];
        sort(a, a+n);
        sort(b, b+n);
        for(int i=0;i<n;++i){
            ai[a[i]] = i;
        }
        for(int i=0;i<n;++i){
            c[i] = ai[ba[i].second];
        }
        int p = c[0], cnt = 0;
        do{
            p = c[p];
            ++cnt;
        }while(p != c[0]);

        if(cnt < n){
            for(int i=0;i<n;++i){
                if(a[i] > b[i]){
                    cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
        }else{
            for(int i=0;i<n-1;++i){
                if(a[i+1] <= b[i]){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            cout << "No" << endl;
        }       
    }

    return 0;
}

/*
1 2 3
v123
v132
v213
 231
 312
v321

1 2 3 3 4 6
2 2 3 3 4 8
*/

Measured memory_bytes: 16256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define FOR(i, a, b) for(i=a; i<b; ++i)
#define EFOR(i, a, b) for(i=a; i>b; --i)

#define MAXN 100000
#define MAXX 100000000

int moveLen(int *a, int start, int end) {
	//printf("s %d e %d\n", start, end);
	int absStart = abs(a[start]);
	int absEnd = abs(a[end]);
	if (a[start]<0 && a[end]<0)
		return absStart;
	else if (a[start]>0 && a[end]>0)
		return absEnd;
	else
		return min(2*absStart+absEnd, 2*absEnd+absStart);
}

void soluver(int *nums, int numsSize, int k) {
	int i,j;
	int tmp = 0;
	int pathMin = 3*MAXX+1;

	if (k>numsSize) {
		return;
	}

	EFOR(i, numsSize-1, -1) {
		if (nums[i]<0)
			break;
	}

	int start = max(i+1-k, 0);
	int end = min(numsSize-k, start+k);

	//printf("s %d e %d\n", start, end);

	FOR(i, start, end+1) {
		tmp = moveLen(nums, i, i+k-1);

		if (tmp<=pathMin)
			pathMin = tmp;
	}
	printf("%d\n", pathMin);
	return;
}

int main() {
	int i,n,k;
	int a[MAXN] = {0};

	scanf("%d %d", &n, &k);

	FOR(i, 0, n) {
		scanf("%d", &a[i]);
	}

	soluver(a, n, k);
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<stdio.h>

using namespace std;



int main(){
    int n;
    cin >> n;
    int v[n], c[n];
    for (int i = 0; i < n; i++)
        cin >> v[i];
    
    int ans = 0;
    for (int i = 0; i < n; i++){
        cin >> c[i];
        int gap = v[i] - c[i];
        if (gap > 0)
            ans += gap;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//Optional FAST
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
 
//Required Libraries
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
//Required namespaces
 
using namespace std;
using namespace __gnu_pbds;
//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll z[1001][11]={0};
int main()
{/*
    
   #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif 
    */
    fio;
    ll n;
    cin>>n;
    ll a[n];
    forin(i,0,n-1)
    {
        cin>>a[i];
    }
    ll mx=n;
    ll ans=0;
    forin(i,0,n-1)
    {
        mx=min(a[i],mx);
        if(a[i]==mx)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

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

signed main() {
  INIT;
	VAR(int, h, w);
	VEC(string, t, h);

	REP(hi, h) {
		REP(wi, w) {
			if (t[hi][wi] == '#') d[hi][wi] = -1;
		}
	}
	
	REP(hi, h) {
		REP(wi, w) {
			if (d[hi][wi] >= 0) continue;
			REP(i, 8) {
				int x = wi + dx[i];
				int y = hi + dy[i];
				if (!(0 <= x && x < w &&
							0 <= y && y < h )) continue;
				if (d[y][x] < 0) continue;
				
				d[y][x]++;
			}
		}
	}

	REP(hi, h) {
		REP(wi, w) {
			if (d[hi][wi] < 0) cout << "#";
			else cout << d[hi][wi];
		}
		BR;
	}
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2*1e5+5;
long long n,a[N],b[N];
long long ans=0;
int main()
{
    cin>>n;
    int f=0;
    ans=0;
    for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
            ans+=a[i];
            if(a[i]!=b[i])
                f=1;
        }
    if(!f)
    {
        cout<<0<<endl;
    }
    else
    {
        //sort(a,a+n);
        //sort(b,b+n);
        long long p=2000000000+7;
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])
                p=min(p,b[i]);
        }
        cout<<ans-p<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
from collections import deque
 
s=input()
sd=deque(s)
d=deque()
while(len(sd)>0):
  crr = sd.popleft()
  if(len(d)<1):
    d.append(crr)
    continue
  if(len(d)>=1 and d[-1]!=crr):
    d.pop()
  else:
    d.append(crr)
print(len(s)-len(d))

Measured memory_bytes: 4212
import numpy as np
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
sum=np.sum(b)
for i in reversed(range(n)):
  k = a[i+1]
  l = a[i]
  m = b[i]
 
  a[i+1] = max(k-m, 0)
  b[i] = max(m-k, 0)
 
  a[i] = max(l-b[i], 0)
  b[i] = max(b[i]-l, 0)
postsum=np.sum(b)
print(sum-postsum)

Measured memory_bytes: 27324
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
A.sort()
chk = [True]*1000001
if n == 1:
    ans = 1
else:
    for i in range(n):
        num = A[i]
        if chk[num] == True:
            if i == 0:
                if num != A[i+1]:
                    ans += 1
                for j in range(num, 1000001, num):
                    chk[j] = False
            elif i == n-1:
                if num != A[n-2]:
                    ans += 1
            else:
                if num != A[i+1] and num != A[i-1]:
                    ans += 1
                for j in range(num, 1000001, num):
                    chk[j] = False
print(ans)

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

using namespace std;


bool comparator(int x, int y)
{
    if(x % 10 == 0  || y % 10 == 0) return ((x % 10) <= (y % 10));
    else return  ((x % 10) > (y % 10));
}

int main()
{

    vector<int> dishes;
    for(int i =0; i < 5; ++i)
    {
        int t;
        cin >> t;
        dishes.push_back(t);
    }

    sort(dishes.begin(), dishes.end(), comparator);

//    for(int x : dishes) cout << x << endl;

    int sum = 0;
    for(int i = 0; i < dishes.size(); ++i)
    {
        if(i == 4 || dishes[i] % 10 == 0)
        {
            sum += dishes[i];
        } else
        {
            sum += (dishes[i] + (10 - (dishes[i] % 10) ));
        }
    }

    cout << sum << "\n";

    return 0;
}


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

typedef long long ll;

int main() {
  ll N;
  ll A, B;
  cin >> N >> A >> B;
  ll ans;
  if (A <= B) {
    if (N > 1) {
      ans = ((N - 2) * B - (N - 2) * A) + 1;
    } else {
      if (A == B) ans = 1;
      else ans = 0;
    }
  } else {
    ans = 0;
  }
  // 解答
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Mon Apr  2 23:49:05 2018
//
package main

import (
	"fmt"
)

var N, M int

func main() {
	fmt.Scan(&N, &M)
	boxes := make([]int, N)
	reds := make([]bool, N)

	for i := range boxes {
		boxes[i] = 1
	}
	reds[0] = true
	for i := 0; i < M; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		x--
		y--
		boxes[x]--
		boxes[y]++
		if reds[x] {
			reds[y] = true
		}
		if boxes[x] == 0 {
			reds[x] = false
		}
	}

	count := 0
	for i := range reds {
		if reds[i] {
			count++
		}
	}

	fmt.Println(count)
}


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

typedef long long lint;
const int maxn = 200005;

int n, Q, tot;
int fa[maxn], d[maxn];
lint ans;

struct edge
{
	int u, v, w;
	bool operator < (const edge &a) {
		return w < a.w;
	}
} e[maxn * 2];

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int find(int x)
{
	if (fa[x] == x) return x;
	return fa[x] = find(fa[x]);
}

int main()
{
	n = gi(); Q = gi();
	memset(d, 63, sizeof(int) * n);
	for (int u, v, w, i = 1; i <= Q; ++i) {
		u = gi(); v = gi(); w = gi();
		e[++tot] = (edge) {u, v, w};
		d[u] = min(d[u], w + 1); d[v] = min(d[v], w + 2);
	}

	d[0] = min(d[0], d[n - 1] + 2); for (int i = 1; i < n; ++i) d[i] = min(d[i], d[(i - 1 + n) % n] + 2);
	d[0] = min(d[0], d[n - 1] + 2); for (int i = 1; i < n; ++i) d[i] = min(d[i], d[(i - 1 + n) % n] + 2);
	for (int i = 0; i < n - 1; ++i) e[++tot] = (edge) {i, i + 1, d[i]}; e[++tot] = (edge) {n - 1, 0, d[n - 1]};

	sort(e + 1, e + tot + 1);
	for (int i = 0; i < n; ++i) fa[i] = i;
	for (int i = 1, j = 1; i < n; ++i) {
		while (find(e[j].u) == find(e[j].v) && j <= tot) ++j;
		fa[find(e[j].u)] = e[j].v; ans += e[j].w;
	}

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


Measured memory_bytes: 7168
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# a,b,c = map(int, input().split())
# n = int(input())
# a = list(map(int,input().split()))
s,t = input().split()
a,b = map(int, input().split())
u = input()
if u == s: print(a-1,b)
else: print(a,b-1)




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

class Program
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(x => Int64.Parse(x)).ToArray();
        var ans = Math.Min(GetNumberOfOperations(a,true), GetNumberOfOperations(a, false));
        Console.WriteLine(ans);
    }
    static long GetNumberOfOperations(long[] array, bool isPositiveNumberFirst)
    {
        var length = array.Length;
        var count = 0L;
        var num = 0L;
        var isPositiveNumber = isPositiveNumberFirst;
        for (int i=0;i<length;++i)
        {
            if (isPositiveNumber && (num + array[i] < 1))
            {
                count += Math.Abs(1 - (num + array[i]));
                num = 1;
            }
            else if (!isPositiveNumber && (-1 < num + array[i]))
            {
                count += Math.Abs(-1 - (num + array[i]));
                num = -1;
            }
            else num += array[i];

            isPositiveNumber = !isPositiveNumber;
        }
        return count;
    }
}


Measured memory_bytes: 29148
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
h = list(li())
INF = float('inf')

dp = [INF]*n
dp[0] = 0

for idx in range(n):
    for jdx in range(min(idx, k)):
        dp[idx] = min(dp[idx],
                      dp[idx-jdx-1] + abs(h[idx]-h[idx-jdx-1]))

print(dp[-1])

Measured memory_bytes: 55184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int dy[] = {-1, 0, 0, 1};
int dx[] = {0, -1, 1, 0};
int w, h;
pii s, g;
int n;
int f[110][110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> w >> h, w) {
    cin >> s.second >> s.first;
    s.second--, s.first--;
    cin >> g.second >> g.first;
    g.second--, g.first--;    
    cin >> n;
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x--, y--;
      if (d == 0) {
        for (int j = 0; j < 2; j++) {
          for (int k = 0; k < 4; k++) {
            f[y + j][x + k] = c;
          }
        }
      } else {
        for (int j = 0; j < 4; j++) {
          for (int k = 0; k < 2; k++) {
            f[y + j][x + k] = c;
          }
        }
      }
    }
    if (f[s.first][s.second] == 0) {
      cout << "NG" << endl;
      continue;
    }
    bool used[110][110] = {};
    used[s.first][s.second] = true;
    queue<pii> que;
    que.emplace(s);
    while (!que.empty()) {
      pii u = que.front(); que.pop();
      int y = u.first, x = u.second;
      for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny >= 0 && ny < h && nx >= 0 && nx < w && f[ny][nx] == f[y][x] && !used[ny][nx]) {
          used[ny][nx] = true;
          que.emplace(ny, nx);
        }
      }
    }
    cout << (used[g.first][g.second] ? "OK" : "NG") << endl;
  }

  return 0;
}


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


using namespace std;
                                                                    

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int first = 0,second = 0, third = 0;
  for(int i = 0; i < n; i++){
  	int t;
  	cin >> t;
  	if(t <= a) first++;
  	else if(t <= b) second++;
  	else third++;
  }
	cout << min(min(first,second),third) << endl;
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

}

           	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
ll MOD = 1e9+7;
ll fact(ll N){
    ll ans = 1;
    rep(i,1,N+1){
        ans = (ans * i) % MOD;
    }
    return ans;
}
main(){
    ll N,M;
    cin >> N >> M;
    if(abs(N - M) > 1){
        cout << 0 << endl;
        return 0;
    }
    if(N == M){
        cout << ( (fact(N) * fact(N)) % MOD * 2 % MOD )<< endl;
    }else{
        cout << ( (fact(N) * fact(M)) % MOD )<< endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char letter;
  scanf("%c", &letter);
  if(letter >= 'A' && letter <= 'Z'){
    //uppercase
    printf("A\n");
  }
  if(letter >= 'a' && letter <= 'z'){
    //lowercase
    printf("a\n");
  }
  return 0;
}


Measured memory_bytes: 1592
h,w = map(int,input().split())
s_input = list(map(str,[input() for i in range(h)]))
ans_map = [[0 for i in range(w)] for i in range(h)]

def checker(s_input,point):
    tmp=0
    x,y = map(int,point)
    def next_check(y,x):
        if 0<=y<=(h-1) and 0<=x<=(w-1):
            if s_input[y][x]=='#':
                return 1
        return 0
    tmp+=next_check(y-1,x-1)
    tmp+=next_check(y-1,x)
    tmp+=next_check(y-1,x+1)
    tmp+=next_check(y,x-1)
    tmp+=next_check(y,x+1)
    tmp+=next_check(y+1,x-1)
    tmp+=next_check(y+1,x)
    tmp+=next_check(y+1,x+1)
    return tmp

for i in range(h):
    for j in range(w):
        if s_input[i][j]=='#':
            ans_map[i][j]='#'
        else:
            ans_map[i][j]=checker(s_input,[j,i])

for m in ans_map:
    print(''.join(map(str,m)))


    


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int W, H;
char G[1001][1001];
int vis[1001][1001];

bool bfs(int x, int y) {
  const static int dx[] = {1,0,-1,0};
  const static int dy[] = {0,1,0,-1};
  queue<int> que;
  que.push(x+y*W);
  while(!que.empty()) {
    x = que.front()%W;
    y = que.front()/W;
    que.pop();
    for(int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx < 0 || nx >= W) continue;
      if(ny < 0 || ny >= H) continue;
      if(vis[ny][nx]) continue;
      if(G[ny][nx] == '#') {
	vis[ny][nx] = 1;
	continue;
      }

      if(G[ny][nx] == 't') return true;
      que.push(nx+ny*W);
      vis[ny][nx] = 2;
    }
  }
  return false;
}

int main() {
  cin >> W >> H;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> G[i][j];
    }
  }

  int N;
  cin >> N;
  int x, y;
  x = y = 0;
  for(int i = 0; i < H; ++i) fill(vis[i],vis[i]+W,0);
  vis[0][0] = 1;
  int ans = -1;
  for(int i = 0; i <= N; ++i) {
    if(ans == -1 && vis[y][x] == 1 && bfs(x,y)) ans = i;
    if(i != N) {
      cin >> x >> y;
      if(G[y][x] == '#') G[y][x] = '.';
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5768
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

ll n;int m,x;
int to[100010][65];
ll table[100010][65];

void solve(){
    cin >> n >> x >> m;
    rep(i,m){
        to[i][0]=(ll)i*(ll)i%m;
        table[i][0]=i;
    }
    rep(j,35){
        rep(i,m){
            to[i][j+1]=to[to[i][j]][j];
            table[i][j+1]=table[i][j]+table[to[i][j]][j];
            //cout << i << " " << j+1 << " " << table[i][j+1] << endl;
        }
    }
    ll ans=0;int pos=x;
    rep(j,35){
        if(n&(1ll << j)){
            //cout << table[pos][j] << endl;
            ans+=table[pos][j];
            pos=to[pos][j];
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 79792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,p;
    cin>>n>>p;
    if(n==1)
    {
        cout<<p<<endl;
        return 0;
    }
    int ma=1;
    for(int i=2;i<=p;i++)
    {
        if(i>1e6+5) break;
        int cnt=0;
        while(p%i==0)
        {
            p/=i;
            cnt++;
        }
        if(cnt>=n)
            ma*=pow(i,cnt/n);
    }
    cout<<ma;
}





Measured memory_bytes: 256
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

INF = pow(10,5)

def countProcedure(lst,char,cnt=0):
  flags = [x == char for x in lst]
  if all(flags):
    return cnt
  else:
    lst = [char if lst[i] == char or lst[i+1] == char else lst[i] for i in range(len(lst)-1)]
    return countProcedure(lst,char,cnt+1)

# @njit
def solve(s):
  s = list(s)
  res = INF
  for char in (chr(ord("a") + i) for i in range(26)):
    res = min(res,countProcedure(s,char))

  return res



def main():
  s = input()
  print(solve(s))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9032
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
    #include <unordered_map>
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef unsigned long long int128;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define mod1 1000000007
#define mod2 998244353
#define eps 1e-10
#define pi acos(-1)
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1^1)
const int dx[4]={0,0,1,1},dy[4]={1,0,1,0};
const int maxn=5007;
int n;
int sz[maxn];
vector<int> g[maxn];
ll pw[maxn];
ll dp[maxn][maxn][2];
ll pre[maxn][2];
void cal(int x,int p)
{
	sz[x]=1;dp[x][1][0]=1;
	rep(i,g[x].size())
	{
		int to=g[x][i];
		if(to==p)continue;
		cal(to,x);
		for(int j=1;j<=sz[x];j++)
		{
			pre[j][0]=dp[x][j][0];pre[j][1]=dp[x][j][1];
			dp[x][j][0]=dp[x][j][1]=0; 
		}
		for(int j=1;j<=sz[x];j++)
		{
			for(int k=1;k<=sz[to];k++)
			{
				rep(dir,4)
				{
					int xd=dx[dir],tod=dy[dir];
				//	cout<<xd<<" "<<tod<<endl;
				//	system("pause");
					dp[x][j+k][(xd+tod)%2]=(dp[x][j+k][(xd+tod)%2]+1ll*pre[j][xd]*dp[to][k][tod]%mod1)%mod1;
					dp[x][j][(xd+tod+1)%2]=(dp[x][j][(xd+tod+1)%2]+1ll*pre[j][xd]*dp[to][k][tod]%mod1*pw[k]%mod1)%mod1;
					
				}
			}
		}
		sz[x]+=sz[to];
	}
}
int main()
{
	scanf("%d",&n);
	rep(i,n-1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	pw[0]=1;
	for(int i=2;i<=n;i+=2)pw[i]=(pw[i-2]*1ll*(i-1))%mod1;
	cal(1,0);
	ll ans;
	ans=0;
	for(int rm=2;rm<=n;rm+=2)
	{
	//	cout<<dp[1][rm][0]<<" "<<dp[1][rm][1]<<endl;
		ans=(ans+pw[rm]*(dp[1][rm][0]-dp[1][rm][1]+mod1)%mod1)%mod1;
	}
	printf("%lld\n",ans%mod1);
	return 0;
}

Measured memory_bytes: 391424
// problem: "https://atcoder.jp/contests/abc159/tasks/abc159_d"

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll n;
    cin>>n;

    ll i;
    vector<ll>V(n);
    for(i=0;i!=n;i++)
        cin>>V[i];

    vector<ll>C(n+1,0);
    for(i=0;i!=n;i++)
        C[V[i]]++;

    ll c = 0;
    for(i=0;i!=n+1;i++)
        c += (C[i]-1) * C[i]/2;

    for(i=0;i!=n;i++)
        cout<<c - C[V[i]] + 1<<'\n';

    return 0;
}


Measured memory_bytes: 5760
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        check = []
        for j in range(m):
            tmp = 0
            for k in swich[j][1:]:
                tmp += i[k-1]
            check.append(tmp%2)
        if check == check_p:
            cnt +=1

    print(cnt)

main()

Measured memory_bytes: 3188
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

int main() {
  ll n;

  cin >> n;

  ll curarm;
  ll ans = n;

  vP robs(n);
  rep(i, n) {
    ll x, l;
    cin >> x >> l;
    robs[i] = P(x,l);
  }
  Sort(robs);

  rep(i, n) {
    ll x, l;
    tie(x, l) = robs[i];
    if (i == 0) {
      curarm = x + l;
      continue;
    }
    if (curarm > x - l) {
      ans--;
      chmin(curarm, x + l);
    } else {
      curarm = x + l;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
S = {}
S["a"] = input()
S["b"] = input()
S["c"] = input()
now = "a"
d = {}
d["a"] = 0
d["b"] = 0
d["c"] = 0
while(d[now] < len(S[now])):
  tmp = S[now][d[now]]
  d[now] += 1
  now = tmp
print(now.upper())

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

int main()
{
	int a,b;
	string s;
	vector<string>v;
	cin>>a>>b;
	for(int i=0;i<a;i++)
	{
		cin>>s;
		v.push_back(s);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<a;i++)
	{
		cout<<v[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n, r;
	scanf("%d %d", &n, &r);
	if(n >= 10) {
		printf("%d\n", r);
	} else {
		printf("%d\n", r + (100 * (10 - n)));
	}
	return 0;
}

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

int main(){
  ll N, K; cin >> N >> K;
  vector< ll > arr(MAX + 1, 0LL);
  for(ll i = 0; i < N; i++){
    ll a, b; cin >> a >> b;
    arr[a] += b;
  }
  
  ll cnt = 0;
  for(ll i = 1; i <= MAX; i++){
    cnt += arr[i];
    if(cnt < K) continue;
    else{
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include <algorithm>


using namespace std;

int main(){
	
	int N, k, p[1010];

	cin >> N >> k;

	for (int i = 0; i < N; ++i)
		cin >> p[i];

	sort(p,p+N);

	int sum = 0;

	for (int i = 0; i < k; ++i)
		sum += p[i];

	cout << sum << endl;

}



Measured memory_bytes: 3544
#include <stdio.h>

int main(void)
{
	int x;
	char a[1201];
	
	fgets(a, 1200, stdin);
	for(x = 0; a[x] != 0x00; x++){
		if(('A' <= a[x]) && (a[x] <= 'Z')){
			a[x] |= 0x20;
		}else if(('a' <= a[x]) && (a[x] <= 'z')){
			a[x] &= 0xdf;
		}else{
		}
	}
	printf("%s", a);
	
	return(0);
}



Measured memory_bytes: 1776
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << max(0, min(d, b) - max(a, c)) << endl;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

map<int , ll> dp;

ll fn(int x){
	if(x < 0)
		return 0;
	if(x == 0)
		return 1;
	if(dp.find(x) != dp.end()) return dp[x];
	ll ans = 0;
	for(int i = x; i >= 3; -- i){
		ans += fn(x - i);
		if(ans > MOD)
			ans -= MOD;
	}
	return dp[x] = ans;
}

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    int s;
    cin >> s;

    cout << fn(s);

    return 0;
}

/*

*/

Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
//int k = 0;
vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }

    //int p = min(int(out.size()+k), int(d));
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    //cout << out.size() << " " << d << endl;
    //int p = min(int(out.size()+k), d);
    //int k = 13;
    //int p = min(int(out.size()+k), d);
    ll q = LLONG_MIN;
    for(int k = 0; k < 26; k++) {
        int p = out.size()+k;
        ll tmp = 0;
        for(int i = out.size(); i < p; i++) {
            for(int j = 0; j < 26; j++) {
                //score -= c[j]*((i)-last[j]);
                tmp -= c[j]*((i)-last[j]);
            }
        }
        if(tmp > q) {
            q = tmp;
        }
    }
    return score+q;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


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


  int n, m;
  cin>>n>>m;
  vector<int> A(n);
  vector<int> B(m);
  cin>>A>>B;

  int i = 0, j = 0;
  int ans1 = 0;
  vector<int> V;
  while(i < n && j < m){
    if(i < n && A[i] < B[j]) i++;
    else if(j < m && A[i] > B[j])j++;
    else ans1++, V.push_back(A[i]), i++, j++;
  }

  set<int> S;
  for(int i=0;i<n;i++) S.insert(A[i]);
  for(int i=0;i<m;i++) S.insert(B[i]);
  int ans2 = S.size();
  cout<<ans1<<" "<<ans2<<endl;

  for(int i=0;i<(int)V.size();i++) cout<<V[i]<<endl;
  for(auto p:S) cout<<p<<endl;
  
  
  return 0;
}



Measured memory_bytes: 14032
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 100;
        int b = (n-a*100) / 10;
        int c = n % 10;
        int ans = 0;
        if(a == 1){
            ans += 900;
        }else{
            ans += 100;
        }
        if(b == 1){
            ans += 90;
        }else{
            ans += 10;
        }
        if(c == 1){
            ans += 9;
        }else{
            ans += 1;
        }
        System.out.println(ans);
    }    
}


Measured memory_bytes: 22100