akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
const ll N = 2e5+5;
const ll MOD = 1e9+7;
ll n;
ll dp[N] = {};
ll ans[N] = {};
ll fac[N] = {};
ll siz[N] = {};
vector< vi > graph(N);
ll fast_exp(ll base, ll exp)
{
  ll res=1;
  while(exp>0)
    {
      if(exp%2==1) res=(res*base)%MOD;
      base=(base*base)%MOD;
      exp/=2;
    }
  return res%MOD;
}

ll getInverse(ll n)
{
  return fast_exp(n, MOD-2) ;
}

ll divide(ll a, ll b)
{
  a=a%MOD ;
  b=b%MOD ;
  return (a*(getInverse(b)%MOD))%MOD ;
}
void dfs(ll i, ll p)
{
    ll j, si = graph[i].size();
    siz[i] = 1;
    FOR0(j, si)
    {
        ll v = graph[i][j];
        if(v == p) continue;
        dfs(v, i);
        siz[i] += siz[v];
    }
}
void dfs2(ll i, ll p)
{
    ll j, si = graph[i].size();
    dp[i] = fac[siz[i]-1];
    FOR0(j, si)
    {
        ll v = graph[i][j];
        if(v == p) continue;
        dfs2(v, i);
        dp[i] *= dp[v];
        dp[i] %= MOD;
        dp[i] = divide(dp[i], fac[siz[v]]);
        dp[i] %= MOD;
    }
}

void dfs3(ll i, ll p, ll prev)
{
    ll j, si = graph[i].size();
    if(i != 0)
    {
        ans[i] = prev*siz[i];
        ans[i] %= MOD;
        ans[i] = divide(ans[i], n-siz[i]);
        ans[i] %= MOD;
    }
    FOR0(j, si)
    {
        ll v=  graph[i][j];
        if( v== p) continue;
        dfs3(v, i, ans[i]);
    }
}

int main()
{
    she_told_me_dont_worry
    cin>>n;
    ll i;
    FOR0(i, n-1)
    {
        ll u, v;
        cin>>u>>v;
        u--;
        v--;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    fac[0] = 1;
    FOR(i, 1, n+3)
    {
        fac[i] = (i%MOD*fac[i-1]%MOD)%MOD;
    }
    dfs(0, 0);
    dfs2(0, 0);
    ans[0] = dp[0];
    dfs3(0, 0, ans[0]);
    FOR0(i, n) cout<<ans[i]<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 20212
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        n=int(input())
        a=int(input())
        for i in range(21):
            for j in range(a+1):
                if 500*i+1*j==n:
                    return 'Yes'
        return 'No'
    print(main())
resolve()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h, w;
  cin >> h >> w;
  vector<string> t(h);
  for(int i = 0; i < h; ++i) cin >> t[i];
  int H = 0, W = 0;
  bool flag = true;
  int all = 0;
  int passed = 1;
  for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) if(t[i][j] == '#') all++;
  while(H != h - 1 || W != w - 1){
    if(W + 1 <= w - 1 && H + 1 <= h - 1){
      if(t[H + 1][W] == '#' && t[H][W + 1] == '#'){
        flag = false;
        break;
      }
    }
    if(W + 1 <= w - 1){
      if(t[H][W + 1] == '#'){
        ++W;
        passed++;
        continue;
      }
    }
    if(H + 1 <= h - 1){
      if(t[H + 1][W] == '#'){
        ++H;
        passed++;
        continue;
      }
    }
    flag = false;
    break;
  }
  if(flag && all == passed) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	int i,j,flg;
	scanf("%d",&n);
	flg=0;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(i*j==n){
				flg=1;
			}
		}
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;

int N, W, H;
int x, y;
int S, T;
char F[501][501];

int main() {
	while(cin >> N, N) {
		cin >> W >> H;
		memset(&F[0][0], 0, sizeof(char) * 501 * 501);

		rep(i,N) {
			cin >> x >> y;
			F[x][y] = 1;
		}
		cin >> S >> T;

		int mt = 0;
		repa(j,1,H-T+1) {
			repa(i,1,W-S+1) {
				int t = 0;
				rep(l,T) {
					rep(k,S) {
						if(F[i+k][j+l]) t++;
					}
				}

				if(mt < t) {
					mt = t;
				}
			}
		}

		cout << mt << endl;
	}
}

Measured memory_bytes: 1412
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,D,E,x,y,cou=0,v[3];
    char S[3],s[3],X,Y;
    scanf("%d %d",&A,&B);
    printf("%d",(A-1)*(B-1));
    return 0;
}

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

