akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAX_N 100
using namespace std;
struct Node
{
	int parent, left, right;
};
struct Node T[MAX_N];
vector<int> v1, v2, v3;

void Preorder(int u);
void Inorder(int u);
void Postorder(int u);

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		T[i].parent = -1;
	for(int i = 0; i < n; i++)
	{
		int p, l , r;
		cin >> p >> l >> r;
		T[p].left = l;
		T[p].right = r;
		if(l != -1) 
			T[l].parent = p;
		if(r != -1)
			T[r].parent = p;
	}
	int root;
	for(int i = 0; i < n; i++)
	{
		if(T[i].parent != -1)
			continue;
		root = i;
	}
	Preorder(root);
	Inorder(root);
	Postorder(root);
	cout << "Preorder" << endl;
	for(int i = 0; i < v1.size(); i++)
		cout << " " << v1[i];
	cout << endl;
	cout << "Inorder" << endl;
	for(int i = 0; i < v2.size(); i++)
		cout << " " << v2[i];
	cout << endl;
	cout << "Postorder" << endl;
	for(int i = 0; i < v3.size(); i++)
		cout << " " << v3[i];
	cout << endl;
}
void Preorder(int u)
{
	if(u == -1)
		return;
	v1.push_back(u);
	Preorder(T[u].left);
	Preorder(T[u].right);
}
void Inorder(int u)
{
	if(u == -1)
		return;
	Inorder(T[u].left);
	v2.push_back(u);
	Inorder(T[u].right);
}
void Postorder(int u)
{
	if(u == -1)
		return;
	Postorder(T[u].left);
	Postorder(T[u].right);
	v3.push_back(u);
}



Measured memory_bytes: 3144
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intAbs(x int) int {
	return int(math.Abs(float64(x)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt() - (i + 1)
	}
	sort.Ints(A)

	var b int
	if N%2 == 1 {
		b = A[(N-1)/2]
	} else {
		b = (A[N/2] + A[N/2-1]) / 2
	}
	ans := []int{0, 0}
	for _, a := range A {
		ans[0] += intAbs(a - b)
		ans[1] += intAbs(a - b - 1)
	}
	sort.Ints(ans)

	fmt.Println(ans[0])
}


Measured memory_bytes: 5924
n=int(input())
h=list(map(int,input().split()))
max=0
count=0
old=h[0]
for i in range(1,n):
  if(old>=h[i]):
    count=count+1
  else:
    if(max<count):
      max=count
    count=0
  old=h[i]
if(max<count):
  max=count
print(max)

Measured memory_bytes: 14224
from sys import setrecursionlimit as SRL, stdin

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

q = [[]]
l = [0] * 1005
d = [0] * 1005
hv = [0] * 1005

def dfs(x,y):
    hv[x] = 1
    for i in range(l[x],n-1):

        if q[x][i] == y:
            l[x] = i+1
            hv[x] = 0

            d[q[x][i]] += 1
            d[x] += 1
            d[x] = max(d[x],d[q[x][i]])
            d[q[x][i]] = max(d[x], d[q[x][i]])

            return
        if hv[q[x][i]]:
            print(-1)
            exit(0)
        dfs(q[x][i],x)
        d[x] = max(d[q[x][i]],d[x])


    hv[x] = 0
    l[x] = n

n = int(input())
for i in range(n):
    a = list(rrd())
    q.append(a)

for i in range(1,n+1):
    dfs(i,0)

print(max(d))


Measured memory_bytes: 64476
#include <iostream>
#include <algorithm>
#include <cmath>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

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

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if(a%2 == 1 && i%2 == 1)
            ans++;
    }

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

