akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//第一大和第二大的数值和出现次数 
typedef long long ll;
pair<pair<ll,ll>,pair<ll,ll>> s(ll cnt[100005])
{
	pair<ll,ll> a,b;
	a.first = -10000;
	b.first = -10000;
	for(ll i=0;i<100005;i++)
	{
		if(cnt[i]>=a.first)
		{
			b=a;
			a.first = cnt[i];
			a.second = i;
		}                                              
		else if(cnt[i]<a.first&&cnt[i]>b.first)
		{
			b.first = cnt[i];
			b.second = i;
		}
	}
	return make_pair(a,b);
}
ll cnto[100005],cnte[100005];
vector<ll> odd,even;
int main()
{
	ll n;
	cin>>n;
	vector<ll> vi;
	//统计个数，输入 
	for(ll i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		vi.push_back(a);
		if(i%2 == 0)
		{
			odd.push_back(a);
			cnto[a]++; 
		}
		else
			even.push_back(a) , cnte[a]++;
	}
	// 第一大和第二大的数值和出现次数。
	//是两个格的 
	pair<ll,ll> fo = s(cnto).first;
	pair<ll,ll> so = s(cnto).second;
	pair<ll,ll> fe = s(cnte).first;
	pair<ll,ll> se = s(cnte).second;
	ll x = fo.second;
	ll y = fe.second;
	//如果两个最大的数相等，就把第二大多的哪一个设为那一列的评判标准 
	if(fo.second == fe.second)
	{ 
		if(so.first>se.first)
			x = so.second;
		else
			y = se.second;
	}
	ll sum = 0;
	//如果是奇数列，而且不是X，就需要被替换。
	//如果是偶数列，而且不是Y，就需要被替换。 
	for(ll i=0;i<vi.size();i++)
	{
		if(vi[i]!=x&&i%2 == 0)
			sum++;
		else if(vi[i]!=y&&i%2)
			sum++;
	} 
	cout<<sum<<endl;
}

Measured memory_bytes: 3704
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto N = readln.chomp.to!int;
    auto dx = readln.split.to!(int[]);
    auto D = dx[0];
    auto X = dx[1];
    int[] AS;
    AS.length = N;
    foreach (i; 0..N) AS[i] = readln.chomp.to!int;
    foreach (d; 0..D) {
        foreach (a; AS) if (d%a == 0) ++X;
    }
    writeln(X);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin>>N;
    vi a(N);
    cin>>a;
    sort(ALL(a));
    map<int,int> cnt;
    REP(i,N) {
        cnt[a[i]]++;
    }
    int ans=0;
    FORE(p,cnt) {
        if(p.first>p.second) {
            ans+=p.second;
        } else {
            ans+=p.second-p.first;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	double n, k;
	cin >> n >> k;
	set<int> st;

	vector<int> v(200001);

	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		st.insert(tmp);
		v[tmp]++;
	}
	if (st.size() <= k) {
		cout << 0 << "\n";
		return 0;
	}
	sort(v.begin(), v.end());
	vector<int> vv;

	for (int i = 0; i <= 200000; i++) {
		if (v[i]>0) {
			vv.push_back(v[i]);
		}
	}
	int ans = 0;
	for (int i = 0; i < st.size()-k; i++) {
		ans += vv[i];
	}
	cout << ans << "\n";
}


Measured memory_bytes: 11516
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int m=s.length(),n=t.length();
  vector<vector<int>> dp(m+1,vector<int>(n+1));
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);//1st by excluding ans 2nd by including
    }
  }
  string str="";
  int row=m,col=n;
  while(row>0 && col>0){
    if(dp[row][col]!=max(dp[row-1][col],dp[row][col-1])){
      str+=string(1,t[col-1]);
      row--;
      col--;
    }
    else if(dp[row][col]==dp[row-1][col]) row--;
    else col--;
  }
  reverse(str.begin(),str.end());
  cout<<str;
  return 0;
}
      

Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define mod 1e9+7
using namespace std;
ll dp[3001][3001];
ll arr[3001];
ll DP(int st, int end)
{
    if(st>end) return 0;
    if(st==end) return arr[st];
    if(dp[st][end]) return dp[st][end];
    return dp[st][end]=max(arr[st]-DP(st+1, end),arr[end]-DP(st,end-1));
}
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        scanf("%lld", &arr[i]);
    ll ans=DP(0, n-1);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 70144
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

