akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
// *************** TEMPLATE END *************** 

void solve() {
  int H, W, R, C; cin >> H >> W >> R >> C;
  if (H == 0) exit(0);
  vector<vector<int>> hor(H + 1 + 2, vector<int>(W + 2));
  vector<vector<int>> ver(H + 2, vector<int>(W + 1 + 2));
  REP (i, 2 * H + 1) {
    if (i % 2) {
      REP (j, W + 1) cin >> ver[i / 2 + 1][j + 1];
    } else {
      REP (j, W) cin >> hor[i / 2 + 1][j + 1];
    }
  }
  vector<vector<int>> dp(H + 2, vector<int>(W + 2));
  REP (i, H + 2) dp[i][0] = dp[i][W + 1] = 1;
  REP (j, W + 2) dp[0][j] = dp[H + 1][j] = 1;
  queue<ii> q;
  REPI (i, 1, H + 1) {
    REPI (j, 1, W + 1) {
      if (i == 1 || i == H || j == 1 || j == W) q.push({i, j});
    }
  }
  while (!q.empty()) {
    ii p = q.front(); q.pop();
    int i = p.fi, j = p.se;
    if (dp[i][j]) continue;
    vector<int> ok(2);
    ok[ver[i][j]] |= dp[i][j - 1];
    ok[ver[i][j + 1]] |= dp[i][j + 1];
    ok[hor[i][j]] |= dp[i - 1][j];
    ok[hor[i + 1][j]] |= dp[i + 1][j];
    if (ok[0] && ok[1]) {
      dp[i][j] = 1;
      q.push({i - 1, j});
      q.push({i + 1, j});
      q.push({i, j - 1});
      q.push({i, j + 1});
    }
  }
  bool ok = false;
  ok |= !hor[R][C] & dp[R - 1][C];
  ok |= !hor[R + 1][C] & dp[R + 1][C];
  ok |= !ver[R][C] & dp[R][C - 1];
  ok |= !ver[R][C + 1] & dp[R][C + 1];
  cout << (ok ? "Yes" : "No") << endl;
}
signed main() {
  while (1) solve();
}



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

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    string g;
    rep(i,s.length()){
        if(s[i]=='B') {
            if(g.length()>0) g.pop_back();
        }
        else g.push_back(s[i]); 
    }
    cout<<g;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,T,a,b;
    int mA=0;
    vector<PP> AB;
    vector<int> A,B;
    cin >> N >> T;
    REP(i,N){
        cin >> a >> b;
        mA=max(mA,a);
        AB.push_back({a,b});
    }
    sort(AB.begin(),AB.end());
    REP(i,N){
        A.push_back(AB[i].first);
        B.push_back(AB[i].second);
    }
    
    vector<vector<int>> dp(6200, vector<int>(3100, -INF));
    dp[0][0]=0;
    REP(j,N){
        REP(i,T+mA){
            dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
            if(0<= i-A[j] && i-A[j]<T){
                dp[i][j+1]=max(dp[i][j+1],dp[i-A[j]][j]+B[j]);
            }
        }
    }
    
    int Ans=0;
    REP(i,T+mA){
        Ans=max(Ans,dp[i][N]);
    }
    /*
    REP(j,N+1){
        REP(i,(T+mA)/10){
            if(dp[i*10][j]<=-INF/10){
                cout << "-INF" << " ";
            }else{
                cout << dp[i*10][j] << " ";
            }
        }cout << endl;
    }cout << endl;
    */
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 150784
using System;
using System.Linq;

class Program
{
  static void Main()
  {
    long N = long.Parse(Console.ReadLine());
    long[] A = new long[N];
    for(int i = 0; i < N; i++)
    {
      A[i] = long.Parse(Console.ReadLine());
    }
    var A_sort = A.OrderBy(x => x).ToArray();
    long max = A_sort[N - 1];
    long semimax = A_sort[N - 2];
    
    string[] str = new string[N];
    for(int i = 0; i < N; i++)
    {
      if(A[i] != max){
        str[i] = max.ToString();
      }
      else
      {
        str[i] = semimax.ToString();
      }
    }
    
    Console.WriteLine(string.Join("\n", str));
    
  }
}

