akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
ll pwr(ll b,ll p)
{
    if(p==0)
        return 1;
    if(p%2==0)
    {
        ll a=pwr(b,p/2);
        return a*a;
    }
    else
        return b*pwr(b,p-1);
}
int t,n,i;
string s;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  cin>>n;
  vector<pair<int,int> >v(n);
  for(i=0;i<n;++i)
      cin>>v[i].first>>v[i].second;
      bool b=true;
  for(i=0;i+2<n;++i)
  {
      if(v[i].first==v[i].second&&v[i+1].first==v[i+1].second&&v[i+2].first==v[i+2].second)
      {
          b=false;
          cout<<"Yes\n";
          break;
      }
  }
  if(b)
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3640
while(1):
    h,w=map(int,input().split())
    if h==w==0 :break
    for i in range(h):
        for j in range(w):
            if i==0 or i==h-1 or j==0 or j==w-1 : print("#",end="")
            else: print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
from itertools import groupby as gb
n,k,g,t,p,s=map(lambda v:v if v[0] in "rsp" else int(v),open(0).read().split())
r,ss,pa=0,0,0
l=[""]*k
for x,i in enumerate(list(s)):
  if l[x%k]==i:l[x%k]="";continue
  if i=="r":pa+=1
  elif i=="s":r+=1
  else:ss+=1
  l[x%k]=i
print(r*g+ss*t+pa*p)

Measured memory_bytes: 4724
def gcd(x,y):
    if x == 0:
        return y
    elif y == 0:
        return x
    if x%y == 0:
        return y
    x, y = y, x%y
    return gcd(x,y)

n = int(input())
a = [0] + [int(i) for i in input().split()]

L = [0] * (n+2)
R = [0] * (n+2)
for i in range(n+1):
    L[i+1] = gcd(L[i],a[i])

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

M = []
for i in range(1,n+1):
    M.append(gcd(L[i],R[i+1]))

print(max(M))

Measured memory_bytes: 68204
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W)->np.ndarray:
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

N, K = ints()
A = read_matrix(N, N)


# from numba import njit


# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    for i in range(X.shape[0]):  # Xの行
        for j in range(Y.shape[1]):  # Yの列
            tmp = (X[i, :] * Y[:, j]) % MOD
            ret[i, j] = tmp.sum() % MOD
    return ret


def matmul_mod_try(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    YT = Y.T
    for i in range(X.shape[0]):  # Xの行
        Xi = X[i, :]
        tmp = (YT * Xi) % MOD
        ret[i, :] = tmp.sum(1) % MOD
    return ret


def matmul_mod_fast(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    X3d = X[:, :, np.newaxis].transpose(0, 2, 1)
    Y3d = Y[:, :, np.newaxis].transpose(2, 1, 0)
    return ((X3d * Y3d) % MOD).sum(2) % MOD


A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        ans = matmul_mod_fast(ans, A_double)
    A_double = matmul_mod_fast(A_double, A_double)

print(ans.sum() % MOD)


Measured memory_bytes: 29080
k, n = map(int, input().split())
a = list(map(int, input().split()))
# print('a:', a)
b = [(k-a[-1])+a[0]]
for i in range(1, n):
    x = a[i]-a[i-1]
    b.append(x)
# print('b:', b)
ma = max(b)
print(sum(b) - ma)

Measured memory_bytes: 25840
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray().map { it.toString() }

    val wSum = Array(n){0L}
    wSum[0] = if(s[0] == "W") 1 else 0
    for (i in 1 until n){
        wSum[i] = if(s[i] == "W") wSum[i-1] + 1 else wSum[i-1]
    }

    val eSum = Array(n){0L}
    eSum[0] = if(s[0] == "E") 1 else 0
    for (i in 1 until n){
        eSum[i] = if(s[i] == "E") eSum[i-1] + 1 else eSum[i-1]
    }

    var min = if(eSum[n - 1] - eSum[0] > wSum[n - 2]) wSum[n - 2] else eSum[n - 1] - eSum[0]
    for(i in 1 until n - 1){
        val c = wSum[i - 1] + eSum[n - 1] - eSum[i]
        if(min > c) min = c
    }
    println(min)
}

Measured memory_bytes: 86732
#include<stdio.h>
#include<math.h>

int main(){
    double x1, x2, x3, y1, y2, y3, r, xp, yp;
    double a1, b1, c1, a2, b2, c2;
    int n,i;

    scanf("%d",&n);

    for(i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3);

        a1 = 2*(x2-x1);
        b1 = 2*(y2-y1);
        c1 = x1*x1-x2*x2+y1*y1-y2*y2;
        a2 = 2*(x3-x1);
        b2 = 2*(y3-y1);
        c2 = x1*x1-x3*x3+y1*y1-y3*y3;

        xp = (b1*c2-b2*c1)/(a1*b2-a2*b1);
        yp = (c1*a2-c2*a1)/(a1*b2-a2*b1);

        r = sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));

        printf("%.3lf %.3lf %.3lf\n", xp, yp, r);
    }
    return 0;
}

