akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAX 1000006
#define MOD 1000000007
#define LL long long
#define NL '\n'
using namespace std;

int fk[200005], arr[1000000];

void reset(){
    for( int i = 0; i < 200005; i++ ) fk[i] = 999999;
}

int main(){
    std::ios_base::sync_with_stdio(0);
    reset();

    int n, k, cnt = 0, nm = 0;
    cin >> n >> k;

    for( int i = 0; i < n; i++ ){
        cin >> arr[i];
        if( fk[arr[i]] == 999999 ) {
            fk[arr[i]] = 0;
            nm++;
        }
        fk[arr[i]]++;
    }

    if( nm <= k ){
        cout << 0 << NL;
        return 0;
    }

    sort(arr, arr+n);
    sort(fk, fk+200005);

    for( int i = 0; i < nm-k; i++ ){
        cnt += fk[i];
    }

    cout << cnt << NL;

    return 0;
}



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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (0 >= a && 0 <= b) {
        cout << "Zero\n";
        return 0;
    } 
    if (a > 0) {
        cout << "Positive\n";
        return 0;
    }
    int cnt = b - a + 1;
    if (cnt % 2 == 0) {
        cout << "Positive\n";
        return 0;
    } else {
        cout << "Negative\n";
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())

a = list(map(int,input().split(' ')))

sorted_a = sorted(a)

for i in range(N):
    if a[i] < sorted_a[int(N/2)]:
        print(sorted_a[int(N/2)])
    else:
        print(sorted_a[int(N/2)-1])



Measured memory_bytes: 25220
S = list(input())
ans = 0
B_count = 0
for i in range(len(S)-1):
    if S[i] == 'B' and S[i+1] == 'W':
        B_count += 1
        S[i+1] = 'B'
        ans += B_count
        B_count -= 1
    elif S[i] == 'B':
        B_count += 1

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

vector<vector<ll> > table;
vector<P> roads;
vector<P> qs;

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

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

  sort(lst.begin(), lst.end());
  reverse(lst.begin(), lst.end());
  
  ll Alice = 0;
  ll Bob = 0;
  for (size_t i = 0; i < lst.size(); i++) {
    if (i % 2 == 0)
      Alice += lst[i];
    else
      Bob += lst[i];
  }

  ll ans = Alice - Bob;
  cout << ans << endl;

  return 0;
}


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

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a == b) {
		printf("NO\n");
	}else{
		for(int i = b + c; i <= 10000; i += b) {
			if(i % a == 0) {
				printf("YES\n");
				return 0;
			}
		}
		printf("NO\n");
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 comb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(begin(a), end(a));

    i64 s[2] = {};
    for (int t = 0; t < 2; ++t) {
        for (int i = k - 1; i < n; ++i) {
            s[t] += (a[i] + mod) * comb(i, k - 1) % mod;
        }
        s[t] %= mod;
        reverse(begin(a), end(a));
    }
    cout << (s[0] - s[1] + mod) % mod << endl;
    return 0;
}

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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

ll dp[200][200];
char s[200][201];

ll func1(ll r, ll c){
    if(dp[r][c] != -1) return dp[r][c];

    // dp[r][c] = s[r][c] == '.' ? 0 : 1;
    if(r==0) {
        dp[r][c] = func1(r, c-1);
        dp[r][c] += s[r][c] != s[r][c-1] && s[r][c] == '#' ? 1 : 0;
    }
    else if(c ==0){
        dp[r][c] = func1(r-1, c);
        dp[r][c] += s[r][c] != s[r-1][c] && s[r][c] == '#' ? 1 : 0;
    }
    else{
        dp[r][c] = MIN(func1(r, c-1) + (s[r][c] != s[r][c-1] && s[r][c] == '#' ? 1 : 0), 
                       func1(r-1, c) + (s[r][c] != s[r-1][c] && s[r][c] == '#' ? 1 : 0));
    }
    return dp[r][c];
}

int main(){
  ll H, W, k, m, cnt;  
  ll s1,t1, s2, t2;
  scanf("%lld%lld", &H, &W);

  for (int i = 0; i < H; i++)
  {
      scanf("%s", s[i]);
  }

  for (int i = 0; i < H; i++)
  {
      for (int j = 0; j < W; j++)
      {
          dp[i][j] = -1;
      }
  }
  

  printf("%lld", func1(H-1, W-1));
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数
    int N; cin >> N;

    // グラフ入力受取
    Graph G(N);
    vector<int> deg(N, 0); // 各頂点の出次数
    for (int i = 0; i < N; ++i) {
        int a, b; cin >> a >> b;
        --a, --b; // 0-indexed にする
        G[a].push_back(b);
        G[b].push_back(a);
        ++deg[a], ++deg[b];
    }

    // 葉たちをキューに挿入する
    // 今回は無向グラフなので、deg[v] == 1 が葉の条件になります
    queue<int> que;
    for (int v = 0; v < N; ++v) if (deg[v] == 1) que.push(v);

    // 探索
    vector<bool> ispushed(N, false);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        ispushed[v] = true;
        for (auto nv : G[v]) {
            --deg[nv];
            if (deg[nv] == 1) que.push(nv);
        }
    }

    // クエリに答える
    int Q; cin >> Q;
    for (int _ = 0; _ < Q; ++_) {
        int a, b; cin >> a >> b; --a, --b;
        if (!ispushed[a] && !ispushed[b]) cout << 2 << endl;
        else cout << 1 << endl;
    }
}



