akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[100] = {0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; i++) {
        int Max = 0;
        int id = 0;
        for (int j = 0; j < n; j++) {
            if (Max < a[j]) {
                Max = a[j];
                id = j;
            }
        }
        a[id] = 0;
        if (i % 2 == 0) {
            cnt1 += Max;
        } else {
            cnt2 += Max;
        }
    }
    //cout << cnt1 << " " << cnt2 << endl;
    cout << abs(cnt2 - cnt1) << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int a,b,k,i;
    string ans="NG";
    cin >> k >> a >> b;

    for(i=a; i<=b; i++)
    {
        if(i%k == 0){
            ans = "OK";
            break;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class T,typename I=typename T::iterator>auto&operator<<(ostream&os,T t){bool b=1;for(auto s:t)os<<(abi::__cxa_demangle(typeid(decltype(*declval<I>())).name(),0,0,0)[2]=='d'||exchange(b,0)?"":" ")<<s;return os<<endl;}

int main(){
	int n;
	cin>>n;
	vi v={1};
	for(int i=9;i<=100000;i*=9){
		v.push_back(i);
	}
	for(int i=6;i<=100000;i*=6){
		v.push_back(i);
	}
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	reverse(all(v));
    vi dp(100001,INF);
    dp[0]=0;
    queue<int> q({0});
    while(!q.empty()){
        int c=q.front(); q.pop();
        for(auto p:v){
            if(c+p<=100000 and dp[c+p]==INF){
                dp[c+p]=dp[c]+1;
                q.push(c+p);
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int v, n;
    char comma;
    int vsum = 0, nsum = 0;
    int cnt = 0;
    while(cin >> v >> comma >> n) {
        vsum += v*n;
        nsum += n;
        cnt++;
    }
    cout << vsum << endl;
    cout << round((double)nsum/cnt) << endl;
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stack>

using namespace std;
long long n;
string s;

int main() {
//    printf("%c", 'a' + 0);
    cin >> n;
    stack<char> s;
    while (n > 0) {
        n--;
        int mod = n % 26;
        s.push('a' + mod);
        n /= 26;
    }

    while (!s.empty()) {
        char c = s.top();
        cout << c;
        s.pop();
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const ll inf = 1000000000000000L;

struct TKeepMaximalElements {
  int k;
  multiset<ll> s;
  ll sum = 0;
  TKeepMaximalElements(int k):
    k(k)
  {
  }

  void Add(ll x) {
    if (s.size() < k) {
      sum += x;
      s.insert(x);
      return;
    }
    if (x <= *s.begin()) return;
    sum += x;
    sum -= *s.begin();
    s.erase(s.begin());
    s.insert(x);
  }

  ll GetSum() {
    if (s.size() < k) return -inf;
    return sum;
  }
};

int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  int n = (x + y + z);
  vector<ll> a(n), b(n), c(n);
  vector<pair<ll, ll>> p;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    sum += a[i];
    p.push_back(make_pair(-a[i] + b[i], -a[i] + c[i]));
  }

  sort(p.begin(), p.end(), [](pair<ll, ll> a, pair<ll, ll> b) { return a.first - a.second > b.first - b.second; });

  vector<ll> L(n);
  {
    TKeepMaximalElements st(y);
    for (int i = 0; i < n; ++i) {
      st.Add(p[i].first);
      L[i] = st.GetSum();
    }
  }

  vector<ll> R(n);
  {
    TKeepMaximalElements st(z);
    for (int i = n - 1; i >= 0; --i) {
      st.Add(p[i].second);
      R[i] = st.GetSum();
    }
  }

  ll result = 0;
  for (int i = 0; i < n - 1; ++i) {
    result = max(result, sum + L[i] + R[i + 1]);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 9328
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}

signed main()
{
	io;
	string a;cin>>a;
	for(int i=0;i<a.size();i++)cout<<"x";

	getchar(); //
	getchar();
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
r = m
ans = 0
for i in range(n + 1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i + r)
print(ans)


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

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

    vector<int> A(N);
    long long int ans = 0;
    long long int max, h;
    int i;
    for( i = 0; i < N; i++ ){
        if( i == 0 ){
            cin >> max;
        }
        else{
            cin >> h;
            if( h < max ) ans += max - h;
            else max = h;
        }
    }
                
    cout << ans << endl;

}



Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define MOD ll(1e9L+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll tt;cin>>tt;while(tt--) 
#define t2() ll tt2; cin>>tt2; for(ll tti=1;tti<=tt2;tti++)
#define printcj "Case #"<<tti<<": "
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define debugarray(arr,n,x) { cout << "[" ; for(ll i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"] , "<<#x<<" = "<<x<<'\n';}


int main()
{
    fastio;
    ll n;
    cin>>n;
    vector<ll>dp(1<<n);
    vector<vector<ll>>a(n,vector<ll>(n));
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>a[i][j];

    // dp[i] = number of ways to select bitmask-i women

    dp[0] = 1;//base case, there is one way to select none women

    for(ll mask=0;mask<(1LL<<n)-1;mask++){
        ll men = __builtin_popcountll(mask);
        for(ll women=0;women<n;women++){
            if(a[men][women] && !(mask & (1LL<<women)) )
            {
                ll newmask = mask | (1LL<<women);
                dp[newmask] = (dp[newmask] + dp[mask])%MOD;
            }
        }
    }
    cout<<dp[(1LL<<n)-1];


    
}


Measured memory_bytes: 19504
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll N, x, y;
ll memo[(ll)1e5][3];
ll activities[(ll)1e5][3];

ll hp(int i, int ac){
	if (i >= N) return 0;
	if (memo[i][ac]) return memo[i][ac];
	ll maxv = 0;
	for (int au = 0; au < 3; au++)
		if (ac != au)
			maxv = max(maxv, hp(i + 1, au));
	return memo[i][ac] = activities[i][ac] + maxv;
}

int main(){
	cin >> N;
	for (x = 0; x < N; x++)
		for (y = 0; y < 3; y++)
			cin >> activities[x][y];
	y = 0;
	for (x = 0; x < 3; x++)
		y = max(y, hp(0 , x));
	cout << y;
}


Measured memory_bytes: 12984
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N, A, B, C, X;
	while( 1 ){
		cin >> N >> A >> B >> C >> X;
		if( !N && !A && !B && !C && !X ) break;
		vector<int> Y(N);
		for( int i = 0; i < N; i++ ){
			cin >> Y[i];
		}
		int frame = 0;
		int i = 0;
		while( 1 ){
			if( Y[i] == X ){
				i++;
				if( i == N ) break;
			}
			X = ( A * X + B ) % C;
				//cout << X << ' ' << frame << endl;
			if( frame == 10000 ){
				frame = -1;
				goto end;
			}
			frame++;
			/*if( i == N ) break;
			if( Y[i] == X ){
				X = ( A * X + B ) % C;
				frame++;
			}*/
		}
		Y.clear();
	end:
		cout << frame << endl;
	}
}

Measured memory_bytes: 1192
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <map>
#include <unordered_map>  
#include <climits>

using namespace std;

long long dp[51][51][2501];


class Main {
public:
	const int INDEX_MAX = 51;
	const int NUM_MAX = 51;
	const int NOWSUM_MAX = 2501;
	Main() {
		for (int i = 0;i < INDEX_MAX;i++) {
			for (int j = 0;j < NUM_MAX;j++) {
				for (int k = 0;k < NOWSUM_MAX; k++) {
					dp[i][j][k] = -1;
				}
			}
		}
	}

	long long numOfPatterns(vector<int> &arr, int ave, int index, int num, int nowSum) {
		if (dp[index][num][nowSum] == -1) {
			if (index >= arr.size()) {
				dp[index][num][nowSum] = (num != 0 && (((double)nowSum / num) == ave)) ? 1 : 0;
			}
			else {
				dp[index][num][nowSum] = numOfPatterns(arr, ave, index + 1, num + 1, nowSum + arr[index])
					+ numOfPatterns(arr, ave, index + 1, num, nowSum);
			}
		}

		return dp[index][num][nowSum];
	}
};

int main()
{
	Main m;
	int n,a;
	vector<int> arr;

	cin >> n >> a;
	for (int i = 0;i < n;i++) {
		int temp;
		cin >> temp;
		arr.push_back(temp);
	}

	cout << m.numOfPatterns(arr, a, 0, 0, 0) << endl;

    return 0;
}



Measured memory_bytes: 51072
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  ll n;cin >> n;
  cout << pow(n,3)<<endl;

  return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    vector<string> ss;
    ss.push_back("a");
    for (int i = 1; i < n; ++i) {
        vector<string> ts;
        for (auto& s : ss) {
            char max_c = 0;
            for (char c : s) {
                max_c = max(c, max_c);
            }
            for (char c = 'a'; c <= max_c + 1; ++c) {
                ts.push_back(s + c);
            }
        }
        ss = ts;
    }
    sort(begin(ss), end(ss));
    for (auto s : ss) {
        cout << s << '\n';
    }
    return 0;
}

Measured memory_bytes: 10908
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define lint long long
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
const int N=200010;int a[N];
inline int gabs(int x) { return x<0?-x:x; }
int main()
{
	int n=inn();lint ans=0;
	for(int i=1;i<=n;i++) a[i]=inn()-i;
	sort(a+1,a+n+1);int b=a[(n+1)/2];
	for(int i=1;i<=n;i++) ans+=gabs(b-a[i]);
	return !printf("%lld\n",ans);
}

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

int main() {
    string s;
    cin >> s;
    int a_count = 0;
    long ans = 0;
    bool ab_flag = false;
    for (char c: s) {
        switch (c) {
        case 'A':
            if (ab_flag) {
                a_count = 0;
                ab_flag = false;
            }
            a_count++;
            break;
        case 'B':
            if (a_count && !ab_flag) {
                ab_flag = true;
            } else {
                a_count = 0;
                ab_flag = false;
            }
            break;
        case 'C':
            if (ab_flag) {
                ans += a_count;
                ab_flag = false;
            } else {
                a_count = 0;
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<vector<char>> S(60, vector<char>(60));
vector<vector<bool>> check(60, vector<bool>(60, 0));
ll H,W;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin>>H>>W;
    ll bcou=0;
    for(ll i=0;i<H;++i)
        for(ll j=0;j<W;++j){
            cin>>S[i][j];
            if(S[i][j]=='#')bcou++;
        }
    vector<ll> dx={1,0,-1,0};
    vector<ll> dy={0,1,0,-1};
    queue<P> que;
    que.emplace(P(0,0));
    vector<vector<ll>> d(60, vector<ll>(60, INF));
    d[0][0]=0;
    while(!que.empty()){
        P z=que.front();
        que.pop();
        ll x=z.first;
        ll y=z.second;
        for(ll i=0;i<4;++i){
            ll nx=x+dx[i],ny=y+dy[i];
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&d[nx][ny]==INF&&S[nx][ny]=='.'){
                d[nx][ny]=d[x][y]+1;
                que.emplace(P(nx,ny));
            }
        }
    }
    if(d[H-1][W-1]==INF){
        prt(-1)return 0;
    }
    prt(H*W-bcou-d[H-1][W-1]-1)
    

    return 0;
}


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

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

    int k,x;
    cin >> k >> x;
    
    for(int i=x-k+1; i<=x+k-1; i++){
        cout << i << ' ';
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,max=-1;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin >> a.at(i);
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++){
            if(i==j)
                continue;
            if(abs(a.at(i)-a.at(j))>max)
                max = abs(a.at(i)-a.at(j));
        }
    cout << max << endl;
}


Measured memory_bytes: 256
s = gets
t = gets

s_past = []
t_past = []

s_res = ""
t_res = ""

s.each_char do |char| #20000
  s_index = s_past.index(char) #26
  # p s_index
  # p s_past
  if s_index.nil?
    s_past.push(char)
    s_res.concat((s_past.count - 1).to_s)
  else
    s_res.concat(s_index.to_s)
  end
end

t.each_char do |char|
  t_index = t_past.index(char)
  # p t_index
  # p t_past
  if t_index.nil?
    t_past.push(char)
    t_res.concat((t_past.count - 1).to_s)
  else
    t_res.concat(t_index.to_s)
  end
end

if t_res == s_res
  puts "Yes"
else
  puts "No"
end

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

ll pre[100005];
ll even[100005];
ll A[100005];
ll N, Q;
ll ask;

int main() {
//  freopen("inp", "r", stdin);
  cin >> N >> Q;
  A[0] = -1000000000000000LL;
  for(ll i = 1; i <= N; i++){
    cin >> A[i];
  }
  for(ll i = 1; i <= N; i++){
    pre[i] = pre[i-1] + A[i];
    if(i&1)even[i] = even[i-1];
    else even[i] = even[i-1] + A[i];
  }
  while(Q--){
    cin >> ask;
    if(ask >= A[N-1]){
      if(N&1)cout << pre[N] - even[N] << "\n";
      else cout << even[N] << "\n";
      continue; 
    }
    ll pos = lower_bound(A+1, A+N+1, ask) - A;
    ll l = pos-1, r = N;
    while(r-l>1){
      ll mid = (l+r)>>1;
      ll Taka = N-mid+1;
      ll Aoki = mid - (lower_bound(A, A+N+1, (ask<<1)-A[mid]) - A);
      if(Taka - Aoki <= 1)r = mid;
      else l = mid;
    } 
    ll ans = pre[N] - pre[r-1];
    pos = N-((N-r+1)<<1);
    ans += (pos&1 ? pre[pos] - even[pos] : even[pos]);
    cout << ans << "\n";
  }
}

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

int par[10010];

int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);  //経路圧縮
    }
}

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

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    par[x] = y;
}

int main(){
    int N,Q;
    cin >> N >> Q;
    
    //init
    for(int i = 0;i < N;i++) par[i] = i;
    //par[i] = i ならば根
    for(int i = 0;i < Q;i++){
        int com,x,y;
        cin >> com >> x >> y;
        if(com){
            cout << same(x,y) << endl;
        }else{
            unite(x,y);
        }
    }
    
    
}


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

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    
    int a, b;
    cin >> a >> b;
    cout << a*(a-1)/2 + b*(b-1)/2 << "\n";

    return 0;
}

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

int main()
{
    int tc =0;
    int mc =0;
    
    for(int i=0; i < 4; i++){
        char a;
        cin >> a;
        if(a == '+'){
            tc +=1;
        }else{
            mc -=1;
        }
    }
    int count;
    count = tc + mc;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <iostream>
#define MAXC 222222
#define MODD 1000000007
#define ll long long
using namespace std;


int A[111111];
int fwd_gcd[111111];
int bck_gcd[111111];

ll gcd(ll a, ll b) {
    while(b!=0) {
        ll t = b;
        b=a%b;
        a=t;
    }
    return a;
}


int GetGcd(int x,int y) {
    if (x == 0)
        return y;
    if (y == 0)
        return x;
    return gcd(x,y);
}

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        cin>>A[i];
    }
    
    fwd_gcd[0]=0;
    fwd_gcd[1]=A[1];
    for(int i=2;i<=N;i++){
        fwd_gcd[i]=gcd(fwd_gcd[i-1],A[i]);
    }
    
    
    bck_gcd[0]=0;
    bck_gcd[N]=A[N];
    for(int i=N-1;i>=1;i--) {
        bck_gcd[i]=gcd(bck_gcd[i+1],A[i]);
    }
    
    
    int ans = fwd_gcd[N];

    for(int i=1;i<=N;i++) {
        ans = max(ans, GetGcd(fwd_gcd[i-1],bck_gcd[i+1]));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);

	  int a = scan.nextInt();
	  int b = scan.nextInt();
	  int h = scan.nextInt();
	  int ans = ( a + b ) * h / 2;
	  System.out.println(ans);
  }
}

Measured memory_bytes: 21076
#include<stdio.h>

int main()
{
	int i,flag,A, B;
	char S[12];

	scanf("%d%d", &A, &B);
	scanf("%s", S);

	flag = 1;

	for (i = 0; S[i] != '\0'; i++)
	{
		if (i == A)
		{
			if (S[i] != '-')
				flag = 0;
		}
		else
		{
			if (S[i] == '-')
				flag = 0;
		}
	}

	if (flag == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

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

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

    double sum;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    double m = round(sum / (double)n);
    
    double ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (a[i] - m) * (a[i] - m);
    }
    
    cout << (int)ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);
  int h[n];
  for (int i = 0; i < n; i++){
    scanf("%d", &h[i]);
  }
  
  int count = 0;
  for (int i = 0; i < n; i++){
    if (h[i] >= k) count++;
  }
  
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 512
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()));
        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)*}
    };
}

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

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,
        a: [usize; n],
        b: [usize; n]
    }
    let sa: usize = a.iter().clone().sum();
    let sb: usize = b.iter().clone().sum();
    if sa < sb {
        println!("-1");
        return;
    }
    let mut ans = 0;
    let mut m = 0;
    let mut d: Vec<usize> = Vec::new();
    for i in 0..n {
        if a[i] < b[i] {
            ans += 1;
            m += b[i] - a[i];
        } else {
            d.push(a[i] - b[i]);
        }
    }
    if ans == 0 {
        println!("0");
        return;
    }
    d.sort_by(|x, y| y.cmp(x));
    let mut st = 0;
    for i in 0..d.len() {
        ans += 1;
        st += d[i];
        if st >= m {
            break;
        }
    }
    println!("{}", ans);
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;
const ll N= 1e5+55,mod = 1e9+7;
int main() {
// 	freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	ll n,i,j,x,y,q,h,s,d,ans;
	sc(q);sc(h);sc(s);sc(d);sc(n);
	ans=0;
	double a,b;
	vector< pair<double,double> >v;
	v.pb(mp(d/2.0,2));
	v.pb(mp(s,1));
	v.pb(mp(2*h,0.5));
	v.pb(mp(4*q,0.25));
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++){
		x=v[i].ff;b=v[i].ss;
		//cout<<n<<" "<<b<<"\n";
		if(n<b)continue;
		if(b==2){
			ans+=(n/2)*d;
			n=n%2;
			//cout<<"1\n";
		}
		else if(b==1){
			ans+=(n/1)*s;
			n=n%1;
			//cout<<"2\n";
		}
		else if(b==0.5){
			y=n/0.5;
			ans+=y*h;
			n-=y*0.5;
			//cout<<"3\n";
		}
		else{
			y=n/0.25;
			ans+=y*q;
			n-=y*0.25;
			//cout<<"4\n";

		}
	}
	pr(ans);
}