Measured memory_bytes: 668
#include<bits/stdc++.h>
using namespace std;
int a,b,c,k;
int main(){
	cin>>a>>b>>c>>k;
	if(k<=a)cout<<k<<endl;
	else if(k>a&&k<=a+b)cout<<a<<endl;
	else if(k<=a+b+c)cout<<a-(k-a-b)<<endl;
	else cout<<a-c<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int l, r, sum=0;
  for (int i=0; i<N; i++){
    cin >> l >> r;
    sum +=(1+r);
    sum -=l;
  }
  cout << sum << endl;
}

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

using namespace std;

void solve() {
    int n; cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


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

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<int> B(61,0);
    for(int i=0; i<N; i++){
        ll a = A[i]; int bit = 0;
        while(a > 0){
            B[bit] += a%2;
            a /= 2;
            bit++;
        }
    }

    ll ans = 0, n2 = 1;
    for(int i=0; i<61; i++){
        ll addx = (((n2*B[i])%MOD)*(N-B[i]))%MOD;
        ans += addx; ans %= MOD;
        n2 *= 2; n2 %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 15
using namespace std;
int main() {
  int n;
  cin >> n;
  if(n==1) {
    cout << "Hello World" << endl;
  } else {
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
  }

  return 0;
}

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


int main() {
  int N;
  cin >> N;
  int t[N], x[N], y[N];
  for (int i=0; i < N; ++i) {
    cin >> t[i] >> x[i] >> y[i];
  }
  string ans = "Yes";
  int nowT = 0;
  int nowX = 0;
  int nowY = 0;
  for (int i=0; i < N; ++i) {
    int sumV = abs(x[i] - nowX) + abs(y[i] - nowY);
    int diffT = t[i] - nowT;
    if (sumV <= diffT) {
      if ((diffT - sumV) % 2 == 0) {
        nowT = t[i];
        nowX = x[i];
        nowY = y[i];
      }
      else {
        ans = "No";
        break;
      }
    }
    else {
      ans = "No";
      break;
    }
  }
  cout << ans << "\n";
}
  
      
    

Measured memory_bytes: 1408
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Measured memory_bytes: 7656
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.next();
		boolean flag = true;
		for(int i = 0; i < string.length(); i++){
			char c = string.charAt(i);
			int count=0;
			for(char x: string.toCharArray()){
				if(x == c){
					count++;
				}
			}
			if(count % 2 == 1){
				System.out.println("No");
				flag = false;
				break;
			}
		}
		if(flag){
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	int mx_a=-1,mx_b=-1,mi_a=1e10,mi_b=1e10;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		mx_a=max(mx_a,a[i]);
		mi_a=min(mi_a,a[i]);
		mx_b=max(mx_b,b[i]);
		mi_b=min(mi_b,b[i]);
	}
	sort(all(a));
	sort(all(b));
	int ans;
	if (n%2)  ans=b[n/2]-a[n/2];
	else  ans=b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1];
	ans++;
	cout<<ans;
	re 0;
}

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

