akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define inf 999999999
using namespace std;

typedef int weight;
typedef vector<weight> array;
typedef vector<array> matrix;

void backward_traverse(int v, int s, int r, matrix &g,
  vector<int> &no, vector< vector<int> > &comp,
  vector<int> &prev, vector<weight> &mcost,
  vector<int> &mark, weight &cost, bool &found) {
  const int n = g.size();
  if (mark[v]) {
    vector<int> temp = no;
    found = true;
    do {
      cost += mcost[v];
      v = prev[v];
      if (v != s) {
        while (comp[v].size() > 0) {
          no[comp[v].back()] = s;
          comp[s].push_back(comp[v].back());
          comp[v].pop_back();
        }
      }
    } while (v != s);
    for (int j = 0; j < n; ++j)
      if (j != r && no[j] == s)
        for (int i = 0; i < n; ++i)
          if (no[i] != s && g[j][i] < inf)
            g[j][i] -= mcost[ temp[j] ];
  }
  mark[v] = true;
  for (int i = 0; i < n; ++i)
    if (no[i] != no[v] && prev[ no[i] ] == v)
      if (!mark[ no[i] ] || i == s)
        backward_traverse(i, s, r, g,
            no, comp, prev, mcost, mark, cost, found);
}

weight minimum_spanning_arborescence(int r, matrix &g) {
  const int n = g.size();

  vector<int> no(n);
  vector< vector<int> > comp(n);
  for (int i = 0; i < n; ++i) {
    no[i] = i;
    comp[i].push_back(i);
  }
  weight cost = 0;
  while (1) {
    vector<int> prev(n, -1);
    vector<weight> mcost(n, inf);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == r) continue;
        if (no[i] != no[j] && g[j][i] < inf) {
          if (g[j][i] < mcost[ no[j] ]) {
            mcost[ no[j] ] = g[j][i];
            prev[ no[j] ] = no[i];
          }
        }
      }
    }
//for(int I=0;I<n;I++)printf("%d\n",mcost[I]);
    bool stop = true;
    vector<int> mark(n);
    for (int i = 0; i < n; ++i) {
      if (i == r || mark[i] || comp[i].size() == 0) continue;
      bool found = false;
      backward_traverse(i, i, r, g,
          no, comp, prev, mcost, mark, cost, found);
      if (found) stop = false;
    }
    if (stop) {
      for (int i = 0; i < n; ++i)
        if (prev[i] >= 0)
          cost += mcost[i];
      return cost;
    }
  }
}

int main(){
	int V,E,r,s,t,w;
	scanf("%d%d%d",&V,&E,&r);
	matrix g(V);
	for(s=0;s<V;s++){
		g[s].resize(V);
		for(t=0;t<s;t++)g[s][t]=inf;
		g[s][t++]=0;
		for(;t<V;t++)g[s][t]=inf;
	}
	for(;E--;)scanf("%d%d%d",&s,&t,&w),g[t][s]=w;
	printf("%d\n",minimum_spanning_arborescence(r,g));
}

Measured memory_bytes: 1112
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():

    N = int(input())
    cnt = Counter(prime_factorize(N))
    # stock = {k : 1 for k in cnt}
    ans = 0
    for prime in cnt:
        needed = 1
        while cnt[prime] >=needed:         
            ans += 1
            cnt[prime] -= needed
            needed += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65836
import java.util.*
fun main(args: Array<String>)
{
    val sc=Scanner(System.`in`)
    var (r,g,b)=sc.nextLine().split(" ").map{it.trim().toInt()}.toTypedArray()
    var k=sc.nextLine().toInt()
    var flag=false
    for(i in 1..k)
    {
        if(g<=r)
            g*=2
        else if(b<=g)
            b*=2
        if(g>r && b>g)
        {
            flag=true
            break
        }
    }
    if(flag)
        println("Yes")
    else
        println("No")

}

Measured memory_bytes: 38448
all_N = []
while True:
	N = list(map(int, input().split(' ')))
	if N[0] == 0 and N[0] == 0:
		break
	all_N.append(N)

for i in range(len(all_N)):
	print('#' * all_N[i][1])
	for j in range(all_N[i][0]-2):
		print('#%s#' % ((all_N[i][1]-2) * '.'))
	print('#' * all_N[i][1])
	print('')

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