Measured memory_bytes: 39508
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool b=true;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='L'){
        b=false;
      }
    }
    if(i%2==1){
      if(s[i]=='R'){
        b=false;
      }
    }
  }
  if(b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
l = [[] for i in range(n)]
for i in range(n):
    l2 = [i + 1]
    cnt = 0
    while True:
        l2.append(p[l2[-1] - 1])
        cnt += c[l2[-1] - 1]
        l[i].append(cnt)
        if l2[-1] == i + 1:
            break
ans = -float("inf")
for i in range(n):
    le = len(l[i])
    for j in range(min(k, le)):
        cnt = l[i][j]
        if l[i][-1] > 0:
            cnt += (k - j - 1) // le * l[i][-1]
        ans = max(ans, cnt)
print(ans)

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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[100010];
ll d1[100010];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v;
  rep(i, 0, n) {
    ll a;
    cin >> a;
    v.pb(a);
  }
  ll mx = 0;
  clr(d, 0);
  rep(i, 0, v.sz) {
    d[i + 1] += v[i];
    d[i + 1] += d[i];
  }
  clr(d1, 0);
  rep(i, 0, v.sz) {
    if (v[i] > 0) {
      d1[i + 1] += v[i];
    }
    d1[i + 1] += d1[i];
  }
  rep(i, 0, v.sz - k + 1) {
    mx = max(mx, d1[i] + d[i + k] - d[i] + d1[n] - d1[i + k]);
    mx = max(mx, d1[i] + d1[n] - d1[i + k]);
  }
  printf("%lld\n", mx);
  return 0;
}

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

int main(){
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;

    int rui[100010] = {};

    for(int i = 1;i < n;i++){
        if(s[i] == 'C' && s[i-1] == 'A'){
            rui[i]++;
        }
        rui[i] += rui[i-1];
    }

    for(int i = 0;i < q;i++){
        int l, r;
        cin >> l >> r;
        cout << rui[r-1]-rui[l-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 

void solve()
{
   ll n,k;
   cin>>n>>k;
   ll a[n];
   f(i,0,n)
   cin>>a[i];
   bool dp[k+1] = {false};
   f(i,1,k+1)
   {
      f(j,0,n)
      {
         if(i-a[j]<0)
         continue;
         else if(dp[i-a[j]]==false)
         dp[i] = true;
         
      }
   }
   if(dp[k]==true)cout<<"First\n";
   else cout<<"Second\n";
}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 384
# import math

s = [input() for i in range(2)]
n = int(s[0])
a = list(map(int, s[1].split()))

# n = 5
# a = [1, 1, 2, 2]

x = [0] * n
for i in range(0, n - 1):
    x[a[i] - 1] += 1

for line in x:
    print(line)


Measured memory_bytes: 33472
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d%*c", &n);
	rep(i, n){
		char str[258];
		fgets(str, 258, stdin);

		set<string> words;
		stringstream stin(str);
		string tmp;
		while(stin >> tmp){
			if(tmp.size() == 4)
				words.insert(tmp);
		}

		int alpha=0, beta=0;
		bool keep = true;
		for(int i=1; keep; ++i){
			if(i%2==0 || i%13==0)
				continue;
			rep(j, 26){
				char samples[][5] = {"that", "this"};
				rep(k, 2){
					rep(l, 4) samples[k][l] = ((samples[k][l]-'a')*i+j)%26+'a';
					if(words.count(string(samples[k]))){
						alpha = i;
						beta = j;
						j=100;
						keep = false;
					}
				}
			}
		}

		map<char, char> conv;
		rep(i, 26)
			conv.insert(make_pair((i*alpha+beta)%26+'a', i+'a'));
		rep(i, strlen(str))
			putchar(isalpha(str[i]) ? conv[str[i]] : str[i]);
	}

	return 0;





// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
// bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb


}

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

// #pragma comment(linker, "/STACK:16777216")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
#define F first
#define S second
//#define int ll
#define pii pair<int, int>
const int SZ = 2e5 + 4;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

struct custom_hash {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return x + FIXED_RANDOM;
    }
};

int n;
int a[SZ];

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

void solve() {
    int cnt = 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == cnt) {
            ++cnt;
        }
    }
    if (cnt == 1) {
        cout << -1;
        return;
    }
    cout << n - cnt + 1;
}

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

    read();
    solve();

    return 0;
}