Measured memory_bytes: 3160
/** 
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long ans = 0;
  long long n;
  cin >> n;
  if (n == 2) {
    cout << 1 << '\n';
    return 0;
  }
  long long m = n - 1;
  for (long long d = 2; d * d <= m; d++) {
    if (m % d != 0) continue;
    long long d1 = d, d2 = m / d;
    ++ans;
    ans += (d2 != d1);
  }
  ++ans;
  auto Add = [&](long long x) {
    long long k = n;
    while (k % x == 0) {
      k /= x;
    }
    if (k == 1) {
      ++ans;
      return;
    }
    ans += (k % x == 1);
  };
  for (long long d = 2; d * d <= n; d++) {
    if (n % d != 0) continue;
    Add(d);
    if (n / d != d) {
      Add(n / d);
    }
  }
  Add(n);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N >> M;
	vector<int>p(N+1);
	vector<vector<int>>node(N + 1);
	for (int i = 1; i <= N; i++)cin >> p[i];
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		node[x].push_back(y);
		node[y].push_back(x);
	}
	vector<bool>flag(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		if (flag[i])continue;
		set<int> set;
		queue<int>q;
		q.push(i);
		while (!q.empty()) {
			int now = q.front();
			q.pop();
			set.insert(now);
			flag[now] = 1;
			for (int j : node[now]) {
				if (flag[j] == 0)q.push(j);
			}
		}
		for (auto itr = set.begin(); itr != set.end(); itr++) {
			if(set.count(p[*itr]))ans++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int main(){

  int N,M;
  string scan;
  vector<string> ID;
  bool door=false;
  bool flag=false;

  cin >> N;

  for(int i=0; i<N; ++i){
    cin >> scan;
    ID.emplace_back(scan);
  }

  cin >> M;

  for(int i=0; i<M; ++i){
    cin >> scan;

    for(int k=0; k<ID.size(); ++k){
      if(ID[k]==scan){
	flag=true;
      }
    }

    if(flag){
      if(door){
	door=false;
	cout << "Closed by " << scan << endl;
      }else{
	door=true;
	cout << "Opened by " << scan << endl;
      }
    }else{
      cout << "Unknown " << scan << endl;
    }

    flag=false;
  }

  
  return 0;
}


Measured memory_bytes: 3204
# @param [Number] x
# @param [Number] a
# @param [Number] b
def solve(x, a, b)
  d1 = (x-a).abs
  d2 = (x-b).abs
  return d1 < d2 ? 'A' : 'B'
end

unless ENV['SKIP_IO'] == '1'
  x, a, b = gets.split.map(&:to_i)
  puts solve x, a, b
end


Measured memory_bytes: 1788
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	while(true){
    	    int h = sc.nextInt();
    		int w = sc.nextInt();
    		if(h == 0 && w == 0){
    		 break;   
    		}
     		for(int i=0;i<h;i++){
    			for(int j=0;j<w;j++){
    				if(i == 0 || i == h-1 || j == 0 || j == w-1){
    				 System.out.print("#");   
    				}else{
    				 System.out.print(".");   
    				}
    			}
    			System.out.println();
    		}
     		System.out.println();
    	}
    }
}


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

int main(void){
    int n,ans=0 ;
    cin >> n ;
    int d[n] ;
    for (int i=0; i<n; i++){
        cin >> d[i] ;
    }
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            ans+=d[i]*d[j] ;
        }
    }
    cout << ans << endl ;
}

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

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    # 降順にぶちこむ人を選んでいく。
    # 実際に手で書けばわかるが、ある数がn個あるとき、
    # n+1回心地よさを感じるようになる。
    dic = {}
    for a in As:
        if not a in dic: dic[a] = 0
        dic[a] += 1

    keys = []
    for key in dic.keys():
        keys.append(key)
    keys.sort(reverse=True)

    ans = 0
    n = N - 1
    dic[keys[0]] -= 1
    ans += keys[0]
    n -= 1

    for i, key in enumerate(keys):
        if dic[key] == 0:
            continue

        if (dic[key]*2) <= n:
            ans += key*(dic[key]*2)
            n -= dic[key]*2
        else:
            ans += key*n
            n -= n
            break

    print(ans)


if __name__ == "__main__":
    solve()


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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {

            var n = long.Parse(Console.ReadLine());
            var a = long.Parse(Console.ReadLine());
            var b = long.Parse(Console.ReadLine());
            var c = long.Parse(Console.ReadLine());
            var d = long.Parse(Console.ReadLine());
            var e = long.Parse(Console.ReadLine());

            var list = new List<long>();

            list.Add(a);
            list.Add(b);
            list.Add(c);
            list.Add(d);
            list.Add(e);

            var min = list.Min();

            if(min >= n)
            {
                Console.WriteLine(5);
            }
            else
            {
                if (n % min == 0)
                {
                    var group = n / min;
                    Console.WriteLine(5 + group - 1);
                }
                else
                {
                    var group = n / min + 1;
                    Console.WriteLine(5 + group - 1);
                }
            }
        }
    }
}


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

class Program
{
    static void Main()
    {
        string s_data = Console.ReadLine();
        string judge = string.Empty;
        bool result = false;

        for(int i = 0; i < 10; i++)
        {
            foreach (var x in Enumerable.Repeat(i, 3)) judge += x;
            result = s_data.Contains(judge);

            if (result)
            {
                Console.WriteLine("Yes");
                break;
            }
            judge = string.Empty;
        }
        if (!result) Console.WriteLine("No");
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

Int dp[101][100005];

int main() {
    ios::sync_with_stdio(false);
    Int N, W;
    cin >> N >> W;
    vector<Int> w(N), v(N);
    for (Int i = 0; i < N; i++) cin >> w[i] >> v[i];
    for (Int i = 0; i < N; i++) {
        for (Int j = 1; j <= W; j++) {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if (j - w[i] >= 0) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    Int res = 0;
    for (Int i = 0; i <= W; i++) res = max(res, dp[N][i]);
    dump(res);
    return 0;  
} 

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
int n,a[maxn],ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=1;i<=n;i++) {
		if (a[i]==ans+1) ans++;
	}
	if (!ans) printf("-1\n");
	else printf("%d\n",n-ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
x = int(input())
x = int(x / 50)
cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        left = x - i * 10
        left -= j * 2
        if 0 <= left and  left <= c:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
    long long int n;
    cin >>n ;
    long long int a=1;
    for(long long int i=0; i<n; i++){
           a=a*(i+1);
        if(a>=(1000000000+7)){
           a=a%(1000000000+7);
        }
    }
    cout <<a <<endl;
    return 0;
}

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

int c[3][3];

#define rep(i) for(int i = 0;i < 3;i++)


int main()
{
	rep(i)
	{
		rep(j)
		{
			cin >> c[i][j];
		}
	}

	int dx[2] = {c[1][0] - c[0][0] , c[2][0] -c[1][0]};

	rep(i)
	{
		rep(j)
		{
			if(j < 2)
			{
				if(dx[j] + c[j][i] != c[j + 1][i])
				{
					cout << "No";
					return 0;
				}
			}
		}
	}
	int dy[2] = {c[0][1] - c[0][0] , c[0][2] -c[0][1]};

	rep(i)
	{
		rep(j)
		{
			if(j < 2)
			{
				if(dy[j] + c[i][j] != c[i][j + 1])
				{
					cout << "No";
					return 0;
				}
			}
		}
	}

	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;
int ans = INT_MAX / 2;
bool flag = true;
string ck = "01234567";
vector< string > his;

int dd[4] = {1, -1, 4, -4};

int main(void) {
	map<string, int> memo;
	memo[string("01234567")] = 0;

	queue<pair<string, int>> q;
	q.push(make_pair(string("01234567"), 0));

	while (q.size()) {
		auto p = q.front();
		q.pop();
		string tiles = p.first;
		int cnt = p.second;
		int pos = tiles.find('0');

		for (int i = 0; i < 4; i++) {
			int target = pos + dd[i];
			if (target < 0 || 7 < target) {
				continue;
			}
			if (min(pos, target) == 3 && max(pos, target) == 4) {
				continue;
			}

			string next_tiles(tiles);
			swap(next_tiles[pos], next_tiles[target]);

			if (!memo.count(next_tiles)) {
				memo[next_tiles] = cnt + 1;
				q.push(make_pair(next_tiles, cnt + 1));
			}
		}
	}

	string str(8, '0');

	while (cin >> str[0]) {
		for (int i = 1; i < 8; i++) {
			cin >> str[i];
		}
		
		cout << memo[str] << endl;
	}

	return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  int r = n * (l + (l + n - 1)) / 2;
  if (0 < l) {
    r -= l;
  } else if (l + n - 1 < 0) {
    r -= l + n - 1;
  }
  cout << r << endl;
}


Measured memory_bytes: 256
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> hs(n);
    for(int i = 0; i < n; ++i) cin >> hs[i];
    vector<int> highest_neighbors(n, -1);
    for(int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        highest_neighbors[u] = max(highest_neighbors[u], hs[v]);
        highest_neighbors[v] = max(highest_neighbors[v], hs[u]);
    }
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(highest_neighbors[i] == -1 || highest_neighbors[i] < hs[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}



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

int main(){
	string s;
  	cin >> s;
  	int n = s.size();
  	reverse(s.begin(), s.end());
  	int x = 1, tot = 0;
  	vector<int> cnt(m);
  	ll ans = 0;
  
  	rep(i, n){
    	cnt[tot]++;
      	tot += (s[i]-'0') * x;
      	tot %= m;
      	ans += cnt[tot];
      	x = x*10%m;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3756
/*
 * FileName:     swap
 * CreatedDate:  2020-07-10 22:09:57 +0900
 * LastModified: 2020-07-10 22:18:36 +0900
 */