int main() {
  int n; cin >> n;
  map<int, int> mp;
  vector<int> a(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans=0;
  for (int i=0; i<n; i++) {
    bool ok=mp[a[i]]==1 && mp[1]==0;
    for (int j=2; j <= (int)sqrt(a[i]) && ok; j++) {
      if (a[i]%j) continue;
      if (mp.find(j) != mp.end() || mp.find(a[i]/j) != mp.end())
        ok=0;
    }
    if(ok || (a[i] == 1 && mp[1] == 1)) ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 13124
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
ans = 0
mons = 0
yusha = 0
for i in range(N):
    mons = max(A[i] - yusha, 0)
    ans += min(yusha, A[i])
    ans += min(mons, B[i])
    yusha = max(0, B[i] - mons)
ans += min(yusha, A[N])
print(ans)


Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<lint> ret(n, 0);
    lint ans = 0;
    for (int i = 1; i < n; ++i) {
        if (h[i - 1] >= h[i]) {
            ret[i] = ret[i - 1] + 1;
            ans    = max(ans, ret[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main(){
	char S[101],K[101];
	int i=0,k,ans;
	scanf("%s %s",S,K);
	int l=strlen(K);
	
	if(l>=3){k=100;}
	else if(l==2){k=(K[0]-48)*10+K[1]-48;}
	else{k=K[0]-48;}
	
	if(k==1){
		printf("%c",S[0]);
	}
	else{
		for(;;){
			if(S[i]=='1') i++;
			else{
				ans=S[i]-48;
				break;
			}
		}
		if(k<=i) printf("1");
		else printf("%d",ans);
	}
}

Measured memory_bytes: 128
import           Data.Char                      ( toLower )

main = map (read :: String -> Int) . words <$> getLine >>= \_x ->
  case _x of
      [_, k] -> getLine >>= \s ->
        return
          $ let _h = take (k - 1) s
                _b = toLower (s !! (k - 1))
                _t = drop k s
            in  _h ++ [_b] ++ _t
    >>= putStrLn


Measured memory_bytes: 3824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int ans = 0;
		for(int i = 1;i <= 5; i++) {
			int x = sc.nextInt();
			if(x == 0)ans = i;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32624
n=int(input())
p=input().split()  
p=list(map(int,p))          
cnt=0

for i in range(n-2):
  l=p[i:i+3]
  if l[0]>=l[1] and l[1]>=l[2]:
    cnt+=1
  if l[2]>=l[1] and l[1]>=l[0]:
    cnt+=1

print (cnt)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,x,cnt1,cnt2,s;
long long c(int n,int m)
{
	int s=1,i,j;
	for (i=1;i<=m;i++) 
	{
		s*=(i+(n-m));
		s/=i;
	}
	return s;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cin>>x;
		if (x%2) cnt1++;
			else cnt2++;
	}
	//cerr<<cnt1<<cnt2<<endl;
	for (i=0;i<=cnt1;i++)
	{
		if ((i%2)==(m%2)) s+=c(cnt1,i);
	}
	for (i=1;i<=cnt2;i++) s*=2;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,K,count = 0;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        if(x < K - x){
            count += 2 * x;
        }
        else{
            count += (K - x) * 2;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	int N; cin >> N;
	string name; cin >> name;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		string  st; cin >> st;
		bool ok = false;
		for (int l = 0; l < st.size(); ++l) {
			for (int num = 1; num < 100; ++num) {
				bool aok = true;
				if (l + (name.size() - 1)*num >= st.size())continue;
				for (int k = 0; k < name.size(); ++k) {
					const int now = l + k*num;
					if (st[now] == name[k]) {

					}
					else {
						aok = false;
					}
				}
				if (aok)ok = true;
			}
		}
		if (ok)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3116
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int ar[N];
int dp[N];
int ans = 0;

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        // 6 6 5
        if(ar[i - 1] >= ar[i] && i != 1){
            dp[i] = dp[i - 1] + 1;
            ans = max(ans , dp[i]);
        }
        //cout << dp[i] << " " ;
    }
    printf("%d\n" , ans);
}


Measured memory_bytes: 1024
N=int(input())
bricks=list(map(int,input().split()))

manzoku=1
hakai = 0
for i in range(N):
    if bricks[i] == manzoku:
        manzoku += 1
    else:
        hakai += 1

if hakai == N:
    print(-1)
else: 
    print(hakai)
        



Measured memory_bytes: 77516
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a, b, c, d;

ll dp[1010][1010];


ll mod_pow(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

ll mod_inverse(ll x) {
    return mod_pow(x, mod-2);
}

const int max_n = 2010;
ll fact[max_n];
ll fact_inv[max_n];
void calc_fact() {
    fact[0] = 1;
    for (ll i = 1; i < max_n; i++)
        fact[i] = (fact[i-1] * i) % mod;
    fact_inv[max_n-1] = mod_inverse(fact[max_n-1]);
    for (ll i = max_n-2; i >= 0; i--)
        fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod;
}
ll mod_comb(ll n, ll k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return (fact[n] * fact_inv[k] % mod) * fact_inv[n-k] % mod;
}

ll calc_comb(int m, int s, int k) {
    ll res = 1;
    for (int i = 0; i < s; i++) {
        res = res * mod_comb(m, k) % mod;
        m -= k;
    }
    res = res * fact_inv[s] % mod;
    return res;
}

ll calc(int m, int k) {
    if (m == 0) return 1;
    if (m < 0 || k > b) return 0;
    if (dp[m][k] < 0) {
        ll res = calc(m, k+1);
        for (int i = c; i <= d && m >= i*k; i++) {
            res = (res + calc_comb(m, i, k) * calc(m-i*k, k+1)) % mod;
        }
        dp[m][k] = res;
    }
    return dp[m][k];
}

ll solve() {
    memset(dp, -1, sizeof(dp));
    calc_fact();
    return calc(n, a);
}

void input() {
    cin >> n >> a >> b >> c >> d;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int k,n; cin >> k >> n;int diff = 0;
    int a[n];cin >> a[0];
    for(int i = 1;i < n;i++){
        cin >> a[i];
        diff = max(diff,abs(a[i]-a[i-1]));
    }
    diff = max(diff,abs(k-a[n-1])+a[0]);
    cout << k - diff;
}




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

using namespace std;
using ll = long long;


int main()
{
    ll n; cin >> n;
    map<ll,ll> mp;
    for(ll i = 0; i < n; i++) {
        ll t; cin >> t;
        mp[t]++;
    }
    ll q; cin >> q;
    ll sum = 0;
    for(auto i : mp)sum += i.first * i.second;

    for(ll i = 0; i < q; i++) {
        ll b, c; cin >> b >> c; //b -> c;
        sum += (c - b) * mp[b];
        mp[c] += mp[b];
        mp.erase(b);
        cout << sum << endl;
    }

}

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

using namespace std;

int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    if((a[0]==a[1]&&a[1]!=a[2])||(a[0]!=a[1]&&a[1]==a[2])) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e6+10;
int n,st,q,d[MAXN];
ll pos[MAXN],mn[MAXN];

int main()
{
    scanf("%d%d",&n,&st);
    pos[0]=st;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&d[i]);
        pos[i]=min(pos[i-1],abs(d[i]-pos[i-1]));
    }
    mn[n+1]=1;
    for(int i=n;i>=1;i--)
        if(d[i]>=2*mn[i+1]) mn[i]=mn[i+1];
        else mn[i]=mn[i+1]+d[i];
    
    scanf("%d",&q);
    while(q--)
    {
        int x;scanf("%d",&x);
        puts((pos[x-1]>=mn[x+1])?"YES":"NO");
    }
    return 0;
}

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

int main(){
	
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W>=x+r&&H>=y+r&&x>=r&&y>=r){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}	
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int t;
double dp[301][301][301];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin >> t;
  short a[3] = {0};
  for(int i=0;i<t;i++) {
    int x; cin >> x;
    a[x-1]++;
  }
  for(int threes = 0;threes <=t;threes++) {
    for(int twos = 0;twos <= t-threes; twos++) {
      for(int ones=0;ones<=t-threes-twos;ones++) {
        double sum = ones + twos + threes;
        if (sum <=0.5 ) continue;
        double p_waste = t / sum;
        auto &p = dp[ones][twos][threes];
        if (ones > 0) {
          p += (ones)*(p_waste + dp[ones-1][twos][threes]);
        }
        if (twos > 0) {
          p += (twos) * (p_waste + dp[ones+1][twos-1][threes]);
        }
        if (threes > 0) {
          p += (threes)*(p_waste + dp[ones][twos+1][threes-1]);
        }
        p /= sum;
      }
    }
  }
  cout << setprecision(10) << dp[a[0]][a[1]][a[2]];
  return 0;
}

Measured memory_bytes: 213248
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int a, b, C;
		double S, L, h;
		Scanner sc = new Scanner(System.in);
		a = Integer.parseInt(sc.next()); b = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next()); sc.close();
		S = a * b * Math.sin(Math.toRadians(C)) / 2;
		L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(C)));
		h = b * Math.sin(Math.toRadians(C));
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);
	}
}