Measured memory_bytes: 256
S=input()

if S=="SAT":
    print(1)
elif S=="FRI":
    print(2)
elif S=="THU":
    print(3)
elif S=="WED":
    print(4)
elif S=="TUE":
    print(5)
elif S=="MON":
    print(6)
elif S=="SUN":
    print(7)


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

const ll inf = 1e18;

int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll m = 0;
    for(int i=1;i<n;i++)m = max(m, min(a[i], a[0]-a[i]));

    bool exist = false;
    for(int i=0;i<n;i++){
        if(a[i] == m)exist = true;
    }
    if(!exist) m = a[0] - m;

    cout << a[0] << " " << m << endl;
}

Measured memory_bytes: 4056
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int ans = 0;
	int cnt = 0;
	int pre = 0;
	while (n--)
	{
		int x;
		cin >> x;
		if (x <= pre) cnt++;
		else cnt = 0;
		pre = x;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back
signed main()
{
  int n,p;
  cin>>n>>p;
  int a[n+1];
  for(int i=1;i<=n;i++)
    cin>>a[i];
  vector<int>v;
  set<int>s;
  int k=1,r=-1,idx;
  while(1)
  {
      if(s.find(k)==s.end())
      {
           v.pb(k);
      }
      else
      {
          r=k;
          break;
      }

    s.insert(k);
     k=a[k];

  }
   for(int i=0;i<v.size();i++)
   {
       if(v[i]==r)
       {
           idx=i;
           break;
       }
   }
   if(p<idx)
    cout<<v[p]<<endl;
   else
   {
       r=v.size()-idx;
       p-=idx;
       cout<<v[idx+p%r]<<endl;
   }
}


Measured memory_bytes: 15460
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

r = int(input())
print(2*r*math.pi)

Measured memory_bytes: 9488
import sys
from string import ascii_lowercase

alphs = list(ascii_lowercase)

n = int(sys.stdin.readline().rstrip())

def main():
    cur = ['a']
    for _ in range(n-1):
        nex = []
        for s in cur:
            i = 0
            for c in s:
                i = max(i, ord(c) - 97)
            for al in alphs[:i+2]:
                nex.append(s + al)
        cur = nex
    return sorted(cur)

if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')


Measured memory_bytes: 15092
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = 0x3f3f3f3f;

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

    vector <int> w(n), v(n);

    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    vector <vector <long long>> dp(n + 1, vector <long long> (W + 1, -INF));

    for (int i = 0; i <= W; i++) {
        dp[0][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= W; j++) {
            if (j - w[i - 1] >= 0)
                dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

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

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

int main(){
  ll a,b,n;
  cin >>n >>a >>b;
  if((b-a)%2==0) cout << (b-a)/2 << endl;
  else {
    ll m = min(a-1, n-b);
    cout << m+1+(b-a-1)/2 << endl;
  }
  return 0; 
}

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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    m1 += k;
    h1 += m1 / 60;
    m1 %= 60;
    int diff = h2 - h1;
    diff *= 60;
    diff += m2 - m1;
    cout << max(0, diff) << endl;
}

Measured memory_bytes: 3676
N = int(input())
A = list(map(int, input().split()))
ct = 0
flag = 0
while flag == 0:
    for i in range(N):
        if A[i] % 2 != 0:
            flag = 1
            break
        else:
            A[i] /= 2
    if flag == 1:
        break
    ct += 1
print(ct)

Measured memory_bytes: 3060
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();
    let (n, m) = (line[0], line[1]);

    if n*2 >= m{
        println!("{}", m/2);
    }else{
        println!("{}", (m+2*n)/4);
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef long long int int64;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
void run(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a%2==0 || b%2==0 || c%2==0){
    printf("0\n");
  } else {
    int x=MIN(a,MIN(b,c));
    int y=MIN(a,b)+MIN(b,c)+MIN(c,a)-2*x;
    printf("%lld\n",(int64)x*y);
  }
}
int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    N = read_int()
    S = inp()
    print(solve(N, S))


def solve(N, S):
    i = 0
    count = 0
    while i < N - 1:
        if S[i] != S[i + 1]:
            count += 1
            i += 2
        else:
            i += 1
    return count


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

using namespace std;

int
main(void){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	a *= 100;
	b *= 100;
	float cmp = -1;
	int ans1 = 0, ans2 = 0;
	for(int i = 0; i <= f; i += a){
		for(int j = 0; i + j <= f; j += b){
			if(i + j == 0) continue;
			int w = i + j;
			int maxs = (w * e)/100;
			for(int k = 0; k <= maxs; k += c){
				for(int l = 0; k + l <= maxs; l += d){
					int s = k + l;
					if(s + w > f) continue;
					float cur = (10000 * s)/(s + w);
					if(cur > cmp){
						ans1 = s + w;
						ans2 = s;
						cmp = cur;
					}	
				}
			}
		}
	}
	cout << ans1 << " " << ans2;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        while(!(n==0)){
        String str=br.readLine();
        int[] in=new int[n];double sum=0;
        Scanner sc=new Scanner(str);
        for(int i=0;i<n;i++){
        	
        	in[i]=sc.nextInt();
        	sum+=in[i];
        	  }
        double m=sum/n;
        
        
        double t=0;
        for(int i:in){
       	t+=Math.pow(i-m,2);
        	
        }
        double ar=Math.sqrt(t/n);
        System.out.printf("%.8f%n",ar);
        n=Integer.parseInt(br.readLine());
}
}}

Measured memory_bytes: 23980
//abc 158:A

     #include <bits/stdc++.h>
     #include <cstdio>
     #include <cstring>
     #include <cmath>
     #include <cstring>
     #include <chrono>
     #include <complex>
     #define endl "\n"
     #define ll long long int
     #define vi vector<int>
     #define vll vector<ll>
     #define vvi vector < vi >
     #define pii pair<int,int>
     #define pll pair<long long, long long>
     #define mod 1000000007
     #define inf 1000000000000000001;
     #define all(c) c.begin(),c.end()
     #define mp(x,y) make_pair(x,y)
     #define mem(a,val) memset(a,val,sizeof(a))
     #define eb emplace_back
     #define f first
     #define s second

     using namespace std;
     int main()
     {
         std::ios::sync_with_stdio(false);
        int a,b;
        cin>>a>>b;

        int ans=0;
        ans+=a*(a-1)/2;
        ans+=b*(b-1)/2;
        cout<<ans<<endl;

         return 0;
     }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> sieve(int n) {
  vector<int> primes;
  vector<bool> is_prime(n + 1, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (!is_prime[i]) continue;
    primes.push_back(i);
    for (int j = i + i; j <= n; j += i) {
      is_prime[j] = 0;
    }
  }
  return primes;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> primes = sieve(50000);
  set<int> st;
  vector<int> aa = a;
  for (int i = 0; i < n; i++) {
    for (int p : primes) {
      if (aa[i] % p == 0) {
        st.insert(p);
        while (aa[i] % p == 0) aa[i] /= p;
      }
    }
    if (aa[i] > 1) st.insert(aa[i]);
  }
  long long ans = 0;
  for (int x : st) {
    long long cur = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % x == 0) cur += a[i];
    }
    ans = max(ans, cur);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3276
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != null){
                if (input.Length % 2 == 1) {
                    Console.WriteLine("NA");
                }
                else {
                    char[] output = new char[input.Length / 2];
                    bool success = true;
                    for(int i=0; i < input.Length; i += 2){
                        int[] inputData = new [] { input[i] - '0' - 1, input[i + 1] - '0' - 1 };
                        if(inputData[0] < 6 && inputData[1] < 5 && ((inputData[0] | inputData[1]) & (1 << 31)) == 0) {
                            char addChar = (char)('a' + (inputData[0] * 5 + inputData[1]));
                            switch (addChar) {
                                case '{': addChar = '.'; break;
                                case '|': addChar = '?'; break;
                                case '}': addChar = '!'; break;
                                case '~': addChar = ' '; break;
                            }
                            output[i / 2] = addChar;
                        }
                        else {
                            success = false;
                            break;
                        }
                    }
                    Console.WriteLine(success ? new string(output) : "NA");
                }
            }
        }
    }
}