Measured memory_bytes: 1024
//ABC 042-A
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	int A, choushi5 = 0, choushi7 = 0;

	for (int i = 0; i < 3; i++){
		cin >> A;
		if(A == 5) choushi5++;
		else if(A == 7) choushi7++;
	}
	if(choushi5==2 && choushi7 == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
#define MAXN 610
LL n, d1, d2;
bool cannot[MAXN][MAXN];

void Set(LL d) {
	LL b = 0;
	while (!(d%4)) d >>= 2, ++b;
	if (d&1) {
		for (int i = 0; i <= n << 1; ++i)
			for (int j = 0; j <= n << 1; ++j)
				if (((i >> b) + (j >> b)) & 1)
					cannot[i][j] = true;
	} else {
		for (int i = 0; i <= n << 1; ++i)
		 	for (int j = 0; j <= n << 1; ++j)
			 	if ((i >> b) & 1)
				 	cannot[i][j] = true;
	}
}
int main() {
	cin >> n >> d1 >> d2;
	Set(d1); Set(d2);
	/*for (int i = 0; i < n << 1; ++i, cout << endl)
		for (int j = 0;j < n << 1; ++j)
			cout << cannot[i][j];*/
	int cnt = 0;
	for (int i = 0; i < n << 1; ++i)
		for (int j = 0;j < n << 1; ++j)
			if (cnt < n * n && !cannot[i][j]) {
				cout << i << " " << j << endl;
				++cnt;
			}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    ll N, A, B;
    scanf("%lld %lld %lld", &N, &A, &B);

    ll sum = N / (A + B) * A + min(N % (A + B), A);
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <array>

using namespace std;

int main()
{
	int N; cin >> N;
	unordered_map<string,long long int> umap;
	long long int ans = 0;
	for (int i=0; i<N; i++) {
		string s; cin >> s;
		sort(s.begin(), s.end());
		if (umap[s] != 0) {
			ans += umap[s];
          	umap[s]++;
		} else {
			umap[s] = 1;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int dp[MAX];

int main(){
    
    string S;cin>>S;
    int N=S.size();
    
    int bit=0;
    vector<int> data(N+1,0);
    map<int,vector<int>> MA;
    for(int i=0;i<N;i++){
        bit^=(1<<(S[i]-'a'));
        if(MA[bit].size()==2) MA[bit].pop_back();
        MA[bit].push_back(i+1);
        data[i+1]=bit;
    }
    for(int i=1;i<=N;i++) dp[i]=INF;
    dp[0]=0;
    
    for(int i=0;i<N;i++){
        if(dp[i]>=INF) continue;
        for(auto to:MA[data[i]]) dp[to]=min(dp[to],dp[i]+1);
        //if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);
        
        for(int j=0;j<26;j++){
            data[i]^=(1<<j);
            //if(i==0) cout<<j<<" "<<data[i]<<endl;
            //if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);
            for(auto to:MA[data[i]]) dp[to]=min(dp[to],dp[i]+1);
            data[i]^=(1<<j);
        }
    }
    
    cout<<dp[N]<<endl;
    
    //for(int i=0;i<=N;i++) cout<<i<<" "<<data[i]<<" "<<dp[i]<<endl;
    
}


Measured memory_bytes: 347652
using System;
using System.Linq;

class prog{
  static void Main(){
    int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int N = input[0];
    int A = input[1];
    int B = input[2];
    
    int sum = 0;
    for(int i = 1; i <= N; i++){
      int sum_ = 0;
      foreach (var s in i.ToString()){
        sum_ += int.Parse(s.ToString());
      }
      if(sum_ >= A&&sum_ <= B) sum += i;
    }
    
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 13396
n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=a[0..m-1].inject(:+)
max=sum
(n-m).times do |i|
    sum+=a[i+m]
    sum-=a[i]
    max=sum if max<sum
end

p (max+m)/2.0

Measured memory_bytes: 14980
#include<iostream>
#include<vector>
#include<string>
#include<map>

int main(){
    int n;
    std::cin >> n;
    std::map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        mp[a] = i + 1;
    }

    for(auto m : mp){
        std::cout << m.second << " ";
    }
    return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const int N = 1e5 + 100;
int p[N];
bool used[N];

void make_pair(int i) {
    p[i] = i;
}

int find_id(int a) {
    if (p[a] == a)
        return a;
    return p[a] = find_id(p[a]);
}

void union_pair(int a, int b) {
    a = find_id(a);
    b = find_id(b);
    if (a == b)
        return;
    p[b] = a;
}

int main() {
    used[0] = 1;
    for (int i = 0; i < N; ++i)
        make_pair(i);
    int n, m;
    scanf("%d%d", &n, &m);
    vector<pair<int, int> > f;
    for (int i = 0; i < n; ++i) {
        int t, cost;
        scanf("%d%d", &t, &cost);
        t = m - t + 1;
        if (t < 0)
            continue;
        f.push_back({cost, t});
    }
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    long long ans = 0;
    for (auto x : f) {
        int tmp = find_id(x.second);
        while(tmp != 0 && used[tmp]) {
            union_pair(tmp - 1, tmp);
            tmp = find_id(tmp);
        }
        if (!used[tmp]) {
            ans += x.first;
            union_pair(tmp - 1, tmp);
            used[tmp] = 1;
        }
    }
    printf("%lld", ans);
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,W;
    cin>>n>>W;
    vector<vector<ll> > dp(n+100,vector<ll>(W+100));
    vint w(n+1);
    vint v(n+1);
    REP(i,1,n+1){
	cin>>w[i]>>v[i];
    }
    REP(i,1,n+2){
	rep(j,W+1){
	    if(j-w[i]>=0){
		dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
	    }
	    else{
		dp[i][j]=dp[i-1][j];
	    }
	}
    }
    cout<<dp[n][W]<<'\n';
    return(0);
}


Measured memory_bytes: 157824
x, y = map(int, input().split())

award = 0
if x == 3:
	award += 100000
elif x == 2:
	award += 200000
elif x == 1:
	award += 300000

if y == 3:
	award += 100000
elif y == 2:
	award += 200000
elif y == 1:
	award += 300000

if x == y == 1:
	award += 400000

print(award)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
    int num = 0;
    
    cin >> num;
    
    if(num < 1200)
    {
        cout << "ABC" << endl;
    }
    else if(num < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int x, y, size, i, j, count = 0, max = 0;
	int grid[12][12] = {};

	while (scanf("%d,%d,%d", &x, &y, &size) != EOF) {
		grid[x][y]++;
		grid[x-1][y]++;
		grid[x+1][y]++;
		grid[x][y-1]++;
		grid[x][y+1]++;
		if (size > 1) {
			grid[x+1][y+1]++;
			grid[x+1][y-1]++;
			grid[x-1][y+1]++;
			grid[x-1][y-1]++;
		}
		if (size == 3) {
			grid[x][y+2]++;
			grid[x+2][y]++;
			grid[x][y-2]++;
			grid[x-2][y]++;
		}
	}
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			if (grid[i][j] == 0) count++;
			else if (grid[i][j] > max) max = grid[i][j];
		}
	}
	printf("%d\n%d\n", count, max);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';

bool validM(ll a) { return a >= 1 && a <= 12; }
bool validY(ll b) { return true; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;

  ld res = 0;

  for (ll i = 1; i <= n; i++) {
    ll curr = i;
    ll j;

    if (curr >= k) {
      res += 1;
      continue;
    }
    for (j = 1;; j++) {
      curr *= 2;
      if (curr >= k)
        break;
    }

    res += (ld)1 / (pow(2, j));
  }

  res /= n;
  cout << fixed << setprecision(12) << res << en;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main()
{
	int n, y;
	cin >> n >> y;

	int r10000 = -1;
	int r5000 = -1;
	int r1000 = -1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; i+j <= n; j++) {
			int k = n - i - j;
				int total = 10000 * i + 5000 * j + 1000 * k;
				if (total == y) {
					r10000 = i;
					r5000 =j;
					r1000 = k;
				}
			
		}
	}
	cout << r10000<<" "<< r5000 << " " << r1000 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(gcd(a, b));
    }
    static int gcd (int a, int b) {
        int num;
        while((num = a%b)!=0) {
            a = b;
            b = num;
        }
        return b;
    }

}


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

using namespace std;
constexpr int INF = 1000000000;

int main() {
  int s,n,m;
  cin>>s>>n>>m;
  if (m >= n) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(s);
  REP(i,s) cin>>x[i];
  vector<int> tn(n);
  REP(i,n) {
    int t,p;
    cin>>t>>p;
    --p;
    tn[i] = t-x[p];
  }
  sort(ALL(tn));
  int offset=-tn.front();
  REP(i,n) tn[i]+=offset;
  vector<vector<int>> tb(n, vector<int>(n, 0));
  REP(i,n)REP(j,i-1) {
    tb[j][i] = tb[j][i-1] + (tn[i] - tn[i-1]) * (i-j-1);
  }
  vector<vector<int>> dp(m+1, vector<int>(n, INF));
  REP(i,n) dp[1][i] = tb[0][i] + tn[i];
  FOR(i,2,m+1) {
    REP(k,n) {
      FOR(j,k+1,n) {
        dp[i][j] = min(dp[i][j], dp[i-1][k] + tb[k][j]);
      }
    }
  }
  cout << dp[m][n-1] << endl;
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

// 座標圧縮 {{{
// O(N*log(N))
template <typename T>
vector<int> compress(vector<T> v){
    int n = v.size();
    vector<int> res(n);

    auto u = v;
    sort(u.begin(), u.end());
    map<T, int> m;

    T b = u[0];
    int now = 0;
    inc(i, 0, n){
        if(b != u[i]) now++;
        m[u[i]] = now;
        b = u[i];
    }

    inc(i, 0, n){
        res[i] = m[v[i]];
    }

    return res;
}// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    inc(i, 0, n) cin >> a[i];

    auto b = compress(a);

    int ans = 0;
    inc(i, 0, n){
        if(i%2 != b[i]%2) ans++;
    }
    cout << ans/2 << endl;
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      	int sum = 0;
     
		for (int i = 0; i <= n; i++) {
   		 sum += i;
		}
			
		System.out.print(sum);
      
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
template<typename T, typename U>
inline auto cmn (T& a, U b) {if (a > b) {a = b; return true;} return false;}
template<typename T, typename U>
inline auto cmx (T& a, U b) {if (a < b) {a = b; return true;} return false;}
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, A, B;
  std::cin >> n >> A >> B;
  std::vector<int> p(n);
  std::for_each(p.begin(), p.end(), [](auto& x){std::cin >> x;});
  p.insert(p.begin(), 0), p.push_back(n + 1);
  constexpr long long inf = 1LL << 60;
  auto dp = std::vector<long long>(n + 2, inf);
  dp.at(0) = 0;
  for (int i = 1; i <= n + 1; i++) {
    auto crr = p.at(i);
    int lower = -1;
    long long now = 0;
    for (int j = i - 1; j >= 0; j--) {
      auto prv = p.at(j);
      assert(crr != prv && prv != lower);
      if (prv > crr) {
        now += A;
      } else {
        if (prv > lower) cmn(dp.at(i), dp.at(j) + now);
        now += B;
      }
    }
  }
  std::cout << dp.at(n + 1) << std::endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

const int MAXN = 120000;
int n, m;
int dd[MAXN * 4];
vector<pair<int, int> > vv[MAXN];

void add(int v, int tl, int tr, int l, int r, int d) {
	if (r <= tl || tr <= l)
		return;
	if (l <= tl && tr <= r) {
		dd[v] += d;
		return;
	}
	int m = (tl + tr) >> 1;
	add(v * 2 + 1, tl, m, l, r, d);
	add(v * 2 + 2, m, tr, l, r, d);
}

int get(int v, int tl, int tr, int x) {
	if (tl + 1 == tr)
		return dd[v];
	int m = (tl + tr) >> 1;
	if (x < m)
		return get(v * 2 + 1, tl, m, x) + dd[v];
	else
		return get(v * 2 + 2, m, tr, x) + dd[v];
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		++r;
		vv[r - l].push_back(make_pair(l, r));
	}
	int now = n;
	for (int i = 1; i <= m; ++i) {
		int ans = now;
		for (int j = i; j <= m; j += i)
			ans += get(0, 0, m + 1, j);
		printf("%d\n", ans);
		for (auto e: vv[i])
			add(0, 0, m + 1, e.first, e.second, 1), --now;
	}
	return 0;
}




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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    n = 3 * n;
    vector<ll> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }    
    sort(ALL(a));
    ll ans = 0;
    for(int i = 1, j = n; i <= j; i++, j -= 2){
        ans += a[j - 1];
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll x;
    cin >> x;
    REP(i, -200, 201) REP(j, -200, 201) {
        if (pow(i, 5) - pow(j, 5) == x) {
            cout << i << " " << j << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 4076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool compare(P a,P b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    int n;cin>>n;
    vector<int> perm(8);
    REP(i,8){
        perm[i] = i;
    }
    vector<P> xy(n);
    REP(i,n){
        int x,y; cin >> x >> y;
        xy[i] = P(x,y);
    }
    sort(ALL(xy),compare);
    do{ 
        vector<P> permutation(8);
        REP(i,8){
            permutation[i] = P(i,perm[i]);
        }
        bool flag1 = true;
        REP(i,n){
            if(!binary_search(ALL(permutation),xy[i], compare)) {
                flag1 = false; break;
            }
        }
        if(!flag1) continue;

        bool flag = true;
        REP(i,7){
            FOR(k,i+1,8){
                if(abs(k-i) == abs(perm[k]-perm[i])){
                    flag = false; break;
                }
            }
            if(!flag) break;
        }
        if(flag == true){
            REP(i,8){
                REP(k,8){
                    if(binary_search(ALL(permutation),P(i,k),compare)){
                        cout<<'Q';
                    }
                    else cout<<'.';
                }
                cout<<endl;
            }
            return 0;
        }
        

    }while(next_permutation(ALL(perm)));
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    string S;
    cin >> S;
    vector<int> s;
    using T = unsigned long long;
    int l = S.length();
    for (int i = 0; i < l; ++i)
    {
        s.push_back(int(*(S.c_str() + i) - '0'));
    }
    T sum = 0;
    for (int i = 0; i < (1 << (l - 1)); ++i)
    {
        bitset<10> b(i);
        T n = 0;
        T partial_sum = 0;
        for (int j = 0; j < l; ++j)
        {
            n *= 10;
            n += s[j];
            if (b[j])
            {
                partial_sum += n;
                n = 0;
            }
        }
        partial_sum += n;
        //        cout << partial_sum << endl;
        sum += partial_sum;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
  int N = B - A + 1;
  int n = 0;
  for (int i=0; i < N; i++){
    int K = A + i;
    int a;
    int b;
    int c;
    int d;
    a = K / 10000;
    b = (K / 1000) - 10*a;
    c = (K / 10) - (K / 100) * 10;
    d = K - ( K/10 ) * 10;
  if (a == d && b == c){
  n = n + 1;
  }
  }
  cout << n << endl;
}
    

Measured memory_bytes: 3584
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	h1, m1, h2, m2, k := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	mins1 := 60*h1 + m1
	mins2 := 60*h2 + m2
	a := mins2 - mins1 - k

	fmt.Println(a)

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1756
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int ok = 1e9, ng = 0;
	while(ok - ng > 1){
		int mid = (ok + ng) / 2;
		int cost = 0;
		rep(i,n){
			cost += max(0, (a[i] + mid - 1) / mid - 1);
		}
		if(cost <= k) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 3988
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
   for j in range(w):
      if S[i][j]!="#":
         dp=[[inf for _ in range(w)]for _ in range(h)]
         dp[i][j]=0
         que=deque([(i,j)])
         while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
               if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                  if dp[ni][nj]>dp[si][sj]+1:
                     dp[ni][nj]=dp[si][sj]+1
                     que.append((ni,nj))
                     ans=max(ans,dp[si][sj]+1)
print(ans)

Measured memory_bytes: 48476
package main

import (
	"fmt"

)

func main(){
  var x float64;
  fmt.Scan(&x);
  principal:=float64(100)
  year:=float64(0)
  for total:=principal;total<x;year++{
	total*=1.01
	total=float64(int(total))
  }
  fmt.Println(year)
}

Measured memory_bytes: 1752
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
ans=0
for i in range(n):
    if i%2==0 and a[i]%2==1:
        ans+=1
print(ans)

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

using namespace std;
typedef long long int ll;

int main (){
  int K,r;
  cin >> K;
  queue<ll> X;
  for(int i = 1; i < 10; i++){
    X.push(i);
  }
  for(ll i = 1; i < K; ){
    r = X.front() % 10;
    if(r != 0){X.push(X.front()*10 + r -1);}
    X.push(X.front()*10 + r);
    if(r != 9){X.push(X.front()*10 + r +1);}
    X.pop();i++;
  }
  cout << X.front() << endl;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
string s;
int n,q;
int a[1<<17];
main()
{
	cin>>n>>q>>s;
	for(int i=0;i<n;i++)
	{
		a[i+1]=a[i];
		if(i>0&&s[i-1]=='A'&&s[i]=='C')a[i+1]++;
	}
	for(;q--;)
	{
		int l,r;cin>>l>>r;
		cout<<a[r]-a[l]<<endl;
	}
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> d;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  d.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());

  int v1 = d[N / 2 - 1];
  int v2 = d[N / 2];

  cout << v2 - v1 << endl;
  return 0;
}

Measured memory_bytes: 640
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


int a[105];
signed main() {
    //ifstream cin("E:\\acm dream\\in.in");
	//ofstream cout("E:\\acm dream\\out.out");
	FIO;
    #ifdef err
	double be = clock();
    #endif

    int ans=0;
    int n;cin>>n;
    _for(i,0,n)cin>>a[i];
    _for(i,0,n-2){
        _for(j,i+1,n-1){
            _for(k,j+1,n){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j])++ans;
            }
        }
    }
    cout<<ans;
    
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

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

int main(){
  int N,M;cin >> N >> M;
  vector<int> S(N,1);
  vector<int> T(N,0);
  T[0] = 1;
  for(int j=0;j<M;j++){
    int x,y;cin >> x >> y;
    x --;
    y --;
    S[x] --;
    S[y] ++;
    if(T[x]==1){
      T[y]=1;
      if(S[x]==0){
        T[x]=0;
      }
    }
  }
  int sum=0;
  for(int i=0;i<N;i++){
    if(T[i]==1){
      sum ++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4020
fun main(args: Array<String>){
    val N :Int = readLine()!!.toInt()
    val (D , X) = readLine()!!.split(" ").map(String::toInt)
    val A = mutableListOf<Int>()
    var sum :Int = 0
    for(i in 1..N){
        A.add(readLine()!!.toInt())
    }
    for(i in A.indices){
        sum = sum + ((D+A[i]-1)/A[i])
    }
    println(sum + X)
}


Measured memory_bytes: 37848
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int X;

int main()
{
    cin >> X;
    if (X == 3 || X == 5 || X == 7)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  inl(N);
  vi ans;
  int s = 0;
  for(int i = 1 ; i <= N ; i++){
    ans.pb(i); s += i;
    if(s >= N) break;
  } 
  if(s != N){
    ans.erase(ans.begin() + (s - N - 1));
  }
  each(x , ans) out(x);
}

Measured memory_bytes: 384
# sum(nCm) 
# 1:1 1 = 2     2
# 2:1 2 1 = 4
# 3:1 3 3 1 = 8  (1+x)**3
# 4:1 4 6 4 1 = 16
# 5:1 5 10 10 5 1 = 32 (1+x)^5

MOD = 1000000007

def modpow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = (res * a) % MOD
        a = (a * a) % MOD
        n = n >> 1
    return res

def modinv(a):
    return modpow(a, MOD-2)

def fact(k):
    d = 1
    for i in range(1, k+1):
        d = (d * i) % MOD
    return d

def C(n, k):
    p = 1
    for i in range(n-k+1, n+1):
        p = (p * i) % MOD
    d = 1
    for i in range(1, k+1):
        d = (d * i) % MOD
    return (p * modinv(d)) % MOD
#for i in range(1, 13): print(modinv(i))
n, a, b = map(int, input().split())
base = modpow(2, n)
base = (base - C(n,a)) % MOD
base = (base - C(n, b)) % MOD
print(base-1)


Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Stack;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		while (scan.hasNext()) {
			String token = scan.next();
			switch (token) {
			case "+": {
				int v1 = stack.pop();
				int v2 = stack.pop();
				stack.push(v2 + v1);
				break;
			}
			case "-": {
				int v1 = stack.pop();
				int v2 = stack.pop();
				stack.push(v2 - v1);
				break;
			}
			case "*": {
				int v1 = stack.pop();
				int v2 = stack.pop();
				stack.push(v2 * v1);
				break;
			}
			default: {
				stack.push(Integer.valueOf(token));
				break;
			}
			}
		}
		System.out.println(stack.pop());
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26316
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


fun main() {
    val n = readLine()!!.toLong()
    val ai = readLongList()
    val mod = 1000000007L
    var ans = 0L
    var x = 0L
    for (i in 0 until n) {
        ans = (ans +ai[i.toInt()]*x)%mod
        x = (x + ai[i.toInt()])%mod
    }
    println(ans)
}


Measured memory_bytes: 74976
#include <bits/stdc++.h>
using namespace std;
const int maxn = 222222, mod = 1000000007;
int mul(long long a, long long b){
	return a * b % mod;
}
int p2[maxn], p3[maxn];
int main(){
	p2[0] = p3[0] = 1;
	for(int i = 1; i < maxn; i++){
		p2[i] = mul(p2[i - 1], 2);
		p3[i] = mul(p3[i - 1], 3);
	}
	string s; cin >> s;
	int ans = 0, fac = 1, len = s.size();
	for(int i = 0; i < len; i++){
		if(s[i] == '1'){
			ans += mul(fac, p3[len - i - 1]);
			if(ans >= mod) ans -= mod;
			fac = mul(fac, 2);
		}
	}
	ans += fac;
	if(ans >= mod) ans -= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    int k, n; cin >> k >> n;
    vector<int> a(n);
    int tmp;
    rep(i, n){
        cin >> tmp;
        a[i] = tmp;
    }
    sort(all(a));
    int ans = a[n-1] - a[0];
    rep(i, n-1){
        ans = min(a[i] - a[i+1] + k, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152