akhauriyash/Code-Regression huggingface dataset:
function main(input) {
    var rows = input.trim().split("\n");
    rows.shift();
    rows.map(function (r, i) {
            var c = r.split(" ");
            return {
                id: i + 1,
                name: c[0],
                score: c[1] * 1
            };
        }).sort(function (a, b) {
            if (a.name == b.name) return b.score - a.score;
            if (a.name < b.name) return -1;
            if (a.name > b.name) return 1;
            return 0;
        })
        .forEach(function (c) {
            console.log(c.id);
        });
}


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

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<ll> A(N * 2);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[N + i] = A[i];
	}
	vector<vector<ll>> dp(N * 2, vector<ll>(N * 2 + 1, -1e16));
	for (int i = 0; i < N * 2; i++) {
		dp[i][i + 1] = A[i];
	}
	ll res;
	for (int len = 2; len <= N; len++) {
		res = 0;
		if (len & 1) {
			for (int i = 0; i + len <= N * 2; i++) {
				if (dp[i + 1][i + len] > 0) {
					dp[i][i + len] = max(dp[i][i + len], dp[i + 1][i + len] + A[i]);
					res = max(res, dp[i + 1][i + len] + A[i]);
				}
				if (dp[i][i + len - 1] > 0) {
					dp[i][i + len] = max(dp[i][i + len], dp[i][i + len - 1] + A[i + len - 1]);
					res = max(res, dp[i][i + len - 1] + A[i + len - 1]);
				}
			}
		}
		else {
			for (int i = 0; i + len < N * 2; i++) {
				if (A[i] > A[i + len]) {
					dp[i][i + len] = max(dp[i][i + len], dp[i + 1][i + len]);
					res = max(res, dp[i + 1][i + len]);
				}
				else {
					dp[i + 1][i + len + 1] = max(dp[i + 1][i + len + 1], dp[i + 1][i + len]);
					res = max(res, dp[i + 1][i + len]);
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}



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

int main(){
    char S[3],T[3];
    int exact=0;
    for(int i=0;i<3;i++)
        cin>>S[i]; 
    for(int i=0;i<3;i++)
        cin>>T[i];
        
    for(int i=0;i<3;i++){
        if(S[i]==T[i]) 
            exact++;
    }

    cout<<exact<<endl;
    return 0;
}

Measured memory_bytes: 256
#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);
	string s; cin>>s;	
	int n=s.size();
	for (int i=0; i<n; i++) {
		if (s.substr(i,2)=="AC") { 
			cout<<"Yes\n"; 
				return 0;
		}
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
//const int N = 2e5 + 5;
  
 
int32_t  main() {

	IOS;

	int N, K;

	cin >> N >> K;
	 
	
	vector<int> arr(N);

	for (int i = 0; i < N; i++) {
		 
		cin >> arr[i];
		 
		arr[i]--;
	}

	vector<int> vis(N);

	vector<int> start, cyc;

	int x = 0;

	while (true) {

		vis[x] = 1;
		start.push_back(x);

		x = arr[x];
		
		if (vis[x]) {

			while (true) {

				cyc.push_back(start.back());

				int tmp = start.back();
				start.pop_back();

				if (tmp == x) {
					break;
				}


			}
			break;
		}

	}

	reverse(cyc.begin(), cyc.end());
	if (  K < start.size()) {
		cout << start[K] + 1 << endl;
	}
	else {

		K -= start.size();

		K%= cyc.size();

		cout << cyc[K] + 1 << endl;


	}



}


Measured memory_bytes: 10240
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

  vector<int> rem; // s[i] where s[i]%10 != 0
  for (int i = 0; i < n; ++i) {
    if (s[i] % 10 != 0)
      rem.push_back(s[i]);
  }
  sort(rem.begin(), rem.end());
  int sum = accumulate(s.begin(), s.end(), 0);

  if (sum % 10) {
    cout << sum << "\n";
  } else if (rem.size()) {
    cout << sum - rem[0] << "\n";
  } else {
    cout << "0\n";
  }

  return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 15, msksz = (1 << nsz) - 1, inf = 0x3f3f3f3f;
int n, m, full, lg[msksz + 5], g[nsz + 5], w[nsz + 5][nsz + 5];
int sum[msksz + 5], sm[msksz + 5][nsz + 5], dp[msksz + 5][nsz + 5];

int inline at(int S, int id) { return S >> id & 1; }

int inline lb(int S) { return S & -S; }

void inline upd(int &a, int b) { if (a < b) a = b; }

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m;
	full = (1 << n) - 1;
	cont (i, m) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;
		g[u] |= 1 << v;
		g[v] |= 1 << u;
		::w[u][v] = ::w[v][u] = w;
	}
	loop (i, n) lg[1 << i] = i;
	
	cont (S, full) {
		int u = lg[lb(S)];
		sum[S] = sum[S - lb(S)];
		for (int t = g[u] & S, d = t & -t; t; t -= d, d = t & -t) {
			int v = lg[lb(t)];
			sum[S] += w[u][v];
		}
	}
	
	cont (S, full) {
		int pS = S - lb(S), p = lg[lb(S)];
		for (int rS = S ^ full, t = rS, d = t & -t; d; t -= d, d = t & -t) {
			int u = lg[lb(t)];
			sm[S][u] = sm[pS][u] + w[p][u];
		}
	}
	
	memset(dp, -inf, sizeof(dp));
	cont (S, full) {
		if (!at(S, 0) || at(S, n - 1)) continue;
		dp[S][0] = sum[S];
	}
	circ (S, 0, full) {
		for (int rS = (S ^ full), T = rS; T; T = (T - 1) & rS) {
			int mx = 0;
			for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
				int u = lg[d];
				upd(mx, sm[T][u]);
			}
			for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
				int u = lg[d];
				if (dp[S][u] < 0) continue;
				upd(dp[S | T][u], dp[S][u] + mx + sum[T]);
			}
		}
		for (int t = S, d = t & -t; t; t -= d, d = t & -t) {
			int u = lg[d];
			if (dp[S][u] < 0) continue;
			for (int rS = (S ^ full) & g[u], t = rS, d = t & -t; d; t -= d, d = t & -t) {
				int v = lg[d];
				upd(dp[S | (1 << v)][v], dp[S][u] + w[u][v]);
			}
		}
	}
	cout << sum[full] - dp[full][n - 1] << ln;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

int N;
ll A, B, C;

ll fact[200001], invfact[200001];

ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll ret = mod_pow(x * x % MOD, n / 2) % MOD;
	if(n & 1) return ret * x % MOD;
	return ret;
}