#include <stdio.h>
#include <stdlib.h>
void swapRange(int b, int e, int t, int *a){
    for(int k=0; k<e-b; k++){
        int tmp = a[b+k];
        a[b+k] = a[t+k];
        a[t+k] = tmp;
    }
}
void copy(int *a, int *c, int n){

}
int main(void){
    int n;scanf("%d", &n);
    int *a = malloc(n*sizeof(int));
    for(int i=0; i<n; i++){
        scanf("%d", a+i);
    }
    int q;scanf("%d", &q);
    for(int i=0; i<q; i++){
        int b, e, t;scanf("%d%d%d", &b, &e, &t);
        swapRange(b, e, t, a);
    }
    printf("%d", a[0]);
    for(int i=1; i<n; i++){
        printf(" %d", a[i]);
    }
    printf("\n");
    free(a);
    return 0;
}



Measured memory_bytes: 2148
n=int(input())
number_list=list(map(int,input().split()))
new_list=sorted(number_list,reverse=True)
#print(new_list)
alice_number=[]
for i in range(n):
    if i%2==1:
        continue
    alice_number.append(new_list[i])
#print(alice_number)
bob_number=[]
for i in range(n):
    if i%2==0:
        continue
    bob_number.append(new_list[i])
#print(bob_number)
result=sum(alice_number)-sum(bob_number)
print(result)

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