using namespace std;
typedef long long ll;
ll t , n , k1 , k2 ,a , b, c, d, x, y, z, cntr , sum , ans ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    ll arr[61];
    memset(arr , 0 , sizeof arr);
    string s;
    const ll MOD = 1e9+7;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> x;
        s="";
        c=0;
        while(x>0)
        {
            if(x%2==1)
            {
                s+='1';
            }
            else s+='0';
            x/=2;
        }
        for(int j = 0 ;  j < s.size() ;j++)
        {
            arr[j]+=(s[j]-'0');
            arr[j]%=MOD;
        }
    }
    c=1;
    ans=0;

    for(int i=0  ; i <61 ;i++)
    {
        ans+=((((n-arr[i])%MOD*arr[i]%MOD)*c%MOD)%MOD);
        ans%=MOD;
        c*=2;
        c%=MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
S=input()

def count_diff2(q, a):
    return sum(
        c1 != c2 for c1, c2 in zip(q, a)
    )


if len(S)%2==0:
    Cut=int((len(S))/2)
    MAE=S[:Cut]
    USHIRO=S[-(Cut):]
    USHIRO=USHIRO[::-1]
    
    if MAE==USHIRO:
        print(0)
        quit()
    
    print(count_diff2(MAE,USHIRO))
    quit()

else:
    Cut=int((len(S))//2)
    MAE=S[:Cut]
    USHIRO=S[-(Cut):]
    USHIRO=USHIRO[::-1]
    
    if MAE==USHIRO:
        print(0)
        quit()
    
    print(count_diff2(MAE,USHIRO))
    quit()



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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    for(ll i=k;i<n;i++){
        if(a[i-k]<a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}











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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

int main(){

    ll a, b, c, d; cin >> a >> b >> c >> d;

    a--;
    cout << (b-((b/c+b/d)-(b/(c*d/__gcd(c,d)))))-(a-((a/c+a/d)-(a/(c*d/__gcd(c,d))))) << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n!=0){
    int rem=n%10;
    n=n/10;
    if(rem==7){
      cout<<"Yes";
      return 0;
  }
  }
    cout<<"No";
  return 0;
}


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

long double f(int n,long double d,long double x){
	if(n==0)	return 0;
	return d+(n-0.5)*x+f(n-1,((2*n+2)*d+5*x)/2/n,x*(2*n+4)/2/n);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,d,x;
	cin>>n>>d>>x;
	cout<<fixed<<setprecision(20)<<f(n,d,x)<<endl;
}


Measured memory_bytes: 15872
t,*L=open(0)
H,W=map(int,t.split())
bef=[0]*(W+1)
a=0
for l in L:
	cur=[0]*(W+1)
	for i in range(W):
		if l[i*2]=="0":
			cur[i+1]=min(cur[i],bef[i],bef[i+1])+1
	a=max(a,max(cur))
	bef=cur
print(a**2)


Measured memory_bytes: 10180
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]

def f(dt, dx, dy):
	if dt == dx + dy:
		return True
	elif dt < dx + dy:
		return False
	else:
		return f(dt-2, dx, dy)

N = read()
t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)
for i in range(1, N+1):
	t[i], x[i], y[i] = reads()

ans = True
for i in range(N):
	dt = t[i+1] - t[i]
	dx = abs(x[i+1] - x[i])
	dy = abs(y[i+1] - y[i])
	ans = ans and f(dt, dx, dy)

if ans:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 11668
#include<iostream>
#include<string>
using namespace std;
int main() {
  
  int s, m, h;
  cin >> s;

  h = s / 3600;
  m = (s - h * 3600) / 60;
  s = (s - h * 3600 - m * 60);

  cout << h << ":" << m << ":" << s << endl;

  return (0);
}


Measured memory_bytes: 3124
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-03-22 20:08:07
 * @LastEditTime: 2020-03-22 20:16:07
 * @FilePath: \VSCode\C++\Practice\AC abc159 B.cpp
 */
#include<bits/stdc++.h>
using namespace std;

string s;
inline bool ispalin(string s){
    string t=s;
    reverse(t.begin(),t.end());
    return t==s;
}

