akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1000;
int h, w, v[5]={0, 1, 0, -1, 0};
string s[N];
queue<pii> q, qq;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  FOR(i, 0, h)cin >> s[i];
  FOR(i, 0, h)FOR(j, 0, w) if(s[i][j] == '#') q.push(mp(i, j));
  int ans = -1;
  while(!q.empty()){
    while(!q.empty()){
      pii t = q.front(); q.pop();
      FOR(i, 0, 4){
        int _h=t.fi+v[i], _w=t.se+v[i+1];
        if(0<=_h && _h<h && 0<=_w && _w<w && s[_h][_w]=='.'){
          s[_h][_w] = '#';
          qq.push(mp(_h, _w));
        }
      }
    }
    swap(q, qq);
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9616
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    ///a*x+b*y=c
    ///all is about time 
   	int n = readInt();
   	for (int i = 0; i <= 100; i++) {
   		for (int j = 0; j <= 100; j++) {
   			if (i * 4 + j * 7 == n)  {
   				cout << "Yes";
   				return 0;
   			}
   		}
   	}
   	cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int H1, M1, H2, M2, K;

    AtCoder(FastScanner sc) {
        H1 = sc.nextInt();
        M1 = sc.nextInt();
        H2 = sc.nextInt();
        M2 = sc.nextInt();
        K = sc.nextInt();
    }

    void solve(PrintWriter out) {
        int m = (H2 - H1) * 60 + M2 - M1;
        out.println(Math.max(0, m - K));
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 32580
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    string n;
    cin >> n;
    ll s = 0;
    rep(i, n.size()) s += n.at(i) - '0';
    // cout << s;
    if(stoi(n) % s == 0)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
 
using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU 
 
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    vi A;
    REP(i, q) {
        int com;
        cin >> com;
        if (com == 0) {
            int x;
            cin >> x;
            A.push_back(x);
        }
        else if (com == 1) {
            int p;
            cin >> p;
            cout << A[p] << endl;
        }
        else {
            A.pop_back();
        }
    }
    PAU;
    return 0;
}


Measured memory_bytes: 3916
import sys
sys.setrecursionlimit(200000+10)

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

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
            # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

UF = UnionFind(N)
li = [i for i in range(N+20)]

for i in range(len(AB)):
    AB[i][0] -= 1
    AB[i][1] -= 1
    UF.Unite(AB[i][0], AB[i][1])

cnt = [UF.Count(i) for i in range(N)]
print(max(cnt))

Measured memory_bytes: 132896
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

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

    int sum = 0;
    REP(i,0,n){
        int l,r;
        cin >> l >> r;
        sum += (r - l + 1);
    }
    cout << sum << endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define endl '\n'

struct __init {
    __init() {
        cin.tie(nullptr);
        std::iostream::sync_with_stdio(false);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        std::mt19937 rand(300);
    }

    ~__init() {
        #ifdef SEREZHKA
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC << endl;
        #endif
    }
} init;

const ll inf = (ll) 1e9 + 7ll;
const int maxn = (int) 1e6 + 17;

int n, m;
int a[maxn];
vector<int> g[maxn], vec[maxn];
bool used[maxn];

bool read() {
    if (!(cin >> n >> m))
        return false;

    forn (i, n)
        cin >> a[i];

    forn (i, m) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    return true;
}

void dfs(int v, int p) {
    used[v] = true;
    vec[p].push_back(a[v]);

    for (auto to : g[v])
        if (!used[to])
            dfs(to, p);
}

void solve() {
    ll ans = 0;
    int cnt = 0;

    forn (i, n)
        if (!used[i]) {
            dfs(i, i);
            sort(vec[i].begin(), vec[i].end(), std::greater<int>());
            ans += vec[i].back();
            vec[i].pop_back();
            ++cnt;
        }

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

    std::multiset<int> ms;

    forn (i, n)
        for (auto t : vec[i])
            ms.insert(t);

    forn (i, cnt - 2)
        if (ms.empty()) {
            cout << "Impossible\n";
            return ;
        } else {
            ans += *ms.begin();
            ms.erase(ms.begin());
        }

    cout << ans << endl;
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int n;
  cin >> n;
  vt<int> a(n), b(n), c(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n) cin >> c[i];

  sort(all(a));
  sort(all(c));
  i64 ans = 0;
  rep(i, 0, n) {
    i64 aa = lower_bound(all(a), b[i]) - a.begin();
    i64 cc = n - (upper_bound(all(c), b[i]) - c.begin());
    ans += aa * cc;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;

int main() {
	int n;
    cin >> n;
    vector<int> x(n), y(n), xrev(n), yrev(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
        xrev[x[i]] = yrev[y[i]] = i;
    }

    dsu d(n);
    set<int, greater<int>> s;
    for (int x = 0; x < n; ++x) {
        int i = xrev[x];
        auto itr = s.upper_bound(y[i]);
        if(itr == s.end()) {
            s.insert(y[i]);
        } else {
            while(1) {
                d.merge(i, yrev[*itr]);
                if(*itr == *prev(s.end())) break;
                s.erase(itr);
                itr = s.upper_bound(y[i]);
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << d.size(i) << endl;
    }
}


Measured memory_bytes: 11672
<?php

while(fscanf(STDIN, "%d%d", $h, $w)){
    if($h == 0 && $w == 0){
        return 1;
    }

$count = 1;

for($j = 1; $j <= $h; $j++){

    if($count % 2 == 1){

//#.#.#.
    for($i = 1; $i <= $w; $i++){
        if($i % 2 == 1){
            echo "#";
        }else{
            echo ".";
        }
    }
    echo PHP_EOL;
    $count++;
    }else{

//.#.#.#
    for($i = 1; $i <= $w; $i++){
        if($i % 2 == 1){
            echo ".";
        }else{
            echo "#";
        }
    }
    echo PHP_EOL;
    $count++;
    } // if count()
    
} // for($j =)
echo PHP_EOL;

} //while

?>

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

using namespace std;
long long a[200010],ans = 0;
int main(){
    int i,n,k;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a + n);
    for(i=0;i<n - k;i++){
        ans += a[i];
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    int mini = n + 1, ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        mini = min(mini, x);
        if (x == mini) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
H,W,D=map(int, input().split())
A=[list(map(int,input().split())) for i in range(H)]
Q=int(input())
LR=[list(map(int,input().split())) for i in range(Q)]
pos=[(-1,-1) for i in range(H*W+1)]
for h in range(H):
    for w in range(W):
        pos[A[h][w]]=(h,w)
cost=[0]*(H*W+1)
for i in range(1+D,H*W+1):
    cost[i]=cost[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])
for q in range(Q):
    print(cost[LR[q][1]]-cost[LR[q][0]])

Measured memory_bytes: 42224
#include<bits/stdc++.h>                   
using namespace std;                      
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)   
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
                                          
#define pb push_back                      
#define PII pair<int,int>                 
                                          
#define VS vector<string>                 
#define VI vector<int>                    
#define ll long long int                  
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {                          
    int n;cin >> n;                       
    vector<int> a(n);                     
    REP(i,n) cin >> a[i];                 
    sort(a.begin(),a.end());              
    int count = 1;                        
    FOR(i,1,a.size()) {                   
        if(a[i] != a[i-1]) count++;       
    }                                     
    cout << count - 1 + (count%2) << endl;                                                                                                 
} 

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <map>
using namespace std;

int main(){
    typedef pair<int,long double> P;
    int n,tmp;
    long double tmp1,tmp2;
    while(cin >> n,n){
        P p;
        p.first = 1000001;
        p.second = 10000;
        for(int i=0;i<n;i++){
            cin >> tmp >> tmp1 >> tmp2;
            tmp1 /= 100;
            tmp1 *= tmp1;
            tmp2 /= tmp1;
            tmp2 -= 22.000;
            tmp2 = fabs(tmp2);
            if(tmp2 < p.second || (tmp2 <= p.second && tmp < p.first)){
                p.first = tmp;
                p.second = tmp2;
            }
        }
        cout << p.first << endl;
    }
}

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

long long n,k;

int main()
{
    cin>>n>>k;
    int cnt=0;
    long long p=1;
    for(long long i=1;i<=n;i++)
    {
        if(n<pow(k,i))
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
string s,sir;
int mx,mn,lst,i;
char ch;
int main()
{
    cin>>sir;mn=10000;
    for(ch='a';ch<='z';ch++)
    {
        lst=-1;mx=0;s=sir+ch;
        for(i=0;i<s.size();i++)
        {
            if(s[i]==ch) mx=max(mx,i-lst-1),lst=i;
        }
        if(mx<mn) mn=mx;
    }
    cout<<mn;
    return 0;
}

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

vector<int> g[100010];
int d[100010];
int res = 0;

// for d[]
void dfs(int pre, int cur, int depth) {
    d[cur] = depth;
    for(int to : g[cur]){
        if (to == pre) continue;
        dfs(cur, to, depth + 1);
    }
}

void chase(int pre, int cur, int turn) {
    if (turn >= d[cur] && (int)g[cur].size() > 1) {
        res = max(res, turn);
    }
    for(int to : g[cur]){
        if (to == pre) continue;
        chase(cur, to, turn + 1);
    }
}

int main(void){
    int n, u, v;
    cin >> n >> u >> v;
    u--,v--;
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(-1,u,0);
    chase(-1,v,0);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

int f(int n){
    int ans = 0;
    for(int x = 1; x*x <= n; x++){
        if(x*x > n) continue;
        for(int y = 1; x*x + y*y + x*y <= n; y++){
            if(x*x + y*y > n) break;
            for(int z = 1; x*x + y*y + z*z + x*y + y*z + z*x <= n; z++){
                if(x*x + y*y + z*z + x*y + y*z + z*x == n) ans++;
            }
        }
    }
    return ans;
}



signed main() {
    int n;
    int ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        printf("%d\n", f(i));
    }
    return 0;
}

Measured memory_bytes: 3588
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,a,b) for (int i = a; i < b; i++)
using namespace std;
typedef long long ll;

vector<int> adj[200005];
int ans[200005];

void dfs(int v, int p) {
    for (auto u: adj[v]) {
        if (u == p)
            continue;
        ans[u] += ans[v]; 
        dfs(u, v);
    }
}

int main(void) {
   int n, q;
   cin >> n >> q;
   REP(i, 0, n - 1) {
       int a, b;
       cin >> a >> b;
       a--; b--;
       adj[a].push_back(b);
       adj[b].push_back(a);
   }

   REP(i, 0, q) {
       int p, x;
       cin >> p >> x;
       p--;
       ans[p] += x;
   }

   dfs(0, -1);
   REP(i, 0, n) cout << ans[i] << endl;
}

Measured memory_bytes: 23424
n = gets.chomp.to_i

a = Math.sqrt(n).to_i

arr = []
1.upto(a).each do |v|
  r = n % v
  next if r.nonzero?
  b = n / v
  arr.push [v,b]
end

puts arr.map{|v| v[0] + v[1] - 2}.min


Measured memory_bytes: 1916
use proconio::*;

fn run() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    }
    let x = x.abs();
    let ans = if x / d >= k {
        x - k * d
    } else {
        let q = x / d;
        let x = x - q * d;
        let k = k - q;
        if k % 2 == 0 {
            x
        } else {
            d - x
        }
    };
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2144
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
long long n,a[200000],b[200000],q,memo,x,y,r,m,l,i;
int main()
{
    cin >> n;
    r=10000000000;
    for(i=0;i<n;i++){
      cin >> a[i];
      b[i]=a[i];
    }
    sort(b,b+n);
    q=b[n-1];
    if(q%2==0){
      x=q/2;
      y=q/2;
    }else{
      x=q/2;
      y=q/2+1;
    }
    for(i=0;i<n;i++){
      if(a[i]==q){;
      }else{
      if(abs(a[i]-x)<abs(a[i]-y))m=abs(a[i]-x);
      else m=abs(a[i]-y);
      if(m<r){r=m;
              memo=i;
             }
      }
    }
    printf("%lld %lld",q,a[memo]);
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		idea2();
	}

	// これで提出したら不正解だった…原因は不明
	private static void idea1() {

		// 入力
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long v = sc.nextInt();
		long b = sc.nextInt();
		long w = sc.nextInt();
		long t = sc.nextInt();

		// 子Bの逃げる速さが、鬼Aと同速かそれ以上だったら、永遠に追いつけない
		if (v <= w) {
			System.out.println("NO");
			return;
		}

		// ２人の距離は１秒にどれくらい縮まるか？
		long speed = v - w;

		// ２人は最初どのくらい離れているか？
		long dis = (a < b) ? (b - a) : (a - b);

		// 追いつくのに何秒かかるか？
		long need = dis / speed;

		// t秒以内に追いつけたらYES
		System.out.println((need <= t) ? "YES" : "NO");

	}

	private static void idea2() {

		// 入力
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long v = sc.nextInt();
		long b = sc.nextInt();
		long w = sc.nextInt();
		long t = sc.nextInt();

		// ２人は最初どのくらい離れているか？
		long dis = (a < b) ? (b - a) : (a - b);

		for (int i = 1; i <= t; i++) {
			// ふたりの距離を更新
			dis = dis - v + w;

			// 追いついたらYES
			if (dis <= 0) {
				System.out.println("YES");
				return;
			}

		}

		System.out.println("NO");

	}

}


Measured memory_bytes: 35792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll A[n];
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
        }
        sort(A,A+n);
        cout<<A[n-1]-A[0];
    }    
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define ff first
#define ss second

int main() {
    ll n, ai, bi, ci, sum = 0, q;
    int arra[100002];
    memset(arra, 0, sizeof(arra));
    cin >> n;
    while(n--){
        cin >> ai;
        arra[ai]++;
        sum += ai;
    }
    cin >> q;
    while(q--){
        cin >> bi >> ci;
        sum = sum - (bi*arra[bi]) + (ci*arra[bi]);
        arra[ci] += arra[bi];
        arra[bi] = 0;
        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 3984
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int X, Y, Z;

  cin >> X >> Y >> Z;

  X -= Z;

  cout << X / (Y + Z) << endl;


  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<stack>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define rrep(f,i,n) for(int (i)=0;(i) < (f); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define mset(a,x) memset(a,x,sizeof(a))

#define MAX 101
#define MAX_V 15
long long a[200005];
long long b[200005];
int main()
{
	long long n, s = 0;
	cin >> n;
	rep(i, n) {
		cin >> b[i];
		if (i)
			a[i] = a[i - 1] + b[i];
		else
			a[i] = b[i];
	}
	long long m = a[n - 1] /2;
	long long r = a[0];
	int j=0;
	for (int i = 1; i < n - 1; i++) {
		if (abs(m - a[i]) <= abs(m - r)) {
			r = a[i];
			j = i;
		}
	}
	for (int i = j + 1; i < n; i++) {
		s += b[i];
	}
	cout << abs(s - r) << endl;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll vet[n+2];
    map<int,int> cont;
    ll soma=0;
    rep(i,0,n){
        cin>>vet[i];
        soma+=vet[i];
        cont[vet[i]]++;
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        ll qt = cont[b];
        cont[b]-=qt;
        soma += qt*(c-b);
        cont[c]+=qt;
        cout<<soma<<"\n";
    }
    return 0;  
}   

Measured memory_bytes: 8708
import sys

icase=0
if icase==0:
    n,k=map(int,input().split())
    s=input()

if n==1:
    print(1)
    sys.exit()

ss=[]
if s[0]=="1" and s[1]=="1":
    zcnt=1
elif s[0]=="1" and s[1]=="0":
#    ss.append(1)
    zcnt=1
elif s[0]=="0" and s[1]=="0":
    ss.append(0)
    zcnt=1
elif s[0]=="0" and s[1]=="1":
    ss.append(0)
#    ss.append(1)
    zcnt=1

for i in range(1,n-1):
    if s[i]=="0" and s[i-1]=="0":
        zcnt+=1
    elif s[i]=="0" and s[i-1]=="1":
        ss.append(zcnt)
        zcnt=1
    elif s[i]=="1" and s[i-1]=="1":
        zcnt+=1
    elif s[i]=="1" and s[i-1]=="0":
        ss.append(zcnt)
        zcnt=1
        
for i in range(n-1,n):
    if s[i]=="0" and s[i-1]=="0":
        zcnt+=1
        ss.append(zcnt)
        ss.append(0)
    elif s[i]=="0" and s[i-1]=="1":
        ss.append(zcnt)
        ss.append(1)
        ss.append(0)
    elif s[i]=="1" and s[i-1]=="1":
        zcnt+=1
        ss.append(zcnt)
    elif s[i]=="1" and s[i-1]=="0":
        ss.append(zcnt)
        ss.append(1)

#print(ss)

if len(ss)<=2*k+1:
    print(n)
    sys.exit()

smax=0
for i in range(2*k+1):
    smax+=ss[i]
#print(smax)    
ssum=smax    
kk=2*k
for i in range(2,len(ss)-kk,2):
    ssum=ssum-ss[i-2]-ss[i-1]+ss[i+kk-1]+ss[i+kk]
    smax=max(smax,ssum)

print(smax)
    

Measured memory_bytes: 10040
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPS(i, n) for (int i = 1; i <= (n); i++)
#define RREPS(i, n) for (int i = (n); i > 0; i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int d = min(A+B,2*C);
  int ans;
  if(X >= Y){
    ans = Y*d + (X-Y)*min(A,2*C);
  }
  else{
    ans = X*d + (Y-X)*min(B,2*C);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n , a , b , l , r , len , rb , ra , e , Ra , rem;
void doit(int a , int b , int len , int l , int r) {
    int L = 0 , R = a / len , ans = -1;
    while(L <= R) {
	int mid = (L + R) >> 1 , res = 0;
	res = (b - mid + 1) / (a - mid * len + 1); if((b - mid + 1) % (a - mid * len + 1) != 0) ++ res;
	if(res > len)  R = mid - 1; else L = mid + 1 , ans = mid;
    }
    for(int i = l;i <= min(r , ans * (len + 1) - 1);++ i) if(i % (len + 1) == 0) putchar('B'); else putchar('A');
    if(r < ans * (len + 1)) return;
    l = max(l , ans * (len + 1));
    rb = b-(ans - 1),ra=a-ans * len;e = ans * (len + 1);
    if(l == e) {
	++ l; putchar('B'); if(l > r) return;
    }
    ++ e;-- rb;
    Ra = rb / len + (rb % len != 0) - 1;
    e = e + ra - Ra;
    for(int i = l;i <= min(r , e - 1);++ i) putchar('A');
    l = max(l,e); ra = Ra; if (l> r) return;
    rem = len - ((ra + 1) * len - rb);
    for(int i = l;i <= r;++ i) if(i < rem + e) putchar('B');else if(i % (len + 1) == (rem+e) % (len + 1)) putchar('A'); else putchar('B');
}

main(void) {
    for(cin >> n;n--;) {
	cin >> a >> b >> l >> r;
	if(a > b) len = (a / (b + 1)) + (a % (b + 1) != 0);else len = b / (a + 1) + (b % (a + 1) != 0);doit(a , b , len , l , r);puts("");
    }
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int abs(int n)
{
    if (n > 0) return (n);
 
    return (n * -1);
}
 
int max(int a, int b)
{
    a = abs(a);
    b = abs(b);
 
    if (a > b) return (a);
 
    return (b);
}
 
int main(void)
{
    int i;
    int n;
    int x[3], y[3];
    int t[2];
    int sum;
 
     
    cin >> t[0] >> t[1] >> n;
    x[0] = y[0] = 1;
    sum = 0;
     
    cin >> x[0] >> y[0];
    for (i = 0; i < n - 1; i++) {
     
        cin >> x[1] >> y[1];
 
        x[2] = x[1] - x[0];
        y[2] = y[1] - y[0];
 
        if ((x[2] > 0 && y[2] > 0) || x[2] < 0 && y[2] < 0) {
            sum += max(x[2], y[2]);
        }
        else {
            sum += abs(x[2]) + abs(y[2]);
        }
 
        x[0] = x[1];
        y[0] = y[1];
    }
 
     
    cout << sum << endl;
 
    return 0;
}


Measured memory_bytes: 3060
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math

s = input().split()
p = [int(w) for w in s] #これで勝手にNまで拾ってくれます

N = p[0]
K = p[1]


#とりあえずそのまま計算
A = (N+1) * (N+2) * N / 6
B = K * (K-1) * (2*K - 3*N - 4) / 6
C = N - K + 2
ans = int(A+B+C) 
#print(ans)
print(ans % 1000000007)


Measured memory_bytes: 9820
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int skill[][] = new int [n][m];
    int price[] = new int[n];
    int res = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      price[i] = sc.nextInt();
      for (int j = 0; j < m; j++) {
        skill[i][j] = sc.nextInt();
      }
    }
    for (int i = 0; i < (int)Math.pow(2, n); i++) {
      String tmp = Integer.toBinaryString(i);
      int sumPri = 0;
      int und[] = new int[m];
      Arrays.fill(und, 0);
      for (int j = 0; j < tmp.length(); j++) {
        if (tmp.charAt(tmp.length()-1-j) == '0') continue;
        for (int k = 0; k < m; k++) {
          und[k] += skill[j][k];
        }
        sumPri += price[j];
      }
      int min = Integer.MAX_VALUE;
      for (int j = 0; j < m; j++) {
        min = Math.min(min, und[j]);
      }
      if (min >= x) {
        res = Math.min(res, sumPri);
      }
    }
    if (res == Integer.MAX_VALUE) res = -1;
    System.out.println(res);
    // for (int i = 0; i < n; i++) {
    //   int ind = price[i].index;
    //   int tmp = Integer.MAX_VALUE;
    //   for (int j = 0; j < m; j++) {
    //     und[j] += skill[ind][j];
    //     tmp = Math.min(tmp, und[j]);
    //   }
    //   res += price[i].price;
    //   if (tmp >= x) {
    //     System.out.println(res);
    //     return;
    //   }
    // }
    // System.out.println(-1);
    sc.close();
  }

  static class Data implements Comparable<Data>{
    int index; int price;
    Data(int index, int price) {
      this.index = index;
      this.price = price;
    }

    @Override
    public int compareTo(Data o) {
      return Integer.compare(price, o.price);
    }
  }
}

Measured memory_bytes: 38400
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    // input
    static int N;
    static String[] s;

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        s = new String[N];
        for(int i=0;i<N;i++){
            s[i] = sc.next();
        }
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){
        int ans;
        int ab = 0;
        int ba = 0;
        int a=0;
        int b=0;

        for(int i=0;i<N;i++){
            ab += s[i].split("AB", -1).length - 1;
            boolean _b = false;
            boolean _a = false;

            if(s[i].charAt(0) == 'B'){
                _b = true;
            }
            if(s[i].charAt(s[i].length() - 1) == 'A') {
                _a = true;
            }

            if (_a && _b) ba ++;
            if (_a && !_b) a ++;
            if (!_a && _b) b ++;
        }

        if (ba > 0) {
            ans = ab + ba - 1;
            if (a>0) {
                ans ++;
                a --;
            }
            if (b>0) {
                ans ++;
                b --;
            }
            ans += Math.min(a,b);
        } else {
            ans = ab + Math.min(a,b);
        }

        System.out.println(ans);

    }

    public static void main(String args[]) {

        input();

        solve();
    }
}


Measured memory_bytes: 36400
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nums = br.readLine().split(" ");
		String arr = br.readLine();
		int total = Integer.valueOf(nums[0]);
		int internal = Integer.valueOf(nums[1]);
		int external = Integer.valueOf(nums[2]);
		int internal_count = 0;
		int external_count = 0;
		int total_qual = internal +external;


		for (int index = 0; index < total; index++) {
			if(internal_count+external_count >= total_qual){
				System.out.println("No");
				continue;
			}
			if (arr.charAt(index) == 'a') {
				if(internal_count < internal+external){
					System.out.println("Yes");
					internal_count++;
				}
				else{
					System.out.println("No");
				}
			}
			else if (arr.charAt(index) == 'b') {
				if(external_count < external){
					System.out.println("Yes");
					external_count++;
				}
				else{
					System.out.println("No");
				}

			} else {
				System.out.println("No");

			}
		}

	}

}


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

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  
  ll ans = 0;
  if (N % 2) {
    ll x = 0, y = 0;
    
    for (int j = N-1; j >= N/2 + 2; j--) {
      x += 2 * a[j];
    }
    x += a[N/2+1] + a[N/2];
    for (int j = 0; j < N/2; j++) {
      x -= 2 * a[j];
    }
    
    
    for (int j = N-1; j >= N/2 + 1; j--) {
      y += 2 * a[j];
    }
    y -= (a[N/2] + a[N/2 -1]);
    for (int j = 0; j < N/2 -1; j++) {
      y -= 2 * a[j];
    } 
    
    
    ans = max(x,y);
  } else {
    for (int j = N-1; j >= N/2 + 1; j--) {
      ans += 2 * a[j];
    } 
    ans += a[N/2];
    ans -= a[N/2 -1];
    for (int j = 0; j < N/2 -1; j++) {
      ans -= 2 * a[j];
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 4032
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n, m;
ll cnt[maxn];
ll res[maxn];

void MAIN() {

    cin >> n >> m;
    res[0] = 1;
    fill(cnt, cnt + n, 1);
    fori (i, m) {
        ll x, y; cin >> x >> y; --x, --y;
        if (res[x]) res[y] = 1;
        if (--cnt[x] == 0) res[x] = 0;
        ++cnt[y];
    }
    ll ans = 0;
    fori (i, n) ans += res[i];
    cout << ans << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
4 4
1 2
2 3
4 1
3 4
    )";
    MAIN();
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    for (int m = n; m != 0; m /= 10) sum += m % 10;
    cout << (n % sum == 0 ? "Yes" : "No") << endl;
}


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

int main() {
    char a, b;
    cin >> a >> b;
    cout << (a == b ? "H" : "D") << endl;
}


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

int digits(int N) {
	int sum = 0;
	while (N > 0) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}

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

	int ans = digits(N);
	if (N % ans == 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  ll n;
  cin >> n;
  ll ans = n / 500 * 1000;
  n %= 500;
  ans += n / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
t1,t2 = list(map(int, input().split()))
a1,a2 = list(map(int, input().split()))
b1,b2 = list(map(int, input().split()))
x=(a1-b1)*t1 + (a2-b2)*t2
if x == 0:
    print("infinity")
elif x*(a1-b1) > 0:
    print(0)
else:
    s,t = divmod(abs((a1-b1)*t1), abs(x))
    if t:
        print(s*2+1)
    else:
        print(s*2)


Measured memory_bytes: 38384
#include<stdio.h>

int main()
{
  int n,m,x;
  
  scanf("%d%d%d",&n,&m,&x);
  
  int a[m];
  int i,j;
  
  for(i=0;i<m;i++)
  {
    scanf("%d",&a[i]);
  }
  
  int cnt_a=0,cnt_b=0;
  
  for(i=0;i<x;i++)
  {
    for(j=0;j<m;j++)
    {
      if(i==a[j])
      {
        cnt_a++;
      }
    }
  }
  
  for(i=x+1;i<=n+1;i++)
  {
    for(j=0;j<m;j++)
    {
      if(i==a[j])
      {
        cnt_b++;
      }
    }
  }
  
  if(cnt_a<=cnt_b)
  {
    printf("%d\n",cnt_a);
  }
  
  else
  {
    printf("%d\n",cnt_b);
  }
  
  return 0;
}

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

int a[25][25];
int dp[1 << 21];

const int MOD = 1000000007;
template<class T> inline void add_mod(T &a, const T b) {
	a += b;
	if(a >= MOD) a -= MOD;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			scanf("%d", &a[i][j]);
	dp[0] = 1;
	for(long bits = 0; bits < (1 << n) - 1; bits++) {
		int m = bitset<21> (bits).count();
		for(int w = 0; w < n; w++) {
			if(a[m][w] && !(bits & (1 << w))) {
				int next = bits ^ (1 << w);
				add_mod(dp[next], dp[bits]);
			}
		}
	}
	printf("%d\n", dp[(1 << n)-1]);
}


Measured memory_bytes: 8448
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll W, H, N;
    cin >> W >> H >> N;

    ll t = H, b = 0, l = 0, r = W;
    ll x, y, a;
    rep(i, N){
        cin >> x >> y >> a;
        switch(a){
            case 1:
                l = max(l, x);
                break;
            case 2:
                r = min(r, x);
                break;
            case 3:
                b = max(b, y);
                break;
            case 4:
                t = min(t, y);
                break;
        }
    }

    if(t <= b || l >= r){
        cout << 0 << endl;
    }else{
        cout << (t - b) * (r - l) << endl;
    }

    return 0;
}


Measured memory_bytes: 3544