void solve() {
    int N, K; cin >> N >> K;
    vector<mint> num(K+1);

    mint ans = 0;

    for (int i = K; i >= 1; i--) {
        mint k = K / i;
        mint n = modpow(k, N);

        for (int j = 2*i; j <= K; j+=i) n -= num[j];
        num[i] = n;

        ans += (mint)i * n;
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

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

using namespace std;
using int64 = long long;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template<class T, class C> using pbds_tree =
    tree<T, null_type, C, rb_tree_tag, tree_order_statistics_node_update>;

constexpr int DEBUG = 0;

// Returns a vector of cumulative sums.
// Let c_sums be the return value.
// - c_sums[k] is the sum of xs over [0, k).
// - c_sums[r] - c_sums[l] is the xum of xs over [l, r).
template<class T> vector<T> CumulativeSumVector(const vector<T>& xs) {
  int n = xs.size(); vector<T> c_sums(n + 1);
  for (int i = 0; i < n; i++) c_sums[i + 1] = c_sums[i] + xs[i];
  return c_sums;
}

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

  int n;
  int64 k;
  cin >> n >> k;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    xs[i] -= k;
  }
  auto c_sums = CumulativeSumVector(xs);
  
  pbds_tree<pair<int64, int>, less<pair<int64, int>>> tree;
  for (int i = 1; i <= n; i++) {
    tree.insert(make_pair(c_sums[i], i));
  }

  int64 ans = 0;
  ans += tree.size() - tree.order_of_key(make_pair(0, -1));
  if (DEBUG) cout << "ans: " << ans << endl;
  for (int i = 1; i <= n; i++) {
    tree.erase(make_pair(c_sums[i], i));
    ans += tree.size() - tree.order_of_key(make_pair(c_sums[i], -1));
    if (DEBUG) cout << "ans: " << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 16000
import java.util.Scanner;

public class Main {
    static long n;
    static long a;
    static long b;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        a = sc.nextLong();
        b = sc.nextLong();
        if (a==0) {
            System.out.println(0);
        } else {
            System.out.println((n/(a+b)*a) + Math.min(n%(a+b),a));
        }
    }
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val count = (1..n).map {
        "MARCH".indexOf(readLine()!![0])
    }.groupBy { it }
    var ans = 0L
    for (i in 0 until 5) {
        for (j in i+1 until 5) {
            for (k in j+1 until 5) {
                val counti = (count[i]?.size ?: 0).toLong()
                val countj = (count[j]?.size ?: 0).toLong()
                val countk = (count[k]?.size ?: 0).toLong()
                ans += counti * countj * countk
            }
        }
    }
    println(ans)
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  int num = 0;
  rep(i,n){
    if(s[i] == 'I')num++;
    else num--;
    ans = max(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def solve()

end

n = gets.to_i
a = gets.split.map(&:to_i)

ans = 1
for i in 1...n do
    ok = true
    for j in 0...i do
        if a[j] > a[i]
            ok = false
            break
        end
    end

    if ok
        ans = ans + 1
    end
end

puts ans

Measured memory_bytes: 1788
import math

a,b,C=map(float,input().split())

print("%f"%(1/2*a*b*math.sin(math.radians(C))))
print("%f"%(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))))
print("%f"%((1/2*a*b*math.sin(math.radians(C)))/a*2))



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

int main() {

    int a,b,k ;
    cin >> a >> b >> k ;

    for(int i = 0; i < k; i++){
        if(a + i <= b)cout << a+i << endl;
    }

    for(int i = - k + 1; i <= 0; i++){
        if(b + i >= a + k && b + i >= a) cout << b+i << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
s1 += "1"
state = 0
res = 1
i = 0
while i < n:
    if s1[i] == s1[i + 1]:
        if state == 0:
            res = res * 6 % mod
        elif state == 1:
            res = res * 2 % mod
        else:
            res = res * 3 % mod
        state = 2
        i += 2
    else:
        if state == 0:
            res = res * 3 % mod
        elif state == 1:
            res = res * 2 % mod
        else:
            res = res * 1 % mod
        state = 1
        i += 1

print(res % mod)


Measured memory_bytes: 9060
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

D.sort()
T.sort()

ok = True
idx = 0
for t in T:
  hasSame = False
  while idx <= N-1 and D[idx] <= t:
    d = D[idx]
    idx += 1
    if d == t:
      hasSame = True
      break

  if not hasSame:
    ok = False
    break
      
if ok:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 35408
#include <iostream>
#include <set>

using namespace std;

int main()
{
	int i, n, ret;
	int N;
	string S;
	set<string> s;
	
	cin >> N;
	
	for (i = 0; i < N; i++) {
		cin >> S;
		s.insert(S);	
	}
	
	cout << s.size() << endl;

	return EXIT_SUCCESS;
}


Measured memory_bytes: 19204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s, t;
  in2(s, t);
  ll a = 0;
  rep(i, s.size() + t.size()){
  if(a == 0){
    out(s[i / 2]);
    a++;
  }
  else{
    out(t[i / 2]);
    a--;
  }
  }
  memi;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 7;
const LL LINF = INF * INF;

const int mod = 1e9 + 7;
 
inline void add(int& x, int& y)
{
	x += y;
	if (x >= mod)
		x -= mod;
}

const int MAX = 22;
int n;
int a[MAX][MAX];
int dp[MAX][1 << MAX];
VI bity[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n;
	FOR(i, 0, n)
		FOR(j, 0, n)
			cin >> a[i][j];
	
	FOR(i, 0, n)
		if (a[0][i])
			dp[0][1 << i] = 1;
	
	FOR(i, 0, 1 << n)
		bity[__builtin_popcount(i)].PB(i);
	
	FOR(i, 1, n)
	{
		for(auto j: bity[i])
		{
			FOR(k, 0, n)
			{
				if (!a[i][k] || (j & (1 << k)))
					continue;
				
				add(dp[i][j | (1 << k)], dp[i - 1][j]);
			}
		}
	}
	
	cout << dp[n - 1][(1 << n) - 1] << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 187836
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
//using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
//const in INF=1<<30;
using vec = vector<vector<int>>;
void in(int &a){int x;cin>>x;a=x;}

int main(){
  int n;
  in(n);
  vector<int> a(n);
  rep(i,n) in(a.at(i));
  sort(all(a));
  int x,y,z;
  if(n==2){
    cout<<abs(a[0]-a[1])<<endl;
    cout<<a[1]<<" "<<a[0];
    return 0;}
  
  if(a[0]>0) x=1;
  else if(a[n-1]<0) x=2;
  else x=3;
  int sum =0;
  
  
  if(x==1){
    rep(i,n-1) sum += a[i+1];
    sum -=a[0];
    cout<<sum<<endl;
    y=a[0];
    rep(i,n-2){
       cout<<y<<" "<<a[i+1]<<endl;
      y -=a[i+1];
    }
    cout<<a[n-1]<<" "<<y<<endl;
  }
  
  if(x==2){
    rep(i,n-1) sum -= a[i];
    sum += a[n-1];
    cout<<sum<<endl;
    y=a[n-1];
    rep(i,n-2){
       cout<<y<<" "<<a[i]<<endl;
      y -=a[i];
    }
    cout<<y<<" "<<a[n-1]<<endl;
  }
  
  if(x==3){
    rep(i,n) sum += abs(a[i]);
    cout<<sum<<endl;
    y=a[0];
    z=a[n-1];
    for(int i=1;i<n-1;i++){
      if(a[i]>=0){cout<<y<<" "<<a[i]<<endl;
                  y -=a[i];
                 }
      else{
         cout<<z<<" "<<a[i]<<endl;
        z -=a[i];
      }
    }
    cout<<z<<" "<<y<<endl;
  }
  
  
  
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+10;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll l = 0;
    ll r = INF;
    while (r-l>1) {
        ll x = (l+r)/2;
        ll num = 0;
        rep(i, n) {
            ll z = (a[i]-1)/x;
            num += z;
        }
        if (num<=k) r = x;
        else l = x;
    }
    ll ans = r;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4772
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) (int)(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define ld long double
#define inf LONG_MAX
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = 1e9 + 7;
using namespace std;

#ifndef ONLINE_JUDGE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}

//Check N size twiceeeeeeeeeeeeeeeeee, and verify it
const int N = 2*1e5 + 10;


int32_t main(){_
	
	int x,y;
	cin>>x>>y;

	cout<<x + y/2	;

	return 0;
}

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

int main(){
    string ss;
    cin>>ss;
    int n = ss.length();
    for(int i=0;i<n/2;i++){
        if(ss[i]!=ss[n-i-1]){
            cout<<"No";
            return 0;
        }
    }
    for(int i=0;i<(n-1)/2-1;i++){
        if(ss[i]!=ss[(n+3)/2-1+i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    sort(H.rbegin(),H.rend());
    ll ans = 0;
    for(int i=K;i<N;i++){
        ans+=H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define  N 100

int bubbleSort(int *B, int n) {
  int i, j, tmp, count = 0;
  
  for(i = 0; i < n; i++) {
    for (j = n-1; j > i; j--) {
      if(B[j] < B[j-1]) {
	tmp = B[j];
	B[j] = B[j-1];
	B[j-1] = tmp;
	count++;
      }
    }
  }
  return count;
}

int main() {
  int i, A[N], n, cnt;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  cnt = bubbleSort(A, n);
  
  for(i = 0; i < n; i++) {
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", cnt);
  
  return 0;
}

Measured memory_bytes: 604
n = int(input())
cx,cy = 0,0
list_xyh = []
for i in range(n):
    list_xyh.append(list(map(int, input().split())))
for cx in range(0,101):
    for cy in range(0,101):
        for i in range(n):
            if list_xyh[i][2] != 0:
                H = abs(cx - list_xyh[i][0]) + abs(cy - list_xyh[i][1]) + list_xyh[i][2]
                break
        for i in range(n):
            if max(H - abs(cx - list_xyh[i][0]) - abs(cy - list_xyh[i][1]),0) == list_xyh[i][2]:
                continue
            else:
                break
        else:
            print(cx,cy,H)
            break
    else:
        continue
    break


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

int n;
vector<int> v(30),c(30);

int dfs(int d,int sum){
  if(d==n){
    return sum;
  }
  int r1=dfs(d+1,sum+v[d]-c[d]);
  int r2=dfs(d+1,sum);
  return max(r1,r2);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
      cin>>v[i];
    }
    rep(i,n){
      cin>>c[i];
    }
    cout<<dfs(0,0)<<endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
    for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 N, M, Q;
    while (cin >> N >> M >> Q && N+M+Q) {
        vector<string> S(Q), B(Q+1);
        vector<vector<char>> res(M);

        B[0] = string(M, '0');
        REP(i, Q) cin >> S[i] >> B[i+1];
        REP(i, N) {
            vector<int> nxt(M);
            iota(all(nxt), 0);
            REP(j, Q) {
                vector<int> nxt2;
                for (auto &k : nxt) {
                    if ((B[j + 1][k] != B[j][k]) == (S[j][i] == '1'))
                        nxt2.push_back(k);
                }
                swap(nxt, nxt2);
            }
            for (auto &k : nxt) {
                if (i < 10)
                    res[k].push_back(i+'0');
                else
                    res[k].push_back(i-10+'A');
            }
        }
        REP(i, M) {
            if (res[i].size() != 1) cout << '?';
            else cout << res[i][0];
        }
        cout << endl;
    }
}



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

#define ll long long

int main()
{
//    freopen("a.in","r",stdin);
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=1000;i++)
        if((int)((double)i*.08)==a and (int)((double)i*.1)==b)
                return cout<<i,0;
    cout<<-1;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i=0;i<=n;i++)
		cin >> a[i];
	vector<long long> mx(n+1);
	long long tmp=0;
	for(int i=n;i>=0;i--)
	{
		tmp+=a[i];
		mx[i]=tmp;
	}
	tmp=1;
	long long ans=0;
	for(int i=0;i<=n;i++)
	{
		if(tmp>mx[i])tmp=mx[i];
		ans+=tmp;
		tmp-=a[i];
		if(tmp<0)
		{
			cout << -1 << endl;
			return 0;
		}
		tmp*=2;
	}
	cout << ans << endl;

}

Measured memory_bytes: 3824
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = a+b;
		if(c>=24){
			System.out.println(c-24);
		}
		else{System.out.println(c);}
	}
}

Measured memory_bytes: 22228
n, m = map(int, input().split())

for i in range(m):
    l, r = map(int, input().split())
    if i == 0:
        l_max = l
        r_min = r
    else:
        l_max = max(l_max, l)
        r_min = min(r_min, r)

print(max(r_min - l_max + 1, 0))

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

using namespace std;

int main()
{
    int N,M;
    vector<int> D;
    vector<int> T;

    cin >> N;
    D.resize(N);
    for(int i=0; i<N; ++i) {
        cin >> D[i];
    }

    cin >> M;
    T.resize(M);
    for(int i=0; i<M; ++i) {
        cin >> T[i];
    }

    sort(D.rbegin(),D.rend());
    sort(T.rbegin(),T.rend());

    int j=0;
    for(int i=0; i<M; ++i) {
        while(D[j]>T[i]) {
            ++j;
        }
        if(D[j]<T[i]) {
            cout << "NO" << endl;
            return 0;
        } else {
            ++j;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1792
// In the name of God

#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5+5;
map<string, long long> mp;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	long long ans = 0;
	for(int i=0;i<n;i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 11264
x1, y1, x2, y2 = map(int, input().split())

x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

x3 = x1 + (x4 - x1) + (x2 - x1)
y3 = y1 + (y4 - y1) + (y2 - y1)

print(x3, y3, x4, y4)

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

int main() {
    ll N; cin >>  N;
    ll ans = 0;
    map<ll,ll> res;
    vector<ll> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a.at(i);
        res[a.at(i)] = 0; 
    }

    for(int i = 0; i < N; i++) {
        res[a.at(i)]++; 
    }

    for(auto x:res) {
        ans += x.second*(x.second-1)/2;
    }

    for(int i = 0; i < N; i++) {
        cout << ans - (res[a.at(i)] - 1) << endl;;
    }  
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    rep(0,i,5){
        ll x;
        cin>>x;
        if(!x){
            cout<<i+1;
            return 0;
        }
    }
}


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

using namespace std;

const int MAXN = 3e5 + 10;

int n, x, sec[MAXN], sz;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x;
	if (n == 2){
		if (x == 2){
			cout << "Yes\n";
			cout << "1\n2\n3\n";
		}
		else
			cout << "No\n";
		return 0;
	}
	int mx = n+n-1;
	if (x == 1 || x == mx){
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	for (int i = 1; i <= mx; i++)
		if (i < x - 2 || i > x + 2)	sec[sz++] = i;

	for (int i = 0; i < sz/2; i++)
		cout << sec[i] << "\n";
	if (x + 2 <= mx)
		cout << x+2 << "\n";
	cout << x - 1 << "\n";
	cout << x << "\n";
	cout << x + 1 << "\n";
	if (x - 2 > 0)
		cout << x - 2 << "\n";
	for (int i = sz/2; i < sz; i++)
		cout << sec[i] << "\n";
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
       int a,b,c;
       scanf("%d%d",&a,&b);
       c=a*b;
       if(c%2==1) printf("Odd");
       else printf("Even");
       return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{

    long inputN,  aElement = 0;
    scanf("%ld", &inputN);
    
    long FizzBuzzSum = 0;
    
    for(int i = 0; i < inputN; i++)
    {
        aElement++;
        if(aElement % 3 != 0  && aElement % 5 != 0)
        {
           FizzBuzzSum += aElement;
        }
    }
    
    printf("%ld \n", FizzBuzzSum);
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;

int main()
{
    long long n,k,q,w1;
    //cin>>n;
    //long long h[n+1],w[n+1],v[n+1],w1,a[n+1],b[n+1],c[n+1],last;
    cin>>n>>w1;
    long long dp[n+1][w1+1],w[n+1],v[n+1];
    for (long long i = 0; i < n; ++i)
    {
        cin>>w[i]>>v[i];
    }
    for (long long i = 0; i <= n; ++i)
    {
        for (long long j = 0; j <= w1; ++j)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(j>=w[i-1])
                dp[i][j]=max(dp[i-1][j-w[i-1]]+v[i-1],dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w1];
}

/*long long main()
{
    long long t;
    cin>>t;
    string s1,s2;
    for (long long i = 0; i < 2*k; ++i)
    {
        cin>>s1>>s2;
    }
    for (long long i = s1.length(); i > 0; --i)
    {
        
    }
}*/

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int n; cin >> n;
  int w[n];
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> w[i];
    sum += w[i];
  }
  int ans = 100100100;
  for(int i = 0; i < n-1; i++){
    int temp = 0;
    for(int j = 0; j <= i; j++){
      temp += w[j];
    }
    int a = sum - temp;
    int b = abs(temp - a);
    ans = min(ans, b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
# sum_a = a[0]+(a[0]-1)+(a[0]-1)
b=0
for i in range(100000000):
   if(a[1]==1):
      break
   if(i==0):
      if(b>=a[1]): 
         break
      b=a[0]
   else:
      if(b>=a[1]):
         break
      b=b+(a[0]-1)

print(i)


Measured memory_bytes: 3060
import itertools
from collections import Counter
import sys
N=int(input())
balls=[]

for i in range(N):
    x,y=[int(j) for j in input().split(" ")]
    balls.append((x,y))

pqs=[]
if N==1:
    print(1)
    sys.exit()
for i in itertools.permutations(balls,2):
    p=i[1][0]-i[0][0]
    q=i[1][1]-i[0][1]
    pqs.append((p,q))

c=Counter(pqs)
c=dict(c)
c=sorted(c.items(),key=lambda w:w[1],reverse=True)
print(N-c[0][1])


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

using namespace std;

map<string, int> item;
map<string, vector<string>> recipe;

int min_score(string tage) {
	if (recipe[tage].size() == 0)return item[tage];

	int sum = 0;
	for (int i = 0; i < recipe[tage].size(); i++) sum += min_score(recipe[tage][i]);

	return min(sum, item[tage]);
}

int main() {
	int n;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			string tmp; cin >> tmp;
			cin >> item[tmp];
		}
		int recipe_n; cin >> recipe_n;
		for (int i = 0; i < recipe_n; i++) {
			string targetItem; int targetItemRecipe;
			cin >> targetItem >> targetItemRecipe;
			for (int i = 0; i < targetItemRecipe; i++) {
				string tmp;
				cin >> tmp;
				recipe[targetItem].push_back(tmp);
			}
		}

		string tage;
		cin >> tage;
		cout << min_score(tage) << endl;

		item.clear();
		recipe.clear();
	}
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;
	for(int i = 0; i < 9; i++){
		string t = "000";
		t[0] += i, t[1] += i, t[2] += i;
		if(s.find(t) != string::npos){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

using namespace std;

int main() {
    int N;
    int num   = 0;
    int max   = -10;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        int temp  = i;
        int count = 0;
        while (true) {
            if (temp % 2 != 0) {
                break;
            }
            temp /= 2;
            count++;
        }
        if (count > max) {
            max = count;
            num = i;
        }
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    int N;
    cin>>N;
    long X[N],x[N];
    for(int i=0;i<N;i++){
        cin>>X[i];
        x[i]=X[i];
    }
    sort(x,x+N);
    int mid1=x[N/2]; int mid2=x[N/2-1];
    for(int i=0;i<N;i++){
        if(X[i]>=mid1){cout<<mid2<<endl;}
        else {cout<<mid1<<endl;}
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S1, S2;  
  for(int i = 0; i < N; i ++){
    cin >> S1;
   if(S1 == "Y"){
   S2 = "Y";
}
}
if( S2 == "Y"){
cout << "Four" << endl;
}
else  {
  cout << "Three" << endl;
}
}


Measured memory_bytes: 256
def actual(A, B, C, X):
    count = 0

    for n_500yen in range(A + 1):
        for n_100yen in range(B + 1):
            for n_050yen in range(C + 1):
                amount = 500 * n_500yen + 100 * n_100yen + 50 * n_050yen

                if amount == X:
                    count += 1

    return count

A = int(input())
B = int(input())
C = int(input())
X = int(input())

print(actual(A, B, C, X))


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

int main(){
	int K,A,B;
  	vector<int> vec(0);
  	cin>>K>>A>>B;
  	for(int i=A;i<B+1;i++){
      if(i%K==0){
        cout<<"OK"<<endl;
        break;
      }
      else {
        vec.push_back(0);
      }
      if(vec.size()==B-A+1){
        cout<<"NG"<<endl;
      }
    }
	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=505,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int a,b;cin>>a>>b;
        if(a&1) cout<<(a-1)*127+b<<endl;
        else cout<<(a-1)*127+127-b<<endl;
    }
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<int,int> P;
#define fi first
#define se second
vector<vector<int>> graph; 
#define pb push_back
int main(){
    int n,m;
    cin>>n>>m;
   vector<vector<bool>> path(n,vector<bool>(n)),cp(n,vector<bool>(n,false));
   vector<P> brid(m);
   graph.resize(n);
   for(int i=0;i<m;i++){
       int a,b;
       cin>>a>>b;
       a--;b--;
       brid.at(i)=P(a,b);
       graph.at(a).pb(b);
       graph.at(b).pb(a);
       cp[a][b]=true;
       cp[b][a]=true;
   }
   int ans=0;
for(int i=0;i<m;i++){
    vector<bool> check(n,false);
    path=cp;
    path[brid.at(i).fi][brid.at(i).se]=false;
    path[brid.at(i).se][brid.at(i).fi]=false; 
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        for(int i=0;i<graph.at(now).size();i++){
            if(check[graph.at(now).at(i)])continue;
            if(!path[now][graph.at(now).at(i)])continue;
            check[graph.at(now).at(i)]=true;
            q.push(graph.at(now).at(i));
        }
    }
    for(int i=0;i<n;i++){
        if(!check[i]){
            ans++;
            break;
        }
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
n =int(input())
A = list(map(int,input().split()))

B = [0]*n

for i in range(n)[::-1]:
  tmp = 0
  j = i+1
  
  while j<=n:    
    tmp += B[j-1]
    j += i+1
    
  if tmp%2 != A[i]:    
    B[i] = 1

print(sum(B))
print(*[i+1 for i in range(n) if B[i]])

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

int main()
{
    int N, K;
    long h[100000];
    long ans = -1;

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

    for(int i = 0; i < N; i++) {
        //cout << h[i] << " ";
    }
    cout << endl;

    for(int i = 0; i <= N - K; i++) {
        //cout << i << ": " << h[i + K] << " " << h[i] << endl;
        if(ans == -1 || ans > h[i + K - 1] - h[i]) {
            ans = h[i + K - 1] - h[i];
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  
  vector<string> s(n);
  
  for(int i = 0; i < n; i++) {
  	cin >> s.at(i);
  }
  
  sort(s.begin(), s.end());
  
  for(int i = 0; i < n; i++) {
  	cout << s.at(i);
  }
  
  cout << endl;
  
}


Measured memory_bytes: 256
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	int a, b, c, d; 
	cin >> a >> b >> c >> d; 
	if (a*b%2==1&&(c+d)%2==1)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}




Measured memory_bytes: 3124
#include <cmath>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int a, b, c;
int main() {
	cin >> a >> b >> c;
	if (a * b * c == 175) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
 
using namespace std;
int main(void){
    int N;
    int K;
    cin >> N >> K;     
    
    int neko = 0;
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        if(tmp >= K){
            neko++;
        }
    }
    cout << neko << endl;
    
    
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 2e6 + 10 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T> void read(T &a)
{
	int f = 1 ; a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	a *= f;
}

ll n, k;

char s[maxn];

ll sum, tmp, ans, fi;

signed main()
{
	scanf("%lld %lld", &n, &k);
	scanf("%s", s + 1);
	tmp = 1;
	rep(i, 2, n)
	{
		if(s[i] == s[i - 1]) tmp ++;
		else
		{
			sum ++;
			ans += tmp - 1;
			tmp = 1;
		}
	}
	sum ++;
	ans += tmp - 1;
	if(sum == 1) return printf("%lld\n", ans), 0;
	if(!(sum & 1)) fi = 1, sum --;
	sum /= 2;
	ans += min(sum, k) * 2;
	k -= min(sum, k);
	if(k) ans += fi;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
function Main(input){
	input = input.split(" ").map(a=>~~a);
  var x1 = input.shift();
  var y1 = input.shift();
  var x2 = input.shift();
  var y2 = input.shift();
  
 	var x3 = x2 - (y2 - y1);
  var y3 = y2 + (x2 - x1);
  var x4 = x3 - (x2 - x1);
  var y4 = y3 - (y2 - y1);
  return [x3,y3,x4,y4].join(" ");
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
31 -41 -59 26
`);

Measured memory_bytes: 22084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 18;
const int INF = 1e9;
int a[N], b[N];
int dp[1 << N][N];

int val(int i, int p) {
  return ((p - i) % 2 == 0) ? a[i] : b[i];
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      dp[mask][i] = INF;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[1 << i][i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  for (int mask = 1; mask < (1 << n); mask++) {
    const int pos = __builtin_popcount(mask) - 1;
    if (pos == 0) continue;
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        int sub = mask ^ (1 << i);
        int cost = 0;
        for (int k = 0; k < i; k++) {
          if ((sub & (1 << k)) == 0) cost++;
        }
        for (int j = 0; j < n; j++) {
          if ((sub & (1 << j)) && val(j, pos - 1) <= val(i, pos)) {
            dp[mask][i] = min(dp[mask][i], cost + dp[sub][j]);
          }
        }
      }
    }
  }

  int ans = INF;
  for (int i = 0; i < n; i++) {
    ans = min(ans, dp[(1 << n) - 1][i]);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n,a; cin>>n>>a;
    cout<<n*n-a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;

void solve(void){
    int N, P;
    int odd = 0, even = 0;
    cin >> N >> P;
    rep(N, i) {
        int A; cin >> A;
        if (A%2==0) even++;
        else odd++;
    }

    if (odd==0) {
        cout << (ll)(P?0:(pow(2, N))) << '\n';
    }
    else {
        cout << (ll)(pow(2, N-1)) << endl;
    }
}

int main(void){
  solve();
  return 0;
}


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

#define endl "\n"
#define lli long long int
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ct1(x) cout<<x<<endl;
#define ct2(x,y) cout<<x<<" "<<y<<endl;
#define ct3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define ct4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define ct5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define ct6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define sq(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second

const int MOD = (int)1e9 + 7;

lli solve(){
	int n, i,x,k,j,minVal;
    cin>>n>>k;
    vector<int>v;
    vector<int>dp(n,0);
    for(i=0; i<n; i++){
    	cin>>x;
    	v.pb(x);
    }
    if(n==0)
    	return 0;
    // if(n==1)
    // 	return abs(v[1]-v[0]);
    // dp[1]=abs(v[1]-v[0]);
    // cout<<dp[1]<<" ";
    for(i=1; i<n; i++){
        minVal=INT_MAX;
        for(j=i-1; j>=max(0,i-k); j--){
            minVal=min(minVal, dp[j]+abs(v[j]-v[i]));
        }
    	dp[i]=minVal;
    }
    // cout<<"a";
    return dp[n-1];
}

int main() {
    FASTER
	// lli testCases;
	// cin>>testCases;
	// for(lli caseLevel=1; caseLevel<=testCases; caseLevel++)
	// {
	    // cout<<"Case #"<<caseLevel<<": ";
        cout<<solve()<<endl;
        // cout<<endl;
	// } /
	return 0;
}

Measured memory_bytes: 4248
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S;
    cin >> S;
    int Q; cin >> Q;
    string front_S = "";
    string end_S = "";
    int cnt = 0;
    REP(i,Q) {
        int t; cin >> t;
        if(t == 1) {
            cnt++;
            string tmp;
            tmp = front_S;
            front_S = end_S;
            end_S = tmp;

        }
        else if(t == 2) {
            int f;
            string C;
            cin >> f >> C;
            if(f == 1) front_S += C;
            else end_S += C;
        }
    }
    if(cnt%2 != 0) reverse(S.begin(),S.end());
    reverse(front_S.begin(),front_S.end());
    cout << front_S + S + end_S << endl;  
}

Measured memory_bytes: 1348