akhauriyash/Code-Regression huggingface dataset:
/*
                                        //     //     //\\\\\\\\\
                                        \\    //      \\        \\
                                        //   //       //         \\
                                        \\  //        \\          \\
                                        // //         //           \\
                                        \\//          \\            \\       
                                        //\\          //            //
                                        \\ \\         \\           //
                                        //  \\        //          //
                                        \\   \\       \\         //
                                        //    \\      //        //
                                        \\     \\     \\/////////
*/

#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vint vector <int>
#define vll vector <long long int>
#define endl cout<<'\n'
#define fre(i,l,n) for(long long int i=l;i<n;++i)
#define fr(i,l,n) for(long long int i=l;i<=n;i++)
#define rfre(i,n,l) for(long long int i=n-1;i>=l;i--)
#define rfr(i,n,l) for(long long int i=n;i>=l;--i)
#define tab '\t'
#define debug cout<<'*';
#define s(a) cin>>a
#define p(a) cout<<a
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef pair<int,pair<int,int> > tii;
typedef vector<int> vec;
typedef vector<long long> vecll;
typedef vector<pair<int,int> > vec_pii;
typedef vector<pair<long long int,long long int> > vec_pll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<pair<int,int> > > vvpii;
typedef vector<vector<pair<ll,ll> > > vvpll;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define Pi 3.14159265358979
#define gcd(a,b) __gcd(a,b)
#define sf(n) scanf("%lld",&(n))
#define pf(n) printf("%lld\n",(n))
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define w(t) while(t--)
#define flt(a) cout<<fixed<<setprecision(a)
#define cntSetBits(n) __builtin_popcountll(n)
/*****************************
*****************************/



void solve()
{
    ll arr[5];
    ll ans;
    fre(i,0,5)
    {
        s(arr[i]);
        if(!arr[i])
        {
            ans = i+1;
        }
    }
    p(ans);endl;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t=1;
    // s(t);
    w(t)
    {
        solve();
    }
    return 0;
}









Measured memory_bytes: 3628
q,h,s,d=list(map(int,input().split()))
n = int(input())

ans = int(0)
if d < 2*s and d < 4*h and d < 8*q and n >= 2 :
    ans += int(n/2)*d
    n %= 2

if s < 2*h and s < 4*q:
    ans += n*s
elif h < 2*q:
    ans += n*2*h
else:
    ans += n*4*q

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
	if(n%2==0)
        cout<<"0.5";
    else
    {
    	float a;
    	a=n/2+1;
    	a=a/n;
    	cout<<a;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
const int N = 1e2+1;
ll w[N],val[N];
int n;
ll dp[100001][N];
ll f(int n,ll W)
{
    if(n==0 || W==0)
        return 0;
    if(dp[W][n] ==-1)
    {   if(w[n-1] <= W)
            dp[W][n] = max(f(n-1,W-w[n-1])+val[n-1],f(n-1,W));
        else
            dp[W][n] = f(n-1,W);
    }
    return dp[W][n];
}
int main() {
    
    ll W;
    cin>>n>>W;
    fi(i,0,n)
        cin>>w[i]>>val[i];
    memset(dp,-1,sizeof(dp));
    cout<<f(n,W);
return 0;
}


Measured memory_bytes: 79232
#include <stdio.h>

#define max(a, b) (a) > (b) ? (a) : (b)

int main() {
    int A;
    int B;
    scanf("%d", &A);
    scanf("%d", &B);

    int ans = max(max((A + B), (A - B)), A * B);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cmath> 
using namespace std;
int main()
{
	string a,b,cat;double num=0;int len;
	cin>>a>>b;
	cat=a+b;
	len=cat.length();
	//cout<<cat<<endl<<cat.length()<<endl;
	for(int i=1;i<=len;i++)
	{
		num+=(cat[i-1]-'0')*pow(10,len-i);
		//cout<<num<<endl;
	}	
	//cout<<num;
	if(num==int(sqrt(num)+0.5)*int(sqrt(num)+0.5))
	cout<<"Yes";
	else
	cout<<"No";
}

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

int main() {
	int n;
	cin >> n;
	set<string> s;
	for (int i = 0; i < n; i++) {
		string ss;
		cin >> ss;
		s.insert(ss);
	}

	cout << s.size() << endl;

	return 0;
}

Measured memory_bytes: 19224
#include<iostream>
#include<string>
using namespace std;
string s;
int main(){
    cin >> s;
    int w = 0;
    int l= 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'o'){
            w += 1;
        }
        else{
            l += 1;
        }
    }
    if((w + (15-s.size())) >=8){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

inline int addTax(int x, int p) {
    return x * (100 + p) / 100;
}

int main() {
    int x, y, s;
    while (cin >> x >> y >> s && (x || y || s)) {
        int mx = 0;
        for (int i=1; i<=1000; ++i) {
            for (int j=i; j<=1000; ++j) {
                if (addTax(i, x) + addTax(j, x) == s) {
                    mx = max(mx, addTax(i, y) + addTax(j, y));
                }
            }
        }
        cout << mx << endl;
    }
    return 0;
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
const ll inf = LLONG_MIN;
const ll N = (ll)2e5+77;

ll n,k,a[N],b[N];

int main() {
    fast;
    cin>>n>>k;
    k++;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    
    ll remove = 0;
    ll ans = 0;
    for(int i=30;i>=0;i--){
        if(k&(1LL<<i)){
            remove ^= (1LL<<i);
            ll sum = 0;
            for(int j=0;j<n;j++){
                if((a[j]&remove) == 0) sum+=b[j];
            }
            ans = max(ans,sum);
        }
        
        remove ^= (1LL<<i);
    }
    
    cout<<ans<<endl;
    return 0;
}


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

namespace AtCoder {

    class Program {

        static void Main(string[] args) {

            var n = int.Parse(Console.ReadLine());

            var temp = Console.ReadLine().Split(' ');
            var t = int.Parse(temp[0]);
            var a = int.Parse(temp[1]);

            var h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

            var results = new List<double>();
            foreach(var location in h) {

                var ave = t - location * 0.006;
                results.Add(Math.Abs(ave - a));
            }

            Console.WriteLine(results.IndexOf(results.Min()) + 1);
        }
    }
}


Measured memory_bytes: 13328
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a+b==60 && c>30){
			System.out.println(-1);
			return;
		}
			
		for(int i=0;;i++){
			int j=0;
			for(;;j++){
				int d = c+60*j;
				int e = (a+b)*i;
				if(e < d && d<=e+a){
					System.out.println(d);
					return;
				}else if(e+a < d){
					break;
				}else if(j>=100){
					System.out.println(-1);
					return;
				}
			}
		}

	}
}