int main(void){
    int n, a[2][110];
    cin >> n;
    for(int i=0;i<n;++i)cin >> a[0][i];
    for(int i=0;i<n;++i)cin >> a[1][i];
    int max=0;
    for(int i=0;i<n;++i){
        int sum = 0;
        for(int j=0;j<=i;++j){
            sum += a[0][j];
        }
        for(int j=i;j<n;++j){
            sum += a[1][j];
        }
        if(sum > max) max = sum;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
char A[101010], B[101010], C[101010], D[101010];

i64 fact[404040], facti[404040];

i64 modpow(i64 a, int p = MOD - 2)
{
	if (p == 0) return 1;
	i64 tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2 == 1) tmp = tmp * a % MOD;
	return tmp;
}

i64 Comb(int a, int b)
{
	if (a < b) return 0;
	return fact[a] * facti[b] % MOD * facti[a - b] % MOD;
}

i64 lfs[101010], rgs[101010];

int cone(char* s, char* t)
{
	int ret = 0;
	while (s != t) {
		if (*s == '1') ++ret;
		++s;
	}
	return ret;
}

i64 solve(int N, int M, char* A, char* B, char* C, char* D)
{
	int ca = cone(A, A + N);
	int cb = cone(B, B + N);

	if (ca + cb == 0) {
		i64 ret = 1;
		for (int i = 0; i < M; ++i) {
			int c = (C[i] - '0') + (D[i] - '0');
			ret = ret * max(c, 1) % MOD;
		}
		return ret;
	}

	int a, x, y;

	// compute lfs
	a = ca;
	x = y = 0;
	for (int i = 0; i < M; ++i) {
		if (a == 0) {
			lfs[i] = ((x + y == 0) ? 1 : 0);
		} else {
			lfs[i] = Comb(a - 1 + x + y, a - 1);
		}
		if (C[i] == '1') ++x;
		if (D[i] == '1') ++y;
	}

	// compute rgs
	a = cb;
	x = y = 0;
	for (int i = M - 1; i >= 0; --i) {
		if (a == 0) {
			rgs[i] = ((x + y == 0) ? 1 : 0);
		} else {
			rgs[i] = Comb(a - 1 + x + y, a - 1);
		}
		//printf("%d: %lld %lld %lld %lld\n", i, lfs[i], rgs[i], ca, cb);
		if (C[i] == '1') ++x;
		if (D[i] == '1') ++y;
	}

	i64 ret = 0;
	i64 tmp = 0;
	for (int i = 0; i < M; ++i) {
		int ct = (C[i] - '0') + (D[i] - '0');
		if (ct == 0) continue;

		ADD(tmp, lfs[i]);
		tmp = tmp * ct % MOD;
		ADD(ret, tmp * rgs[i]);
	}
	return ret;
}

int main()
{
	fact[0] = facti[0] = 1;
	for (int i = 1; i <= 400000; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		facti[i] = modpow(fact[i]);
	}
	scanf("%d%d", &N, &M);
	scanf("%s%s%s%s", A, B, C, D);

	if (cone(A, A + N) + cone(B, B + N) + cone(C, C + N) + cone(D, D + N) == 0) {
		puts("1");
		return 0;
	}

	i64 ret = 0;
	ADD(ret, solve(N, M, A, B, C, D));
	ADD(ret, solve(M, N, C, D, A, B));

	printf("%lld\n", ret);

	return 0;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n; cin >> n;
  vector<lint> a(n),b(n);
  for(lint i=0;i<n;i++) { cin >> a[i]; }
  for(lint i=0;i<n;i++) { cin >> b[i]; }

/*
  if(accumulate(a.begin(),a.end(),0) < accumulate(b.begin(),b.end(),0)) {
    cout << -1 << endl;
    return 0;
  }
*/
  vector<lint> d(n); // diff
  for(lint i=0;i<n;i++) { d[i] = a[i]-b[i]; }
  sort(d.begin(),d.end());

  lint sum=0, cnt=0;
  for(lint i=0;i<n;i++) {
    if(d[i] < 0) {
      cnt++;
      sum += d[i];
    }
  }

  for(lint i=n-1;i>=0;i--) {
    if(sum < 0 && d[i] > 0) {
      sum += d[i];
      cnt++;
    }

    if(sum >= 0) {
      cout << cnt << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 2560
N,M,Q=map(int,input().split())
S=[]
for i in range(Q):
    S.append(list(map(int,input().split())))
try_lis=[]
def dfs(A):
    if len(A)==N:
        try_lis.append(A[::1])
        return   
    for v in range(1,M+1):
        if v>=A[-1]:
            A.append(v)
            dfs(A)
            A.pop()
dfs([1])
total=0
for one_case in try_lis:
    tmp=0
    for j in S:
        if one_case[j[1]-1]-one_case[j[0]-1]==j[2]:
            tmp+=j[3]
    total=max(total,tmp)
print(total)

Measured memory_bytes: 16120
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#define NDEBUG

#ifndef NDEBUG
#define trace(var)  {cerr << "Line " << __LINE__ << ": " << #var << "=" << (var) << nl;}
#else
#define trace(var)	{}
#endif

class ModInt {
  int val; static const int MOD = 1e9+7; static_assert(MOD > 0, "Modulus not set!");
  int modInverse(int a) { // simplified extended GCD, only solving for x
    int b = MOD, x = 0, x_ = 1, q; while (a != 0) { q = b / a; swap(b, a); a %= b;
    swap(x, x_); x_ -= q * x; } assert(b == 1); return (x %= MOD) < 0 ? (x + MOD) : x; }
  public: ModInt() : val(0) { } ModInt(int v) : val(v) { if ((val %= MOD) < 0) val += MOD; }
    ModInt& operator += (const ModInt& b) { if ((val += b.val) >= MOD) val -= MOD; return *this; }
    ModInt& operator -= (const ModInt& b) { if ((val -= b.val) < 0) val += MOD; return *this; }
    ModInt& operator *= (const ModInt& b) { val = ((ll)val*(ll)b.val) % MOD; return *this; }
    ModInt& operator /= (const ModInt& b) {
      return (*this) *= modInverse(b.val);
      //if (((val *= modInverse(b.val)) %= MOD) < 0) val += MOD; return *this;
    }
#define _op(op, btype, op2) ModInt operator op (btype b) const { ModInt ans = *this; return ans op2 b; }
    _op(+, const ModInt&, +=); _op(-, const ModInt&, -=); _op(*, const ModInt&, *=); _op(/, const ModInt&, /=);
    _op(+, int, +=); _op(-, int, -=); _op(*, int, *=); _op(/, int, /=);
#undef _op
    operator int() const { assert(0 <= val && val < MOD); return val; }
};

ModInt fact(int n) {
  ModInt ans = 1;
  while(n) {
    ans *= (n--);
  }
  return ans;
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, x;
  cin >> n >> x;
  VI s(n);
  forx(i,n) cin >> s[i];
  // decresing order
  sort(s.begin(), s.end(), greater<int>());
  // forall s, either mod by it or don't
  vector<ModInt> cnt(x+1, 0);
  cnt[x] = fact(n);
  trace(cnt[x]);
  forx(i, n) {
    trace(s[i]);
    const int left = n - i;
    //fraction of outcomes skipping s[i] is 1/left
    for(int j = s[i]; j < x+1; j++) {
      //apply % s[i]
      if (cnt[j]) {
        //assert(cnt[j] % left == 0);
        ModInt rem = (cnt[j] / left);
        cnt[j % s[i]] += rem;
        cnt[j] -= rem;
      }
    }
  }
  ModInt ans = 0;
  forx(i, x+1) {
    if (cnt[i]) {
      trace(i);
      trace(cnt[i]);
      ans += (cnt[i] * i);
    }
  }
  cout << ans << nl;
  
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

  ll fastpow(ll a, ll pw) {
  	ll res = 1;
  	while (pw) {
  		if (pw & 1) res = res * a % MOD;
  		a = a * a % MOD;
  		pw >>= 1;
  	}
  	return res;
  }

int main() {
    cin>>N;
    vec a(N);
    ll xorsum = 0;
    rep(i,N){
        cin>>a[i];
        xorsum = xorsum ^ a[i];
    }
    if(xorsum != 0){
        ll temp = 0;
        vec dp(2, 0);
        dp[0] = 1;
        rep(i,N){
            temp = temp ^ a[i];
            if(temp == 0) (dp[0] += dp[1])%=MOD;
            else if(temp == xorsum) (dp[1] += dp[0])%=MOD;
        }
        cout<<dp[0]<<endl;
    }else{
        vec bit(N + 10, 0);
        mat id(1LL<<20, vec(0));
        ll temp = 0;
        rep(i,N){
            temp = temp ^ a[i];
            if(temp == 0) bit[i] = 1;
            else id[temp].push_back(i);
        }
        reps(i, 1, N + 10) bit[i] += bit[i-1];
        ll ans = fastpow(2, bit[N + 5] - 1);
        reps(d, 1, 1LL<<20){
            if(!id[d].empty()){
                int n = id[d].size();
                vec dp(n, 0), sum(n, 0), num0(n, 0);
                dp[0] = sum[0] = 1;
                num0[0] = bit[id[d][0]];
                (ans += dp[0])%=MOD;
                reps(i, 1, n){
                    dp[i] = (1 + sum[i-1] * bit[id[d][i]] + MOD - num0[i-1])%MOD;
                    sum[i] = (sum[i-1] + dp[i])%MOD;
                    num0[i] = (num0[i-1] + dp[i] * bit[id[d][i]])%MOD;
                    (ans += dp[i])%=MOD;
                }
            }
        }
        cout<<ans<<endl;
    }
}

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

using ll = long long;
using namespace std;

int N, K, h[(int)1e5];
ll dp[(int)1e5];

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

	for(int i = 0; i < N; ++i) dp[i] = LONG_MAX;
	dp[0] = 0;
	for(int i = 0; i < N; ++i){
		for(int j = 1; j <= K; ++j){
			if(i - j >= 0){
				dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	cout << dp[N-1] << endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int X;
  cin >> X;

  set<int> ans;
  FOR(b,1,X+1){
	FOR(p,2,100){
	  int pp = 1;
	  REP(j,p) pp *= b;
	  if(pp <= X) ans.insert(pp);
	  else break;
	}
  }
  cout << *rbegin(ans) << endl;
  
  return 0;
}


Measured memory_bytes: 892
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
from itertools import accumulate
import bisect

import sys
input = sys.stdin.readline
import math as mt

MAXN = 10**6 +1
  
# stores smallest prime factor for 
# every number 
spf = [0 for i in range(MAXN)] 
  
# Calculating SPF (Smallest Prime Factor)  
# for every number till MAXN. 
# Time Complexity : O(nloglogn) 
def sieve(): 
    spf[1] = 1
    for i in range(2, MAXN): 
          
        # marking smallest prime factor  
        # for every number to be itself. 
        spf[i] = i 
  
    # separately marking spf for  
    # every even number as 2 
    for i in range(4, MAXN, 2): 
        spf[i] = 2
  
    for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
          
        # checking if i is prime 
        if (spf[i] == i): 
              
            # marking SPF for all numbers 
            # divisible by i 
            for j in range(i * i, MAXN, i):  
                  
                # marking spf[j] if it is  
                # not previously marked 
                if (spf[j] == j): 
                    spf[j] = i 


def getFactorization(x): 
    ret = set([]) 
    while (x != 1): 
        ret.add(spf[x]) 
        x = x // spf[x] 
  
    return ret 


def solve(n,a):
    sieve()
    gcd_primes = getFactorization(a[0])
    seen_primes = set([])
    flag_pcp = True
    for aa in a:
        ps = getFactorization(aa)
        if flag_pcp:
            if not (seen_primes & ps):
                seen_primes |= ps
            else:
                flag_pcp = False
        gcd_primes &= ps
    if flag_pcp:
        print('pairwise coprime')
    elif gcd_primes:
        print('not coprime')
    else:
        print('setwise coprime')





            


            

def main():
    n = int(input())
    a = list(map(int,input().split()))
    solve(n,a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 193196
#include <iostream>

using namespace std;

int main()
{
    int n,cnt=0;
    cin>>n;
    int number[n];
    bool flag=true;
    for (int i=0; i<n; i++) cin>>number[i];
    while (flag)
    {
        for (int i=0; i<n; i++)
        {
            if (number[i]%2!=0) flag=false;
        }
        if (flag)
        {
            for (int i=0; i<n; i++)
            {
                number[i]=number[i]/2;
            }
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 124B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP PIC X(80).
01 N   PIC 9(2).
01 I   PIC 9(2).
01 CNT PIC 9(2).
01 H   PIC 9(3).
01 MAX PIC 9(3).
01 P1  PIC 9(2).
01 P2  PIC 9(2).
01 OUT PIC Z9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
  ACCEPT INP.
  MOVE 0 TO CNT MAX.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO H
    IF (H >= MAX)
      ADD 1 TO CNT
    END-IF
    IF (H > MAX)
      MOVE H TO MAX
    END-IF
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.


Measured memory_bytes: 636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner	sc = new Scanner(System.in);
		String s = sc.next();
		int ans = 700;
		for(int i = 0 ; i < 3 ; i++) {
			if(s.charAt(i) == 'o') {
				ans += 100;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL MOD = 1e9 + 7;

LL bit[300000][60] = {{0}};
LL sum[60][300001] = {{0}};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];

    REP(i,n){
        LL x = a[i];
        for(int j = 0; x > 0; j++){
            bit[i][j] = x % 2;
            x /= 2;
        }
    }

    REP(i,60){
        sum[i][0] = 0;
        REP(j,n + 1){
            sum[i][j + 1] = sum[i][j] + bit[j][i];
        }
    }

    VL z(60);
    z[0] = 1;
    FOR(i,1,60){
        z[i] = z[i - 1] * 2;
        z[i] %= MOD;
    }

    LL ans = 0;
    REP(i,n - 1){
        REP(j,60){
            LL s = 0;
            if(bit[i][j] == 0){
                s = sum[j][n] - sum[j][i + 1];
            }else{
                s = sum[j][n] - sum[j][i + 1];
                s = (n - i - 1) - s;
            }
            // ans += 2^j * s
            ans += z[j] * s;
            ans %= MOD;
        }
    }

    PUTS(ans);
}

Measured memory_bytes: 283904
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(i64, i64); n],
    }
    let mut p: Vec<(i64, i64)> = p.into_iter().filter(|p| p.0 != 0 || p.1 != 0).collect();
    let n = p.len();
    let func = |mut p: (i64, i64)| -> (usize, i64, i64) {
        let mut c = 0;
        while !(p.0 > 0 && p.1 >= 0) {
            c += 1;
            p = (p.1, -p.0);
        }
        (c, p.0, p.1)
    };
    p.sort_by(|a, b| {
        let a = func(*a);
        let b = func(*b);
        if a.0 != b.0 {
            a.0.cmp(&b.0)
        } else {
            (a.2 * b.1).cmp(&(a.1 * b.2))
        }
    });
    let mut ans = 0i64;
    for i in 0..n {
        let (a, b) = p[i];
        let mut j = (i + 1) % n;
        let mut v = (a, b);
        ans = std::cmp::max(ans, v.0 * v.0 + v.1 * v.1);
        while j != i && a * p[j].1 - b * p[j].0 >= 0 {
            v.0 += p[j].0;
            v.1 += p[j].1;
            ans = std::cmp::max(ans, v.0 * v.0 + v.1 * v.1);
            j = (j + 1) % n;
        }
    }
    let d = (ans as f64).sqrt();
    println!("{:.11}", d);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <vector>
#include <iostream>
using namespace std;
const int mod = 998244353;
int n, x[209], y[209], pw[209]; bool vis[209][209];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
	pw[0] = 1;
	for (int i = 0; i < n; i++) pw[i + 1] = pw[i] * 2 % mod;
	int ret = (pw[n] - n - 1 + mod) % mod;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (!vis[i][j]) {
				vector<int> v;
				int dx = x[j] - x[i], dy = y[j] - y[i];
				for (int k = 0; k < n; k++) {
					int ex = x[k] - x[i], ey = y[k] - y[i];
					if (dx * ey == ex * dy) v.push_back(k);
				}
				ret = (ret - (pw[v.size()] - v.size() - 1 + mod) % mod + mod) % mod;
				for (int k : v) {
					for (int l : v) {
						vis[k][l] = true;
					}
				}
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,i,f=0;cin>>n;vs v(n),x;for(i=0;i<n;i++) cin>>v[i];map<string,ll>mp;
	for(i=0;i<n;i++) mp[v[i]]++,f=max(f,mp[v[i]]);
	for(i=0;i<n;i++) if(mp[v[i]]==f) x.pb(v[i]),mp[v[i]]=0;
	sort(all(x));for(i=0;i<x.size();i++) cout<<x[i]<<endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);

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

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

    for(int i=0; i<N-1; i++) {
        cin >> C[i];
    }

    int before = -100;
    int score = 0;
    for(int k=0; k<N; k++) {
        int i = A[k]-1;
        score += B[i];
//        cout << "B[i]: " << B[i] << "  score: " << score << endl;
        if (before == (i-1)) {
            score += C[i-1];
//            cout << "C[i-1]: " << C[i-1] << "  score: " << score << endl;
        }
        before = i;
    }

    cout << score << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[100010][2],b[100010],c[100010];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&a[i][0],&a[i][1]);
	for (int i=1;i<=n;i++) b[i]=1;
	for (int i=2;i<=n;i++) c[i]=0;c[1]=1;
	for (int i=1;i<=m;i++)
	{
		b[a[i][0]]--;b[a[i][1]]++;
		if (c[a[i][0]])
		{
			c[a[i][1]]++;
			if (!b[a[i][0]]) c[a[i][0]]=0;
		}
	}
	int ans=0;
	for (int i=1;i<=n;i++) if (c[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,a,b,c,d,h,w,x,y;
string str;

signed main(){

  cin >> n >> a >> b;
  cout << (a>b ? b : a) __ (n<a+b ? a+b-n : 0) fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

void bitout(int x){ cerr << bitset<20>(x) << endl; }

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;
using i64=int64_t;

int highest(i64 A,i64 B){
    rep(i,0,60){
        if((A^B)&(i64(1)<<(59-i))) return 59-i;
    }
    return -1;
}

i64 intersection(i64 l1,i64 r1,i64 l2,i64 r2){
    return max(i64(0),min(r2,r1)-max(l1,l2)+1);
}

i64 intersection(i64 l1,i64 r1,i64 l2,i64 r2,i64 l3,i64 r3){
    return max(i64(0),min({r3,r2,r1})-max({l1,l2,l3})+1);
}

void solve(){
    i64 A,B;
    cin >> A >> B;

    if(A==B){
        cout << 1 << endl;
        return;
    }
    int i=highest(A,B)+1;
    i64 C=0;
    rep(j,i,60) C|=(i64(1)<<j)&A;
    A-=C;
    B-=C;
    i64 l1=A,r1=(i64(1)<<highest(A,B))-1;
    i64 l2=r1+1,r2=l2|((i64(1)<<(highest(l2,B)+1))-1);
    i64 l3=l1+l2,r3=l2*2-1;
    cout << (r1-l1+1)+(r2-l2+1)+(r3-l3+1)-intersection(l1,r1,l2,r2)-intersection(l2,r2,l3,r3)-intersection(l3,r3,l1,r1)+intersection(l1,r1,l2,r2,l3,r3) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import math
n, d = map(int, input().split())
ans = 0
x = 0
y = 0
frag = 0
for i in range(n):
    x, y = map(int, input().split())
    ans = x ** 2 + y ** 2
    ans = math.sqrt(ans)
    if ans <= d:
        frag += 1
print(frag)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  int ans = 0;

  for (int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  } 

  for (int i = 0; i < n; i++){
    if(a[i] >= (double) (sum) / (4 * m)) ans++;
  }

  if (ans >= m) cout << "Yes";
  else cout << "No";
  
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    int x,y,z;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  N++;
  vector<long long int> L(N);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < N; i++) L.at(i) = L.at(i-2) + L.at(i-1);
  cout << L.at(N-1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int Q; cin >> Q;
  rep(dummy, Q) {
    ll A, B; cin >> A >> B;
    ll l=0, r=2*pow(10,9), m;
    while(l!=r) {
      m = (l+r+1)/2;
      if (m*m>A*B*4) r=m-1;
      else l=m;
    }
    m = l;
    ll result = 0;
    result = (A*B*4==m*m&&A!=B) ? m-3 : m-2;
    cout << fixed << setprecision(10) << result << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

const double pi=3.1415926535897932384626;

int main()
{
	double a,b,x;
	cin >> a >> b >> x;

	double t=(2*(b/a-x/(a*a*a)));
	double dig=atan(t)/pi*180;

	if(t*a>b)
	{
		t=a*b*b/(2*x);
		dig=atan(t)/pi*180;
	}
		
	cout << fixed << setprecision(15) <<  dig << endl;





}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;

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

    vector<vector<pair<int32_t, int32_t>>> A(n);

    for (int32_t i = 0; i < n; i++) {
        int32_t u, k;
        cin >> u >> k;

        for (int32_t j = 0; j < k; j++) {
            int32_t v, c;
            cin >> v >> c;
            A[u].push_back(make_pair(c, v));
        }
    }

    vector<int32_t> d(n, INT32_MAX);
    vector<bool> visited(n, false);
    priority_queue<pair<int32_t, int32_t>, vector<pair<int32_t, int32_t>>, greater<pair<int32_t, int32_t>>> q;
    q.push(make_pair(0, 0));

    while (!q.empty()) {
        int32_t u, d_u;
        tie(d_u, u) = q.top();
        q.pop();

        if (visited[u]) continue;
        visited[u] = true;

        d[u] = d_u;

        for (auto e : A[u]) {
            int32_t v, d_uv;
            tie(d_uv, v) = e;

            if (d[v] > d_u + d_uv) {
                q.push(make_pair(d_u + d_uv, v));
            }
        }
    }

    for (int32_t i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

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

int main() {
  vector<long long> vec(3);
  long long tmpA,tmpB;

  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  sort(vec.begin(), vec.end());
  
  tmpA = vec.at(0) * vec.at(1) * (vec.at(2) / 2);
  tmpB = vec.at(0) * vec.at(1) * (vec.at(2) - vec.at(2) / 2);
  
  cout << abs(tmpB - tmpA);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    
    int[] d = new int[N];
    for (int i = 0; i < N; i++) {
      d[i] = Integer.parseInt(sc.next());
    }
    
    int sum = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        sum += d[i] * d[j];
      }
    }
    
    System.out.println(sum);
  }
}

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

int main() {
    int n, t, curr_max, global_max;
    scanf("%d", &n);
    curr_max = global_max = 1;
    bool isPeriod = false;
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        if (!isPeriod && t == 0) continue;
        if (isPeriod && t == 1) curr_max++;
        else if (isPeriod && t == 0) {
            global_max = max(global_max, curr_max);
            curr_max = 1; isPeriod = false;
        }
        else if (!isPeriod && t == 1) isPeriod = true, curr_max++;
    }
    if (isPeriod) global_max = max(global_max, curr_max);
    printf("%d\n", global_max);
    return 0;
}



Measured memory_bytes: 2736