ll nCk(int n, int k){
	return fact[n] * invfact[n - k] % MOD * invfact[k] % MOD;
}
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main(){
	cin >> N >> A >> B >> C;
	for(int i = 0; i <= 2 * N; i++){
		if(i == 0) fact[i] = 1;
		else{
			fact[i] = fact[i - 1] * i;
			fact[i] %= MOD;
		}
	}
	for(int i = 0; i <= 2 * N; i++){
		if(i == 0) invfact[i] = 1;
		else{
			invfact[i] = invfact[i - 1] * mod_pow(i, MOD - 2);
			invfact[i] %= MOD;
		}
	}
	ll a = A * mod_pow(A + B, MOD - 2) % MOD;
	ll b = B * mod_pow(A + B, MOD - 2) % MOD;
	ll res = 0;
	for(int i = 0; i < N; i++){
		ll p = mod_pow(a, N) * mod_pow(b, i) % MOD;
		p = p * nCk(N - 1 + i, i) % MOD;
		p = p * (N + i) % MOD;
		p = p * 100 % MOD;
		p = p * mod_pow(100 - C, MOD - 2) % MOD;
		res += p;
		res %= MOD;
		ll q = mod_pow(a, i) * mod_pow(b, N) % MOD;
		q = q * nCk(N - 1 + i, i) % MOD;
		q = q * (N + i) % MOD;
		q = q * 100 % MOD;
		q = q * mod_pow(100 - C, MOD - 2) % MOD;
		res += q;
		res %= MOD;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<cmath>
#include<vector>
#include<map>
#include<random>
#include<sstream>
using namespace std;

int main(){
    string t;cin >> t;
    string ty,tm,td={};
    int j = 0;
    for(int i = 0;i < t.size();i++){
        if(t[i] =='/'){
            j++;
            continue;
        }
        if(j == 0)ty += t[i];
        else if(j == 1)tm += t[i];
        else td += t[i];
    }
    int y = stoi(ty);
    int m = stoi(tm);
    int d = stoi(td);
    if(y > 2019){cout << "TBD" << endl;}
    else if(m > 4){cout << "TBD" << endl;}
    else if(d > 30){cout << "TBD" << endl;}
    else cout << "Heisei" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const ll INF = 10000000000;
int main() {
    ll n,k;
    cin >> n >> k;
    if (n < k) {
        cout << min(n,k - n);
    }
    else {
        cout << min(n % k, k - n % k);
    }
    return 0;
}

Measured memory_bytes: 256
/*************************************************
       Author       :   NIYOUDUOGAO
       Last modified:   2018-08-01 09:00
       Email        :   pjm000@163.com
       Filename     :   t2.cpp
 *************************************************/
#include <bits/stdc++.h>
#define mset(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int a[N];
int vis[N];
ll f[N];
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv(ll b){return qpow(b,mod-2);}
void init() {
    f[0] = 1;
    for (int i = 1; i <= 100005; i++) {
        f[i] = (f[i - 1] * i) % mod;
    }
}
ll C(int x, int y) {
    return f[x] * inv(f[y]) % mod * inv(f[x - y]) % mod;
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    init();
    int n;
    cin >> n;
    int Index1, Index2;
    for (int i = 1; i <= n + 1; i++) {
        cin >> a[i];
        if (vis[a[i]]) {
            Index1 = vis[a[i]] - 1;
            Index2 = i;
        }
        vis[a[i]] = i;
    }
    ll t1, t2;
    for (int i = 1; i <= n + 1; i++) {
        t1= C(n + 1, i) % mod;
        if (n + 1 - Index2 + Index1 >= i - 1) {
            t2 = C(n + 1 - Index2 + Index1, i - 1) % mod;
        } else {
            t2 = 0;
        }
        cout << (t1 - t2 + mod) % mod << "\n";
    }
    return 0;
}

Measured memory_bytes: 2816
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {
    cout.precision(15);
    cout << fixed;
    string T;
    cin >> T;
    REP(i,T.size()) {
        if (T[i]=='?')
            T[i]='D';
    }
    cout<<T<<endl;
}



Measured memory_bytes: 3752
#include<stdio.h>

int main(){
  int n[100],i,j,gyou,m,change = 0;

  scanf("%d",&gyou);

  for(i = 0;i < gyou;i++){
    scanf("%d",&n[i]);
  }

  for(i = 0;i < gyou;i++){
    for(j = gyou - 1;j >= i + 1;j--){
      if(n[j] < n[j - 1]){
	m = n[j];
	n[j] = n[j - 1];
	n[j - 1] = m;
	change++;
      }
    }
  }

  for(i = 0;i < gyou;i++){
    if(i > 0) printf(" ");
    printf("%d",n[i]);
  }

  printf("\n");
  printf("%d\n",change);
  
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    int n,a,b;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;++i)
        ans+=(ll)i*(n-i+1);
    for(int i=1;i<n;++i)
    {
        cin>>a>>b;
        if(a>b)
            swap(a,b);
        ans-=(ll)(a-1+1)*(n-b+1);
    }
    cout<<ans<<endl;
}


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

int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    string result = "No";
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            if (M * i + N * j - 2 * i * j == K)
            {
                result = "Yes";
                break;
            }
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>

int main()
{
	char input[32] = { 0 };
	std::cin.getline(input, sizeof(input));

	std::string s = input;

	int len[2] = { 0, 0 };
	len[0] = std::stoi(s);
	len[1] = std::stoi(s.substr(s.find(' ', 0)));

	std::cout << len[0] * len[1] << " " << (len[0] + len[1]) * 2 << std::endl;
	return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

class UFTree {
private:
	static const int	UFTREE_NODE_NUM = 100001;
	int mNode[UFTREE_NODE_NUM];
	int mRank[UFTREE_NODE_NUM];

public:
	void init(int n)
	{
		for (int i = 0; i < n; i++) {
			mNode[i] = i;
			mRank[i] = 0;
		}
	}

	int find(int x)
	{
		if (mNode[x] == x) {
			return x;
		}
		else {
			mNode[x] = find(mNode[x]);
			return mNode[x];
		}
	}

	void unite(int x, int y)
	{
		int idxX = find(x);
		int idxY = find(y);

		if (idxX == idxY) {
			return;
		}

		if (mRank[idxX] > mRank[idxY]) {
			mNode[idxY] = idxX;
		}
		else {
			mNode[idxX] = idxY;
			if (mRank[idxX] == mRank[idxY]) {
				mRank[idxY]++;
			}
		}
	}

	bool isSameSet(int x, int y)
	{
		return find(x) == find(y);
	}
};

UFTree tree;


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

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

	tree.init(N + 1);

	for (auto i = 0; i < M; ++i)
	{
		int x, y;
		cin >> x >> y;
		tree.unite(x, y);
	}

	map<int, set<int>> m;
	for (auto i = 1; i <= N; ++i)
	{
		auto n = tree.find(i);
		auto it = m.find(n);
		if (it != m.end())
		{
			auto& s = it->second;
			s.insert(i);
		}
		else
		{
			set<int> temp;
			temp.insert(i);
			m[n] = temp;
		}
	}

	auto result = 0;
	for (auto& pair : m)
	{
		auto& s = pair.second;
		for (auto i : s)
		{
			if (s.find(p[i - 1]) != s.end())
			{
				++result;
			}
		}
	}

	cout << result << endl;

	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int lenS = sz(s);
  bool bl = true;
  rep(i, lenS) {
    if (i&1 && s[i] == 'R') bl = false;
    else if (i%2 == 0 && s[i] == 'L') bl = false;
  }
  if (bl) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3624
#include"bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    ll D, G;
    cin >> D >> G;
    vector<ll> p(D), c(D);
    for (ll i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    ll ans = INT_MAX;
    for (ll i = 0; i < pow(2, D); i++) {
        ll num = 0;
        ll score = 0;
        ll max_index = 0;
        for (ll j = 0; j < D; j++) {
            if (i & (1 << j)) {
                num += p[j];
                score += p[j] * (j + 1) * 100 + c[j];
            } else {
                max_index = max(max_index, j);
            }
        }

        for (ll n = 0; n < p[max_index]; n++) {
            if (score >= G) {
                ans = min(ans, num);
                break;
            }
            score += 100 * (max_index + 1);
            num++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define nl cout<<'\n'
#define pb push_back
#define vi vector<lli>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

void solve(){
	string s;
	cin >> s;
	lli sm = 0;
	for(char c:s) sm += (c - '0');
	if(sm%9==0) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return;
}

int main(){
    fastIO;
    lli t = 1;
	// cin >> t;
	NA(i,0,t) solve();
	return 0;
}



Measured memory_bytes: 3744
n,kingaku = map(int,input().split())
all1000 = n*1000
if all1000>kingaku:
    print(-1,-1,-1)
    exit()
x = 0
y = 0
z = n
for i in range(n+1):
    z=n-i
    x=i
    for j in range(n+1):
        z=n-(i+j)
        y=j
        if z<0:
            break
        money = x*10000 + y*5000 + z*1000
        if money == kingaku:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3064
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
if A[0] > x :
  ans += A[0] - x
  A[0] = x

for i in range(1, N):
  sum2 = A[i - 1] + A[i]
  if sum2 > x:
    ans += sum2 - x
    A[i] = x - A[i - 1]
    #print(A)
print(ans)

Measured memory_bytes: 14148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
	public static void main(String[] arg) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int DATE_QUANTITY = Integer.parseInt(br.readLine());
		for (int i = 0; i < DATE_QUANTITY; i++) {
			String[] splitedLine = br.readLine().split(" ");
			int[] val = new int[3];
			for (int j = 0; j < 3; j++) {
				int tmp = Integer.parseInt(splitedLine[j]);
				val[j] = (int) Math.pow(tmp, 2);
			}
			Arrays.sort(val);
			if ((val[0] + val[1]) == val[2]) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 20204
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LL n, k, pp[5005], cc[5005], ans = -1e16;
LL col[5005];
vector<LL> cyc, pf;

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

	cin >> n >> k;
	for(int i = 1; i<=n; i++)
		cin >> pp[i];

	for(int i = 1; i<=n; i++)
		cin >> cc[i];

	for(int i = 1; i<=n; i++){
		LL tmp = pp[i], ts = cc[i]; 
		pf.clear(); pf.pb(cc[i]);
		while(tmp != i){
			pf.pb(cc[tmp]);
			ts += cc[tmp];
			tmp = pp[tmp];
		}

		for(int i = 1; i<pf.size(); i++)
			pf[i] += pf[i-1];
		
		for(int i = 0; i<min(k, (LL)pf.size()); i++)
			ans = max(ans, pf[i]);

		if(pf.size() < k && ts > 0){
			LL pfsz = pf.size(); 
			for(int i = 0; i<pf.size(); i++){
				LL km = (k - (i + 1));
				ans = max(ans, (km / pfsz) * ts + pf[i]);
			}
		}
	}

	cout << ans << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3812
#include <iostream>

using namespace std;

int main() {
    int n, *H;
    cin >> n;
    H = new int[n];
    for (int i = 0; i < n; i++) 
        cin >> H[i];
    int ans = 1;
    int i = 0;
    for (i = 1; i < n; i++) {
        bool can = true;
        for (int j = 0; j < i; j++) {
            if (H[j] > H[i])
                can = false;
        }
        if (can)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int n;
    long long int temp=0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(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++){
        temp += (a[i] - b[i] < 0 ? a[i]-b[i] : (a[i]-b[i])*2);
        if((a[i]-b[i] <0) && (-1 * (a[i]-b[i])) %2 == 1){
            temp++;
        }
    }
    cout << (temp<=0?"Yes":"No") << endl;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, q;
  string s;
  cin >> n >> q >> s;
  
  vector<int> x(n);
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) == 'A' && s.at(i) == 'C') x.at(i)++;
  }
  
  for (int i = 1; i < n; i++) {
    x.at(i) += x.at(i - 1);
  }
  
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << x.at(r) - x.at(l) << '\n';
  }
}

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

int main() {
  int N;
  cin>>N;
  int a[4];
  a[0]=N/1000;
  a[1]=N/100-a[0]*10;
  a[2]=N/10-a[1]*10-a[0]*100;
  a[3]=N%1000;

int i,j;
int ret=0;
for (i=0;i<4;i++){
  for (j=0;j<4;j++){
    if(a[i]==a[j])ret++;
  }
}
  ret=(ret-4)/2;
  if(ret>=3){
    cout<<"Yes"<<endl;
  }else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0 && b==0) break;
        if(a>b){
            cout<<b<<" "<<a<<endl;
        }else{
            cout<<a<<" "<<b<<endl;
        }
    }
}


Measured memory_bytes: 2992
#include <cstdio>
#include <algorithm>
using namespace std;
int h,n,k,ans;
int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;++i){
        scanf("%d",&h);
        if(h>=k) ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        s: chars,
    }
    let char_to_usize = |c: char| c as usize - 48;
    let mut count = 0;
    let mut fst_checked = vec![false; 10];
    for i in 0..n-2 {
        let p = char_to_usize(*&s[i]);
        if fst_checked[p] {continue;}
        fst_checked[p] = true;
        let mut snd_checked = vec![false; 10];
        for k in i+1..n-1 {
            let snd = char_to_usize(*&s[k]);
            if snd_checked[snd] {continue;}
            snd_checked[snd] = true;
            let mut trd_checked = vec![false; 10];
            for m in k+1..n {
                let trd = char_to_usize(*&s[m]);
                if trd_checked[trd] {continue;}
                trd_checked[trd] = true;
                count += 1;
            }
        }
    }
    println!("{}", count);
}


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

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