Measured memory_bytes: 8664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    if (~n & 1) {
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            long long s = i < n / 2 ? -2 : 2;
            if (i == n / 2 - 1 || i == n / 2) s /= 2;
            ans += s*a[i];
        }
        std::cout << ans << std::endl;
    }
    else {
        long long u = 0;
        for (int i = 0; i < n; i++) {
            long long s = i < n / 2 ? -2 : 2;
            if (i == n / 2 || i == n / 2 + 1) s /= 2;
            u += s*a[i];
        }
        long long v = 0;
        for (int i = 0; i < n; i++) {
            long long s = i <= n / 2 ? -2 : 2;
            if (i == n / 2 || i == n / 2 - 1) s /= 2;
            v += s*a[i];
        }
        std::cout << std::max(u, v) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int bubbleSort(int *,int);
void swap(int *,int *);
int main(void){
	int i,n;
	int count;
	int a[100];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	
	count=bubbleSort(a,n);
	
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i<n-1)
			printf(" ");
	}
	printf("\n");
	printf("%d\n",count);
	
	
	return 0;
}

int bubbleSort(int *a,int n){
	int i;
	int count=0,flag=1;
	while(flag){
		flag=0;
		for(i=n-1;i>0;i--){
			if(a[i]<a[i-1]){
				swap(&a[i],&a[i-1]);
				flag=1;
				count++;
			}
		}
	}
	
	return count;
}