Measured memory_bytes: 17304
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int N, T;
    while (cin >> N >> T) {
        vi t(N);

        multiset<pii> ms;
        rep(i, N) {
            cin >> t[i];
            ms.insert(mp(t[i], 0));
            ms.insert(mp(t[i]+T, 1));
        }
        int l = -1, cnt = 0, ans = 0;
        each(p, ms) {
            if (p.second == 0) { // in
                if (l == -1)l = p.first;
                cnt++;
            }
            else {
                cnt--;
                if (cnt == 0) {
                    ans += p.first - l;
                    l = -1;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 19840
#include <iostream>
using namespace std;
int main(){
	int a;
	int b;
	int c;
	int s;
	cin >> a >> b >> c;
	if (a > b){
		s = a;
		a = b;
		b = s;
	}
	if (b > c){
		s = b;
		b = c;
		c = s;
	}
	if (a > b){
		s = a;
		a = b;
		b = s;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL n;
  cin>>n;
  vector<LL> v(2*n);
  REP(i,2*n){
    cin >> v[i];
  }

  SORT(v);

  LL ans = 0;

  REP(i,n){
    ans += v[i * 2];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int r, g;
    cin >> r >> g;
    cout << r + (g-r)*2 << endl;
}


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

int main(){
    int n,m;
    int a,b;

    cin >> n >> m;

    vector<int> load(n,0);

    for(int i=0; i<m; i++){
        cin >> a >> b;
        load.at(a-1)++;
        load.at(b-1)++;
    }

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

}

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

int main(){
    double w,h,x,y;
    bool b = 0;
    cin >> w >> h >> x >> y;
    if(x==w/2 && y==h/2) b = 1;
    cout << std::setprecision(10) << w*h/2.0 << " ";
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	ll n; cin >> n;
	if(n == 2)
	{
		cout << 1 <<endl;
		return;
	}
	else
	{
		ll ans = 2;
		for (ll i = 2; i * i <= n-1; i++)
		{
			if((n-1)%i == 0)
			{
				ans += 2;
				if((n-1)/i == i)ans--;
			}
		}
		for (ll i = 2; i * i <= n; i++)
		{
			if(n % i == 0)
			{
				ll k = n;
				while (k % i == 0)
				{
					k /= i;
				}
				if(k == 1)ans++;
				else if(k >= i && (k-1) % i == 0)ans++;
			}
		}
		cout << ans << endl;
		return;
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int mod = 1_000_000_007;

        long ans = 1L;
        long zero_cnt = 3;
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i=0;i<N;i++) {
            int A = Integer.parseInt(sc.next());
            if (A==0) {
                if (zero_cnt<0) {
                    System.out.println(0);
                    return;
                }
                if (map.containsKey(A)) {
                    ans = ans*zero_cnt%mod;
                    zero_cnt--;
                    map.put(A, map.get(A)+1);
                } else {
                    ans = ans*zero_cnt%mod;
                    zero_cnt--;
                    map.put(A, 1);
                }
            } else {
                if (map.containsKey(A)) {
                    if (!map.containsKey(A-1)) {
                        System.out.println(0);
                        return;
                    }
                    ans = ans*(map.get(A-1)-map.get(A))%mod;
                    map.put(A, map.get(A)+1);
                } else {
                    if (!map.containsKey(A-1)) {
                        System.out.println(0);
                        return;
                    }
                    ans = ans*map.get(A-1)%mod;
                    map.put(A, 1);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50924
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

A.sort()

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0
    

MINUS=0

for i in range(N):
    if N-i-1<K-1:
        break
    MINUS+=A[i]*Combi(N-i-1,K-1)

PLUS=0
A.reverse()

for i in range(N):
    if N-i-1<K-1:
        break
    PLUS+=A[i]*Combi(N-i-1,K-1)

print((PLUS-MINUS)%mod)


Measured memory_bytes: 70824
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int N, i;
  cin >> N >> i;
  cout << N - i+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
template<typename T>inline T chkmax(T A,T B){return A>B?A:B;}
template<typename T>inline T chkmin(T A,T B){return A<B?A:B;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,cnt1,cnt4,cnt2;
int main()
{
	//file();
	int x;
	read(n);
	For(i,1,n)
	{
		read(x);
		if(x%4==0)cnt4++;
		else
		if(x%2==0)cnt2++;
		else cnt1++;
	}
	if(!cnt2)
	{
		if(cnt1<=cnt4+1)
			puts("Yes");
		else
			puts("No");
	}
	else
	{
		if(cnt1<=cnt4)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n;
    string s;
    cin>>n;
    ll x,y,maxInX=INT_MIN,YforX;
   for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x>=maxInX){
            maxInX=x;
            YforX=y;
        }
    }
    cout<<maxInX+YforX<<endl;






    return 0;
}





Measured memory_bytes: 3616
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	int sum = abs(x[0]);
	for (int i = 1; i < N; i++) {
		sum += abs(x[i] - x[i - 1]);
	}
	sum += abs(x[N - 1] - 0);
	if ((0 < x[0] && x[0] < x[1]) || (0 > x[0] && x[0] > x[1]))
		cout << sum << endl;
	else
		cout << sum - abs(0 - x[0]) - abs(x[0] - x[1]) + abs(0 - x[1]) << endl;
	for (int i = 1; i < N - 1; i++) {
		if ((x[i - 1] < x[i] && x[i] < x[i + 1]) || (x[i - 1] > x[i] && x[i] > x[i + 1]))
			cout << sum << endl;
		else 
			cout << sum - abs(x[i - 1] - x[i]) - abs(x[i] - x[i + 1]) + abs(x[i - 1] - x[i + 1]) << endl;
		
	}
	if ((x[N - 2] < x[N - 1] && x[N - 1] < 0) || (x[N - 2] > x[N - 1] && x[N - 1] > 0))
		cout << sum << endl;
	else
		cout << sum - abs(x[N-2] - x[N-1]) - abs(x[N-1] - 0) + abs(x[N-2] - 0) << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[105];
  int Alice = 0;
  int Bob = 0;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A, A+N, greater<int>());

  for (int i = 0; i < N; i++) {
    if (i%2 == 0) {
      Alice += A[i];
    } else {
      Bob += A[i];
    }
  } 
  cout << Alice - Bob << endl;

}

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

using namespace std;

string s;
int N;

int main() {
  cin >> N;
  while ( N-- ) {
    cin >> s;
    vector<int> data[10000];
    int now = 0;
    for ( int i = 0; i < s.size(); i++ ) {
      if ( s[i] == '[' ) now++;
      else if ( s[i] == ']' ) {
	if ( data[now].size() ) {
	  sort(data[now].begin(), data[now].end());
	  int tmp = 0;
	  for ( int j = 0; j < (data[now].size() + 1) / 2; j++ ) {
	    tmp += data[now][j];
	  }
	  data[now].clear();
	  data[now - 1].push_back(tmp);
	}
	now--;
      }
      else {
	int tmp = 0;
	for(; s[i] != ']'; i++) {
	  tmp *= 10;
	  tmp += s[i] - '0';
	}
	i--;
	data[now].push_back((tmp + 1) / 2);
      }
    }

    cout << data[0][0] << endl;
  }
}

Measured memory_bytes: 3428
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; ++i) {
    cout << s[i] << t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
 
    // N matchsticks
    int N = scanner.nextInt();
    // M: Every digit in the integer must be one of the digits A1~AM
    int M = scanner.nextInt();
    int[] a = new int[M];
    for (int i = 0; i < M; i++)
    {
      a[i] = scanner.nextInt();
    }
      
    int[] cost = new int[] {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int[] dp = new int[N + 1];
    
    // dp[1]~dp[N] = -1
    for (int i = 1; i <= N; i++) 
    {
      dp[i] = -1;
    }
    
    // Trace from the a[i] with smallest cost
    for (int i = 1; i <= N; i++)
    {  
      for (int j = 0; j < M; j++)
      {  
        if (i >= cost[a[j]]) 
          dp[i] = Math.max(dp[i], dp[i - cost[a[j]]] + 1);
      }
    }
    int k = dp[N];
    List<Integer> list = new ArrayList<>();


    for (int i = 0; i < k; i++) 
    {
      int d = 0;
      for (int j = 0; j < M; j++)
      {
        if (N >= cost[a[j]] && dp[N] - dp[N - cost[a[j]]] == 1)
        {
          d = Math.max(d, a[j]);
        }
      }
      list.add(d);
      N -= cost[d];
    }
    Collections.sort(list);
    StringBuilder sb = new StringBuilder();
    for (int i = list.size() - 1; i >= 0; i--) 
    {
      sb.append(list.get(i));
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 24148
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

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

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

func factMod(n, p int) int {
	ans := 1
	for i := 1; i <= n; i++ {
		ans = ans * i % p
	}
	return ans
}

func main() {
	defer stdout.Flush()

	n := readInt()
	m := readInt()
	p := 1000000007

	d := absInt(n - m)
	if d > 1 {
		println(0)
	} else if d == 1 {
		println((factMod(n, p) * factMod(m, p)) % p)
	} else {
		x := factMod(n, p)
		println(x * x * 2 % p)
	}
}


Measured memory_bytes: 640
($N,$A,$B,$C)=glob<>;
$t=<>,push(@l,$t) foreach(1..$N);
print &dfs(0,0,0,0);

sub dfs{
    my($co,$a,$b,$c)=@_;
    return &min($a,$b,$c)?abs($a-$A)+abs($b-$B)+abs($c-$C)-30:1e9 if($co==$N);
    my $r0 = &dfs($co+1,$a,$b,$c);
    my $r1 = &dfs($co+1,$a+$l[$co],$b,$c)+10;
    my $r2 = &dfs($co+1,$a,$b+$l[$co],$c)+10;
    my $r3 = &dfs($co+1,$a,$b,$c+$l[$co])+10;
    return &min($r0,$r1,$r2,$r3);
}

sub min{
    my @k = @_;
    my $m=$k[0];
    $m = $m<$_?$m:$_ for(@k);
    return $m;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    
    int x;
    x = b-a;
    
    int tou[999] = {};
    for(int i=1;i<x;i++){
        tou[i]=tou[i-1]+i;
    }
    reverse(tou,tou+x);
    ans = tou[0]-a;
    
    cout << ans << endl;
return 0;
}



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

int main()
{
	string s; cin >> s;
	int q; cin >> q;
	
	deque<char> deq(s.size()); for (int i = 0; i < s.size(); i++) deq[i] = s.at(i);

	int reverseFlag = 0;

	for (int i = 0; i < q; i++) {

		int tmp_t; cin >> tmp_t;
		
		if (tmp_t == 1) {
			reverseFlag = 1 - reverseFlag;
		}
		else { // a[i] == 2

			int tmp_i; cin >> tmp_i;
			char tmp_c; cin >> tmp_c;

			if (tmp_i == 1 + reverseFlag) {
				deq.push_front(tmp_c);
			}
			else {
				deq.push_back(tmp_c);
			}
		}

	}

	if (reverseFlag == 1) reverse(deq.begin(), deq.end());

	string ans;	for (int i = 0; i < deq.size(); i++) ans += deq.at(i);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1412
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,k = map(int, input().split())
a = list(map(int, input().split()))
ma = []
pa = []
zc = 0
for num in a:
    if num<0:
        ma.append(num)
    elif num>0:
        pa.append(num)
    else:
        zc += 1
mn = len(ma)*len(pa)
ma.sort()
pa.sort()
ma =ma[::-1]

def _sub(m, l1):
    lp = len(l1)
    t = lp-1
    ans = 0
    for s in range(lp):
        if t<=s:
            break
        while l1[s]*l1[t]>m and t>s+1:
            t -= 1
        if l1[s]*l1[t]>m:
            break
        ans += (t-s)
    return ans

def sub1(m):
    # 0以上m以下の値の個数
    ans = 0
    ans += _sub(m, pa)
    ans += _sub(m, ma)
    return ans

def sub2(m):
    # 0以下、m以下の値の個数
    ans = 0
    lp = len(pa)
    lm = len(ma)
    t = 0
    for s in reversed(range(lp)):
        while pa[s]*ma[t]>m and t<lm-1:
            t += 1
        if pa[s]*ma[t]>m:
            break
        ans += lm - t
    return ans

znum = zc*(len(ma)+len(pa)) + (zc-1)*zc//2
if k>mn:
    k -= mn
    if znum>=k:
        ans = 0
    else:
        k -= znum
        l = 0
        r = 10**18+1
        while l<r-1:
            m = (l+r)//2
            v = sub1(m)
            if v>=k:
                r = m
            else:
                l = m
        ans = l+1
else:
    l = -10**18-1
    r = 0
    while l<r-1:
        m = (l+r)//2
        v = sub2(m)
        if v>=k:
            r = m
        else:
            l = m
    ans = l+1
print(ans)

Measured memory_bytes: 90596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
#define chmax(a, b) a = max(a, b)
using ll = long long;

string s,t;
int dp[3009][3009];

string solve(int i,int j){
  string rec;
  if(i==0&&j==0)return "";
  if(i>0&&dp[i][j]==dp[i-1][j]){
    rec=solve(i-1,j);
  }
  else if(j>0&&dp[i][j]==dp[i][j-1]){
    rec=solve(i,j-1);
  }
  else{
    rec=solve(i-1,j-1)+s[i-1];
  }
  return rec;
}

int main(){
  cin>>s>>t;
  rep(i,s.size()){
    rep(j,t.size()){
      if(s[i]==t[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        chmax(dp[i+1][j+1],dp[i+1][j]);
        chmax(dp[i+1][j+1],dp[i][j+1]);
      }
    }
  }
  cout<<solve(s.size(),t.size())<<endl;
  return(0);
}


Measured memory_bytes: 36224
def count(S):
    ans = 0
    i = 1
    while i < len(S):
        if S[i-1] == S[i]:
            i += 1
            ans += 1
        i += 1
    return ans

def first_last_count(S):
    first = 1
    c = S[0]
    for i in range(1, len(S)):
        if S[i] == c:
            first += 1
        else:
            break

    last = 1
    c = S[0]
    for i in range(len(S)-2, 0, -1):
        if S[i] == c:
            last += 1
        else:
            break

    return (first//2) + (last//2) - ((first+last)//2)

def is_same(S):
    c = S[0]
    for i in range(1, len(S)):
        if S[i] != c:
            return False
    return True

def main():
    S = input()
    K = int(input())

    if is_same(S):
        print((len(S) * K) // 2)
        exit()

    ans = count(S)
    ans *= K
    if S[-1] == S[0]:
        ans -= first_last_count(S) * (K-1)

    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	int aa = w + a, bb = w + b;
	if ((bb <= aa && bb >= a) || (b >= a && b <= aa))cout << 0 << endl;
	else if (aa < b)cout << b - aa << endl;
	else cout << a - bb << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define debug(x) std::cout << #x << ": " << x << '\n';
#define pb push_back
const int N = 1e6 + 10, LOG = 25;
ll sum[N], dp[N], dp2[N], p[N];
ll bin_p(ll a, ll b, ll c) {
	if (!b) return 1 % c;
	if (b % 2 == 0) {
		ll cur = bin_p(a, b / 2, c);
		return cur * cur % c;
	}
	else {
		return a * bin_p(a, b - 1, c) % c;
	}
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    std::cin >> n;
    FOR(i, n) {
    	ll x;
    	std::cin >> x;
    	sum[x]++;
    }
    p[1] = 1;
    for (int i = 1; i < N; ++i) {
    	for (int j = 2 * i; j < N; j += i) {
    		p[j] -= p[i];
    	}
    }
    ll answ = 0, mod = 998244353;
    for (int i = N - 1; i >= 1; --i) {
    	dp[i] = (sum[i] * (sum[i] - 1) / 2) % mod * i % mod * i % mod;
    	dp[i] %= mod;
    	dp2[i] = sum[i] * i % mod;
    	for (int j = 2 * i; j < N; j += i) {
    		dp[i] += dp2[i] * (sum[j] * j) % mod + (sum[j] * (sum[j] - 1) / 2) % mod * j % mod * j % mod;
    		dp2[i] += sum[j] * j % mod;
    		dp[i] %= mod;
    	}
    	for (int j = 2 * i; j < N; j += i) {
    		dp[i] -= dp[j];
    		dp[i] = (dp[i] + mod) % mod;
    	}
    	answ += dp[i] * bin_p(i, mod - 2, mod);
    	answ = (answ + mod) % mod;
    }
    answ %= mod;
    std::cout << answ;
}


Measured memory_bytes: 31488
<?php
list($n) = ints();
$s = strs();
for ($i = 0; $i < $n; $i++) {
    if ($s[$i] === 'Y') exit('Four');
}
echo 'Three';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int D=in(),L=in();
	out(D/L+D%L);
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define write(x) printf("%d\n", x)
using namespace std;
typedef long long ll;
template <typename T>
void read(T &x)
{
	x = 0;
	char c;
	while (!isdigit(c = getchar()));
	do
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
	}while (isdigit(c = getchar()));
}
int n;
ll D, A;
struct Monster
{
	ll x;
	ll h;
}M[200005];
bool operator <(Monster A, Monster B)
{
	return A.x < B.x;
}
struct SegmentTree
{
	int l, r;
	ll dat, add;
}t[800050];
ll X[200005];
ll H[200005];
void build(int p, int l, int r)
{
	t[p].l = l;t[p].r = r;
	if (l == r)
	{
		t[p].dat = H[l];
		return ;
	}
	int mid = (l + r) >> 1;
	build((p << 1), l, mid);
	build((p << 1) + 1, mid + 1, r);
	t[p].dat = t[(p << 1)].dat + t[(p << 1) + 1].dat;
}
void spread(int p)
{
	if (t[p].add)
	{
		t[(p << 1)].dat += t[p].add * (t[(p << 1)].r - t[(p << 1)].l + 1);
		t[(p << 1) + 1].dat += t[p].add * (t[(p << 1) + 1].r - t[(p << 1) + 1].l + 1);
		t[(p << 1)].add += t[p].add;
		t[(p << 1) + 1].add += t[p].add;
		t[p].add = 0;
	}
}
void change(int p, int v, int l, int r)
{
	if (l <= t[p].l && t[p].r <= r)
	{
		t[p].add += (ll)v;
		t[p].dat += (ll)v * (t[p].r - t[p].l + 1);
		return ;
	}
	spread(p);
	int mid = (t[p].l + t[p].r) >> 1;
	if (l <= mid) change(p << 1, v, l, r);
	if (r > mid) change((p << 1) + 1, v, l, r);
	t[p].dat = t[(p << 1)].dat + t[(p << 1) + 1].dat;
}
ll ask(int p, int l, int r)
{
	if (l <= t[p].l && t[p].r <= r)
		return t[p].dat;
	spread(p);
	int mid = (t[p].l + t[p].r) >> 1;
	ll val = 0;
	if (l <= mid) val += ask(p << 1, l, r);
	if (r > mid) val += ask((p << 1) + 1, l, r);
	return val;
}
ll cnt;
int main()
{
	read(n);read(D);read(A);
	for (int i = 0;i < n;++i)
		read(M[i].x), read(M[i].h), M[i].h = (M[i].h + A - 1) / A;
	sort(M, M + n);
	for (int i = 0;i < n;++i)
	{
		X[i] = M[i].x;
		H[i] = M[i].h;
	}
	build(1, 0, n - 1);
	for (int i = 0;i < n;++i)
	{
		ll temp = ask(1, i, i);
		if (temp > 0)
		{
			int j = upper_bound(X, X + n, X[i] + 2 * D) - X - 1;
			cnt += temp;
			change(1, -temp, i, j);
		}
	}
	cout << cnt << endl;
	return 0;
}
 

Measured memory_bytes: 21120
class Cursor
  attr_accessor :line, :index
  def initialize
    @line = 0
    @index = 0
  end
  def move(n)
    @index = n
  end
  def up
    @line -= 1
  end
  def down
    @line += 1
  end
end

text = Array.new
while true do
  text.push(gets.chomp)
  break if text.last == "END_OF_TEXT"
end
text.pop

cursor = Cursor.new
buffer = ""
while true do
  case gets.chomp
  when "-"
    break
  when "a"
    cursor.move(0)
  when "e"
    cursor.move(text[cursor.line].size)
  when "p"
    cursor.up if cursor.line > 0
    cursor.move(0)
  when "n"
    cursor.down if cursor.line < text.size - 1
    cursor.move(0)
  when "f"
    if cursor.index != text[cursor.line].size
      cursor.move(cursor.index + 1)
    elsif cursor.line < text.size - 1
      cursor.down
      cursor.move(0)
    end
  when "b"
    if cursor.index != 0
      cursor.move(cursor.index - 1)
    elsif cursor.line > 0
      cursor.up
      cursor.move(text[cursor.line].size)
    end
  when "d"
    if cursor.index != text[cursor.line].size
      text[cursor.line].slice!(cursor.index)
    elsif cursor.line < text.size - 1
      text[cursor.line] += text[cursor.line + 1]
      text.delete_at(cursor.line + 1)
    end
  when "k"
    if cursor.index != text[cursor.line].size
      buffer = text[cursor.line].slice!(cursor.index...text[cursor.line].size)
    elsif cursor.line < text.size - 1
      text[cursor.line] += text[cursor.line + 1]
      text.delete_at(cursor.line + 1)
      buffer = "\n"
    end
  when "y"
    case buffer
    when ""
    when "\n"
      text.insert(cursor.line + 1, text[cursor.line].slice!(cursor.index...text[cursor.line].size))
      cursor.down
      cursor.move(0)
    else
      text[cursor.line].insert(cursor.index, buffer)
      cursor.move(cursor.index + buffer.size)
    end
  end
end

puts text

Measured memory_bytes: 6168