akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n;
    cin >> s;
    ll e_cnt = 0, w_cnt = 0;

    rep(i, 1, n){
        if('E' == s[i]){
            e_cnt++;
        }
    }

    ans = INF;

    rep(i, n){
        cnt = e_cnt + w_cnt;
        ans = min(ans, cnt);

        if(n - 1 > i && 'E' == s[i + 1]){
            e_cnt--;
        }
        if ('W' == s[i]){
            w_cnt++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 720
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b, c, d = [int(elem) for elem in input().split()]

res = (b+1 - a) - ((b) // c) - ((b) // d) + ((a-1) // c) + ((a-1) // d) + ((b) // lcm(c, d)) - ((a-1) // lcm(c, d))
print(res)

Measured memory_bytes: 5088
class BIT:
    def __init__(self, n):
        #A1 ... AnのBIT(1-indexed)
        self.BIT = [0] * (n + 1)
        self.n = n

    #A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    #Ai += x O(logN)
    def add(self, idx, x):
        while idx <= self.n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return
def get_int(f):
    if "." not in f:
        return int(f),0
    return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(input())
p = []
for i in range(n):
    a, b = get_int(input())
    c, d = 0, 0
    while a % 2 == 0:
        c += 1
        a //= 2
    while a % 5 == 0:
        d += 1
        a //= 5
    c -= b
    d -= b
    p.append((c, d))
p.sort(key=lambda x:x[0])
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
    for j in range(now, i, -1):
        if p[i][0] + p[j][0] >= 0:
            t.add(-p[j][1] + 25, 1)
            now -= 1
        else:
            break
    if now < i:
        t.add(-p[i][1] + 25, -1)
    ans += max(0, t.query(25 + p[i][1]))

print(ans)

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

#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcases=1;
    //cin>>testcases;
    //cout<<t;
    //scanf("%d",&t);
    while(testcases--){   
        string s,t;
        cin>>s>>t;
        int c=0;
        fori(0,s.size()){
            if(s[i]!=t[i]) c++;
        }
        cout<<c<<endl;
    }
    
    return 0;
}
 


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

int N;
vector<int> A;

void input() {
    cin >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}

int main() {
    input();
    int x = 1;
    for (int a : A) if (x == a) x++;
    if (x == 1) cout << -1 << endl;
    else cout << N - x + 1 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int a, b, c, x, y;
int main(){
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(2*c <= a + b){
        int t = min(x, y);
        x -= t;
        y -= t;
        ans += 2 * c * t; 
    }
    if(2*c <= a){
        ans += 2 * c * x;
        y = max(0, y - x);
        x = 0;
    }
    if(2*c <= b){
        ans += 2 * c * y;
        x = max(0, x - y);
        y = 0;
    }
    ans += a * x;
    ans += b * y;
    cout << ans;
}

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

int main() {
	int k,s,c=0;
	cin >> k >> s;
	for(int x = 0;x <= k;x++){
		for(int y = 0;y <= k;y++){
			int z = s - x - y;
			if(z < 0){
				break;
			}
			if(z > k){
				continue;
			}
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 7;
int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<int>>dp(H + 1, vector<int>(W, 0));
	dp[0][0] = 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			//同じ列の線パターン全てをbit全探索を使って表している
			for (int k = 0; k < 1 << (W - 1); ++k) {
				bool ok = true;
				//l番目に線があれば１ここではとなりあっていた場合を弾いている
				for (int l = 0; l < W - 2; ++l) {
					if (((k >> l) & 1) && (k >> (l + 1)) & 1)
						ok = false;
				}
				if (ok) {
					if (j >= 1 && ((k >> (j - 1)) & 1)) {
						dp[i + 1][j - 1] += dp[i][j];
						dp[i + 1][j - 1] %= INF;
					}
					else if (j <= W - 2 && ((k >> j) & 1)) {
						dp[i + 1][j + 1] += dp[i][j];
						dp[i + 1][j + 1] %= INF;
					}
					else {
						dp[i + 1][j] += dp[i][j];
						dp[i + 1][j] %= INF;
					}
				}
			}
		}
	}
	cout << dp[H][K - 1] << endl;
	return 0;
}

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


int main() {

	//入力
	int a, b, c, d, e;
	int k;
	cin >> a >> b >> c >> d >> e;
	cin >> k;

	//処理
	string ans;
	int L = e - a;
	if (L <= k) ans = "Yay!";
	else ans = ":(";

	//出力
	cout << ans << endl;
}



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

int main() {
    int N, K;
    cin >> N >> K;
    int count = 0;
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a >= K) {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
// Union Find 木
package main

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

func find(parent []int, i int) int {
	if parent[i] == -1 {
		return i
	}
	parent[i] = find(parent, parent[i])
	return parent[i]
}

func unite(parent []int, i, j int) {
	i = find(parent, i)
	j = find(parent, j)
	if i == j {
		return
	}
	parent[i] = j
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func main() {
	n := readInt()
	k := readInt()
	l := readInt()

	roads := make([]int, n)
	fill(roads, -1)
	rails := make([]int, n)
	fill(rails, -1)

	for i := 0; i < k; i++ {
		p := readInt()
		q := readInt()
		unite(roads, p-1, q-1)
	}

	for i := 0; i < l; i++ {
		p := readInt()
		q := readInt()
		unite(rails, p-1, q-1)
	}

	d := map[int]int{}
	for i := 0; i < n; i++ {
		d[2000001*find(roads, i)+find(rails, i)]++
	}

	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = d[2000001*find(roads, i)+find(rails, i)]
	}
	printIntln(result...)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func printIntln(v ...int) {
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}


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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }

    int main(){
        int k,a,b;
        cin>>k>>a>>b;
        for(int i=a;i<=b;i++){
            if(i%k==0){
                cout<<"OK";
                return 0;
            }
        }
        cout<<"NG";
        return 0;
    }


Measured memory_bytes: 3624
class Solve
  def initialize
    n, m = gets.split.map(&:to_i)
    o = STDIN.read.lines.map{ |l| l.split.map(&:to_i) }

    ans = 0
    m.times do |i|
      g = {}
      tmp = o.dup
      tmp.delete_at(i)
      tmp.each do |a, b|
        g[a] ? (g[a] << b) : (g[a] = [b])
        g[b] ? (g[b] << a) : (g[b] = [a])
      end

      s = Search.new(g)
      s.dfs(1)
      ans += 1 if s.check(n)
    end
    puts ans
  end

  class Search
    def initialize(g)
      @c = {}
      @g = g.dup
    end

    def dfs(v)
      @c[v] = 1
      @g[v].each { |i| dfs(i) unless @c[i]} if @g[v]
    end

    def check(n)
      @c.length != n
    end
  end
end
Solve.new


Measured memory_bytes: 2428
import sys
input = sys.stdin.readline
a=int(input())
b=int(input())
c=int(input())

x=int(input())
cnt=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500+j*100+k*50==x:
                cnt+=1
print(cnt)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using ll =  long long;

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

using namespace std;

int main(){

    int s, w;

    cin >> s >> w;
    
    if(s<=w)
        cout << "unsafe" << endl;
    else
        cout << "safe"  <<  endl;

    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const int MAX= 1e6+100;

ll a[MAX],dp[MAX][3];

int main(){
	fastio;
	ll tc,n,b,x,k,q,l,r;
	cin>>n;
	f(i,1,n+1) cin>>a[i];
	dp[0][0]=dp[0][2]=-1e18;
	dp[1][0]=-1e18;
	dp[1][2]=a[1];
	f(i,2,n+1) {
		if(i&1) f(j,0,3) dp[i][j]=max(dp[i-1][j],a[i]+dp[i-2][j]);
		else{
			f(j,0,2) dp[i][j]=max(dp[i-1][j+1],a[i]+dp[i-2][j]);
			dp[i][2]=a[i]+dp[i-2][2];
		}
	}
	cout<<dp[n][1]<<endl;
  	return 0;
}

Measured memory_bytes: 9864
#! /usr/bin/env python
# -*- coding : utf-8 -*-

import math
import sys

def main() :
	lines=sys.stdin.readlines()
	N=int(lines[0])
	l=map(int, lines[1].split(" "))
	x=int(round(1.0*sum(l)/N))
	print sum(pow(a-x, 2) for a in l)

if __name__=="__main__" :
	main()


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;

int INFp=1000000007;
const string minusinf ="-";
const int mininf = -1;
int cost[10]={0,
    2
    ,
    5
    ,
    5
    ,
    4
    ,
    5
    ,
    6
    ,
    3
    ,
    7
    ,
    6
};
void chmax(string &a,string b){
    if(a == minusinf) a=b;
    else if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}


int main(){
    int n,m;
    int a[15];
    cin>>n>>m;
    for(int i=0;i<m;i++) cin>>a[i];
    
    //sort(a,a+m,greater<int>());
    
    //int dp[11000]={-1};//i本使うときの最大桁数
    const int NONE=-1;
    vector<int> dp(n+1, NONE);
    dp[0]=0;
    
    for(int i=0; i<=n; i++){
        if(dp[i] == -1)
            continue;
        
        int index;
        for(int j=0; j<m; j++){
            index = i + cost[a[j]];
            if(index > n)
                continue;
            
            dp[index] = max(dp[index], dp[i]+1);
        }
    }
    
    
    int costcount=n;
    
    vector<int> ans;
    int cnt = n;
    for(int i=0; i<dp[n]; i++){
        int select = -1;
        for(int j=0; j<m; j++){
            int dst = cnt - cost[a[j]];
            if(dst < 0 || dp[dst] == -1)
                continue;
            
            if(dp[cnt]-dp[dst] == 1)
                select = max(select, a[j]);
        }
        
        ans.push_back(select);
        cnt -= cost[select];
    }
    
    
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	int k, a, b;
	cin >> k >> a >> b;

	if(a + 2 >= b or 1 + k < a){
		cout << 1 + k << endl;
		return 0;
	}

	k -= (a - 1);
	int c = a + (b - a) * (k / 2);

	if(k % 2) c++;
	cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int gcd(int a, int b) {//最大公約数
	if (b == 0)return a;
	return gcd(b, a%b);
}

bool solve(int N, int K) {
	if (N == 1)return true;
	if (N < K)return false;
	if (N%K == 0)return solve(N / K, K);
	else return solve(N % K, K);
}

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

	int N; cin >> N;
	int ans = 0;
	if (N == 2) {
		cout << 1 << endl;
		return 0;
	}

	for (int i = 2; i*i <= N; i++) {
		if (N%i == 0) {
			if (solve(N, i))ans++;
			if (i*i != N) {
				if (solve(N, N / i))ans++;
			}
		}
	}
	if (solve(N, N))ans++;
	N--;
	if (solve(N, N))ans++;
	for (int i = 2; i*i <= N; i++) {
		if (N%i == 0) {
			if (solve(N + 1, i))ans++;
			if (i*i != N) {
				if (solve(N + 1, N / i))ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}



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

int main(){
  int64_t N;
  cin >> N;
  int64_t Ans=0LL;
  for(int64_t i=1; i<=N; i++){
    if(i%3LL==0LL || i%5LL==0LL){
    }
    else{
      Ans+=i;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  map<int, int> freq;
  forn(i, n) {
    int x;
    cin >> x;
    freq[x]++;
    ans += x;
  }

  int q;
  cin >> q;

  while(q--){
    int b,c;
    cin >> b >> c;
    ans -= 1ll*b * freq[b];
    ans += 1ll*c * freq[b];
    freq[c] += freq[b];
    freq[b] = 0;
    cout << ans << "\n";
  }
}


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main(void) {
  while(1) {
    int n;
    cin >> n;

    if(n == 0) break;

    double s[n];
    rep(i, n) cin >> s[i];

    double a=0, m=0;
    rep(i, n) m += s[i];
    m /= n;

    rep(i, n) {
      a += pow((s[i]-m), 2);
    }

    a /= n;
    a = sqrt(a);

    printf("%.15lf\n", a);
  }
}



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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
    public:
    double x, y;
    
    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(a * x, a * y); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x * x + y * y;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}

struct Segment {
    Point p1, p2;
};

typedef Segment Line;

class Circle {
    public:
        Point c;
        double r;
        Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef vector<Point> Polygon;

bool isParallel(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
    return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
    return equals(cross((s1.p2 - s1.p1), (s2.p2 - s2.p1)), 0.0);
}

bool isOrthogonal(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
    return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2) {
    return equals(dot((s1.p2 - s1.p1), (s2.p2 - s2.p1)), 0.0);
}

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point p1 = {x1, y1};
    Point p2 = {x2, y2};
    Segment s = {p1, p2};

    int q;
    cin >> q;
    double x, y;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        Point p = {x, y};

        Point x = project(s, p);

        cout << fixed << setprecision(11) << x.x << " " << x.y << endl;
    }
}



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

int main() {
    string S;
    cin >> S;
    int min_num_changes = (1 << 29) - 1;

    // The first color is black
    int num_changes = 0;
    for (int i = 0; i < S.size(); i++) {
        char color = S.at(i);
        if ((i % 2 == 0 && color == '1') || 
            (i % 2 == 1 && color == '0')) {
            num_changes += 1;
        }
    }
    min_num_changes = min(min_num_changes, num_changes);

    // The first color is white
    num_changes = 0;
    for (int i = 0; i < S.size(); i++) {
        char color = S.at(i);
        if ((i % 2 == 0 && color == '0') ||
            (i % 2 == 1 && color == '1')) {
                num_changes += 1;
        }
    }
    min_num_changes = min(min_num_changes, num_changes);
    cout << min_num_changes << "\n";
}

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

int main() {
	int ng[1001001] = {};
	int n; cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);

	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if(ng[a[i]]) continue;
		else {
			if(a[i] != a[i+1] || i == n-1) res++;
			for (int j = a[i]; j <= 1000000; j+=a[i])
			{
				ng[j] = 1;
			}
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 8220
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

typedef long long LL;
const int MAX_N = 1e5 + 6;

LL a[MAX_N];

int main () {
	LL n;
	while (scanf("%lld",&n) != EOF) {
		LL sum=0;
		for (int i=1;n>=i;i++) {
			scanf("%lld",&a[i]);
			sum += a[i];
		}
		a[n+1] = a[1];
//		cout<<"sum = "<<sum<<endl;
		if (sum%((n+1)*n/2) != 0) {
			puts("NO");
			continue;
		}
		LL T=sum/((n+1)*n/2);
		LL _0=0,_1=0;
		bool ans=true;
		for (int i=1;n>=i;i++) {
			LL dis=a[i+1]-a[i];
			if (abs(T-dis)%n != 0) {
				ans=false;
				break;
			}
			LL x=(T-dis)/n;
			if (x<0 || T-dis<0) {
				ans=false;
				break;
			}
			_1 += x;
			_0 += (n-x);
		}
		if (_1 != T) ans=false;
		if (ans) puts("YES");
		else puts("NO");
	}
}

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

int main()
{
  std::string a;
  std::cin >> a;
  std::vector<int> ans(a.length(), 0);
  int r = 0;
  for (int i = 0; i < a.length(); ++i)
  {
    if (a[i] == 'R')
      r = i;
    else
      ++ans[((i - r) % 2) ? r + 1 : r];
  }
  int l = (int)a.length() - 1;
  for (int i = (int)a.length() - 1; i >= 0; --i)
  {
    if (a[i] == 'L')
      l = i;
    else
      ++ans[((l - i) % 2) ? l - 1 : l];
  }
  for (int i = 0; i < ans.size(); ++i)
    std::cout << ans[i] << ' ';
}

Measured memory_bytes: 1024
fn main(){
    let a: i32 = read();
    for _ in 0..3{
        read::<i32>();
    };
    let e: i32 = read();
    let k: i32 = read();
    if  e - a>k {println!(":(")}
    else { println!("Yay!")};

}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M
import Data.List

main :: IO ()
main = do
    [_, m] <- readInts
    as <- readInts
    print $ solve m as

readInts :: IO [Int]
readInts = map (maybe (error "parse error") fst . B.readInt) . B.words <$> B.getLine

solve :: Int -> [Int] -> Int
solve m =  M.foldl' (+) 0
     . fmap (\x -> x * (x - 1) `div` 2)
     . foldr (M.alter $ return . maybe 1 succ)  M.empty
     . map (`mod` m)
     . scanl' (+) 0


Measured memory_bytes: 19836
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll k,x; cin>>k;
    x=7%k;
    rep(i,k+1){
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
        x = (x*10+7)%k;
    }
    cout<<-1<<endl;
    return 0;
}

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


int main(){
	int n, m;
	cin >> n;
	vector<string> s(n);
	rep(i,n) cin >> s.at(i);
	cin >> m;
	vector<string> t(m);
	rep(i,m) cin >> t.at(i);
	int ans = 0;
	rep(i,n){
		int cnt = 0;
		rep(j,n){
			if(s.at(i)==s.at(j)){
				cnt++;
			}
		}
		rep(j,m){
			if(s.at(i)==t.at(j)){
				cnt--;
			}
		}
		
		ans = max(ans,cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
a,b=input().split()
pp=input().split()
a=int(a)
b=int(b)
p=[]
for pa in pp:
    p.append(int(pa))
x=0
y=-1
while True:
    if a+x not in p:
        aa=a+x
        break
    elif a+y not in p:
        aa=a+y
        break
    x+=1
    y+=-1
print(aa)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    while(1){
        int N;
        cin>>N;
        if(N==0) return 0;

        double x[N],y[N],z[N],r[N];
        rep(i,N) cin>>x[i]>>y[i]>>z[i]>>r[i];

        using pint = pair<int,int>;
        using Edge = pair<double, pint>;
        vector<Edge> edges;

        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                double l=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]));
                if(l>r[i]+r[j]){
                    edges.push_back({l-(r[i]+r[j]), pint(i, j)});
                }
                else{
                    edges.push_back({0, pint(i, j)});
                }
            }
        }

        // Kruskal 法
        sort(all(edges));
        // unionfindのスニペット読み込んで
        UnionFind uf(N);
        double res = 0;
        
        for (auto e : edges) {
            int u = e.second.first, v = e.second.second;
            double cost = e.first;
            if (uf.issame(u, v)) continue;
            uf.merge(u, v);
            res += cost;
        }

        cout<<fixed<<setprecision(3)<<res<<endl;

    }

    
}


 


Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int n,k,a[200100],cnt[400100];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	while(k--)
	{
		bool flag=0;
		for(int i=1;i<=n;i++) if(a[i]<n) flag=1;
		if(!flag) break;
		for(int i=1;i<=n;i++) cnt[i]=0;
		for(int i=1;i<=n;i++) cnt[max(1,i-a[i])]++,cnt[i+a[i]+1]--;
		for(int i=1;i<=n;i++) cnt[i]+=cnt[i-1];
		for(int i=1;i<=n;i++) a[i]=cnt[i];
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 6160
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int main() {
    IO;
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> r, g, b;
    for(int i = 0; i < n; i++)
        if(s[i] == 'R') r.push_back(i);
        else if(s[i] == 'G') g.push_back(i);
        else b.push_back(i);
    ll ans = 0;
    // G in middle
    for(int x : g){
        int i, j;
        ans += (upper_bound(r.begin(), r.end(), x) - r.begin()) * (b.end() - upper_bound(b.begin(), b.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'R' && s[j] == 'B') ans--;

        ans += (upper_bound(b.begin(), b.end(), x) - b.begin()) * (r.end() - upper_bound(r.begin(), r.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'B' && s[j] == 'R') ans--;
    }

    // R in middle
    for(int x : r){
        int i, j;
        ans += (upper_bound(b.begin(), b.end(), x) - b.begin()) * (g.end() - upper_bound(g.begin(), g.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'B' && s[j] == 'G') ans--;

        ans += (upper_bound(g.begin(), g.end(), x) - g.begin()) * (b.end() - upper_bound(b.begin(), b.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'G' && s[j] == 'B') ans--;
    }

    // B in middle
    for(int x : b){
        int i, j;
        ans += (upper_bound(r.begin(), r.end(), x) - r.begin()) * (g.end() - upper_bound(g.begin(), g.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'R' && s[j] == 'G') ans--;

        ans += (upper_bound(g.begin(), g.end(), x) - g.begin()) * (r.end() - upper_bound(r.begin(), r.end(), x));
        for(i = x - 1, j = x + 1; i >= 0 && j < n; i--, j++)
            if(s[i] == 'G' && s[j] == 'R') ans--;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>

int main(void){
    long n;
    scanf("%ld",&n);
    long i,sum=0;
    for(i=1;i<n+1;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    printf("%ld\n",sum);
    return 0;
}


Measured memory_bytes: 1732
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
S, T = "", ""


def set_inputs():
    global S, T
    S = get_str()
    T = get_str()
    return


def main():
    set_inputs()
    dp = [[0 for _ in range(len(T) + 1)] for _ in range(len(S) + 1)]
    for i in range(1, len(S) + 1):
        for j in range(1, len(T) + 1):
            if S[i-1] == T[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i][j-1], dp[i-1][j])

    i = len(S)
    j = len(T)
    ret = ""

    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ret += S[i-1]
            i -= 1
            j -= 1
    print(''.join(reversed(ret)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 120156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        const int WHITE = 0;
        const int GRAY = 1;
        const int BLACK = 2;
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] m = new int[n, n];
            for(int i=0;i<n;++i)
            {
                string[] szarr = Console.ReadLine().Split(' ');
                //int u = int.Parse(szarr[0]);
                int k = int.Parse(szarr[1]);
                for(int j=0;j<k;++j)
                {
                    int v =int.Parse( szarr[j+ 2]);
                    int idx = v - 1;
                    m[i, idx] = 1;
                }
            }
            int[] color = new int[n];
            int[] d = new int[n];
            int[] f = new int[n];
            DFS(0, color, d, f, m);
            for(int i=0;i<n;++i)
            {
                string sz = string.Format("{0} {1} {2}", i + 1, d[i], f[i]);
                Console.WriteLine(sz);
            }
        }
        static void DFS(int u, int[] color, int[] d, int [] f, int[,] m)
        {
            Stack<int> s = new Stack<int>();
            s.Push(u);
            color[u] = GRAY;
            int time = 0;
            d[u] = ++time;
            while(s.Count >= 1)
            {
                u = s.Peek();
                int v = Next(m, u, color);
                if( v != -1)
                {
                    if( color[v] == WHITE)
                    {
                        color[v] = GRAY;
                        d[v] = ++time;
                        s.Push(v);
                    }
                }
                else
                {
                    s.Pop();
                    color[u] = BLACK;
                    f[u] = ++time;
                }

                if( s .Count == 0)
                {
                    // 残ってる頂点検索
                    for(int i=0;i<color.Length;++i)
                    {
                        if( color[i] == WHITE)
                        {
                            s.Push(i);
                            d[i] = ++time;
                            break;
                        }
                    }
                }
            }
         }
        static int Next(int[,] m , int u, int[] color)
        {
            for(int i=0;i<m.GetLength(0);++i)
            {
                if(m[u,i] == 1 && color[i] == WHITE)
                {
                    return i;
                }
            }
            return -1;
        }
    }

}



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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int n,i;
  scanf("%d%d",&n,&i);
  if(n*i%2==0) printf("No");
  else printf("Yes");

  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()
L = LIST()

bound = 1
d = 0
for i in range(N):
	d = d + L[i]
	if d <= X:
		bound += 1
	else:
		break

print(bound)

Measured memory_bytes: 59756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100100
const ll inf = (ll)1e10;
const ll mod = (ll)1e9+7;
ll dp[22][1 << 22];
bool chk ( int pos, int mask ) {
	return mask & (1 << pos);
}
int on ( int pos, int mask ) {
	return mask | (1<<pos);
}
int n;
int mat[22][22];
ll solve ( int pos, int mask ) {
	if ( pos == n ) {
		int taken = __builtin_popcount(mask);
		if ( taken == n ) return 1;
		return 0;
	}
	if ( dp[pos][mask] != -1 ) return dp[pos][mask];
	ll ret = 0;
	for ( int i = 0; i < n; i++ ) {
		if ( mat[pos][i] == 1 && !chk(i,mask) ) ret = (ret+solve(pos+1,on(i,mask)))%mod;
	}
	return dp[pos][mask] = ret;
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) {
			cin >> mat[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << endl;
	return 0;
}
 


Measured memory_bytes: 721152
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

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

    string s; cin >> s;
    s += (s.back() == 's' ? "es" : "s");
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
    string s; cin >> s;
    rep(i, s.size()){
        if((i+1) % 2 == 1 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) continue;
        else if((i+1) % 2 == 0 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
  int N,M;
  int i;
  char S[100010][3];
  int p[100010];
  int w[100010]={0};
  int pen[100010]={0};
  int ans=0;
  int pe=0;
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d %s",&p[i],S[i]);
    if(S[i][0]=='W'){
      if(w[p[i]]==0){
        pen[p[i]]++;
      }
    }
    else if(S[i][0]=='A'){
      if(w[p[i]]==0){
        ans=ans+1;
      }
      w[p[i]]=1;
    }
  }
  for(i=0;i<=N;i++){
    if(w[i]==0){
      pen[i]=0;
    }
    pe=pe+pen[i];
  }
  printf("%d %d\n",ans,pe);
  return 0;
}


Measured memory_bytes: 3196
n,m = map(int,input().split())
l = [[0 for _ in range(n)] for _ in range(m)]
for i in range(n):
    a = list(map(int,input().split()))
    for j in a[1:]:
        l[j-1][i] = 1
c = 0
for t in l:
    if sum(t) == n:
        c+= 1
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int D,N;cin>>D>>N;
    int x=pow(100,D);
    int ans=0;
    REP(i,N){
        ans+=x;
        if((ans/x)%100==0)ans+=x;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int best = 1e8;
    rep(i, n) {
        int x = a[i];
        int c = 0;
        while (x % 2 == 0) {
            x /= 2;
            c++;
        }
        best = min(best, c);
    }
    put(best);

    return 0;
}

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

const int INF = 1e7;

int main(){

    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    for (int i=0; i<m; ++i){
        int a, b;
        cin >> a >> b;
        // 配列の位置と入力の数値を統一する
        --a;
        --b;
        // aからb, bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
        /*
        // aからb, bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
        graph.at(a).at(b);
        graph.at(b).at(a);
        */
    }

    // BFSのためにキューを用意する
    queue<int> q;
    // 原点からの距離とどの部屋からその部屋に行けるかの位置を示す配列を用意
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);

    // 原点への距離を0で初期化
    dist.at(0) = 0;
    // キューに原点を始点として進むことのできる部屋を追加
    q.push(0);

    while (!q.empty()){

        // キューの先頭データをコピー
        int v = q.front();
        // 先頭データを削除
        q.pop();

        // キューに保存された場所から到達できる部屋について距離を確定させる
        for (auto u: graph.at(v)){
            // すでに距離が更新されている場合は、何もしない
            if (dist.at(u) != INF){
                continue;
            }
            // 点vから到達できる点uへの距離は、原点から点vまで到達するまでにかかる距離+1となる
            dist.at(u) = dist.at(v) + 1;
            // 点uにつながる点を記録
            pre.at(u) = v;
            // 点vから到達できる点uをキューに格納し、点uから再びBFSを実施
            q.push(u); 
        }
    }

    cout << "Yes" << endl;
    for (int i=1; i<n; ++i){
//        int ans = ++pre.at(i);
        int ans = pre.at(i);
        ++ans;
        cout << ans << endl;
    }
    return 0;
}


// 二次元配列の宣言方法の違い
// 10行0列の二次元配列の宣言方法
/*
int test_func(){

    int a = 3, b = 2;

    vector <int> to[10];
    to[a].push_back(b);
    to[a].push_back(a);

    vector<vector<int>> test(10);
    test.at(a).push_back(b);
    test.at(a).push_back(a);

    cout << "to is ..." << endl;
    for (auto x: to[3]){
        cout << x << endl;
    }
    cout << "test is ..." << endl;
    for (auto x: test.at(3)){
        cout << x << endl;
    }
    return 0;
}
*/

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int n, m;
  cin >> n >> m;

  vi x(m), y(m);
  rep(i, 0, m){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  vi num(n, 1);
  vector<bool> ans(n);
  ans[0] = true;
  rep(i, 0, m){
    if(ans[x[i]]){
      if(num[x[i]] == 1){
        ans[x[i]] = false;
      }
      ans[y[i]] = true;
    }

    num[x[i]]--;
    num[y[i]]++;
  }

  int res = 0; 
  rep(i, 0, n) res += ans[i];
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2560
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut ans = std::usize::MAX;

    for i in 1..=((n as f64).sqrt().floor()) as usize {
        if n % i == 0 {
            ans = ans.min(i + n / i - 2);
        }
    }
    println!("{}", ans);
}


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

int main(){
	int n,i,j,k,b,f,r,v;
	int matter[4][3][10]={0};



	cin >>n;


	for(i=0;i<n;i++){
		cin >>b>>f>>r>>v;
		matter[b-1][f-1][r-1]+=v;
	}

	for(k=0;k<4;k++){
		for(i=0;i<3;i++){
			for(j=0;j<10;j++){
				cout << " " <<matter[k][i][j];
			}
		cout << endl;
		}
		if(k!=3){
			for(i=1;i<21;i++){
				cout <<"#";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n, w; cin >> n >> w;
    vector<int> v(n), h(n);
    REP(i, n) cin >> v[i] >> h[i];

    auto dp = make_v(n + 1, w + 1, 0);

    REP(i, n )REP(j, w + 1) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

        if (j + h[i] <= w) {
            dp[i][j + h[i]] = max(dp[i][j + h[i]], dp[i][j] + v[i]);
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}



Measured memory_bytes: 6844
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define V_MAX 10000
#define WHITE 1
#define BLACK 2

vector<int> G[V_MAX];
int indig[V_MAX];
int V_color[V_MAX];

vector<int> l;

void init(){
    for(int i = 0; i < V_MAX; i++){
        indig[i] = 0;
        V_color[i] = WHITE;
    }
}

void tpsort(int num){
    queue<int> Q;
    Q.push(num);
    int target;

    while(!Q.empty()){
        target = Q.front(); Q.pop();
        V_color[target] = BLACK;
        l.push_back(target);
        for(int i = 0; i < G[target].size(); i++){
            indig[G[target][i]]--;
            if(indig[G[target][i]] == 0){
                Q.push(G[target][i]);
            }
        }
    }
}

int main(void){
    init();
    int V, E;
    scanf("%d %d", &V, &E);

    for(int i = 0; i < E; i++){
        int s, t, d;
        scanf("%d %d", &s, &t);
        G[s].push_back(t);
        indig[t]++;
    }

    for(int i = 0; i < V; i++){
        if(indig[i] == 0 && V_color[i] == WHITE){
            tpsort(i);
        }
    }

    for(int i = 0; i < l.size(); i++){
        printf("%d\n", l[i]);
    }

    return 0;
}



Measured memory_bytes: 4064
N,M = list(map(int,input().split()))
A = []
B = []
for _ in range(M):
    temp = list(map(int,input().split()))
    A.append(temp[0])
    B.append(temp[1])
cnt = 0
minA = max(A)
maxA = min(B)
if maxA - minA + 1 > 0:
    print(maxA - minA + 1)
else:
    print(0)
        

Measured memory_bytes: 11096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

ll m;
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> m;
    cout << (m / (11)) * 2 + (m%11 ? (m%11 > 6 ? 2 : 1) : 0) << endl;
    return 0;
}


Measured memory_bytes: 256