void swap(int *px,int *py){
	int tmp=*px;
	*px=*py;
	*py=tmp;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll mod=1e9+7 ;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
int n;
ll h[100000+6];
int main(){
	scanf("%d", &n);
	FOR(i,1,n){
		scanf("%lld", h+i);
	}
	bool yes = true;
	FOR(i,2,n){
		if(h[i] == h[i-1]) continue;
		else if(h[i] > h[i-1]) h[i] -= 1;
		else yes = false;
	}
	cout << (yes? "Yes": "No") << endl;
    return 0;
}


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

int  main()
{
  int N;
  std::cin >> N;
  std::vector<int> cards(N);
  for(auto&& card : cards) {
    std::cin >> card;
  }
  std::sort(cards.begin(), cards.end(), std::greater<int>());
  int alice = 0;
  int bob = 0;
  for(int i = 0; i < N; i++) {
    if(i%2 == 0) {
      alice += cards[i];
    } else {
      bob += cards[i];
    }
  }
  std:: cout << alice - bob << std::endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [0]*60001
for i in range(1,100):
  for j in range(1,100):
    for k in range(1,100):
      a[i**2+j**2+k**2+i*j+j*k+k*i]+=1
for i in a[1:N+1]:
  print(i)

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

int main(){
  int A, B;
  cin >> A >> B;
  if(A==1){
    A=14;
  }
  if(B==1){
    B=14;
  }
  if(A<B){
    cout << "Bob" << endl;
  }
  else if(A>B){
    cout << "Alice" << endl;
  }
  else{
    cout << "Draw" << endl;
  }
}


Measured memory_bytes: 256
# coding: utf-8
N = int(input())
_A = sorted(enumerate(map(int, input().split()), 1), key=lambda x:x[1], reverse=True)
dp = [[0] * (N+1) for i in range(N+1)]

for i in range(1,N+1):
    k, Ak = _A[i-1]
    if (N-i-k) < 0:break
    dp[0][i] = dp[0][i-1] + (N-i+1-k) * Ak

for i in range(1,N+1):
    k, Ak = _A[i-1]
    if (k-i) < 0:break
    dp[i][0] = dp[i-1][0] + (k-i) * Ak

for x in range(1, N+1):
    for y in range(1, N-x+1):
        k, val = _A[x+y-1]
        dp[x][y]= max(dp[x-1][y] + abs(k-x)*val,
                      dp[x][y-1] + abs(N-y-k+1) * val)

print(int(max(dp[i][N-i] for i in range(N+1))))


Measured memory_bytes: 135912
O = list(input())
E = list(input())
leng =  len(O) + len(E)
passwd = ""

for i in range(0, leng):
  if i % 2 == 1:
    j = int( (i - 1)/2 )
    passwd += E[j]
  else:
    j = int( i / 2 )
    passwd += O[j]

print(passwd)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
bool cmp(int a,int b){ return a>b; }
int main(){
	int n,k,a[51],ans=0;
	read(n),read(k);
	for(int i=1;i<=n;i++)read(a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
lis = [i for i in map(int, input().split())]

s = sum(lis)
line = s / (4 * m)

count = 0
for i in lis:
    if i >= line:
        count += 1

if count >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M, A, B;
vector<int>v[100001];
ll res;
priority_queue<int>pq;

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> A >> B;
		v[A].push_back(B);
	}
	for (int i = 1; i <= M; ++i) {
		for (int j : v[i]) {
			pq.push(j);
		}
		if (!pq.empty()) {
			res += pq.top();
			pq.pop();
		}
	}
	cout << res << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int> > se(n,vector<int>(26,0));
  rep(i,n){
    string s;
    cin >> s;
    for(c:s) se[i][c-'a']++;
  }
  sort(all(se));
  ll ans = 0;
  ll now = 0;
  ll next = 0;
  while(now<n){
    next++;
    if(next>=n){
      ans += ((next - now) * (next - now - 1)) / 2; 
      break;
    }
    bool flag = true;
    rep(j,26) if(se[now][j] != se[next][j]) flag = false;
    if(!flag){
      ans += ((next - now) * (next - now - 1)) / 2;
      now = next;
      continue;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 13568
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        int tem = 0;
        while (i < n - 1) {
            if (h[i] >= h[i + 1]) {
                tem++;
                i++;
            } else {
                break;
            }

            if (!(i < n - 1)) {
                break;
            }
        }
        ans = max(ans, tem);
    }

    cout << ans << endl;

    return 0;
}

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

ll A[111111];
ll B[111111];
ll ans=0;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<=n;i++){
		cin>>A[i];
	}
	for(int i=0;i<n;i++){
		cin>>B[i];
	}
	for(int i=0;i<n;i++){
		if(B[i]>=A[i]){
			ans+=A[i];
			B[i]-=A[i];
			A[i]=0;
			
			if(B[i]>=A[i+1]){
				ans+=A[i+1];
				B[i]-=A[i+1];
				A[i+1]=0;
			}else{
				ans+=B[i];
				A[i+1]-=B[i];
				B[i]=0;
			}
			
		}else{
			A[i]-=B[i];
			ans+=B[i];
			B[i]=0;
		}
	}
	cout<<ans;
	
	return 0;
} 

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2,vector<int>(n));
  vector<vector<int>> dp(2,vector<int>(n));
  rep(i,2){
    rep(j,n) cin >> a[i][j];
  }
  
  dp[0][0] = a[0][0];
  rep(i,n-1){
    dp[0][i+1] = dp[0][i] + a[0][i+1];
  }
  dp[1][0] = a[0][0] + a[1][0];
  rep(i,n-1){
    dp[1][i+1] = max(dp[0][i+1],dp[1][i]) + a[1][i+1]; 
  }
  /*
  rep(i,2){
    rep(j,n){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  cout << dp[1][n-1] << endl;
  
  return(0);
}

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

int main(){
  string S, T; cin >> S >> T;
  int size=S.size();
  
  vector<int> ss={1}, tt={1};
  for(int i=1; i<size; i++){
    if(S.at(i-1)==S.at(i)) ss.back()++;
    else ss.push_back(1);
    if(T.at(i-1)==T.at(i)) tt.back()++;
    else tt.push_back(1);
  }
  if(ss!=tt){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i=0; i<size; i++){
    if(S[i]!=T[i]){
      char cs=S[i], ct=T[i];
      for(int j=0; j<size; j++){
        if(S[j]==cs)
          S[j]=ct;
        else if(S[j]==ct)
          S[j]=cs;
      }
    }
  }
  
  if(S==T) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 2428
N = int(input())

if(400<=N<=599):
  print("8")
elif(600<=N<=799):
  print("7")
elif(800<=N<=999):
  print("6")
elif(1000<=N<=1199):
  print("5")
elif(1200<=N<=1399):
  print("4")
elif(1400<=N<=1599):
  print("3")
elif(1600<=N<=1799):
  print("2")
else:
  print("1")

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S;
 int T=1,P,Q,R;
  cin >> S;
  for (int i = 0; i < (S.size())/2; i++) {
    Q =i+(S.size()+1)/2;
    P = (S.size()-i)-1;
    R =((S.size()-1)/2)-i-1;
    if (S.at(i) != S.at(P)) {
       T =0;
      break;
    }
    if(S.at(i) != S.at(Q)){
      T = 0;
      break;
    }
    if(S.at(i) != S.at(R)){
     T = 0;
      break;
    } 
  }

  if(T == 1)
  cout << "Yes" << endl;
  if(T == 0)
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
using LL = long long ;

const int kN = 100000 + 5;
int n, a[kN];

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

bool work()
{
    if (n == 1) return a[0] != 1;
    int odd = std::count_if(a, a + n, [&](int x){return x % 2 == 1;});
    if (*std::min_element(a, a + n) == 1) {
        return std::accumulate(a, a + n, 0ll) - n & 1;
    } else if (n > 2) {
        if (odd >= 2) {
            return std::accumulate(a, a + n, 0ll) - n & 1;
        } else {
            for (int i = 0; i < n; ++ i) if (a[i] & 1) {
                if (a[i] == 1) return false;
                a[i] --;
            }
            int x = 0;
            for (int i = 0; i < n; ++ i)
                x = gcd(x, a[i]);
            for (int i = 0; i < n; ++ i)
                a[i] /= x;
            return !work();
        }
    } else {
        if (a[0] % 2 == 1 && a[1] % 2 == 1) return false;
        else return true;
    }
}

int main()
{
    std::cin >> n;
    for (int i = 0; i < n; ++ i) std::cin >> a[i];
    std::cout << (work() ? "First" : "Second") << std::endl;
}


Measured memory_bytes: 640
N,T=map(int,input().split())
List=[list(input().split()) for i in range(N)]
List2=[]
List3=[]
for i in List:
        List2.append([int(s) for s in i])
for i in List2:
        if i[1] <= T:
                List3.append(i[0])
if List3 == []:
        print("TLE")
else:
        print(min(List3))

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

int V, E;
ll cost[105][105];
ll INF = 1e18;

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

  ll cost2[105][105];
  cin >> V >> E;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (i == j) cost[i][j] = 0;
      else cost[i][j] = INF;
      cost2[i][j] = INF;
    }
  }

  for (ll i = 0; i < E; i++) {
    ll a, b; cin >> a >> b; a--; b--;
    ll t; cin >> t;
    cost[a][b] = t;
    cost[b][a] = t;
    cost2[a][b] = t;
    cost2[b][a] = t;
  }

  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i < V; i++) {
    for (ll j = 0; j < V; j++) {
      if (i == j) continue;
      if (cost2[i][j] == INF) continue;
      if (cost[i][j] < cost2[i][j]) ans++;
    }
  }

  cout << ans / 2 << '\n';
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	long long n,k; cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

// Solution for https://atcoder.jp/contests/abc071/tasks/abc071_b

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var s string
	con.Scan(&s)
	h := make([]int, 26)
	for i := 0; i < len(s); i++ {
		h[s[i]-'a']++
	}
	i := 0
	for i = 0; i < 26; i++ {
		if h[i] == 0 {
			con.Println(string('a' + i))
			return nil
		}
	}
	con.Println("None")
	return nil
}


Measured memory_bytes: 2484
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <iomanip>

#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rforr(i, t, n) (int i = n-1; i>=t; --i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1024;

//STRUCTS


//OPERATORS


//GLOBALS


//FUNCTIONS


//PROBLEM: 
//LINK: 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		string s;
		cin >> s;
		int n = s.size();
		bool easy = true;
		forn(i, n)
		{
			if (i%2 == 0 and not (s[i] == 'U' or s[i] == 'R' or s[i] == 'D')) easy = false;
			if (i%2 and not (s[i] == 'L' or s[i] == 'U' or s[i] == 'D')) easy = false;
		}
		if (easy) cout << "Yes"; else cout << "No";



	return 0;
}

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

int main(){
  int n, c;
  long long ans;
  cin >> n >> c;
  int d[c][c], e[n][n], sum[3][c], inco[3][c];
  for (int i=0; i<3; i++)
    for(int t=0; t<c; t++)
      sum[i][t] =0, inco[i][t] = 0;
  for (int i=0; i<c; i++)
    for(int t=0; t<c; t++)
      cin >> d[i][t];
  for (int i=0; i<n; i++){
    for(int t=0; t<n; t++){
      cin >> e[i][t];
      sum[(i+t)%3][e[i][t]-1]++;
    }
  }
  for (int i=0; i<3; i++)
    for(int t=0; t<c; t++)
      for(int s=0; s<c; s++)
        inco[i][t] += sum[i][s]*d[s][t];
  ans = inco[0][0] + inco[1][1] + inco[2][2];
  for (int i=0; i<c; i++)
    for(int t=0; t<c; t++)
      for(int s=0; s<c; s++)
        if(i!=t&&t!=s&&s!=i)
          if(ans > inco[0][i] + inco[1][t] + inco[2][s])
            ans = inco[0][i] + inco[1][t] + inco[2][s];
  cout << ans << endl;
}


Measured memory_bytes: 1280
import java.lang.Math.*

fun main(args: Array<String>?): Unit {
    while(true) {
        val m = readLine()!!.trim().toInt()
        if (m == 0) break
        val first = IntArray(m - 1){ readLine()!!.trim().toInt()}
        val second = IntArray(readLine()!!.trim().toInt() - 1){readLine()!!.trim().toInt()}
        val firstArea = first.sumByDouble { sin(it.toRad()) } + sin((360 - first.sum()).toRad())
        val secondArea = second.sumByDouble { sin(it.toRad()) } + sin((360 - second.sum()).toRad())
        if (abs(firstArea - secondArea) < 1e-9) {
            println(0)
        }else if (firstArea > secondArea) {
            println(1)
        }else {
            println(2)
        }
    }
}
fun Int.toRad(): Double {
    return PI * this / 180
}


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int main(){
  int k,a,b;
  cin >> k;
  cin >> a >> b;
  int i = 1;
  while(true){
    int tmp = k * i;
    if(tmp > b)break;
    if(a <= tmp and tmp <= b){
      cout << "OK" << endl;
      return 0;
    }
    i++;
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<int,int>

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

    int n,k;
    cin>>n>>k;
    cout<<ceil(n*1.0/k)-floor(n/k);

return(0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N,M,P;
	int i;
	int now;
	int sum;
	int winner;
	while(1) {
		scanf("%d%d%d",&N,&M,&P);
		if(N==0 && M==0 && P==0)break;
		sum=winner=0;
		for(i=0;i<N;i++) {
			scanf("%d",&now);
			sum+=now;
			if(i+1==M)winner=now;
		}
		printf("%d\n",winner?sum*100*(100-P)/100/winner:0);
	}
	return 0;
}

Measured memory_bytes: 0
import collections
import math 
from operator import itemgetter
N,a = map(int, input().split())
t =[]
dp = []
qp = []
for i in range(a):
    n,m = map(int, input().split())
    dp.append(n)
    qp.append(m)
m = max(dp)
M = min(qp)
if m > M:s =0
else: s = M-m+1

print(s)


Measured memory_bytes: 56128
from collections import Counter
def myAnswer(N:int,S:list) -> int:
   dic = []
   for s in S:
      dic.append(Counter(s))
   ans = dic.pop(0)
   for d in dic:
      key = set(ans.keys()) - (set(d.keys()) & set(ans.keys()))
      for k in key:
         del ans[k]
      for key,value in d.items():
         if(key in ans.keys()):
            ans[key] = min(value,ans[key])
   result = ""
   for alph,counter in sorted(ans.items()):
      result += alph * counter
   return result

def modelAnswer():
   return
def main():
   N = int(input())
   S = [list(input()) for _ in range(N)]
   print(myAnswer(N,S[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
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;
}

// for (int i = 0; i <= n; ++i)
int main() {
    int n;
    int res = 0;
    // int vv,cc;
    cin >> n;
    vector<long long> v(n), c(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    for (int i = 0; i < n; ++i) cin >> c[i];

    for (int i = 0; i < n; i++) {
        if (v[i] - c[i] >= 0) {
            res += v[i] - c[i];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	char s[10+2];

	while(scanf("%10[A-Za-z]\n", s)==1)
	{
		const char *ws[]={"Sunny", "Cloudy", "Rainy", "Sunny"};
		const char *ans="none";

		for(int i=0;i<3;i++)
		{
			if(strcmp(ws[i], s)==0) ans=ws[i+1];
		}
		printf("%s\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

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

string line[4];
set<string> dict;
map<string, int> cnt;
bool used[4][4];
void dfs(int x, int y, string s){
    if(dict.count(s)){
        cnt[s]++;
    }
    if(s.size() == 8) return;

    REP(r, 8){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(nx >= 0 && nx < 4 && ny >= 0 && ny < 4 && !used[ny][nx]){
            used[ny][nx] = true;
            dfs(nx, ny, s + line[ny][nx]);
            used[ny][nx] = false;
        }
    }
}

int main(){
    int N;
    while(cin >> N){
        cnt.clear();

        vector<string> words(N);
        vector<int> scores(N);
        REP(i, N) cin >> words[i] >> scores[i];
        REP(i, N) dict.insert(words[i]);
        REP(i, 4) cin >> line[i];
        REP(y, 4) REP(x, 4){
            used[y][x] = true;
            dfs(x, y, string(1, line[y][x]));
            used[y][x] = false;
        }

        int T;
        cin >> T;
        int dp[10001] = {};
        for(int i = 0; i < N; i++){
            int w = words[i].size();
            int s = scores[i];
            int rest = cnt[words[i]];
            for(int mul = 1; rest > 0; mul <<= 1){
                int use = min(mul, rest);
                rest -= use;
                for(int j = T; j >= use * w; j--){
                    dp[j] = max(dp[j], dp[j - use * w] + use * s);
                }
            }
        }
        cout << dp[T] << endl;
    }
    return 0;
}

Measured memory_bytes: 1288
import math
import collections

N = int(input())

count_both = 0
count = collections.defaultdict(lambda: [0]*2)
for _ in range(N):
  a, b  = [int(x) for x in input().split(' ')]
  if a == 0 and b == 0:
    count_both += 1
    continue
  if a == 0:
    count[(1, 0)][0] += 1
    continue
  if b == 0:
    count[(1, 0)][1] += 1
    continue
    
  s = math.copysign(1, a*b)
  a = abs(a)
  b = abs(b)
  g = math.gcd(a, b)
  if s > 0:
    count[(a//g, b//g)][0] += 1
  else:
    count[(b//g, a//g)][1] += 1

ans = 1
for _, p in count.items():
  ans *= (2**p[0] + 2**p[1] - 1)
  ans %= 1000000007

ans += count_both + 1000000007 - 1
ans %= 1000000007

# print(count)
print(ans)
    

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

int main(){
	int n,i,a[100];
	cin >> n;
	i=n;
	while(i--) cin >> a[i];
	for(i=0;i<n;i++){
		cout << a[i];
		if(i!=n-1) cout << " ";
	}
	cout << endl;
	return 0;
}

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

using namespace std;
using ll = long long int;

int main()
{
  ll l;
  cin >> l;
  vector<ll> a(l, 0);
  ll maximam = 0;
  for(int i = 0; i < l; i++)
  {
    cin >> a[i];
    maximam += a[i];
  } 
  vector<vector<ll>> dp(l, vector<ll>(5, maximam));
  const int DMINUS = 0; //D以下
  const int SMINUS = 1; //S以下
  const int TMINUS = 2; //T以下
  const int UMINUS = 3; //U以下
  const int UPLUS = 4;  //Uより大きい

  //UMINUS用の更新関数
  auto calcUminus = [&](int index)
  {
    ll result = 0;
    if(a[index] % 2ll == 0)
    {
      if(a[index] == 0)
      {
        result = 2;
      }else{
        result = 0;
      }
    }else{
      result = 1;
    }
    return result;
  };
  //TMINUS用の更新関数
  auto calcTminus = [&](int index)
  {
    ll result = 0;
    if(a[index] % 2ll == 0)
    {
      result = 1;
    }else{
      result = 0;
    }
    return result;
  };

  //l - 1番目の耳について
  dp[l - 1][UPLUS] = a[l - 1];
  dp[l - 1][UMINUS] = calcUminus(l - 1);
  dp[l - 1][TMINUS] = calcTminus(l - 1);
  //dp[l - 1][SMINUS] = calcUminus(l - 1);
  //dp[l - 1][DMINUS] = a[l - 1];
  //l - 2から0までdp配列の更新
  for(int i = l - 2; i >= 0; i--)
  {
    dp[i][UPLUS] = a[i] + dp[i + 1][UPLUS];
    dp[i][UMINUS] = calcUminus(i) + min(dp[i + 1][UPLUS], dp[i + 1][UMINUS]);
    dp[i][TMINUS] = calcTminus(i) + min({dp[i + 1][TMINUS], 
                                        dp[i + 1][UMINUS],
                                        dp[i + 1][UPLUS]});
    dp[i][SMINUS] = calcUminus(i) + min({dp[i + 1][SMINUS], 
                                        dp[i + 1][TMINUS],
                                        dp[i + 1][UMINUS],
                                        dp[i + 1][UPLUS]});
    dp[i][DMINUS] = a[i] + min( {dp[i + 1][DMINUS], 
                                dp[i + 1][SMINUS], 
                                dp[i + 1][TMINUS],
                                dp[i + 1][UMINUS],
                                dp[i + 1][UPLUS]});
  }
  /*for(auto e : dp)
  {
    for(int i = 0; i < 5; i++)
    {
      cout << e[i] << " ";
    }
    cout << endl;
  }*/
  ll result = maximam;
  for(int i = 0; i < 5; i++)
  {
    result = min(result, dp[0][i]);
  }
  cout << result << endl;
}