Measured memory_bytes: 5324
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n; cin >> n;
  vector<int> h(n);
  vector<int> dp(n + 1);

  rep(i, n) cin >> h[i];

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  
  for(int i = 2; i < n; i++)
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));

  pr(dp[n - 1]);

  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
char s[110];
ll dp[110][5][2];// = / <
int main() {
	scanf("%s",s+1);
	int k=read(),n=strlen(s+1);
	dp[0][0][0]=1;
	rep(i,0,n) rep(j,0,k) rep(c,0,1) {
		ll& ans=dp[i][j][c];
		if(!ans) continue;
	//	printf("%d %d %d : %lld\n",i,j,c,ans);
		rep(x,0,9) {
			if(!x) dp[i+1][j][c|(x+'0'<s[i+1])]+=ans;
			else if(x+'0'<=s[i+1]||c) {
				dp[i+1][j+1][c|(x+'0'<s[i+1])]+=ans;
			}
		}
	}
	printf("%lld\n",dp[n][k][0]+dp[n][k][1]);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e16
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll dp[3001][3001];
ll solve(ll a[],ll i,ll j)
{
	if(i>j)
	return 0;
	if(dp[i][j]!=-1)
	return dp[i][j];
	return dp[i][j]=max(a[i]+min(solve(a,i+1,j-1),solve(a,i+2,j)),a[j]+min(solve(a,i+1,j-1),solve(a,i,j-2)));
}
int main()
{
  boost;
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n)
	cin>>a[i];
	memset(dp,-1,sizeof(dp));
	ll ans=solve(a,0,n-1);
	ll sum=0;
	rep(i,0,n)
	sum=sum+a[i];
	sum=sum-ans;
	cout<<ans-sum<<endl;
}

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