signed main(){
    cin>>s;//akasaka
    int n=s.size();//7
    if(!n%2) return puts("No"),0;

    int p1=(n-1)/2-1,p2=(n+3)/2-1;//2 4
    string s1="",s2="";
    register int i;

    for(i=0;i<=p1;++i) s1+=s[i];
    for(i=p2;i<n;++i) s2+=s[i];
    //cout<<s1<<s2<<'\n';

    puts(ispalin(s)&&ispalin(s1)&&ispalin(s2)?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
import math
i = int(input())
st = 0
mt = 0
ht = 0

if i >= 60:
	st = i % 60
	mt = math.floor(i / 60)


if mt >= 60:
	ht = math.floor(mt / 60)
	mt = mt % 60

print(str(ht) + ':' + str(mt) + ':' + str(st))



Measured memory_bytes: 5660
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
#define INF (int)1e9
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> p;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d), sum(d), total(d), partial(d);
	for (int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
		partial[i] = 100 * (i + 1)*(p[i] - 1);
		sum[i] = 100 * (i + 1)*p[i];
		total[i] = sum[i] + c[i];
	}
	int ans = INF;
	for (int i = 0; i < (1 << d); i++) {
		int a = 0;
		int point = 0;
		for (int j = 0; j < d; j++) {
			if (i & 1 << j) {
				a += p[j];
				point += total[j];
			}
		}
	//	cout << i<<" f a=" << a << " p=" << point << endl;
		for (int j = d - 1; 0 <= j; j--) {
			if (!(i & 1 << j)) {
				if (point + partial[j] >= g) {
					int plus= (int)ceil(max((double)0, (double)(g - point)) / (double)(100 * (j + 1)));
	//				cout << plus << " " << j << endl;
					a += plus;
					point += plus * 100 * (j + 1);
					break;
				}
				a += p[j] - 1;
				point += partial[j];
			}
		}
	//	cout << i<<" s a=" << a << " p=" << point << endl;
		if (point >= g) {
			ans = min(a, ans);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long r,g,b,n,ans;
int main()
{
	long long i,j,u,v;
	cin>>r>>g>>b>>n;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=n;j++)
		{
			u=n-(i*r)-(j*g);
			if(u%b==0 && u/b>=0)
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return(0);
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    string s;cin>>s;
    int n=s.length();
    rep(i,0,n){
        if(s[i]=='?'){
                s[i]='D';
            
        }
    }
    cout<<s;
 
return 0;
}

Measured memory_bytes: 3768
o = gets.chomp.split("")
e = gets.chomp.split("")
ans = []
o_index = e_index = 0
(o.size + e.size).times do |i|
    if i % 2 == 0
        ans << o[o_index]
        o_index += 1
    else
        ans << e[e_index]
        e_index += 1
    end
end

puts ans.join("")

Measured memory_bytes: 1788
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc037/tasks/agc037_b

最適な配り方とは何かを考えるべき
そうすれば自然なdpに落ちるんだろうな

RGBが出たら合体させないといけない？
→これは正しそう

RGGRBB
112212 →4+3=7
112221 →5+2=7
121212 →4+4=8
なので、RGBが出たらランダムに合わせればいいわけではない

2つでたら合体しなければいけない説

RG→合体
GR→合体
B →2通り
B →1通り
なので2通り？
それっぽいぞ

BBRGRRGRGGRBBGB

B1/B
B1/B2
R2/RB,B
G2/B
R2/RB
R2/R,RB
G2/R
R2/R2
G4/RG,R
G4/RG2
R4/RG2,R
B8/RG,R
B8/R
G8/RG
B8/
8通り…少なすぎるな
あ、5!を掛ければ答えじゃね

あってるっぽさそう？
"""

N = int(input())
S = input()

R = 0
G = 0
B = 0
RG = 0
RB = 0
GB = 0

ans = 1
mod = 998244353
for i in range(1,N+1):
    ans *= i
    ans %= mod

for i in range(3*N):

    if S[i] == "R":
        if GB > 0:
            ans *= GB
            GB -= 1
        elif G > 0:
            ans *= G
            G -= 1
            RG += 1
        elif B > 0:
            ans *= B
            B -= 1
            RB += 1
        else:
            R += 1
            
    elif S[i] == "G":
        if RB > 0:
            ans *= RB
            RB -= 1
        elif R > 0:
            ans *= R
            R -= 1
            RG += 1
        elif B > 0:
            ans *= B
            B -= 1
            GB += 1
        else:
            G += 1

    else:
        if RG > 0:
            ans *= RG
            RG -= 1
        elif R > 0:
            ans *= R
            R -= 1
            RB += 1
        elif G > 0:
            ans *= G
            G -= 1
            GB += 1
        else:
            B += 1

    ans %= mod

print (ans)


Measured memory_bytes: 49448
let A = stdin.ReadLine() |> int
let B = stdin.ReadLine() |> int
let C = stdin.ReadLine() |> int
let D = stdin.ReadLine() |> int

let ab x y = 
 if x < y then x
 else y
 
let cd x y =
 if x < y then x
 else y
 
let sum x y =
 x + y

printfn "%d" (sum (ab A B) (cd C D))

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

#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
typedef long long ll;

int n, m, x, a[200];

signed main() {
	cin >> n >> m >> x;
	rep(i,m) cin >> a[i];
	rep(i,m) if (x<a[i]) return cout << min(i,m-i) << endl, 0;
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

void shell_sort(int a[], int n){
  int i, j, h;
  int m = 0;
  int cnt = 0;
  int x[100] ={1};

  if(n < 2){
  printf("1\n1\n0\n");  
  }else{
  for(h = n / 2; h > 0; h /=2, m++){
        x[m] = h;
    for(i = h; i  < n; i++){
      int tmp = a[i];
      for(j = i - h; j >= 0 && a[j] > tmp; j -= h){
        a[j + h] = a[j];
        cnt++;
      }
      a[j + h] = tmp;
    }
  }
  printf("%d\n", m);
  for(i = 0; i < m - 1; i++){
    printf("%d ", x[i]);
  }
  printf("%d\n", x[i]);
  printf("%d\n", cnt);
  }
}

int main(void){
  int n, i;
  int *A;

  scanf("%d", &n);
  A = calloc(n, sizeof(int));

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

  shell_sort(A, n);

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

  free(A);

  return 0;
}



Measured memory_bytes: 5496
N=int(input())
E=[[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c=map(int,input().split())
    E[a].append((b,c))
    E[b].append((a,c))

Q,K=map(int,input().split())
qs=[tuple(map(int,input().split())) for _ in range(Q)]


#DFS
stack=[(K,0)]
dist=[0]*(N+1)
dist[K]=0
while stack:
    n,c=stack.pop()
    for to,cost in E[n]:
        if dist[to]:
            continue
        dist[to]=c+cost
        stack.append((to,c+cost))

for x,y in qs:
    print(dist[x]+dist[y])

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

using namespace std;

int main(){
    int H,W;

    while(cin >> H >> W){
        if(H == 0 && W == 0){
            break;
        }
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
        cout << endl;
        }

        cout << endl;
    }

    return 0;
}


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

int main()
{
  long long n, a, b;
  cin >> n >> a >> b;
  vector<long long> x(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  long long ans = 0;
  for(int i = 0; i < n - 1; i++)
  {
    long long walk = (x[i+1] - x[i]) * a;
    ans += min(walk, b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    map<char, char> dic;
    dic['A'] = 'T'; dic['T'] = 'A';
    dic['C'] = 'G'; dic['G'] = 'C';

    string in; cin >> in;
    for(auto& c : in) c = dic[c];

    cout << in << endl;

    return 0;
}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    int digk = log2(k + 0.1) + 1;
    if(k == 0) digk = 0;
    vector<int> bit_w(digk, 0);
    // これだと x が k を超えちゃう
    for(int i=0; i<digk; i++){
        int bcnt = 0;
        int bit = (1LL<<i);
        for(int j=0; j<n; j++){
            if((a[j] & bit) == 0){
                bcnt++;
            }
        }
        if(bcnt > n-bcnt){
            bit_w[i] = bit * (2*bcnt-n);
        }
    }

    // 半分全探索からの二分探索
    vector<int> sum1((1LL<<digk/2), 0);
    vector<int> sum2((1LL<<(digk-digk/2)), 0);
    vector<pair<int, int>> elim_sum1;
    vector<pair<int, int>> elim_sum2;
    int now_v = -1;
    for(int i=0; i<(1<<digk/2); i++){
        for(int j=0; j<digk/2; j++){
            if(i & (1LL<<j)){
                sum1[i] += bit_w[j];
            }
        }
        if(now_v < sum1[i]){
            now_v = sum1[i];
            elim_sum1.push_back(make_pair(i, sum1[i]));
        }
    }
    now_v = -1;
    for(int i=0; i<(1<<(digk-digk/2)); i++){
        for(int j=0; j<digk-digk/2; j++){
            if(i & (1LL<<j)){
                sum2[i] += bit_w[j+digk/2];
            }
        }
        // 荷物が重くなってるのに価値が上がってないような候補はあほなので除いておきたい
        if(now_v < sum2[i]){
            now_v = sum2[i];
            elim_sum2.push_back(make_pair((i<<digk/2), sum2[i]));
        }
    }

    int maxv = 0, maxw = 0;
    for(int i=0; i<elim_sum1.size(); i++){
        int ok_weight = k - elim_sum1[i].first;
        pair<int, int> p = make_pair(ok_weight+1, 0);
        auto itr = lower_bound(elim_sum2.begin(), elim_sum2.end(), p);
        int idx = distance(elim_sum2.begin(), itr);
        if(idx > 0){
            idx--;
            int val = elim_sum1[i].second + elim_sum2[idx].second;
            if(maxv < val){
                maxv = val;
                maxw = elim_sum1[i].first + elim_sum2[idx].first;
            }
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        ans += maxw ^ a[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 37524
#include <iostream>
using namespace std;
int main() {
    int n, x;
    while(true){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        int count = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                for(int k = 1; k <= n; k++){
                    if(i + j + k == x){
                        if(i == j || i == k || j == k){
                            continue;
                        }
                        else{
                            count++;
                        }
                    }
                }
            }
        }
        cout << count/6 << endl;
    }
    return 0;
}




Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
ll ans=0;
vec(vis,9);
vector<pair<ll,ll>> a(30);
mat(gra,30,30);

void dfs(ll d,ll now,ll ma){
    if(d==ma){
        ans++;
        //cout<<endl;
        return;
    }
    for(int i=1;i<=ma;i++){
        if(gra[now][i]>0&&vis[i]==0){
            vis[i]=1;
            //op(i);
            dfs(d+1,i,ma);
            vis[i]=0;
        }
    }
    return ;
    
}

int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        cin>>a[i].first>>a[i].second;
        gra[a[i].first][a[i].second]++;
        gra[a[i].second][a[i].first]++;
    }
    vis[1]=1;
    dfs(1,1,n);
    op(ans);
    return 0;
}

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

string s;

void Input(){
	cin>>s;
}

void Solve(){
	int a=0;
	for(int i=0; i<s.length(); i++){
		int b=s[i]-'0';
		a+=b;
	}
	if(a%9==0){
		cout<<"Yes"<<'\n';
	}else{
		cout<<"No"<<'\n';
	}
}

int main(){
	Input();
	Solve();
}

Measured memory_bytes: 3724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    
    ll N,X[110],MIN=2000000000;
    cin>>N;
    rep(i,0,N)cin>>X[i];
    ll cnt=0;
    rep(i,0,101){
        cnt=0;
        rep(j,0,N){
            cnt+=pow((X[j]-i),2);
        }
        MIN=min(MIN,cnt);
    }
    cout<<MIN<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A[100];
  int number,key,i,j,k;
  
  scanf("%d", &number);
  for( i=0 ; i<number ; i++){
    scanf("%d", &A[i]);
  }
  for( i=0 ; i<number ; i++){
    key = A[i];
    j = i-1;
    while( j>=0 && A[j]>key ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for( k=0 ; k<number ; k++ ){
      printf("%d", A[k]);
      if( k == number-1 ){
	printf("\n");
	break;
      }  
      printf(" ");
    }
  } 
  return 0;
}

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

const int MAXV = 201010;
vector<int> G[MAXV];
int V;
int color[MAXV];
bool makeBipartiteGraph(int v, int c) {
    color[v] = c;
    for (int u : G[v]) {
        if (color[u] == c) return false;
        if (color[u] == 0 and !makeBipartiteGraph(u, -c)) return false;
    }
    return true;
}

void solve() {
    cin >> V;
    rep(i, V-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    makeBipartiteGraph(0, 1);

    int b = 0, w = 0;
    rep(i, V) {
        if (color[i] == 1) b++;
        else w++;
    }

    int N = V;

    vector<int> ans(N, 0);
    vector<int> p1, p2, p0;
    rep(i, N) {
        if ((i+1)%3 == 0) p0.push_back(i+1);
        else if ((i+1)%3 == 1) p1.push_back(i+1);
        else p2.push_back(i+1);
    }
    int cur1 = 0, cur2 = 0, cur0 = 0;

    if (b <= N/3 or w <= N/3) {
        int tmp = (b <= N/3 ? 1 : -1);
        rep(i, N) {
            if (color[i] == tmp) ans[i] = p0[cur0++];
        }
        rep(i, N) {
            if (ans[i] == 0) {
                if (cur0 < p0.size()) ans[i] = p0[cur0++];
                else if (cur1 < p1.size()) ans[i] = p1[cur1++];
                else ans[i] = p2[cur2++];
            }
        }
    }
    else {
        rep(i, N) {
            if (color[i] == 1) {
                if (cur1 < p1.size()) ans[i] = p1[cur1++];
                else ans[i] = p0[cur0++];
            }
        }
        rep(i, N) {
            if (ans[i] == 0) {
                if (cur0 < p0.size()) ans[i] = p0[cur0++];
                else ans[i] = p2[cur2++];
            }
        }
    }

    rep(i, N) cout << ans[i] << " ";
    cout << endl;

}

int main() {
    solve();
}


Measured memory_bytes: 19832
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll A = 0, B =0, C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    //本文
    ll ans2 = max(X,Y)*2*C;
    if(A+B<C*2){
      cout << A*X + B *Y; return 0;
    }
    else{
      ll count = min(X,Y);
      ll ans = min(count*2*C + A*(X-count) + B*(Y-count),ans2);
        cout << ans;
      return 0;
    }
    //出力
    //cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include <sstream>

using namespace std;

int main(void)

{
    string s1, s2, s3, s4;
    int i, a, b;
    cin>>s1>>s2;
    stringstream geek(s1);
    geek >> a;
    stringstream geeks(s2);
    geeks >> b;
    for(i = 0; i < b; i++)
        s3 += s1;
    for(i = 0; i < a; i++)
        s4 += s2;
    if(s3<s4)
        cout<<s3<<"\n";
    else
        cout<<s4<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,n,m,k,l,sum,flag=0,cnt=0,minn,maxn,ans,ans1,ans2,p=0,q=0,r;
    string s;
    char ch;
    cin>>n;
    m=n/500;
    l=n%500;
    sum=l/5;
    ans=1000*m+5*sum;
    cout<<ans<<endl;


}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int a,b,c;cin>>a>>b>>c;
  cout << max(0,c-(a-b)) << endl;
}

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

int main() {
  int n, a[4][13] = {0};                                                                                                                                      
  map<char, int> m;
  char c[4];
  m['S'] = 0; m['H'] = 1; m['C'] = 2; m['D'] = 3;
  c[0] = 'S'; c[1] = 'H'; c[2] = 'C'; c[3] = 'D';                                                                                                             
  cin >> n;
  for (int i = 0; i < n; i++) {
    char suit; int rank;
    cin >> suit >> rank;
    a[m[suit]][rank-1] = 1;                                                                                                                                   
  }
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 13; j++)
      if (a[i][j] == 0) {
        cout << c[i] << ' ' << j + 1;
        cout << endl;
      }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main()
{
int n, k, dp[100005],tab[100005];
long double xd[100000];
bool vis[100005];
cin>>n>>k;
for(int i=1; i<=n; i++){
  cin>>tab[i];
}

dp[1]=0;


for(int i=2; i<=n; i++){
  for(int j=1; j<=k; j++){
    if(j>=i){
      break;
    }
  int a=tab[i]-tab[i-j];
  if(a<0)a*=-1;
  if(vis[i]){
    dp[i]=min(dp[i],dp[i-j]+a);
  }else{
    vis[i]=true;
    dp[i]=dp[i-j]+a;
  }
}
}

cout<<dp[n];


  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include<algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include<map>
#include<set>
#include<sstream>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;

int main()
{
    ll n,a,b;cin>>n>>a>>b;
    if(a==0&&b==0) cout<<0<<endl;
    else{
    ll c=n%(a+b);
    ll t=n/(a+b);
    if(c<=a){
        cout<<t*a+c<<endl;
    }
    else cout<<(t+1)*a<<endl;}
}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  ll n, m; 
  cin >> n >> m;

  vector<ll> coordinates(m); 
  rep(i, m) {
      cin >> coordinates[i];
  }
  if (n >= m) 
  {
      cout << 0 << endl;
      return 0;
  }
  
  sort(coordinates.begin(), coordinates.end());
  // debug
//   rep(i, m) {
//       cout << coordinates[i] << endl;
//   }
  
  vector<ll> distance(m-1); ll max_dist = 0;
  rep(i, m-1) {
      distance[i] = abs(coordinates[i] - coordinates[i+1]);
  }
  sort(distance.begin(), distance.end(), greater<ll>());

  ll sum = 0;
  rep(i, m-1) {
      if (i < n-1)
      {
          /* code */
          continue;
      }
      sum += distance[i];
  }
  cout << sum << endl;

  // debug
//   rep(i, m-1) {
//       cout << distance[i] << endl;
//   }
  return 0;
}

Measured memory_bytes: 1792
import math


A, B, H, M = map(int, input().split())

# 時針の12時からの角度
x = 360 * (H * 60 + M) / (12 * 60)
# 分針の12時からの角度
y = 360 * M / 60

radians = math.radians(abs(x - y))
# 余弦定理
answer = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(radians))
print(answer)          

Measured memory_bytes: 9392
import itertools

N, K = map(int, input().split()) # Nは建物の数、K色以上に塗る
A = list(map(int, input().split()))
N_index = list(range(1,N))

min_cost = float('inf')
for target_indexes in itertools.combinations(N_index, K-1): # N_indexからK個選ぶ方法を全通り試す
    cost = 0
    copy_A = A.copy()
    for i in range(1, N):
        if i in target_indexes:
            if copy_A[i] <= max(copy_A[:i]):
                diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする
                copy_A[i] += diff + 1
                cost += diff + 1

    min_cost = min(min_cost, cost)

print(min_cost)


Measured memory_bytes: 9192
#include <stdio.h>
#include <inttypes.h>

int N;
uint64_t A[114514];
uint64_t B[114514];

int main(void) {
	int i;
	uint64_t ayaseharuka = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu64 "%" SCNu64, &A[i], &B[i]) != 2) return 1;
	}
	for (i = N - 1; i >= 0; i--) {
		uint64_t kurokimeisa = A[i] + ayaseharuka;
		uint64_t aragakiyui = kurokimeisa % B[i] == 0 ? 0 : B[i] - (kurokimeisa % B[i]);
		ayaseharuka += aragakiyui;
	}
	printf("%" PRIu64 "\n", ayaseharuka);
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h> 
#include <ctype.h> 
#include <stdlib.h>
int main() {
int e[101][101];
int R, C, r, c;
int s, total;
scanf("%d%d", &R, &C);
for (r = 1; r <= R; r++) {
for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
}
for (r = 1; r <= R; r++) {
s = 0;
for (c = 1; c <= C; c++) s += e[r][c];
e[r][0] = s;
}
total = 0;
for (c = 1; c <= C; c++) {
s = 0;
for (r = 1; r <= R; r++) s += e[r][c];
e[0][c] = s;
total += s;
}
for (r = 1; r <= R; r++) {
for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
printf("%d\n", e[r][0]);
}
for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
printf("%d\n", total);
return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXN = 41;
int dp[MAXN][MAXN];
bool koji[MAXN][MAXN];

int a, b, n;

int solve(int x, int y)
{
    if(dp[x][y] != -1) return dp[x][y];

    if(koji[x][y]) return 0;
    int ans = 0;
    if(x != 0) ans += solve(x-1, y);
    if(y != 0) ans += solve(x, y-1);

    dp[x][y] = ans;
    return ans;
}

int main()
{
    while(cin >> a >> b && a)
    {
        int x, y;
        memset(koji, false, sizeof(koji));
        memset(dp, -1, sizeof(dp));
        //rep(i,MAXN)rep(j,MAXN)dp[i][j] = -1;

        cin >> n;
        REP(n){ cin >> x >> y; x--;y--; koji[x][y] = true;}

        dp[0][0] = 1;
        cout << solve(a-1, b-1) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {
    
    int input_s,h,m,s;
    scanf("%d",&input_s);
    h=input_s/3600;
    m=(input_s-3600*h)/60;
    s=input_s-3600*h-60*m;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long n = sc.nextLong();

			long tmp = 0;
			for (long i = 0; i * i <= n; i++) {
				tmp = i * i;
			}
			System.out.println(tmp);
		}
	}
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), K = input();
    string S = input<string>();
    
    auto cnt = [](string s, int k, char c) {
        range(i, 0, s.size()) {
            if (s[i] == c) continue;
            s[i] = c;
            if (i + 1 < s.size() && s[i + 1] == c) k--;
            if (!k) break;
        }

        int res = 0;
        range(i, 1, s.size()) res += s[i - 1] == s[i];
        
        return res;
    };
    
    int ans = max(cnt(S, K, 'R'), cnt(S, K, 'L'));
    whole(reverse, S);
    chmax(ans, cnt(S, K, 'L'));
    chmax(ans, cnt(S, K, 'R'));
    
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

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

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end(), greater<>());
    int64_t x = 1;
    double res = 0;
    for(int i=0; i<n-1; i++){
        x *= 2;
        res += v.at(i) / x;
    }
    res += v.at(n-1) / x;
    cout << fixed << setprecision(6);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
   int a, b, ans1, ans2;
   cin >> a >> b;
   ans1=a*b;
   ans2=2*a+2*b;
   cout << ans1 << " " << ans2 << endl; 
   
   return 0;
}


Measured memory_bytes: 3056
from itertools import permutations

def dist(xy1, xy2):
  return ((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2)**.5

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
li = list(permutations(range(N)))
lenli = len(li)

distSum = 0
for line in li:
  for i in range(N-1):
    distSum += dist(XY[line[i]], XY[line[i+1]])
  
print(distSum / lenli)

Measured memory_bytes: 10100
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  llong A,B,K;
  llong comp = 0;
  cin >> A >> B >> K;
  cout << max(A-K, comp) << " " << max(B-max(K-A, comp), comp) << endl;
}

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

int main()
{
    long long n,a,b;
    std::cin >> n >> a >> b;
    std::vector<long long> x(n);
    for(long long i = 0; i < n; i++)std::cin >> x[i];
    long long cur = x[0];
    long long res = 0;
    for(long long i = 0; i < n; i++){
        if((x[i] - cur) * a < b){
            res += (x[i] - cur) * a;
            cur = x[i];
        }else{
            cur = x[i];
            res += b;
        }
    }
    std::cout << res << std::endl;
}


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

int gcd(int a, int b){
  if(a<b){
    int tmp=b;
    b=a;
    a=tmp;
  }
  while(a%b!=0){
    int tmp=b;
    b=a%b;
    a=tmp;
  }
  return b;
}

int main(){
  int k;cin>>k;
  ll cnt=0;
  for(int a=1;a<=k;++a){
    for(int b=1;b<=k;++b){
      for(int c=1;c<=k;++c){
        cnt+=gcd(a ,gcd(b,c));
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

string w;
string s;

int main() {
	cin >> w;
	for(char c: w){
		if(c == 'B'){
			if(!s.empty()){
				s.pop_back();
			}
		}
		else{
			s.push_back(c);
		}
	}
	cout << s << endl;
	return 0;
}

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

int main(){
  string s;
  int K;
  cin >> s >> K;
  
  vector<string> vec;
  
  for(int i=0;i<s.size();i++) for(int j=1;j<K+1;j++) vec.push_back(s.substr(i,j));
  
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  cout << vec[K-1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int n;
vector<int> graph[100100];
bool visited[100100];
map<ll,int> painted;
int maxd = 0;
 
void dfs( int target, int color ){
	visited[target] = true;
	int cnt = 0;
	for( auto node : graph[target] ){
		if( !visited[node] ){
			++cnt;
			ll x = target, y = node;
			if( x > y ) swap(x, y);
			painted[100000*y+x] = (color+cnt)%maxd;
			dfs(node, (color+cnt)%maxd);
		}
	}
}
 
int main(){
	cin >> n;
	vector<ll> candy;
	for( int i = 0; i < n-1; ++i ){
		ll x, y; cin >> x >> y;
		--x; --y;
		graph[x].push_back(y);
		graph[y].push_back(x);
		if( x > y ) swap(x, y);
		candy.push_back(100000*y+x);
	}
	for( auto g : graph ){
		maxd = max(maxd, (int)g.size());
	}
	dfs(0, -1);
	cout << maxd << endl;
	for( auto node : candy ){
		cout << painted[node]+1 << endl;
	}
}

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

int main(void)
{
  int N,K;
  int result = 0;
  cin >> N >> K;
  vector<int> vec(N); // N個の英語の点数データ
 
  // 数学の点数データを受け取る
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  for(int i = 0; i < K; i++){
    result += vec.at(i);
  }
  cout << result << endl; 
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int N;
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    int sum = 0;
    while (N) {
        sum += N % 10;
        N /= 10;
    }
    cout << (sum == 1 ? 10 : sum);
}

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


int main() {

  int n,x;
  cin>>n>>x;

  int m_sum=0,m_min=1001;
  for(int i=0;i<n;i++){
    int wk;
    cin>>wk;

    m_sum+=wk;
    m_min=min(m_min,wk);
  }

  cout<<n+(x-m_sum)/m_min<<endl;

  return 0;
}



Measured memory_bytes: 256
//
// Created by Naman Bhalla on 2019-08-18.
//

#include <bits/stdc++.h>

using namespace std;

int a[1001];

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


    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    long double denom = 0;
    
    for(int i = 1; i <= n; ++i){
        denom += (long double) 1 / a[i];
    }
    
    cout << fixed << setprecision(12) << 1 / denom << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int d(int  n){
	if(!n) return 1;
	else return n%10+d(n/10);
}
int f(char c){
	return c-'0';
}
int32_t main(){
	int n;cin>>n;n++;
	string s = to_string(n);
	int ans = 9*(s.length()-1);
	ans += max(0LL,f(s[0])-1);
	cout<<ans;
}


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

#define ll long long

struct edge
{
    int to;
    ll cost;
};

vector<edge> G[100010];
bool visited[100010];
int d[100010];

bool dfs(int v, int dist)
{
    if (visited[v])
    {
        if (d[v] != dist)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    visited[v] = true;
    d[v] = dist;

    for (auto e : G[v])
    {
        if (dfs(e.to, dist + e.cost))
        {
            return true;
        }
    }
    return false;
}

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

    for (int i = 0; i < M; i++)
    {
        int L, R, D;
        cin >> L >> R >> D;
        L--;
        R--;
        G[L].push_back({R, D});
        G[R].push_back({L, -D});
    }

    for (int i = 0; i < N; i++)
    {
        if (!visited[i] && dfs(i, 0))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 15232