Measured memory_bytes: 15872
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, T = lr()
AB = [lr() for _ in range(N)]
AB.sort()
# 最後の注文はAiが選ぶ料理で最大で、T-1分後に注文するとして良い
dp = np.zeros(T, np.int32)
temp_ans = 0
for a, b in AB:
    temp_ans = max(temp_ans, dp.max()+b)
    dp[a:] = np.maximum(dp[a:], dp[:-a]+b)

print(temp_ans)


Measured memory_bytes: 12780
N=int(input())
H=list(map(int,input().split()))
for i in range(N):
    if i==0:
        H[i]-=1
        continue
    if H[i-1]>H[i]:
        print("No")
        quit()
    if H[i-1]==H[i]:
        continue
    else:
        H[i]-=1
print("Yes")


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

#define int long long

signed main() {
  int Q, H, S, D;
  cin >> Q >> H >> S >> D;

  H = min(Q*2, H);
  S = min(H*2, S);
  D = min(S*2, D);

  int N;
  cin >> N;
  N *= 4;
  
  int ans = 0;
  ans += (N/8) * D;
  N = N%8;
  ans += (N/4) * S;
  N = N%4;
  ans += (N/2) * H;
  N = N%2;
  ans += N * Q;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
/*
 * Click `Run` to execute the snippet below!
 */

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next(), t = sc.next();
    int N = s.length();
    TreeMap<Character, Character> StoT = new TreeMap<>();
    TreeMap<Character, Character> TtoS = new TreeMap<>();
    for(int i = 0; i<N; i++){
      //First Observation for every character in S they can only map to one unique character of T
      if(StoT.containsKey(s.charAt(i)) && StoT.get(s.charAt(i)) != t.charAt(i)){
        System.out.println("No");
        System.exit(0);
      }
      //Second Observation for every character in T they can only map to one unique character of S
      if(TtoS.containsKey(t.charAt(i)) && TtoS.get(t.charAt(i)) != s.charAt(i)){
        System.out.println("No");
        System.exit(0);
      }   
      StoT.put(s.charAt(i), t.charAt(i));
      TtoS.put(t.charAt(i), s.charAt(i));
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 42608
n,m = map(int,input().split())
a = [0] * m
for i in range(m):
    a[i] = int(input())

dp = [999] * (n + 1)
if 0 not in a:
    dp[0] = 1
if 1 not in a:
    dp[1] = 1
if 2 not in a and n >= 2:
    if 1 in a:
        dp[2] = 1
    else:
        dp[2] = 2

mod = 10**9+7

for i in range(len(a)):
    dp[a[i]] = 0

for i in range(3,n+1):
    if dp[i] != 0:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[-1])


Measured memory_bytes: 7668
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10);
    var A = parseInt(args[1], 10);
    var B = parseInt(args[2], 10);

    var max=0;
    var min=0;
    var ans_max=0;

    if(A<B) {
        max = B;
        ans_max = A;
    } else {
        max = A;
        ans_max = B;
    }

    if(N < A + B) {
        min = A + B - N;
    } else {
        min = 0;
    }

    console.log(ans_max +" "+min);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
	long long n,m,k,i,j,cur;
	cin >> m >> k;
	cur=1;
	for(i=0; i<m; i++){
		cur*=2;
	}
	
	if(m==0 && k==0){
		cout << "0 0" << endl;
	}else if(m==1 && k==0){
		cout << "0 0 1 1" << endl;
	}else if(m<=1 || cur<=k){
		cout << -1 << endl;
	}else{
		for(i=0; i<cur; i++){
			if(i==k){
				continue;
			}else{
				cout << i << ' ';
			}
		}
		cout << k << ' ';
		for(i=cur-1; i>=0; i--){
			if(i==k){
				continue;
			}else{
				cout << i << ' ';
			}
		}
		cout << k << endl;
	}
	
}