const int MX = 200005;
int in[MX], out[MX], t[MX], k;
vector<int> to[MX];
int dfs(int v, int p=-1) {
  in[v] = k++;
  t[v] = 1;
  for (int u : to[v]) {
    if (u == p) continue;
    t[v] += dfs(u,v);
  }
  out[v] = k;
  return t[v];
}

vector<int> vs[MX];

ll c2(ll n) { return n*(n+1)/2;}

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  rep(i,n) vs[c[i]-1].push_back(i);
  ll tot = c2(n);
  BIT<int> d(n);
  rep(i,n) d.add(i,1);
  rep(i,n) {
    ll ans = tot;
    vector<int>& nvs = vs[i];
    sort(nvs.begin(), nvs.end(), [&](int a, int b) {
      return in[a] > in[b];
    });
    vector<P> history;
    for (int v : nvs) {
      int cnt = 1;
      for (int u : to[v]) {
        if (in[u] < in[v]) continue;
        int num = d.sum(in[u], out[u]);
        ans -= c2(num);
        // printf("u, v, num: %d %d %d\n", u,v,num);
        cnt += num;
      }
      d.add(in[v], -cnt);
      history.emplace_back(in[v], cnt);
    }
    ans -= c2(d.sum(0,n));
    for (auto p : history) {
      d.add(p.first, p.second);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 38992
#include <cstdio>
#define N 200005

int n;
int f[N];

int main() {
    scanf("%d", &n);
    long long ans = 0;
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        if (i > x) ans += f[i - x];
        if (i + x <= n) ++f[i + x];
    }
    printf("%lld\n", ans);
    return 0;
}


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

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

void dfs(int v[][55], int x, int y){
    v[y][x] = 0;
    for(int i=0;i<8;++i)
        if(v[y+dy[i]][x+dx[i]] == 1)
            dfs(v, x+dx[i], y+dy[i]);
}

int main(){
    int w, h;
    while(cin >> w >> h, w != 0){
        int v[55][55]={0};
        for(int i=0;i<h;++i)
            for(int j=0;j<w;++j)
                cin >> v[i][j];
        int ans = 0;
        for(int i=0;i<h;++i)
            for(int j=0;j<w;++j)
                if(v[i][j] == 1){
                    ans++;
                    dfs(v, j, i);
                }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    while(1){
        int N; cin >> N;
        if(N == 0) break;
        vector<vector<int> > info(N, vector<int>(0));
    
        for(int i = 0; i < N; i++){
            int M; cin >> M;
            for(int j = 0; j < M; j++){
                int p; cin >> p;
                info[i].push_back(p);
            }
        }
    
        int K; cin >> K;
        vector<int> leak(K);
        for(int i = 0; i < K; i++){
            cin >> leak[i];
        }
   
        vector<int> ans;
        for(int i = 0; i < N; i++){
            int cnt = 0;
            for(int j = 0; j < K; j++){
                auto isFind = find(info[i].begin(), info[i].end(), leak[j]);
                if(isFind != info[i].end()){
                    cnt++;
                }
            }
            if(cnt == K){
                ans.push_back(i+1);
            }
        }
        
        if(ans.size() == 1) cout << ans[0] << endl;
        else cout << -1 << endl;
    }
    
    return 0;
}

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

vector<vector<double> >dp;
double  p[3000];
int n;

double prob(int i,int t_left)
{
    if(t_left < 0)
        return 0.0;
    if(i > n)
        return 1.0;
    if(dp[i][t_left] != -1)
        return dp[i][t_left];

    return dp[i][t_left] = p[i]*prob(i+1,t_left) + (1.0-p[i])*prob(i+1,t_left-1);
}
int main()
{
    cin>>n;
    dp.resize(n+1);
    for(int i=0;i<=n;i++)
        dp[i].resize(n/2+1,-1);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    cout<<setprecision(12)<<fixed<<prob(1,n/2)<<endl;
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n/2;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    return 0;
}


Measured memory_bytes: 35712
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = (int)1e5 + 10, MOD = (int)1e9 + 7;
vector <vector <int>> adj;
int n, m;
int dp[N], exc[N];
bool vis[N];

int mul (int a, int b) {
   return int((1ll *(a%MOD) * (b%MOD))%MOD);
}
int add (int a, int b) {
   return ((a%MOD) + (b%MOD))%MOD;
}

void dfs(int u, int pr) {
   vis[u] = true;
   for (int v : adj[u])
      if (v != pr && !vis[v]) dfs(v, u);

   int dp_mul = 1, exc_mul = 1;
   for (int v : adj[u]) {
      if (v == pr) continue;
      dp_mul = mul(dp_mul, dp[v]);
      exc_mul = mul(exc_mul, exc[v]);
   }
   dp[u] = add(dp_mul, exc_mul);
   exc[u] = dp_mul;
   return;
}

void solve() {
   for (int i = 0; i < n; ++i) vis[i] = 0;
   dfs(0, -1);

   cout << dp[0] << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n;
   m = n - 1;
   adj.assign(n, vector <int> ());
   for (int e = 0; e < m; ++e) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
   }
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 13568
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, a, b;
    cin >> n >> a >> b;
    if(n * a > b){
        cout << b << endl;
    }else{
        cout << n * a << endl;
    }
}


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

int main() {
    int n;
    int k;
    int a[n];
    cin>>n>>k;
    for (int i =0;i<n;i++){
       cin >> a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(k<a[i]){
            break;
        }
        if(k>=a[i]){
            k-=a[i];
            ans++;
        }
        if(i==n-1&k!=0){
            ans--;
        }
    }
    cout<<ans;
}


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

//put debug temp

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int x[Sz], y[Sz];


int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
  	cin >> x[i];
  for (int j = 1; j <= m; j++)
  	cin >> y[j];

  ll A = 0;
  for (int i = 1; i < n; i++)
  	A += (x[i + 1] - x[i]) * 1ll * (n - i) % Mod * i % Mod;
  A %= Mod;
  ll B = 0;
  for (int i = 1; i <= m; i++)
  	B += (y[i + 1] - y[i]) * 1ll * (m - i) % Mod * i % Mod;
  B %= Mod;
  cout << A*B%Mod;

  return 0;
}