#define max 200000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main()
{
    int n, i, num_joshi[max], joshi[max];
    
    scanf("%d", &n);
    for (i=2; i<=n; i++) {
        scanf("%d", &num_joshi[i]);
        joshi[i]=0;
    }
    
    for (i=2; i<=n; i++) {
        joshi[num_joshi[i]]++;
    }
    
    for (i=1; i<=n; i++) {
        printf("%d\n", joshi[i]);
    }
    
    return 0;
}



Measured memory_bytes: 3244
#include<cstdio>
#include<utility>
#include<algorithm>
using ll = long long;
using ull = unsigned long long;

bool CompPair(std::pair<int, int> a, std::pair<int, int> b){
	if(a.first < b.first) return true;
	return a.first == b.first && a.second < b.second;
}

int main(){
	int N;
	scanf("%d", &N);
	std::pair<int, int> P[N + 1];
	int A[N + 1];
	for (int i = 1; i <= N; ++i){
		scanf("%d", A + i);
		P[i] = std::make_pair(i - A[i], i);
	}
	std::sort(P+1, P+N+1);
	ll ans = 0;
	for (int i = 1; i < N; ++i){
		int right = std::distance(P, std::upper_bound(P+1, P+N+1, std::make_pair(i + A[i], N), CompPair));
		int left = std::distance(P, std::lower_bound(P+1, P+N+1, std::make_pair(i + A[i], i + 1), CompPair));
		ans += right - left;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int k,x;
	vector<int>v;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++)
	{
		v.push_back(i);
	}
	cout<<v[0];
	for(int i=1;i<v.size();i++)
	{
		cout<<" "<<v[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    kt = tuple(range(1, k + 1))
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in range(n):
        for j in kt:
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 20644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	rep(i, a+1) {
		int sum = 0,d=i;
		rep(j, 5) {
			sum += d % 10;
			d /= 10;
		}
		if (b <= sum && c >= sum) {
			ans+=i;
		}
	}
	cout << ans;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n),sum(n+1,0);
	rep(i,n){
		cin>>a[i];
	}
	sort(begin(a),end(a));
	rep(i,n){
		sum[i+1]=sum[i]+a[i];
	}
	auto solve=[&](ll x){
		//幸福度がx以上になる方法はm通り以上か→これの最大値
		//億マス計算と同じ
		ll cnt=0;
		rep(i,n){
			cnt+=a.end()-lower_bound(begin(a),end(a),x-a[i]);
		}
		return cnt>=m;
	};
	ll ok=0,ng=inf,mid;
	while(ng-ok>1){
		mid=(ok+ng)/2;
		if(solve(mid)) ok=mid;
		else ng=mid;
	}
	ll ans=0,cnt=0;
	for(int i=n-1;i>=0;i--){
		ll tar=(ok+1)-a[i];
		ll ind=lower_bound(begin(a),end(a),tar)-begin(a);
		cnt+=n-ind;
		ans+=a[i]*(n-ind)+sum[n]-sum[ind];
	}
	ans+=(m-cnt)*ok;
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		var n = new int[(int)1e5];
		int N = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse);
		foreach (var item in a)
		{
			n[item]++;
		}
		int count = 0, num = 0;
		for (int i = 0; i < (int)1e5; i++)
		{
			int temp = n[i];
			if (i > 0)
			{
				temp += n[i - 1];
			}
			if (i < (int)1e5 - 1)
			{
				temp += n[i + 1];
			}
			if (temp > count)
			{
				count = temp;
				num = i;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 16992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n,coun=0,c=0;
cin>>n;
string s;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='R'){
coun++;
}
else if(s[i]=='B'){
c++;
}
}
if(coun>c){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 105
int matrix[N][N];
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A
//spanning tree tree
bool power[N]; // start from 1;
int main(){
	int n;
	scanf("%d",&n);
	memset(matrix, 0,sizeof(matrix));
	memset(power,0,sizeof(power));
	for(int i = 1; i<=n; i++){
		for(int j = 1; j<=n; j++){
			scanf("%d",&matrix[i][j]);//-1 means nothing
		}
	}
	int count = 0;
	int res = 0;
	int min = 2005;
	while(count<n-1){
		//find minmila ele from matrix
		int v1 = 0,v2 = 0;
		min = 2005;
		for(int i = 1; i<=n;i++){
			for(int j = 1;j<=n; j++){
				if(matrix[i][j]!=-1 && matrix[i][j]<min){
					if(count==0){
						if(power[i] == 0 && power[j]==0) {
							v1 = i;v2 = j;
							//printf("i:%d j:%d\n",i,j);
							min = matrix[i][j];
						}
						//continue;
					}else {
							if((power[i] == 1 && power[j]==0)||(power[i] == 0 && power[j]==1)){
							v1 = i;v2 = j;
							min = matrix[i][j];
						}
					}
					
				}
			}
		}
		//printf("min:%d\n",min);
		matrix[v1][v2] = -1;
		power[v1] = 1;
		power[v2] = 1;
		res+=min;
		count++;
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 2796
n = int(input())
button = [int(input()) for i in range(n)]
button.insert(0,0)

ans = -1
tap_button = button[1]
for i in range(1,n):
    if tap_button == 2:
        ans = i
        break
    k = tap_button
    tap_button = button[k]
    
print(ans)

Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  int num = N - 1;
  
  vector<int> B(num);
  
  for(int i = 0;i < num;++i){
    cin >> B[i];
  }
  
  vector<int> A(N);
  
  for(int i = 0;i < num;++i){
    if(i == 0){
      A[i] = B[i];
    }
    else{
      A[i] = min(B[i],B[i - 1]);
    }
  }
  
  A[num] = B[num - 1];
    
  int num3 = 0;
  
  for(int i = 0;i < N;++i){
    num3 = A[i] + num3;
  }
  
  cout << num3 << endl;
  
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int x = abs(a-b);
    int y = abs(b-c);
    int z = abs(c-a);
    cout << min( min(x+y, y+z), z+x);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()


ll n;
vll a;
 
void solve(){
 cin >> n;
 a.resize(n);
 rep(i,0,n) cin >> a[i];
 sort(all(a));
  
 vll s(n);
 rep(i,0,n) s[i]=((a[i]<0)?1:0); 
  
 s[0]=1,s.back()=0;
 ll res=0;
 rep(i,0,n) res+=(s[i]?-a[i]:a[i]);

 cout << res << endl;
  
 for(ll i=1;s[i]==1;i++) {
  cout << a.back() << " " << a[i] << endl;
  a.back()-=a[i]; 
 }
 for(ll i=n-2;s[i]==0;i--) {
  cout << a[0] << " " << a[i] << endl;
  a[0]-=a[i]; 
 } 
 cout << a.back() << " " << a[0] << endl; 
}

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

Measured memory_bytes: 3456