Measured memory_bytes: 1792
n = int(input())
a, b = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
x, y, z = 0, 0, 0
for i in num_list:
  if i <= a:
    x += 1
  elif i <= b:
    y += 1
  else:
    z += 1
print(min(x,y,z))
  
  

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int ans=0;
    
    for(int i=1;i<=n;i++){
        for(int j=2;j<=100;j++){
            long long hoge=pow(i,j);
            if(n<hoge) break;
            
            ans=max(ans,(int)hoge);
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005



template<class T> inline bool chmax(T & a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmin(T & a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    string s = to_string(n);
    //cout << s.length() << endl;
    
    if (s[s.length()-1] == '3') {
        cout << "bon" << endl;
    }
    else if (s[s.length()-1] == '0' || s[s.length()-1] == '1' || s[s.length()-1] == '6' || s[s.length()-1] == '8') {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
    
    return 0;

}

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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

using namespace std;

bool r[MAX];
int cnt[MAX];

int main(){
	int n,m;
	sd(n);sd(m);
	
	clr(r);clr(cnt);
	for(int i=1;i<=n;i++) cnt[i]=1;
	
	r[1]=1;
	while(m--){
		int x,y;
		sd(x);sd(y);
		
		if(r[x]) r[y]=1;
		
		if(cnt[x]==1){
			r[x]=0;
		}
		
		cnt[x]-=1;
		cnt[y]+=1;
	}
	
	int ans=0;
	for(int i=1;i<=n;i++) if(r[i]) ans++;
	pd(ans);
}

Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            x += (d-1)/a + 1;
        }

        System.out.println(x);
    }
}


Measured memory_bytes: 21844
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if (a[i] == b[i] and a[i] != c[i]) or\
        (a[i] == c[i] and a[i] != b[i]) or\
        (b[i] == c[i] and b[i] != a[i]):
        ans += 1
    elif a[i] == b[i] == c[i]:
        continue
    else:
        ans += 2
print(ans)

Measured memory_bytes: 3064
import java.io.*; 
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
public static void main(String[] args){
try{
   BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String b = reader.readLine();
     String c = reader.readLine();
     String d = reader.readLine();
    String parts[] = b.split(" ");
    String S = parts[0];
  String T = parts[1];
  String parts2[] = c.split(" ");
  int n1 = Integer.parseInt(parts2[0]);
  int n2 = Integer.parseInt(parts2[1]);
  if(d.compareTo(S)==0){
    System.out.println((n1 - 1) +" "+n2);}else if(d.compareTo(T)==0){
     System.out.println(n1  +" "+(n2-1));
  }else{
     System.out.println(n1  +" "+(n2));
  }
}catch(Exception e){}
}
}

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