// Coded by Z..

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Possible(i) cout<<(i?"Possible":"Impossible")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
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;
}
//
int main(){
	ll N;
	ll A[200000];
	cin>>N;
	FOR(i,0,N){
		cin>>A[i];
		A[i]-=i+1;
	}
	sort(A,A+N);
	//
	ll ans=0;
	if(N%2==1){
		ll n=N/2;
		n=A[n];
		FOR(i,0,N){
			A[i]-=n;
			ans+=abs(A[i]);
		}
	}else{
		ll n=N/2-1,m=N/2;
		ll nm=(A[n]+A[m])/2;
		FOR(i,0,N){
			A[i]-=nm;
			ans+=abs(A[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
 
int main() {
 
  int long long N,M,t=0,i,j,a;
  int long long ans=0;
  
  cin >> N >> M;

  if (N==M)
  {
    cout << "Yes" <<endl;
  }else
  {
    cout << "No" <<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.split(" ").map(&:to_i).sort!

q = gets.to_i
t = gets.chomp.split(" ").map(&:to_i).sort!

count = 0
until s.empty? or t.empty?
  a = s[0]
  b = t[0]
  if a < b
    s.delete_at(0)
  elsif a > b
    t.delete_at(0)
  else
    s.delete_at(0)
    t.delete_at(0)
    count += 1
  end
end
p count

Measured memory_bytes: 6420
#include <iostream>

using namespace std;

int main(){
    int N;
    cin>>N;
    for(int i=0;i<=25;i++){
        for(int j=0;j<=15;j++){
            if(i*4+j*7==N){
                cout <<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout <<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
 
const int MAX_N = int(1e6) + 10;
long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
 
inline ll mul(ll a,ll b){
 
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}
 
  
 
 
#define all(x) (x).begin(),(x).end()
 
 
 
 
//s.reserve(32768); //updated !
//s.max_load_factor(0.25);

const int N=1e5+5;







int main(){

    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    


    



}
 
    
 
 
 
    
 
 
 
    
    
    
 
 
 
 
    
 
 
    
 
    
 
 
 
 
 
 
    
    
 
    
 
    
 
 
 
 
    
 


Measured memory_bytes: 3592
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(define-modify-macro minf (new-value) min)
(defconstant +inf+ #x7fffffff)

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (limit (read))
         (dp (make-array 100001 :element-type 'uint31 :initial-element +inf+)))
    (declare (uint31 n limit))
    (setf (aref dp 0) 0)
    (dotimes (i n)
      (let ((w (read))
            (v (read)))
        (declare (uint31 w v))
        (loop for y from 100000 downto v
              do (minf (aref dp y)
                       (+ (aref dp (- y v)) w)))))
    (println
     (position-if (lambda (w) (<= (the uint31 w) limit))
                  dp :from-end t))))

#-swank (main)


Measured memory_bytes: 21988
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const N = 222222;
char s[N]; int a[N];
int main() {
  int n, p; scanf("%d %d %s", &n, &p, s);
  rep(i, n) a[i] = s[i] - '0';
  if (p == 2 || p == 5) {
    ll ans = 0;
    rep(i, n) if (a[i] % p == 0) ans += i + 1;
    printf("%lld\n", ans);
    return 0;
  }
  map<int, int> mp;
  ll ans = 0;
  int s = 0, z = 1;
  mp[0] = 1;
  for (int i = n - 1; i >= 0; --i) {
    s = (s + a[i] * z) % p;
    ans += mp[s];
    mp[s]++;
    z = z * 10 % p;
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 1664
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int K = sc.nextInt(); //連続するK個が黒
int X = sc.nextInt(); //X番に位置する石は黒
int f = X-K+1; //最初の黒石
int l = X+K-1; //最後の黒石
int p = 0; //印字する
for(int i=f; i<=l; i++){
  p = i;
  System.out.printf(p+" ");
}
}
}

Measured memory_bytes: 25172
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using T=tuple<double,int,int>;

signed _main(){
  v<int> dp(10000+10,INF);
  int H,N; cin >> H >> N;
  v<int> A(N),B(N);
  rep(i,N){
    cin >> A[i] >> B[i];
  }
  dp[0]=0;
  for(int i=1;i<=H;i++){
    rep(j,N){
      if(i-A[j]<0) chmin(dp[i],B[j]);
      else chmin(dp[i],dp[i-A[j]]+B[j]);
    }
  }
  cout << dp[H] << endl;
  return 0;
}


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

const int N = 1004, MOD = 1e9+7;
int n, m;
int d[N][N], dp[N][N];
char x;


int main(){
	memset(dp, 0, sizeof dp);

	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> x;
			if(x == '.') d[i][j] = 1;
			else d[i][j] = 0;
		}
	}
	for(int i = n-1; i >= 0; i--){
		for(int j = m-1; j >= 0; j--){
			if(i == n-1 && j == m-1) dp[i][j] = 1;
			else if(!d[i][j]) continue;
			else dp[i][j] = (dp[i][j+1]%MOD + dp[i+1][j]%MOD) % MOD;
		}
	}
	cout << dp[0][0] << endl;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    int pre = 10 * (s[0] - '0') + (s[1] - '0');
    int pos = 10 * (s[2] - '0') + (s[3] - '0');

    if (pre == 0 || pre > 12) {
        // pre は year
        if (pos > 0 && pos < 13) {
            cout << "YYMM\n";
        } else {
            cout << "NA\n";
        }
    } else {
        if (pos > 0 && pos < 13) {
            cout << "AMBIGUOUS\n";
        } else {
            cout << "MMYY\n";
        }
    }

    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        String[] array = line.split(" ");
        int N = Integer.parseInt(array[0]);
        int K = Integer.parseInt(array[1]);

        line = input.nextLine();
        //array = line.split(" ");
        int ans = 0;
        N -= 1;
        K -= 1;
        if(N % K == 0){
        	ans = N / K;
        }else if(N % K != 0){
        	ans = N / K + 1;
        }
        System.out.println(ans);
	}

}


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


int main(){
    ll x, n = 100, count = 0;
    cin >> x;
    while(n < x){
        n *= 1.01;
        count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 100005;

int n, m;
int a[N];
LL b[N];

int main() {
    int l, r, flag;
    vi ans;
    while (cin >> n >> m) {
        FOR (i, 1, n) cin >> a[i];
        b[0] = 0;
        FOR (i, 1, n) b[i] = b[i - 1] + a[i];
        l = 1, r = n, flag = 1;
        ans.clear();
        while (l != r) {
            if (b[r] - b[l - 1] >= m) {
                if (a[l] + a[l + 1] < m) ans.pb(l++);
                else ans.pb(--r);
            } else {
                flag = 0;
                break;
            }
        }
        if (flag) {
            puts("Possible");
            repit (it, ans) cout << *it << '\n';
        } else {
            puts("Impossible");
        }
    }
    return 0;
}


Measured memory_bytes: 2552