#define int long long

signed main(){
	int n, l, sum = 0, mini = 100001, flag = 0;
	cin >> n >> l;
	for(int i = 1; i <= n; i++){
		sum += (l + i - 1);
		if(mini > abs(l + i - 1)){
			mini = min(mini, abs(l + i - 1));
			if(l + i - 1 > 0) flag = 1;
			else flag = -1;	
		}
	}
	//cout << sum << endl;
	cout << sum - (mini * flag);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#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, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, M;
vector<int> G[8];
int used[8];

int dfs(int v) {
  int flag = 1;
  for (int i = 0; i < N; i++) {
    if (i != v && !used[i]) flag = 0;
  }
  if (flag) return 1;
  int res = 0;
  for (int nv : G[v]) {
    if (used[nv]) continue;
    used[nv] = 1;
    res += dfs(nv);
    used[nv] = 0;
  }
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].PB(b);
    G[b].PB(a);
  }
  used[0] = 1;
  cout << dfs(0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

typedef struct tree_{
    int parent;
    int left;
    int right;
}tree;

void preorder(tree *node, int id){
    printf(" %d",id);
    if(node[id].left!=-1){
        preorder(node, node[id].left);
    }
    if(node[id].right!=-1){
        preorder(node, node[id].right);
    }
}

void inorder(tree *node, int id){
    if(node[id].left!=-1){
        inorder(node, node[id].left);
    }
    printf(" %d",id);
    if(node[id].right!=-1){
        inorder(node, node[id].right);
    }
}

void postorder(tree *node, int id){
    if(node[id].left!=-1){
        postorder(node, node[id].left);
    }
    if(node[id].right!=-1){
        postorder(node, node[id].right);
    }
    printf(" %d",id);
}

int main(){
    int i, n, id, l, r;

    scanf("%d",&n);

    tree node_[n+1];
    tree *node = node_+1;

    for(i=0;i<n;i++)node[i].parent = -1;

    for(i=0;i<n;i++){
        scanf("%d %d %d",&id,&l,&r);
        node[id].left = l;
        node[id].right = r;
        node[l].parent = id;
        node[r].parent = id;
    }

    for(i=0;i<n;i++)if(node[i].parent==-1)break;
    if(i==n)return -1;
    int root = i;

    printf("Preorder\n");
    preorder(node, root);
    printf("\n");

    printf("Inorder\n");
    inorder(node, root);
    printf("\n");

    printf("Postorder\n");
    postorder(node, root);
    printf("\n");

    return 0;
}



Measured memory_bytes: 2740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

string str;

string encode(string code){
  map<char, string> m;
  m['A'] = "00000";
  m['B'] = "00001";
  m['C'] = "00010";
  m['D'] = "00011";
  m['E'] = "00100";
  m['F'] = "00101";
  m['G'] = "00110";
  m['H'] = "00111";
  m['I'] = "01000";
  m['J'] = "01001";
  m['K'] = "01010";
  m['L'] = "01011";
  m['M'] = "01100";
  m['N'] = "01101";
  m['O'] = "01110";
  m['P'] = "01111";
  m['Q'] = "10000";
  m['R'] = "10001";
  m['S'] = "10010";
  m['T'] = "10011";
  m['U'] = "10100";
  m['V'] = "10101";
  m['W'] = "10110";
  m['X'] = "10111";
  m['Y'] = "11000";
  m['Z'] = "11001";
  m[' '] = "11010";
  m['.'] = "11011";
  m[','] = "11100";
  m['-'] = "11101";
  m['\''] = "11110";
  m['?'] = "11111";
  string ret = "";
  rep(i, code.size())
    ret += m[code[i]];

  return ret;
}

string decode(string code){
  string ret = "";

  map<string, char>m;
  m["101"] = ' ';
  m["000000"] = '\'';
  m["000011"] = ',';
  m["10010001"] = '-';
  m["010001"] = '.';
  m["000001"] = '?';
  m["100101"] = 'A';
  m["10011010"] = 'B';
  m["0101"] = 'C';
  m["0001"] = 'D';
  m["110"] = 'E';
  m["01001"] = 'F';
  m["10011011"] = 'G';
  m["010000"] = 'H';
  m["0111"] = 'I';
  m["10011000"] = 'J';
  m["0110"] = 'K';
  m["00100"] = 'L';
  m["10011001"] = 'M';
  m["10011110"] = 'N';
  m["00101"] = 'O';
  m["111"] = 'P';
  m["10011111"] = 'Q';
  m["1000"] = 'R';
  m["00110"] = 'S';
  m["00111"] = 'T';
  m["10011100"] = 'U';
  m["10011101"] = 'V';
  m["000010"] = 'W';
  m["10010010"] = 'X';
  m["10010011"] = 'Y';
  m["10010000"] = 'Z';

  rep(i, code.size()){
    string tmp = "";
    REP(j, i, code.size()){
      tmp += code[j];
      if(m.count(tmp) == 0) continue;
      //      cout << tmp << endl;

      ret += m[tmp];
      i = j;
      break;
    }
  }
  return ret;
}

int main(){
  while(getline(cin, str)){
    string res;
    res = encode(str);
    //    cout << res << endl;
    res = decode(res);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair

void solve(int test)
{
    ll n,x,mi;
    cin>>n>>x>>mi;

    ll i,j;

    ll ans = 0;

    if(x==0){cout<<0<<endl;return;}

    if(x==1){cout<<n<<endl;return;}

    ll curr = x;

    map<ll, pair<ll,ll> >m;


    for(i=1;i<=n;i++)
    {
        if(curr==0){cout<<ans<<endl; return;}
        if(curr==1){ans = ans + (n-i+1LL);cout<<ans<<endl; return;}

        if(m.find(curr)!=m.end())
        {
           ll len = n-i+1LL;
           ll si = i - m[curr].first;
           ll div = len/si;

           ll val = ans - m[curr].second;
           val = val*div;
           ans = ans + val;
           i = i + si*div;
           break;
        }
        m[curr] = mp(i,ans);
        ans = ans +curr;
        curr = curr*curr;
        curr = curr%mi;
    }

    for(i;i<=n;i++)
    {
        if(curr==0){cout<<ans<<endl; return;}
        if(curr==1){ans = ans + (n-i+1LL);cout<<ans<<endl; return;}

        ans = ans +curr;
        curr = curr*curr;
        curr = curr%mi;
    }

    cout<<ans<<endl;

    return;
}

int main() {

 int t = 1;
// cin>>t;

 for(int x=1;x<=t;x++)
 {
    solve(x);
 }
  return 0;
}


Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
bool ans(const vector<string>& W){
	const int n=W.size();
	for (int i=0;i<n-1;++i){
		if (W[i].back()!=W[i+1].front())
			return false;
	}
	for (int i=0;i<n;++i){
		for (int j=i+1;j<n;++j){
			if (W[i]==W[j])
				return false;
		}
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	vector<string> W(n);
	for (int i=0;i<n;++i){
		cin>>W[i];
	}
	if(ans(W))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
 
 
//typedef tuple <int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define siz(x) (int)(x).size()
#define Y second
#define X first
#define IN insert
#define PB push_back
#define P pop_back
#define PU push
#define PO pop
//#define F find
#define ED end()
#define MP( a, b) make_pair( a, b )
 
//#define MOD 1000000007ll
#define INF 1000000000
#define endl "\n"
#define rep(a,i,b) for (ll i = (a); i < (b); ++i)
#define reps(a,i,b) for (ll i = (a); i <= (b); ++i)
#define repd( num, i, ed ) for(ll (i)= (num)-1; (i) >= ed; --(i))
#define repkt( bg, i, num, kt ) for(ll (i)= (bg); (i) < (num) && (kt); ++(i))
#define repchar( i ) for(char (i)= 48; (i) <= 122; (i)++)   
#define in(n) scanf("%lld", &n)
#define out(n) printf("%lld\n", n)
#define outS(s) printf("%s\n", s)
#define setA(a,n) for(ll i= 0, j= sizeof(a)/sizeof(a[0]); i < j; ++i) a[i]= n;
#define repe(num,i,ed) for(ll (i)= (num); (i) >= ed; --(i))
// const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const ll N=1e5+5,K=105;
const int si=(1<<20);
const ll M=50+5;
const ll oo=1e18+5;
const double INFdb=1e10;

int n,k;
int h[N];
int dp[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
    #endif
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>h[i];
    for(int i=0;i<N;++i) dp[i]=INF;
    h[0]=h[1];
    dp[0]=dp[1]=0;
    for(int i=1;i<=n;++i){
		for(int j=i+1;j<=i+k;++j){
			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n];
    cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";                                                                          
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;

const long long MOD = 1000000007;


void solve(long long N, long long K){
    long long ans=0;
    for(long long i=K;i<=N+1;i++){
        long long min,max;
        min=((0+i-1)*i)/2;
        max=(2*N-i+1)*i/2;
        //cout<<max-min+1<<endl;
        ans+=(max-min+1)%MOD;
        ans=ans%MOD;
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector< pair<int, int> >  v;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(b, a));
  }
  sort(v.begin(), v.end());
  int sumjob = 0;  
  for(int i =0;i<n; i++) {
    sumjob += v[i].second;
    if(sumjob > v[i].first) {
      cout << "No" << endl;
      return 0;
    }    
  }
  cout << "Yes" << endl;
  // for(auto p : v) {
  //   cout << p.first << " " << p.second << endl;
  // }
  return 0;
}


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

int main(){
    string s;
    int i, c = 0;
    cin >> s;
    for(i=0; i<s.length(); i++){
        if(s[i] == 'o') c++;
    }
    if(15-s.length()+c<8){
        cout << "NO";
    }else{
        cout << "YES";
    }
    return 0;
}

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

using namespace std;

typedef long long	ll;

int main(){
	ll x;

	cin >> x;

	ll ans = (x / 500LL) * 1000LL;
	x %= 500LL;

	ans += (x / 5LL) * 5LL;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//std::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b;
	cin>>a>>b;
	ll gd=__gcd(a,b);
	map<ll,ll> mp;
	mp.clear();
	mp[1]=1;
	// mp[a/gd]=1;
	// mp[b/gd]=1;
	ll n=gd;
  	ll ct=1;
  
	for (ll i=2; i<=sqrt(n); i++) 
	    { 
	        if (n%i == 0) 
	        { 
	        	mp[i]=1;
	        	ct++;
	        	//cout<<i<<endl;
	        	while(n%i==0)
	        		n/=i;
	        } 
	    } 
	    if(n!=1)
	    	ct++;
    	cout<<ct<<endl;
    //       cout << p << " ";
	return 0;
}

Measured memory_bytes: 256
pairBase :: String -> String
pairBase "A" = "T"
pairBase "T" = "A"
pairBase "C" = "G"
pairBase "G" = "C"
pairBase _ = "X"  -- (^_^;)


main :: IO ()
main = do
    b <- getLine
    putStrLn $ pairBase b

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>

using namespace std;

bool check(int s, vector<int> d) {
    while(s != 0) {
        int n = s % 10;
        for(int i = 0; i < d.size(); i++) {
            if(d[i] == n) return false;
        }
        s /= 10;
    }
    return true;
}

int main() {
    int N, K;
    cin >> K >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }

    for(int i = K;;) {
        bool ans = check(i, d);
        if(ans) {
            cout << i << endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#include <cmath>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> i_i;


int main(){
    for(;;){
        int n;
        cin >> n;
        if(!n)break;
        vector<int> I(n,0);
        rep(i, n) cin >> I[i];
        int S=0,A=0,C=0;
        double h=100000000000;
        for (int s=0; s<=15; s++) {
            for (int a=0; a<=15; a++) {
                for (int c=0; c<=15; c++) {
                    vector<int> R(n);
                    vector<double> memo(257,0);
                    R[0]=(a*s+c)%256;
                    for (int i=1; i<n; i++) {
                        R[i]=(a*R[i-1]+c)%256;
                    }
                    vector<double> O(n);
                    rep(i, n){
                        O[i]=(I[i]+R[i])%256;
                        memo[O[i]]++;
                    }
                    sort(O.begin(), O.end());
                    double hh=0.0;
                    int p=0;
                    while (p<n-1) {
                        if ( O[p]!=O[p+1]) {
                            double in = memo[O[p]]/n;
                            if(in!=0)hh+=(in)*log(in);
                        }
                        p++;
                    }
                    double in = memo[O[p]]/n;
                    if(in!=0)hh+=(in)*log(in);
                    if(hh!=0) hh*=-1;
                    hh *= 100000000;
                    int hoge = hh;
                    if (hoge < h) {
                        h = hoge;
                        S = s;
                        C = c;
                        A = a;
                    }
                }
            }
        }
        cout << S<<" "<<A<<" "<<C<<endl;
    }
}

Measured memory_bytes: 1256
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


n, k, s = zz()
if (s == 10 ** 9):
    A = np.array([10**9-1]*n)
else:
    A = np.array([10**9]*n)

A[:k] = s
print(*A)


Measured memory_bytes: 47020
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, r = 0;
char s[110];
int main() {
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n; i++)
		r += (s[i] == 'R' ? 1 : -1);
	if (0 < r)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    int N;
    cin>>N;
    vector<int>Llist(N,0);


    int ans =0;
    for (int i = 0; i < N; ++i) {
        cin>>Llist[i];
    }
    std::sort(Llist.begin(),Llist.end());

    for (int a = 0; a < N - 2; ++a) {
        for (int b = a+1; b <N-1 ; ++b) {
            for(int c = b+1;c<N;++c){
                if(Llist[c] > abs(Llist[a]-Llist[b])){
                    if(Llist[c]<(Llist[a]+Llist[b])){
                        ans ++;
                        continue;
                    }
                    else{
                        break;
                    }

                }

            }

        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int H,W;
    while(true){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <map>
#include <tuple>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    map<int, int> a;
    REP(i, 0, n) {
        int t;
        cin >> t;
        a[t]++;
    }

    vector<int> MOD1(m, 0), MOD2(m, 0);
    for (auto &it : a) {
        int t, s;
        tie(t, s) = it;
        if (s % 2) {
            MOD1[t % m]++;
        }
        MOD2[t % m] += (s / 2 * 2);
    }
    int ans = (MOD1[0] + MOD2[0]) / 2;
    REP(i, 1, m) {
        int j = m - i;
        if (i > j) continue;
        //dump(ans, MOD1[i], MOD1[j], MOD2[i], MOD2[j]);
        if (i != j) {
            int tmp = min(MOD1[i], MOD1[j]);
            MOD1[i] -= tmp;
            MOD1[j] -= tmp;
            ans += tmp;
            if (MOD1[i] != 0) {
                int t = min(MOD2[j], MOD1[i]);
                MOD1[i] -= t;
                MOD2[j] -= t;
                ans += t;
            }
            if (MOD1[j] != 0) {
                int t = min(MOD2[i], MOD1[j]);
                MOD1[j] -= t;
                MOD2[i] -= t;
                ans += t;
            }
            ans += MOD2[i] / 2;
            ans += MOD2[j] / 2;
        } else {
            ans += (MOD1[i] + MOD2[i]) / 2;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353

// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}

signed main(){
    IOS
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
  int k;
  cin >>k;
  string s;
  cin >>s;
  if(s.size()<=k) cout <<s;
  else{
    rep(i,0,k){
      cout <<s[i];
    }
    cout <<"...";
  }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

ll n,m,q;
vi a,b,c,d;

ll solve(ll last,vi v,ll sz)
{
    if(sz==n)
    {
        ll ans=0;
        for(ll i=0;i<q;i++)
        {
            if(v[b[i]]-v[a[i]]==c[i])
                ans+=d[i];
        }
        // cout<<v<<ans<<endl;
        return ans;
    }
    ll ans=0;
    for(ll i=last;i<=m;i++)
    {  
        vi vv=v;
        vv.pb(i); 
        ans=max(ans,solve(i,vv,sz+1));
    }
    return ans;
}

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l;
        cin>>n>>m>>q;
        for(i=0;i<q;i++)
        {
            ll ai,bi,ci,di;
            cin>>ai>>bi>>ci>>di;
            ai--;bi--;
            a.pb(ai);b.pb(bi);c.pb(ci);d.pb(di);
        }
        ll ans=0;
        for(i=1;i<=m;i++)
        {
            vi v;
            v.pb(i);
            ans=max(ans,solve(i,v,1));
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3668
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

#define LL long long int

int N;
int A[100];

string ans = "";

void solve(){
	for(int i=0;i<N;i++){
		if(A[i]%2==0){
			if(!(A[i]%3==0 || A[i]%5==0)){
				ans = "DENIED";
				return;
			}
		}
	}
	ans = "APPROVED";
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();

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


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const ll P = 1e9+7;
int N;
int primes[1000];
int cnt[1000];

int main(){
    cin >> N;

    int nprime = 1;
    primes[0] = 2;
    for(int i=3; i<=1000; i+=2){
        bool ok = true;
        for(int j=0; j<nprime; j++){
            if(i%primes[j] == 0){
                ok = false;
                break;
            }
        }
        if(ok){
            primes[nprime++] = i;
        }
    }

    for(int i=2; i<=N; i++){
        int x = i;
        int j=0;
        while(x > 1){
            if(x%primes[j] == 0){
                x /= primes[j];
                cnt[j]++;
            }
            else{
                j++;
            }
        }
    }

    ll ans=1;
    for(int i=0; i<nprime; i++){
        //cout << primes[i] << " " << cnt[i] << endl;
        if(cnt[i] ==0) continue;
        ans = (ans*(cnt[i]+1))%P;
    }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

vector<lint> apply(vector<lint> v) {
    lint n = v.size();
    sort(v.begin(), v.end());
    repeat(i, n-1) v[i] += 1;
    v[n-1] -= n;
    return v;
}

int main(void) {
    lint k;
    cin >> k;
    
    lint q = (k + 49) / 50;
    lint r = (k % 50 == 0 ? 50 : k % 50);
    
    vector<lint> v(50);
    repeat(i, 50) v[i] = 49 + q;
    rep(50 - r) v = apply(v);
    sort(v.begin(), v.end());
    
    cout << 50 << endl;
    repeat(i, 50) cout << v[i] << " ";
    cout << endl;
    
    return 0;
}
        

Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    int n=read(),a=read(),b=read();
    int d=abs(a-b);
    if (d&1) puts("Borys");
    else puts("Alice");
    return 0;
}

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

//main---------------------------------------------------------
int main() {
    int n, x, t, ans; //使う数の型を決めておくぜ
    cin >> n >> x >> t; //入力
    if (n % x == 0) ans = n / x * t;
    else ans = ( (n / x) + 1 ) * t;    
    cout << ans << endl; //カウントを出力
    return 0; //終了
}

Measured memory_bytes: 3592
#include<iostream>

using namespace std;

int main(){
  int P, Q, R;
  
  cin >> P >> Q >> R;
  
  int times[3] = {P, Q, R};
  int min=400;
  
  
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(i==j){
        continue;
      }else{
        int time = times[i]+times[j];
        min = (time < min ? time : min);
      }
    }
  }
  
  cout << min << endl;
  
  return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  if (K == 0) { cout << (long long)N * N << endl; return 0; }
  long long ans = 0;
  for (int b = K + 1; b <= N; b++) {
    ans += ((N + 1) / b) * (b - K) + max((N + 1) % b - K, 0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

ll N, K;
string s;

int main(){
  cin >> N >> K;
  cin >> s;
  ll cnt = N - 1;
  for(int i=1;i<s.size();i++){
    if (s[i-1] != s[i]) cnt--;
  }
  ll ans = min(cnt + 2 * K, N - 1);
  cout << ans << endl;  
  return 0;
}
  

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x)  (x).begin(),(x).end()

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;

    int ans = b/a;
    if (ans > c)
    {
        ans = c;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y;

  return 0;
}


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


a,b = map(int, input().split())
if a>0:
    ans = "Positive"
elif b<0:
    if (b-a+1)%2==0:
        ans = "Positive"
    else:
        ans = "Negative"
else:
    ans = "Zero"
print(ans)

Measured memory_bytes: 61776
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;

int main(){
    double n,k;
    cin >> n >> k;
    double ans=0.0;
    for(int i=1;i<=n;i++){
        int j=0;
        while(k>i*pow(2,j)){
            j++;
        }
        //cout << i << " " << j << endl;
        ans+=1/(n*pow(2,j));
    }
    cout << setprecision(20) << ans << endl;
    return 0;
}

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


int main(){
  long long a;
  long double b;
  cin >> a >> b;
  
  //cout << b << endl;
  b += 0.0001;
  //cout << b << endl;
  b *= 100;
  //cout << b << endl;
  long long nb = (long long)b;
  //cout << nb << endl;
  long long ans = a*nb/100;
  
  cout << ans << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

int h, w, a, b;
int dp[1000000], gyakudp[1000000];

int gyakugen(int n){
  int ret = 1, nownum = n, m = MOD - 2;
  while(m > 0){
    if(m & 1){
      ret *= nownum;
      ret %= MOD;
    }
    nownum *= nownum;
    nownum %= MOD;
    m >>= 1;
  }
  return ret;
}

int soujou(int n){
  if(n == 1 || n == 0){
    return 1;
  }
  if(dp[n] != -1){
    return dp[n];
  }
  return dp[n] = n * soujou(n - 1) % MOD;
}

int gyakusoujou(int n){
  if(n == 1 || n == 0){
    return 1;
  }
  if(gyakudp[n] != -1){
    return gyakudp[n];
  }
  return gyakudp[n] = gyakugen(n) * gyakusoujou(n - 1) % MOD;
}

int ans = 0;
signed main()
{
  cin >> h >> w >> a >> b;
  memset(dp, -1, sizeof dp);
  memset(gyakudp, -1, sizeof gyakudp);

  if(b < w - 1){
    for(int i = 1; i <= h - a; i++){
      int sum = 1;
      sum *= soujou(b + i - 1);
      sum *= gyakusoujou(b);
      sum %= MOD;
      sum *= gyakusoujou(i - 1);
      sum %= MOD;

      sum *= soujou(w - b - 2 + h - i);
      sum %= MOD;
      sum *= gyakusoujou(w - b - 2);
      sum %= MOD;
      sum *= gyakusoujou(h - i);
      sum %= MOD;
      
      ans += sum;
      ans %= MOD;
    }
  }
  {
    int sum = 1;
    sum *= soujou(b + h - a - 1);
    sum *= gyakusoujou(b);
    sum %= MOD;
    sum *= gyakusoujou(h - a - 1);
    sum %= MOD;

    sum *= soujou(a - 1 + w - b - 1);
    sum %= MOD;
    sum *= gyakusoujou(a - 1);
    sum %= MOD;
    sum *= gyakusoujou(w - b - 1);
    sum %= MOD;

    ans += sum;
    ans %= MOD;
  }

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


Measured memory_bytes: 18944