int main(){
  int N;
  cin >> N;
  vector<int>num(N);
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  int max=-101;
  int min=101;
  for(int i=0;i<N;i++){
    if(num[i]>max){
      max=num[i];
    }
    if(num[i]<min){
      min=num[i];
    }
    else{
      continue;
    }
  }
  int ss=0;
  int ts=0;
  if(max==min){
    cout << ss << endl;
  }
  else{
    for(int i=min;i<max+1;i++){
      for(int j=0;j<N;j++){
        ts+=pow((num[j]-i),2);
      }
      if(i==min){
        ss=ts;
      }
      else if(ts<ss){
        ss=ts;
      }
      else{
        continue;
      }
      ts=0;
    }
    cout << ss << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
 
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool b = false;
    if(n%2 == 0){
    REP(i,n/2){
        if(s[i]==s[i+n/2]) b = true;
        else{
            b = false;
            break;
        }
    }
    }
    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


template<typename T>
struct Compress {
	vector<T> v;
	Compress() {}
	Compress(vector<T> _v) :v(_v) {
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
	}

	void build(vector<T> _v) {
		v = _v;
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
	}
	int get(T x) {
		return lower_bound(v.begin(), v.end(), x) - v.begin();
	}

	int upper_bound(T x) {
		return std::upper_bound(v.begin(), v.end(), x) - v.begin();
	}
	T& operator[](int i) { return v[i]; }


	int size() {
		return (int)v.size();
	}
};

template<class T>
struct CumulativeSum2D {
	vector<vector<T>> data;
	int H, W;
	CumulativeSum2D() :H(0), W(0) {}
	CumulativeSum2D(int _H, int _W) :H(_H), W(_W) {
		data.assign(H + 1, vector<T>(W + 1));
	}
	CumulativeSum2D(vector<vector<T>>& _data) :H(_data.size()), W(_data[0].size()) {
		data.assign(H + 1, vector<T>(W + 1));
		for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) data[i + 1][j + 1] += _data[i][j];
		build();
	}

	void add(int h, int w, T x) {
		data[h + 1][w + 1] += x;
	}
	void build() {
		for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) data[i + 1][j + 1] += data[i + 1][j] + data[i][j + 1] - data[i][j];
	}

	T query(int sh, int sw, int gh, int gw) const {
		return data[gh][gw] - data[sh][gw] - data[gh][sw] + data[sh][sw];
	}
};
int main()
{

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

	int n, m; cin >> n >> m;
	Compress<ll> cx, cy;
	vector<ll> vx(n), vy(n);

	for (int i = 0; i < n; i++) {
		cin >> vx[i] >> vy[i];
	}
	cx.build(vx);
	cy.build(vy);
	CumulativeSum2D<int> sum(cx.size() + 1, cy.size() + 1);
	for (int i = 0; i < n; i++) {
		sum.add(cx.get(vx[i]), cy.get(vy[i]), 1);
	}
	sum.build();
	for (int i = 0; i < m; i++) {
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		x1 = cx.get(x1);
		y1 = cy.get(y1);
		x2 = cx.upper_bound(x2);
		y2 = cy.upper_bound(y2);
		cout << sum.query(x1, y1, x2, y2) << "\n";
	}
}