Measured memory_bytes: 26384
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,a,b = MAP()

if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(n-a,b-1)-((b-a)//2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

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

  int a,b;
  cin>>a>>b;
  if(a<b) cout<<0<<endl;
  else cout<<10<<endl;
  
}

Measured memory_bytes: 256
result = ""
while true do
  h, w = gets.chomp.split.map(&:to_i)
  break if h == 0 && w == 0
  result += "#"*w + "\n"
  (h-2).times{ result += "#" + "."*(w-2) + "#" + "\n" }
  result += "#"*w + "\n\n"
end
puts result.chomp + "\n"


Measured memory_bytes: 15944
def val(a, b, x):
	return (a * x) // b - a * (x // b)

def naive(a, b, n):
	ans = 0
	for i in range(1, n + 1):
		ans = max(ans, val(a, b, i))
	return ans

def main(a, b, n):
		return max(val(a, b, n), val(a, b, max((n // b) * b - 1, 1)), val(a, b, max(n - 1, 0)))

# n = 10
# for a in range(1, 1000):
# 	for b in range(1, 1000):
# 		if naive(a, b, n) != main(a, b, n):
# 			print(a, b, naive(a, b, n), main(a, b, n))

a, b, n = list(map(int, input().split()))
print(main(a, b, n))


Measured memory_bytes: 9204
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int n;
	scanf("%d", &n);
	char s[11];
	ll cnt[5] = { 0 };
	REP(i, n) {
		//printf("%d\n", i);
		//*
		scanf("%s",s);
		/*/
		if (i <= 1e4)s[0] = 'M';
		else if (i <= 2e4)s[0] = 'A';
		else if (i <= 3e4)s[0] = 'R';
		else if (i <= 4e4)s[0] = 'C';
		else if (i <= 5e4)s[0] = 'H';
		//*/
		switch (s[0]) {
		case 'M':
			cnt[0]++;
			break;
		case 'A':
			cnt[1]++;
			break;
		case 'R':
			cnt[2]++;
			break;
		case 'C':
			cnt[3]++;
			break;
		case 'H':
			cnt[4]++;
			break;
		}
	}
	ll ans = 0;
	REP(i, 5) {
		SREP(j, i+1, 5) {
			SREP(k, j + 1, 5) {
				//printf("%d %d %d\n", i, j, k);
				ans += cnt[i] * cnt[j] * cnt[k];
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	long long a,b;
	cin>>a>>b;
	if(a <= 0 && b>=0){
		cout<<"Zero"<<endl;
		return 0;
	}
	else if(a == b){
		//cout<<1<<endl;
		cout<<"Positive"<<endl;
		return 0;
	}
	else if(a > 0){
		//cout<<2<<endl;
		cout<<"Positive"<<endl;
		return 0;
	}
	else if(b < 0){
		if((b - a) % 2 == 1){
			//cout<<3<<endl;
			cout<<"Positive"<<endl;
		}
		else{
			//cout<<4<<endl;
			cout<<"Negative"<<endl;
		}
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e5+5;

int main(){
	char s[5];
	cin>>s;
	int flag1=0,flag2=0;
	for(int i=0;i<3;i++){
		if(s[i]=='A')flag1=1;
		if(s[i]=='B')flag2=1;
	}
	if(flag1&&flag2)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N=int(input())
total=1
ans=1
inf=10**9+7
total=[0]*1000
for i in range(1,N+1):
    temp=prime_factorize(i)
    for j in range(len(temp)):
        total[temp[j]-1]+=1


for i in range(1000):
    ans*=total[i]+1
    ans%=inf
print(ans)

Measured memory_bytes: 9120
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	//ABC165 B
	unsigned long long x;
	unsigned long long y = 100;
	unsigned long long i = 1;
	// X

	cin >> x;


	while (1) {
		y += y / 100;
		if (y >= x) {
			break;
		}
		i++;
	}

	cout << i;

	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[][] price = new int[3][26];
		//
		for (int i = 0; i < 3; i++) {
			for (int j = 1; j < 26; j++) {
				switch (i) {
					case 0:
						price[i][j] = price[i][j - 1] + 380;
						if (j % 5 == 0) {
							price[i][j] -= 380;
						}
						break;
					case 1:
						price[i][j] = price[i][j - 1] + 550;
						if (j % 4 == 0) {
							price[i][j] -= 330;
						}
						break;
					case 2:
						price[i][j] = price[i][j - 1] + 850;
						if (j % 3 == 0) {
							price[i][j] -= 306;
						}
						break;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < n / 200 + 1; i++) {
				for (int j = 0; j < n / 300 + 1; j++) {
					for (int k = 0; k < n / 500 + 1; k++) {
						if (i * 200 + j * 300 + k * 500 == n) {
							int sum = price[0][i] + price[1][j] + price[2][k];
							if (sum < min) {
								min = sum;
							}
						}
					}
				}
			}
			System.out.println(min);
		}
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  long long ans = 0;
  for(int b=1;b<=N;b++){
    int p = N/b;
    int r = N%b;
    ans += p * max(0, b-K);
    ans += max(0, r-K+1);
  }
  if(K ==0){
    ans -= N;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#include <queue>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	priority_queue<int> a;
	rep(i,0,n){
		int tmp;
		cin >> tmp;
		a.push(tmp);
	}

	rep(i,0,m){
		int half = a.top();
		a.pop();
		a.push(half/2);
	}
	ll sum = 0;
	while(!a.empty()){
		sum += a.top();
		a.pop();
	}
	cout << sum << endl;
}


Measured memory_bytes: 892
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
llst = [0] * N
rlst = [0] * N

for i in range(N - 1):
    llst[i] = (i + 1) + a[i]
    rlst[-i - 1] = (N - i) - a[-i - 1]

d = defaultdict(int)
for i in range(1, N):
    d[rlst[i]] += 1

cnt = 0
for i in range(N - 1):
    cnt += d[llst[i]]

print(cnt)

Measured memory_bytes: 152908
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int a,b,bj=0;
int main() 
{
    cin>>a>>b;
    if((!((a+b)%3))||(!(b%3))||(!(a%3)))puts("Possible");
    else puts("Impossible");
    return 0;
}

Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    match std::io::stdin().read_line(&mut line) {
        Ok(0) => return Err("eof".to_string()),
        Ok(_) => (),
        Err(err) => return Err(format!("{:?}", err)),
    }

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

struct Answer {
    str: String,
}

impl Answer {
    fn new(str: String) -> Self {
        Self { str }
    }

    fn replace(&mut self, start: usize, end: usize, s: String) {
        let mut j = -1;
        let res = self
            .str
            .chars()
            .enumerate()
            .map(|(i, c)| {
                if i >= start && i <= end {
                    j += 1;
                    s.chars().nth(j as usize).unwrap()
                } else {
                    c
                }
            })
            .collect::<String>();
        self.str = res;
    }

    fn reverse(&mut self, start: usize, end: usize) {
        let r = self.str[start..end + 1]
            .to_string()
            .chars()
            .rev()
            .collect::<String>();
        self.replace(start, end, r)
    }

    fn print(&self, start: usize, end: usize) {
        println!("{}", &self.str[start..end + 1])
    }
}

fn main() {
    let sv = read_parameters::<String>().unwrap();
    let mut ans = Answer::new(sv[0].to_owned());
    let nv = read_parameters::<usize>().unwrap();
    let n = nv[0];

    for _ in 0..n {
        let cmd = read_parameters::<String>().unwrap();
        let (s, e) = (
            cmd[1].parse::<usize>().unwrap(),
            cmd[2].parse::<usize>().unwrap(),
        );

        match cmd[0].as_str() {
            "replace" => ans.replace(s, e, cmd[3].to_owned()),
            "reverse" => ans.reverse(s, e),
            "print" => ans.print(s, e),
            _ => (),
        }
    }
}



Measured memory_bytes: 5044
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define ceil_div(a,b) ((a+(b-1))/b)
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}


int main(){
	int n;IN(n);
	vector<int> a(n);
	rep(i,0,n){
		int t; IN(t); t--;
		a[t] = i;
	}
	rep(i,0,n){
		cout << a[i]+1 << " ";
	}
	cout << el;
	return 0;
}


Measured memory_bytes: 3156
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		while(true){
			int n=sc.nextInt(),p=sc.nextInt();
			if(n==0 && p==0)
				return;
			int ind=0;
			int freestone=p;
			int[] val=new int[n];
			while(val[ind]!=p){
				if(freestone==0){
					freestone=val[ind];
					val[ind]=0;
				}else{
					freestone--;
					val[ind]++;
				}
				ind=(ind+1)%n;
			}
			ln(ind);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 20216
#include "bits/stdc++.h"
using namespace std;
int A,B,K;
int main()
{
	cin>>A>>B>>K;
	for(int i=100;i>=1;i--)
	{
		if(A%i==0&&B%i==0)
		{
			K--;
			if(K==0)
			{
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}
/*
100 100 1
Output:100

75 35 2
Output:1
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2020;
int n;
bitset<N>A[N],l[N],r[N],lt[N],rt[N],dp[N],dpt[N];
int main() {
	read(n);rep(i,2,n){
		char S[N];scanf("%s",S+1);
		rep(j,1,i-1){
			int x=S[j]=='1';A[i][j]=x;A[j][i]=x^1;
		}
	}
	per(i,n,1)rep(j,i,n){
		if(j==i){l[i][j]=lt[j][i]=r[i][j]=rt[j][i]=1;continue;}
		dp[i][j]=dpt[j][i]=(l[i]&(rt[j]>>1)).any();
		int y=(A[i]&lt[j]&dp[i]).any();
		int z=(A[j]&r[i]&dpt[j]).any();
		l[i][j]=lt[j][i]=y;r[i][j]=rt[j][i]=z;
	}
	/*rep(i,1,n){
		rep(j,1,n)printf("%d ",(int)A[i][j]);puts("");
	}
	rep(i,1,n){
		rep(j,1,n)printf("%d ",(int)l[i][j]);puts("");
	}*/
	int res=0;rep(i,1,n)res+=l[i][n]&r[1][i];
	cout<<res;return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout << setprecision(10);
  string S, T;
  cin >> S >> T;
  int ret=0;
  for(int i=0; i<3; i++) ret+=S[i]==T[i]?1:0;
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int H = 0,W = 0;
  int i = 0,j = 0;

  for(;;){
  scanf("%d %d",&H,&W);

  if(H == 0 && W == 0){
    break;
  } else {

    for(i=0;i < H;i++){
      for(j=0;j < W;j++){

        putchar((i+j) % 2 == 0 ? '#':'.');
        /*if( j % 2 == 0){
          printf("#");
          }else {
          printf(".");
          }*/
      }
      puts("");
    }
    puts("");
  }
  }
  return 0;
}

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

int main()
{
int a;
int b;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> a;
	cin >> b;

	if( a > b )
		cout << a - 1 << endl;
	else
		cout << a << endl;

	return 0;
}






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

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}



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

char judge_grade(int pm, int pe, int pj)
{
    if(std::max({pm, pe, pj}) == 100 || (pm + pe) / 2 >= 90 || (pm + pe + pj) / 3 >= 80) {
        return 'A';
    } else if((pm + pe + pj) / 3 >= 70 || ((pm + pe + pj) / 3 >= 50 && std::max(pm, pe) >= 80)) {
        return 'B';
    } else {
        return 'C';
    }
}

int main()
{
    int num;
    
    while(num != 0) {

        std::cin >> num;

        int pm, pe, pj;

        for(int i = 0; i < num; i++) {
            std::cin >> pm >> pe >> pj;
            std::cout << judge_grade(pm, pe, pj) << std::endl;
        }

    }

    return 0;
}

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

void max_self(ll& a, ll b) {
    a = max(a, b);
}
void min_self(ll& a, ll b) {
    a = min(a, b);
}

const ll INF = 1e18L + 5;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<int> weight(n), value(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d%d", &weight[i], &value[i]);
    }
    int sum_value = 0;
    for(int x : value) {
        sum_value += x;
    }
    vector<ll> dp(sum_value + 1, INF); // 0 ... W
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with total value exactly i
    for(int item = 0; item < n; ++item) {
        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= sum_value; ++i) {
        if(dp[i] <= W) {
            answer = max(answer, (ll) i);
        }
        //~ min_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}


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

const int mod=1e9+7;

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>> dp(1001,vector<int>(1001,0));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char x;
            cin>>x;
            if(x=='.'){
                if(i==0 && j==0) dp[i][j]=1;
                else if(i==0) dp[i][j]=dp[0][j-1];
                else if(j==0) dp[i][j]=dp[i-1][j];
                else (dp[i][j]= dp[i][j-1]+dp[i-1][j])%=mod;
            }
            else if(x=='*'){
                dp[i][j]=0;
            }
        }
    }
    cout<<dp[h-1][w-1];

}

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

typedef long long LL;

#define INF 1000000000
#define INF_LL_YJ 1145141919810364364

using namespace std;

#define MAX_N 100005
int N;
LL A[MAX_N];
vector<int> Edge[MAX_N];

void input()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N-1; i++) {
    int f, t;
    cin >> f >> t;
    f--; t--;
    Edge[f].push_back(t);
    Edge[t].push_back(f);
  }
}

LL check(int pos, int pre = -1)
{
  bool leafNode = true;
  for (int i = 0; i < Edge[pos].size(); i++) {
    int next = Edge[pos][i];
    if(pre == next){
      continue;
    }
    leafNode = false;
    if(A[pos] > check(next, pos)){
      return INF_LL_YJ;
    }
  }
  if(leafNode){
    return A[pos];
  }
  else{
    return A[pos];
  }
}

int main()
{
  input();

  vector<int> ans;
  for (int i = 0; i < N; i++) {
    if(check(i) == INF_LL_YJ){
      ans.push_back(i+1);
    }
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
    if(i < ans.size()-1){
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main() {
	int a, l;
	while (cin >> a >> l, a || l) {
		string str = to_string(a);
		vector<string> vs;
		if (str.size() < l) {
			while (l - str.size()>0) {
				str = "0" + str;
			}
		}
		vs.push_back(str);

		int ii, ans;
		bool flag = false;
		while (!flag) {
			sort(str.begin(), str.end());
			string rev = str;
			reverse(rev.begin(), rev.end());

			string sub = to_string(stoi(rev) - stoi(str));
			if (sub.size() < l) {
				while (l - sub.size()>0) {
					sub = "0" + sub;
				}
			}

			REP(i, 0, vs.size()) {
				if (vs[i] == sub) {
					flag = true;
					ii = i;
					ans = vs.size() - i;
					break;
				}
			}

			vs.push_back(sub);
			str = sub;
		}

		cout << ii << " " << to_string(stoi(vs[ii])) << " " << ans << endl;

	}

	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int h, w;
    cin >> h >> w;
    V<string> s(h);
    rep(i,h) cin >> s[i];
    V<V<int>> d(h,V<int>(w, -1));
    d[0][0] = 0;
    queue<P> q;
    q.emplace(0,0);

    while(sz(q)) {
        P v = q.front(); q.pop();
        rep(ci,4) { 
            int ny = v.fi + dy[ci];
            int nx = v.se + dx[ci];
            if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
            if(d[ny][nx] != -1 || s[ny][nx] == '#') continue;
            d[ny][nx] = d[v.fi][v.se] + 1;
            q.emplace(ny,nx);
        }
    }
    if(d[h-1][w-1] == -1) {
        cout << -1 << endl;
        return 0;
    }

    int b_cnt = 0;
    rep(i,h)rep(j,w) {
        if(s[i][j] == '#') b_cnt++;
    }
    int ans = h*w - b_cnt - (d[h-1][w-1]+1);
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <stdio.h>
int main(void)
{
  int i,n,b,f,r,v,j,k;
  int count[4][3][10];
  scanf("%d",&n);
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	count[i][j][k]=0;
      }
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    count[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i==0||i==1||i==2){
      printf("####################\n");
    }
  }
    return 0;
}

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

using namespace std;

int s[31][31],mini[30][30][4];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

struct Data{
    int x,y,dir,cost;
    bool operator<(const Data &obj)const{
        if(cost != obj.cost)return cost > obj.cost;
        return false;
    }
};

int main(){

    while(1){
        int w, h;

        scanf("%d %d",&w,&h);
        if(w == 0 && h == 0)break;

        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                scanf("%d",&s[i][j]);
            }
        }
        int c[4];
        scanf("%d %d %d %d",&c[0],&c[1],&c[2],&c[3]);

        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                for(int k=0;k<4;++k){
                    mini[i][j][k] = INT_MAX;
                }
            }
        }
        mini[0][0][0] = 0;

        priority_queue<Data> Q;
        Q.push((Data){0,0,0,0});

        while(!Q.empty()){
            Data state = Q.top();
            Q.pop();
            if(state.x == w-1 && state.y == h-1){
                cout << state.cost << endl;
                break;
            }
            for(int i=0;i<4;++i){
                int newdir=(state.dir+i)&3, newcost=state.cost;
                int newx=state.x+dx[newdir], newy=state.y+dy[newdir];
                if(newx < 0 || newy < 0 || newx >= w || newy >= h)continue;
                if(s[state.y][state.x] != i)newcost += c[i];
                if(newcost < mini[newy][newx][newdir]){
                    Q.push((Data){newx,newy,newdir,newcost});
                    mini[newy][newx][newdir] = newcost;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1360
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){


    string s;cin>>s;
    string win;
    if(s[0]==s[s.size()-1])win=(s.size()%2==0 ?  "First":"Second");
    else win=(s.size()%2==0 ? "Second":"First");
    cout<<win<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = (1<<29);
vector<int> adj[100005];
int d1[100005], dN[100005];

void dfs1(int v, int dist){
    d1[v] = dist+1;
    for(int i=0; i<adj[v].size(); i++){
        if(d1[adj[v][i]] == INF) dfs1(adj[v][i], dist+1);
    }
}

void dfsN(int v, int dist){
    dN[v] = dist+1;
    for(int i=0; i<adj[v].size(); i++){
        if(dN[adj[v][i]] == INF) dfsN(adj[v][i], dist+1);
    }
}

int main(){
    int N; cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b; cin >> a >> b;
        adj[a].push_back(b), adj[b].push_back(a);
    }

    for(int i=1; i<=N; i++) d1[i] = dN[i] = INF;

    dfs1(1, -1);
    dfsN(N, -1);

    int fe = 0, sn = 0;
    for(int i=2; i<=N-1; i++){
        if(d1[i] <= dN[i]) fe++;
        else sn++;
    }

    if(fe > sn) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

}

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

int main() {
    int x;
    cin >> x;
    vector<int> a;
    int c, p;
    
    a.push_back(1);
    
    for (int i = 2; i < x; i++) {
        c = i * i;
        
        while (c <= x) {
            a.push_back(c);
            c *= i;
        }
    }
    
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    cout << a[a.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

//#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e18;
const int MB = 32;
const int MOD = 1e9 + 7;
const int maxN = 1 << 21;

void solve() {
    string s;
    cin >> s;
    vector<vector<int>> dp(2, vector<int>(s.size() + 1));
    dp[1][0] = 1;
    for (int i = 1; i <= s.size(); i++) {
        dp[0][i] = min(dp[1][i - 1] + 10 - (s[i - 1] - '0'), dp[0][i - 1] + (s[i - 1] - '0'));
        dp[1][i] = min(dp[1][i - 1] + 10 - (s[i - 1] - '0') - 1, s[i - 1] == '9' ? INF : dp[0][i - 1] + s[i - 1] - '0' + 1);
    }
    cout << dp[0].back();
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

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


int main() {
  int N,M,X;
  vector<int> A(M);
  cin >> N>>M>>X;
  for(int i=0;i<M;i++){
    cin >> A.at(i);
  }

  int count_0,count_N;


  for(int i=0;i<M;i++){
    if(A.at(i)<X){
      count_0++;
    }
    else{
      count_N++;
    }
  }



  cout << min(count_0,count_N) << endl;
  
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef pair<int,P> PP;
typedef pair<ll,LP> LPP;

int main(){
    int e;
    while(cin >> e && e!=0){
        int mini=inf;
        for(int z=0;z*z*z<=e;z++){
            for(int y=0;y*y<=e;y++){
                int x=e-z*z*z-y*y;
                if(x<0)break;
                mini=min(mini,z+y+x);
                // printf("x:%d,y:%d,z:%d min:%d\n",x,y,z,mini);
            }
        }
        cout << mini << endl;
    }

    return 0;
}


Measured memory_bytes: 3068
n = int(input())
m = []
a = [[] for i in range(n)]
for i in range(n):
    tmp = int(input())
    m.append(tmp)
    for j in range(tmp):
        a[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        flg = True
        if i >> j & 1:
            cnt += 1
            for k in range(m[j]):
                kj = (i >> (a[j][k][0]-1)) & 1
                if a[j][k][1] != kj:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ans = max(ans, cnt)
            
print(ans)     

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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()

void solve(){
	string s;
  	cin>>s;
  	char c = s[s.length()-1];
  	if(c == 's')
      cout<<s+"es";
  	else
      cout<<s+"s";
  	cout<<endl;
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

long long facTable[20];
int num[26];
long long fac(int n)
{
	if(n==0) return 1;
	if(facTable[n-1]!=0) return facTable[n-1];
	facTable[n-1] = fac(n-1)*n;
	return facTable[n-1];
}

int main()
{
	string s;
	cin >> s;
	for(int i=0;i<s.length();i++)
		num[(int)s[i]-97]++;
	long long res=s.length(),r=1;
	int odd=0;
	int lastOdd=-1;
	for(int i=0;i<26;i++)
	{
		if(num[i]%2==1)
		{odd++;lastOdd=i;}
	}
	if(odd>1) res=0;
	else
	{
		for(int i=0;i<26;i++)
		{
			if(i!=lastOdd)
			{
				r*=fac(num[i]/2);
			} else 
			{
				res--;
				r*=fac((num[i]-1)/2);
			}
		}
		res=fac(res/2)/r;
	}
	cout << res << endl;
	return 0;
}

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

void solve() {
  int n; cin >> n;
  cout << ((n-1) / 1000 + 1) * 1000 - n << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
constexpr ll kInf = ll(1E16 + 10);

int x[20], y[20], dis[20], rx[20], ry[20], v[20];
ll p[20], ans[20];

int ABS(int n) {return n >= 0 ? n : -n;}

int main() {
	int n, sz, tmp, idx, idy;
	ll tans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d%d%lld", &x[i], &y[i], &p[i]);
	for (int i = 0; i <= n; i++) ans[i] = kInf;
	for (int i = 0; i < (1 << n); i++) {
		sz = 0;
		tmp = i;
		while (tmp) {
			v[sz++] = __lg(tmp & -tmp);
			tmp ^= tmp & -tmp;
		}
		for (int j = 0; j < (1 << sz); j++) {
			idx = idy = 0;
			for (int k = 0; k < sz; k++) if (j & (1 << k)) rx[idx++] = x[v[k]];
			else ry[idy++] = y[v[k]];
			for (int k = 0; k < n; k++) if (!(i & (1 << k))) {
				dis[k] = min(ABS(x[k]), ABS(y[k]));
				for (int i = 0; i < idx; i++) dis[k] = min(dis[k], ABS(x[k] - rx[i]));
				for (int i = 0; i < idy; i++) dis[k] = min(dis[k], ABS(y[k] - ry[i]));
			}
			else dis[k] = 0;
			tans = 0;
			for (int k = 0; k < n; k++) tans += dis[k] * p[k];
			ans[sz] = min(ans[sz], tans);
		}
	}

	for (int i = 0; i <= n; i++) printf("%lld\n", ans[i]);
}


Measured memory_bytes: 1736
#2
ans = int(input())
ans_lists=[]
a = [1,2,3,4,5,6,7,8,9]
b = [1,2,3,4,5,6,7,8,9]
for a_youso in a:
    for b_youso in b:
        n=a_youso*b_youso
        ans_lists.append(n)
if ans in ans_lists:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

 
void solve(){
	int n,m;
    cin>>n>>m;
    int x,y;
    vector<int>v(n,1);
    vector<bool>ball(n,false);
    ball[0]=true;
    rep(i,m){
        cin>>x>>y;
        x--;y--;
        v[x]--;v[y]++;
        if(ball[x])ball[y]=true;
        if(v[x]==0)ball[x]=false;
    }
    int ans=0;
    rep(i,n){
        if(ball[i]&&v[i])++ans;
    }
    cout<<ans<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

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

int main() {

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    if(a > k) {
       sum = k;
       cout << sum << '\n';
       return 0;
    }

    k -= a;
    sum += a;

    if(b > k) {
        cout << sum << '\n';
        return 0;
    }

    k -= b;
    sum -= k;

    cout << sum << '\n';

    return 0;
}

Measured memory_bytes: 3596
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
s="".join(s)
t="".join(t)
for i in range(min(len(s),len(t))):
  if ord(s[i])==ord(t[i]):
    continue
  elif ord(s[i])<ord(t[i]):
    print("Yes")
    break
  else:
    print("No")
    break
else:
  if len(s)<len(t):
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	int A[200*1000];
	SET_ZERO(A);
	for (int i = 0; i < N; i++) {
		int tmp;
		scanf("%d", &tmp);
		A[tmp]++;
	}

	sort(A, A+200*1000, greater<int>());
	int ans = 0;
	for (int i = 0; i < 200*1000; i++) {
		if (A[i] == 0) break;
		if (i+1 > K) ans+=A[i];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

int A, B, H, M;
double a, b, c, cc;
double sita, sitaA, sitaB;

int main() {
  std::cin >> A >> B >> H >> M;

  a = (double)A;
  b = (double)B;
  sitaA = 30 * H + 0.5 * M;
  sitaB = 6 * M;
  sita = std::abs(sitaA - sitaB);
  if (sita >= 180) {
    sita = 360 - sita;
  }
  sita = sita * M_PI / 180.0;

  cc = a * a + b * b - 2 * a * b * std::cos(sita);
  c = std::sqrt(cc);

  //std::cout << std::cos(sita) << std::endl;
  std::cout << std::setprecision(30) << c << std::endl;

  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0 && m == 0) break;
    vi a(m, 0);
    REP(i, n) {
      int d, v; cin >> d >> v;
      a[d-1] = max(a[d-1], v);
    }
    int ans = 0;
    REP(i, m) {
      ans += a[i];
    }
    cout << ans << endl;
  }
}



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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> w(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>w[i];
    }
    int res=1e9;
    for(int i=0;i<n;i++){
        int left=0;
        int right =0;
        for(int j=0;j<n;j++){
            if(j<=i)
                left += w[j];
            else
                right +=w[j];
        }
        res = min(res,abs(left-right));
    }
    cout<<res;
}


Measured memory_bytes: 256
# coding: utf-8

from itertools import permutations
import Queue

N, M, R = map(int, raw_input().split())
r = [i - 1 for i in map(int, raw_input().split())]

G = [[] for _ in xrange(N)]

for i in range(M):
    A, B, C = map(int, raw_input().split())
    A -= 1; B -= 1;
    G[A].append((B, C))
    G[B].append((A, C))

# dijkstra Algorithm
def dijkstra(s):
    d = [float("inf") for _ in xrange(N)]
    que = Queue.PriorityQueue()
    d[s] = 0
    que.put([0, s])

    while not que.empty():
        p = que.get()
        v = p[1]
        if d[v] < p[0]:
            continue
        for i, j in G[v]:
            if d[i] > d[v] + j:
                d[i] = d[v] + j
                que.put([d[i], i])
    return d

table = {}

for i in r:
    table[i] = dijkstra(i)

ans = float('inf')

for i in permutations(r):
    ans = min(ans, sum([table[i[j]][i[j+1]] for j in xrange(R-1)]))

print ans


Measured memory_bytes: 7532
N = int(input())
A = [int(a) for a in input().split()]

A.sort()

def divisor(n):
    L = [] 
    i = 1
    while i <= n**0.5:
        if i == n**0.5:
            L.append(i)
        if n%i == 0:
            L.append(i)
            L.append(n/i)
        i += 1
    L.sort(reverse=True)
    return L

List = divisor(A[0]) + divisor(A[1])
List.sort(reverse=True)

for i in range(len(List)):
    c = 0
    for j in range(N):
        if A[j]%List[i] == 0:
            c += 1
    if c >= N-1:
        ans = List[i]
        break

print(int(ans))

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

int main(){
    int N; cin >> N;
    map<string,ll> A;
    rep(i,N){
        string a; cin >> a;
        sort(a.begin(),a.end());
        A[a]++;
    }
    
    ll ans=0;
    for (auto i:A){
        ll x=i.second;
        ans+=x*(x-1)/2;
    }
    cout << ans;
}

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

int main() {
    int N; cin >> N;
    char S[N][N];
    char S2[N][N];
    rep(i, N){
        rep(j, N){
            cin >> S[i][j];
        }
    }

    int ans = 0;
    rep(k, N){
        rep(i, N){
            rep(j, N){
                int x = (i+k) % N;
                S2[x][j] = S[i][j];
            }
        }

        bool ok = true;
        rep(i, N){
            for (int j = i+1; j < N; j++){
                if(S2[i][j] != S2[j][i]){
                    ok = false;
                    break;
                }
            }
            if(!ok)break;
        }
        if(ok)ans++;
    }

    cout << ans * N << endl;

    return 0;
}

Measured memory_bytes: 3808
program main
	implicit none
	integer i, S
	integer(8) N, Nh
	read(*, *) N
	Nh = N
	S = 0
	do i = 1, 10
		S = S + mod(N, 10)
		N = N / 10
		if(N < 10) then
			S = S + N
			exit
		end if
	end do
	if(mod(Nh, S) == 0) then
		write(*, *) 'Yes'
	else
		write(*, *) 'No'
	end if
end program main

Measured memory_bytes: 640
N = int(input())
R = []
B = []

for i in range(N):
    a,b = list(map(int, input().split()))
    R.append([a, b])

for i in range(N):
    c, d = list(map(int, input().split()))
    B.append([c,d])

B.sort()

pair = [0] * N
ans = 0

for i in range(N):
    bx, by = B[i]
    d = -1
    d_j = -1
    for j in range(N):
        ax, ay = R[j]
        if ax < bx and ay < by and pair[j] == 0:
            if ay > d:
                d = ay
                d_j = j
    if d_j != -1:
        pair[d_j] = 1
        ans += 1

print(ans)

Measured memory_bytes: 3064