Measured memory_bytes: 101020
n = int(input())
s = input()

from collections import Counter
count = Counter(s[1:])
x = count["E"]

temp =x
for i in range(1,n):
    if s[i-1] =="W":
        x +=1
    if s[i] =="E":
        x -=1
    temp = min(temp,x)

print(temp)        

Measured memory_bytes: 9752
L,R = map(int, input().split())
Smin=2019
Lo=L%2019
Ro=R-(L-Lo)
if Ro>=2019:
    Smin=0
if Ro<2019:
    for x in range(Lo,Ro):
        for y in range(x+1,Ro+1):
            Sa=x*y
            S=Sa%2019
            if Smin>S:
                Smin=S
print(Smin)



Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;

int main()
{
    int a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a,a+4);
    if(a[0]==a[1]&&a[2]==a[3])
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    return 0;
}



Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
ll n, m,w;
ll vis[111][100099];
vector<ll>v, v2;
ll knapsak(ll x, ll pr)
{
	if (x == n)
		return 0;
	ll &ret = vis[x][pr];
	if (~ret)return ret;
	ret = knapsak(x + 1, pr);
	if (w>= pr + v[x])
		ret = max(knapsak(x + 1, pr + v[x]) + v2[x], ret);
	return ret;
}
int main()
{
	//run();
	M_Sayed;
	memset(vis, -1, sizeof vis);
	cin >> n >> w;
	v.resize(n);
	v2.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> v2[i];
	}
	RT( knapsak(0, 0));
}

Measured memory_bytes: 87040